• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IFormatterLogger类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IFormatterLogger的典型用法代码示例。如果您正苦于以下问题:C# IFormatterLogger类的具体用法?C# IFormatterLogger怎么用?C# IFormatterLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IFormatterLogger类属于命名空间,在下文中一共展示了IFormatterLogger类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DeSerialize

        private object DeSerialize(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
        {
            HttpContentHeaders contentHeaders = content == null ? null : content.Headers;

            // If content length is 0 then return default value for this type
            if (contentHeaders != null && contentHeaders.ContentLength == 0)
            {
                return GetDefaultValueForType(type);
            }

            // Get the character encoding for the content
            Encoding effectiveEncoding = SelectCharacterEncoding(contentHeaders);

            try
            {
                using (var reader = new StreamReader(readStream, effectiveEncoding, false, 512, true))
                {
                    var deserialize = TypedDeserializers.GetTyped(type);
                    return deserialize(reader, _jilOptions);
                }
            }
            catch (Exception e)
            {
                if (formatterLogger == null)
                {
                    throw;
                }
                formatterLogger.LogError(String.Empty, e);
                return GetDefaultValueForType(type);
            }
        }
开发者ID:charla-n,项目名称:ManahostManager,代码行数:31,代码来源:JilFormatter.cs


示例2: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            return Task.Factory.StartNew(() =>
            {
                MemoryStream stream = new MemoryStream();
                readStream.CopyTo(stream);

                IEnumerable<string> xContentHeader;
                var success = content.Headers.TryGetValues("X-Content-Type", out xContentHeader);

                if (!success)
                {
                    throw Error.BadRequest("POST to binary must provide a Content-Type header");
                }

                string contentType = xContentHeader.FirstOrDefault();

                Binary binary = new Binary();
                binary.Content = stream.ToArray();
                binary.ContentType = contentType;

                //ResourceEntry entry = ResourceEntry.Create(binary);
                //entry.Tags = content.Headers.GetFhirTags();
                return (object)binary;
            });
        }
开发者ID:Condeti,项目名称:spark,代码行数:26,代码来源:BinaryFormatter.cs


示例3: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
        {
            var task = Task<object>.Factory.StartNew(() =>
            {
                var ser = JsonNetExtensions.GetJsonSerializer();

                using (var sr = new StreamReader(readStream))
                {
                    using (var jreader = new JsonTextReader(sr))
                    {
                        ser.Converters.Add(new IsoDateTimeConverter());
                        return ser.Deserialize(jreader, type);
                    }
                }
                /*
                var sr = new StreamReader(stream);
                var jreader = new JsonTextReader(sr);

                var ser = new JsonSerializer();
                ser.Converters.Add(new IsoDateTimeConverter());

                object val = ser.Deserialize(jreader, type);
                return val;*/
            });

            return task;
        }
开发者ID:pbdesk,项目名称:PBDesk.WebUtils,代码行数:27,代码来源:JsonNetMediaTypeFormatter.cs


示例4: ReadFromStreamAsync

 public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
 {
     return Task.Factory.StartNew(() =>
     {
         return (object)null;
     });
 }
开发者ID:Condeti,项目名称:spark,代码行数:7,代码来源:ResourceJsonFormatter.cs


示例5: ReadFromStreamAsync

        /// <inheritdoc />
        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            if (type == null)
            {
                throw Error.ArgumentNull("type");
            }

            if (readStream == null)
            {
                throw Error.ArgumentNull("readStream");
            }

            if (type == typeof(DBNull) && content != null && content.Headers != null && content.Headers.ContentLength == 0)
            {
                // Lower-level Json.Net deserialization can convert null to DBNull.Value. However this formatter treats
                // DBNull.Value like null and serializes no content. Json.Net code won't be invoked at all (for read or
                // write). Override BaseJsonMediaTypeFormatter.ReadFromStream()'s call to GetDefaultValueForType()
                // (which would return null in this case) and instead return expected DBNull.Value. Special case exists
                // primarily for parity with JsonMediaTypeFormatter.
                return Task.FromResult((object)DBNull.Value);
            }
            else
            {
                return base.ReadFromStreamAsync(type, readStream, content, formatterLogger);
            }
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:27,代码来源:BsonMediaTypeFormatter.cs


