当前位置: 首页>>代码示例>>C#>>正文


C# IJsonSerializer.Serialize方法代码示例

本文整理汇总了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));
        }
开发者ID:InlineAsm,项目名称:Exceptionless.Net,代码行数:27,代码来源:DefaultSubmissionClient.cs

示例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();
     }
 }
开发者ID:prabirshrestha,项目名称:cassette,代码行数:8,代码来源:PageDataScriptBundle.cs

示例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);
        }
开发者ID:InlineAsm,项目名称:Exceptionless.Net,代码行数:9,代码来源:InMemorySubmissionClient.cs

示例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);
        }
开发者ID:joaomajesus,项目名称:EventFlow,代码行数:13,代码来源:PublishCommandJob.cs

示例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());
        }
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:19,代码来源:SubmissionClient.cs

示例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));
        }
开发者ID:mgnslndh,项目名称:Exceptionless.Net,代码行数:23,代码来源:SubmissionClient.cs

示例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));
        }
开发者ID:mgnslndh,项目名称:Exceptionless.Net,代码行数:23,代码来源:SubmissionClient.cs

示例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;
            }
        }
开发者ID:brucezhang80,项目名称:NetworkSocket,代码行数:23,代码来源:FastWebSocketCommon.cs

示例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);
 }
开发者ID:InlineAsm,项目名称:Exceptionless.Net,代码行数:5,代码来源:InMemorySubmissionClient.cs

示例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));
     }
 }
开发者ID:Core2D,项目名称:Core2D,代码行数:7,代码来源:XProject.IO.cs


注:本文中的IJsonSerializer.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。