本文整理汇总了C#中IJsonSerializer.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# IJsonSerializer.Serialize方法的具体用法?C# IJsonSerializer.Serialize怎么用?C# IJsonSerializer.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJsonSerializer
的用法示例。
在下文中一共展示了IJsonSerializer.Serialize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostUserDescription
public SubmissionResponse PostUserDescription(string referenceId, UserDescription description, ExceptionlessConfiguration config, IJsonSerializer serializer) {
if (!config.IsValid)
return new SubmissionResponse(500, message: "Invalid client configuration settings.");
string data = serializer.Serialize(description);
string url = String.Format("{0}/events/by-ref/{1}/user-description", GetServiceEndPoint(config), referenceId);
HttpResponseMessage response;
try {
HttpContent content = new StringContent(data, Encoding.UTF8, "application/json");
// don't compress data smaller than 4kb
if (data.Length > 1024 * 4)
content = new GzipContent(content);
_client.Value.AddAuthorizationHeader(config.ApiKey);
response = _client.Value.PostAsync(url, content).ConfigureAwait(false).GetAwaiter().GetResult();
} catch (Exception ex) {
return new SubmissionResponse(500, message: ex.Message);
}
int settingsVersion;
if (Int32.TryParse(GetSettingsVersionHeader(response.Headers), out settingsVersion))
SettingsManager.CheckVersion(settingsVersion, config);
return new SubmissionResponse((int)response.StatusCode, GetResponseMessage(response));
}
示例2: BuildAssignments
static void BuildAssignments(JavaScriptObject dictionary, StringBuilder builder, IJsonSerializer jsonSerializer)
{
foreach (var pair in dictionary)
{
var value = jsonSerializer.Serialize(pair.Value);
builder.AppendFormat("d.{0}={1};", pair.Key, value).AppendLine();
}
}
示例3: PostEvents
public SubmissionResponse PostEvents(IEnumerable<Event> events, ExceptionlessConfiguration config, IJsonSerializer serializer) {
foreach (Event e in events) {
string data = serializer.Serialize(e);
string referenceId = !string.IsNullOrWhiteSpace(e.ReferenceId) ? e.ReferenceId : Guid.NewGuid().ToString("D");
_eventContainer[referenceId] = data;
}
return new SubmissionResponse(200);
}
示例4: Create
public static PublishCommandJob Create(
ICommand command,
ICommandDefinitionService commandDefinitionService,
IJsonSerializer jsonSerializer)
{
var data = jsonSerializer.Serialize(command);
var commandDefinition = commandDefinitionService.GetDefinition(command.GetType());
return new PublishCommandJob(
data,
commandDefinition.Name,
commandDefinition.Version);
}
示例5: PostUserDescription
public SubmissionResponse PostUserDescription(string referenceId, UserDescription description, ExceptionlessConfiguration config, IJsonSerializer serializer) {
var data = serializer.Serialize(description);
HttpWebResponse response;
try {
var request = CreateHttpWebRequest(config, String.Format("events/by-ref/{0}/user-description", referenceId));
response = request.PostJsonAsyncWithCompression(data).Result as HttpWebResponse;
} catch (AggregateException aex) {
var ex = aex.GetInnermostException() as WebException;
if (ex != null)
response = (HttpWebResponse)ex.Response;
else
return new SubmissionResponse(500, message: aex.GetMessage());
} catch (Exception ex) {
return new SubmissionResponse(500, message: ex.Message);
}
return new SubmissionResponse((int)response.StatusCode, response.IsSuccessful() ? null : response.GetResponseText());
}
示例6: PostUserDescription
public SubmissionResponse PostUserDescription(string referenceId, UserDescription description, ExceptionlessConfiguration config, IJsonSerializer serializer) {
var data = serializer.Serialize(description);
HttpWebResponse response;
try {
var request = CreateHttpWebRequest(config, String.Format("events/by-ref/{0}/user-description", referenceId));
response = request.PostJsonAsyncWithCompression(data).Result as HttpWebResponse;
} catch (AggregateException aex) {
var ex = aex.GetInnermostException() as WebException;
if (ex != null)
response = (HttpWebResponse)ex.Response;
else
return new SubmissionResponse(500, message: aex.GetMessage());
} catch (Exception ex) {
return new SubmissionResponse(500, message: ex.Message);
}
int settingsVersion;
if (Int32.TryParse(response.Headers[ExceptionlessHeaders.ConfigurationVersion], out settingsVersion))
SettingsManager.CheckVersion(settingsVersion, config);
return new SubmissionResponse((int)response.StatusCode, GetResponseMessage(response));
}
示例7: PostEvents
public SubmissionResponse PostEvents(IEnumerable<Event> events, ExceptionlessConfiguration config, IJsonSerializer serializer) {
var data = serializer.Serialize(events);
HttpWebResponse response;
try {
var request = CreateHttpWebRequest(config, "events");
response = request.PostJsonAsyncWithCompression(data).Result as HttpWebResponse;
} catch (AggregateException aex) {
var ex = aex.GetInnermostException() as WebException;
if (ex != null)
response = (HttpWebResponse)ex.Response;
else
return new SubmissionResponse(500, message: aex.GetMessage());
} catch (Exception ex) {
return new SubmissionResponse(500, message: ex.Message);
}
int settingsVersion;
if (Int32.TryParse(response.Headers[ExceptionlessHeaders.ConfigurationVersion], out settingsVersion))
SettingsManager.CheckVersion(settingsVersion, config);
return new SubmissionResponse((int)response.StatusCode, GetResponseMessage(response));
}
示例8: SetRemoteException
/// <summary>
/// 设置远程异常
/// </summary>
/// <param name="serializer">序列化工具</param>
/// <param name="exceptionContext">上下文</param>
/// <returns></returns>
public static bool SetRemoteException(IJsonSerializer serializer, ExceptionContext exceptionContext)
{
try
{
var packet = exceptionContext.Packet;
packet.state = false;
packet.body = exceptionContext.Exception.Message;
var packetJson = serializer.Serialize(packet);
exceptionContext.Session.SendText(packetJson);
return true;
}
catch (Exception)
{
return false;
}
}
示例9: PostUserDescription
public SubmissionResponse PostUserDescription(string referenceId, UserDescription description, ExceptionlessConfiguration config, IJsonSerializer serializer) {
string data = serializer.Serialize(description);
_userDescriptionContainer[referenceId] = data;
return new SubmissionResponse(200);
}
示例10: WriteProject
private static void WriteProject(XProject project, ZipArchiveEntry projectEntry, IFileSystem fileIO, IJsonSerializer serializer)
{
using (var jsonStream = projectEntry.Open())
{
fileIO.WriteUtf8Text(jsonStream, serializer.Serialize(project));
}
}