示例6: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger)
        {
            var tcs = new TaskCompletionSource<object>();
            if (content.Headers != null && content.Headers.ContentLength == 0) return null;
            try
            {
                var serializer = MessagePackSerializer.Get(type, sContext);
                object result;

                using (var unpacker = Unpacker.Create(stream))
                {
                    unpacker.Read();
                    result = serializer.UnpackFrom(unpacker);
                }
                tcs.SetResult(result);
            }
            catch (Exception e)
            {
                if (formatterLogger == null) throw;
                formatterLogger.LogError(String.Empty, e.Message);
                tcs.SetResult(GetDefaultValueForType(type));
            }

            return tcs.Task;
        }
开发者ID:charla-n,项目名称:ManahostManager,代码行数:25,代码来源:MsgPackFormatter.cs


示例7: ReadFromStreamAsync

 public override async Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
 {
     MultipartMemoryStreamProvider multipartMemoryStreamProvider = await content.ReadAsMultipartAsync();
     Collection<HttpContent> contents = multipartMemoryStreamProvider.Contents;
     ImageSet imageSet = await contents.FirstOrDefault<HttpContent>((HttpContent c) => c.Headers.ContentDisposition.Name.NormalizeName() == "imageset").ReadAsAsync<ImageSet>();
     ImageSet images = imageSet;
     Collection<HttpContent> httpContents = multipartMemoryStreamProvider.Contents;
     List<HttpContent> list = (
         from c in httpContents
         where c.Headers.ContentDisposition.Name.NormalizeName().Matches("image\\d+")
         select c).ToList<HttpContent>();
     images.Images = new List<Image>();
     foreach (HttpContent httpContent in list)
     {
         List<Image> images1 = images.Images;
         Image image = new Image();
         Image image1 = image;
         image1.ImageData = await httpContent.ReadAsByteArrayAsync();
         image.MimeType = httpContent.Headers.ContentType.MediaType;
         image.FileName = httpContent.Headers.ContentDisposition.FileName.NormalizeName();
         images1.Add(image);
         images1 = null;
         image1 = null;
         image = null;
     }
     return images;
 }
开发者ID:vmfdesign,项目名称:Portal,代码行数:27,代码来源:ImageSetMediaTypeFormatter.cs


示例8: ReadFromStreamAsync

        public async override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {

            if (!content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var Parts = await content.ReadAsMultipartAsync();
            var FileContent = Parts.Contents.First(x =>
                SupportedMediaTypes.Contains(x.Headers.ContentType));

            var DataString = "";
            foreach (var Part in Parts.Contents.Where(x => x.Headers.ContentDisposition.DispositionType == "form-data"
                                                        && x.Headers.ContentDisposition.Name == "\"data\""))
            {
                var Data = await Part.ReadAsStringAsync();
                DataString = Data;
            }

            string FileName = FileContent.Headers.ContentDisposition.FileName;
            string MediaType = FileContent.Headers.ContentType.MediaType;

            using (var Imgstream = await FileContent.ReadAsStreamAsync())
            {
                return new GenericContent { ContentType = MediaType, Body = ReadToEnd(Imgstream) };
            }
        }
开发者ID:keithb-,项目名称:Valley,代码行数:28,代码来源:GenericMediaTypeFormatter.cs


示例9: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger logger)
        {
            var trades = new Trades();
            var symbol = _symbol;

            using (var reader = new StreamReader(stream))
            {
                var line = reader.ReadLine();
                var seperator = ",".ToCharArray();

                while (null != (line = reader.ReadLine()))
                {
                    if (!line.Contains("502 Bad Gateway"))
                    {
                        var parts = line.Split(seperator);

                        var unixtime = parts[0].Parse();
                        var price = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
                        var quantity = decimal.Parse(parts[2], CultureInfo.InvariantCulture);

                        var datetime = Epoch.AddSeconds(unixtime);

                        trades.Add(symbol, datetime, price, quantity);
                    }
                    else throw new Exception("Bad Gateway");
                }
            }

            var tcs = new TaskCompletionSource<object>();
            tcs.SetResult(trades);
            return tcs.Task;
        }
开发者ID:erdincay,项目名称:CoinTNet,代码行数:32,代码来源:TradeMediaTypeFormatter.cs


示例10: ReadFromStreamArgs

 public ReadFromStreamArgs(Type type, Stream stream, HttpContent content, IFormatterLogger logger)
 {
     Type = type;
     Stream = stream;
     Content = content;
     Logger = logger;
 }
开发者ID:scriptcs-contrib,项目名称:scriptcs-webapi,代码行数:7,代码来源:ReadFromStreamArgs.cs


示例11: ReadFromStream

        public override object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) {

            HttpContentHeaders contentHeaders = content == null ? null : content.Headers;

            // If content length is 0 then return default value for this type
            if (contentHeaders != null && contentHeaders.ContentLength == null) {

                return GetDefaultValueForType(type);
            }

            try {
                using (readStream) {
                    using (var reader = XmlReader.Create(readStream)) {

                        var formatter = new Atom10ItemFormatter();
                        formatter.ReadFrom(reader);

                        var command = Activator.CreateInstance(type);
                        ((IPublicationCommand)command).ReadSyndicationItem(formatter.Item);

                        return command;
                    }
                }
            }
            catch (Exception e) {

                if (formatterLogger == null) {
                    throw;
                }
                formatterLogger.LogError(String.Empty, e);
                return GetDefaultValueForType(type);
            }
        }
开发者ID:mahf,项目名称:ASPNETWebAPISamples,代码行数:33,代码来源:AtomPubMediaFormatter.cs


示例12: ReadFromStreamAsync

    //private readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    //public XmlFormatter()
    //{
    //  SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml"));
    //  SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml"));
    //}

    public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger)
    {
      var task = new TaskCompletionSource<object>();
      var serializer = new XmlSerializer(type);

      using (var ms = new MemoryStream())
      {
        readStream.CopyTo(ms);

        //ms.Seek(0, SeekOrigin.Begin);

        //Log.IfDebugFormat("Content Length: {0}", ms.Length);
        //Log.IfDebugFormat("Content: {0}", new StreamReader(ms).ReadToEnd());

        //var result = XmlSchemaValidator.Instance().Validate(ms, type);

        //if (!string.IsNullOrWhiteSpace(result))
        //task.SetResult(result);
        //else
        {
          ms.Seek(0, SeekOrigin.Begin);
          var obj = serializer.Deserialize(ms);
          task.SetResult(obj);
        }
      }
      return task.Task;
    }
开发者ID:shanmukhig,项目名称:tms,代码行数:35,代码来源:XmlFormatter.cs


示例13: ReadFromStreamAsync

        public async override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger)
        {
            try
            {
                if (!content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                var provider = await content.ReadAsMultipartAsync();

                var mediacontent = provider.Contents.First(x =>
                    SupportedMediaTypes.Contains(x.Headers.ContentType));

                string fileName = mediacontent.Headers.ContentDisposition.FileName;

                string mediaType = mediacontent.Headers.ContentType.MediaType;

                var imagebuffer = await mediacontent.ReadAsByteArrayAsync();

                return new ImageMediaModels(fileName, mediaType, imagebuffer);
            }
            catch (Exception Ex)
            {
                string Err = "Unable to upload the image ";
                Log.LogError("{0}, Error: {1}", Err, Ex.Message);
                throw;
            }
                   
        }
开发者ID:MicrosoftDX,项目名称:AzureLens,代码行数:30,代码来源:ImageMediaModels.cs


示例14: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, System.IO.Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            return Task<object>.Factory.StartNew(() =>
            {
                var reader = new StreamReader(readStream);
                var text = reader.ReadToEnd();

                var regex = new Regex("<wav>[a-zA-Z0-9]*.wav</wav>");
                var wavLink = regex.Match(text).Value.Replace("<wav>", "").Replace("</wav>", "");
                if(string.IsNullOrEmpty(wavLink))
                {
                    wavLink  = "{wav}";
                }

                //<dt>:
                regex = new Regex("<dt>:[a-zA-Z0-9 '.s\"\\(\\):]*<");
                var def = regex.Match(text).Value.Replace("<dt>:", "").Replace("<", "");
                if(string.IsNullOrEmpty(def))
                {
                    def = "{def}";
                }

                return wavLink + ";" +def;
            });
        }
开发者ID:maying,项目名称:CheatWithPals,代码行数:25,代码来源:WordController.cs


示例15: ReadFromStream

        private object ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            var root = GetRootFieldName(type);
            var contentHeaders = content == null ? null : content.Headers;

            // If content length is 0 then return default value for this type
            if (contentHeaders != null && contentHeaders.ContentLength == 0)
                return GetDefaultValueForType(type);

            // Get the character encoding for the content
            var effectiveEncoding = SelectCharacterEncoding(contentHeaders);

            try
            {
                using (var reader = (new StreamReader(readStream, effectiveEncoding)))
                {
                    var json = reader.ReadToEnd();
                    var serializer = new EmberJsonSerializer();
                    var deserialized = serializer.Deserialize(json, root);
                    return deserialized.ToObject(type);
                }
            }
            catch (Exception e)
            {
                if (formatterLogger == null)
                {
                    throw;
                }
                formatterLogger.LogError(String.Empty, e);
                return GetDefaultValueForType(type);
            }
        }
开发者ID:dpollock,项目名称:EmberJS.WebAPI,代码行数:32,代码来源:EmberJsonMediaTypeFormatter.cs


示例16: ReadFromStreamAsync

 public override async Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
 {
     using (var streamReader = new StreamReader(readStream))
     {
         return await streamReader.ReadToEndAsync();
     }
 }
开发者ID:sk8tz,项目名称:Orc.LicenseManager,代码行数:7,代码来源:PlainTextFormatter.cs


示例17: Deserialize

        private async Task<object> Deserialize(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {


            var headers = (content == null) ? null : content.Headers;
            if (headers != null && headers.ContentLength == 0L)
            {
                return MediaTypeFormatter.GetDefaultValueForType(type);
            }

            object result = null;
            try
            {

                result = DeserializeByJsonSerializer(type, readStream, headers);

            }
            catch (Exception exception)
            {
                if (formatterLogger != null)
                {
                    formatterLogger.LogError(string.Empty, exception);
                }

                result = MediaTypeFormatter.GetDefaultValueForType(type);
            }

            return result;
        }
开发者ID:zidanfei,项目名称:Dot.Utility,代码行数:29,代码来源:DateTypeFormatter.cs


示例18: ReadFromStreamAsync

 public override Task<object> ReadFromStreamAsync(Type type, Stream input, HttpContent content, IFormatterLogger formatterLogger)
 {
     var reader = new StreamReader(input);
     Func<TextReader, Options, object> deserialize = TypedDeserializers.GetTyped(type);
     object result = deserialize(reader, _options);
     return Task.FromResult(result);
 }
开发者ID:austinejei,项目名称:sidekick,代码行数:7,代码来源:JilMediaTypeFormatter.cs


示例19: ReadFromStreamAsync

        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            var tcs = new TaskCompletionSource<object>();
            if (content != null && content.Headers.ContentLength == 0) return null;

            try
            {
                var reader = new BsonReader(readStream);

                if (typeof(IEnumerable).IsAssignableFrom(type)) reader.ReadRootValueAsArray = true;

                using (reader)
                {
                    var jsonSerializer = JsonSerializer.Create(_jsonSerializerSettings);
                    var output = jsonSerializer.Deserialize(reader, type);
                    tcs.SetResult(output);
                }
            }
            catch (Exception)
            {
                tcs.SetResult(GetDefaultValueForType(type));
            }

            return tcs.Task;
        }
开发者ID:jcanady20,项目名称:Scheduler.Service,代码行数:25,代码来源:BsonMediaTypeFormatter.cs


示例20: ReadFromStream

        public override object ReadFromStream(Type type, Stream stream, HttpContentHeaders contentHeaders, IFormatterLogger formatterLogger)
        {
            BufferedMediaTypeFormatter innerFormatter = InnerBufferedFormatter;
            MediaTypeHeaderValue contentType = contentHeaders == null ? null : contentHeaders.ContentType;
            object value = null;

            _innerTracer.TraceWriter.TraceBeginEnd(
                _innerTracer.Request,
                TraceCategories.FormattingCategory,
                TraceLevel.Info,
                _innerTracer.InnerFormatter.GetType().Name,
                OnReadFromStreamMethodName,
                beginTrace: (tr) =>
                {
                    tr.Message = Error.Format(
                            SRResources.TraceReadFromStreamMessage,
                            type.Name,
                            contentType == null ? SRResources.TraceNoneObjectMessage : contentType.ToString());
                },
                execute: () =>
                {
                    value = innerFormatter.ReadFromStream(type, stream, contentHeaders, formatterLogger);
                },
                endTrace: (tr) =>
                {
                    tr.Message = Error.Format(
                                SRResources.TraceReadFromStreamValueMessage,
                                FormattingUtilities.ValueToString(value, CultureInfo.CurrentCulture));
                },
                errorTrace: null);

            return value;
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:33,代码来源:BufferedMediaTypeFormatterTracer.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IFormsAuthentication类代码示例发布时间:2022-05-24
下一篇:
C# IFormatterConverter类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap