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


C# Net.TransportContext类代码示例

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


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

示例1: WriteToStreamAsync

        //OnWriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext, TransportContext transportContext)
        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            string uri = HttpContext.Current.Request.Url.Query;
            string method = HttpContext.Current.Request.HttpMethod;
            if(HttpContext.Current.Request.HttpMethod =="GET")
            {

                return Task.Factory.StartNew(() =>
                {
                    var writer = new StreamWriter(writeStream);
                    var query = HttpUtility.ParseQueryString(uri);
                    string callback = query[CallbackQueryParameter];
                    writer.Write(callback + "(");
                    writer.Flush();

                    base.WriteToStreamAsync(type, value, writeStream, content, transportContext).Wait();

                    writer.Write(")");
                    writer.Flush();
                });
            }
            else
            {
                return base.WriteToStreamAsync(type, value, writeStream, content, transportContext);
            }
        }
开发者ID:RapportFraStedet,项目名称:MapGuideForms,代码行数:27,代码来源:JsonpMediaTypeFormatter.cs

示例2: WriteToStreamAsync

        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content, TransportContext transportContext)
        {
            if (type == null) throw new ArgumentNullException("type");
            if (writeStream == null) throw new ArgumentNullException("writeStream");

            var tcs = new TaskCompletionSource<object>();
            try
            {
                if (_writerSettings == null)
                {
                    this._writerSettings = new XmlWriterSettings()
                    {
                        OmitXmlDeclaration = true,
                        Indent = true,
                        Encoding = SelectCharacterEncoding(content != null ? content.Headers : null),
                        CloseOutput = false
                    };
                }
                using (XmlWriter writer = XmlWriter.Create(writeStream, _writerSettings))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(type);
                    xmlSerializer.Serialize(writer, value, _namespaces);
                    tcs.SetResult(null);
                }
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }
            return tcs.Task;
        }
开发者ID:jbrwn,项目名称:tc,代码行数:31,代码来源:ExtendedXmlMediaTypeFormatter.cs

示例3: StreamVideo

        public async Task StreamVideo(Stream stream, HttpContent content, TransportContext transport)
        {
            try
            {
                var buffer = new byte[65536];
                var filename = Path.Combine(String.Format("{0}{1}video.{2}", System.Web.HttpContext.Current.Server.MapPath("~"), Constants.FilePath, _fileExtension));
                using (var file = File.Open(filename, FileMode.Open, FileAccess.Read))
                {
                    var videoLength = (int)file.Length;
                    var placeInFile = 1;

                    while (videoLength > 0 && placeInFile > 0)
                    {
                        placeInFile = file.Read(buffer, 0, Math.Min(videoLength, buffer.Length));
                        await stream.WriteAsync(buffer, 0, placeInFile);
                        videoLength -= placeInFile;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.InnerException);
            }
            finally
            {
                stream.Close();
            }
        }
开发者ID:carlingkirk,项目名称:CarlingKirk.com,代码行数:28,代码来源:Video.cs

示例4: SerializeToStreamAsync

			protected override Task SerializeToStreamAsync (Stream stream, TransportContext context)
			{
				if (OnSerializeToStreamAsync != null)
					OnSerializeToStreamAsync ();

				return base.SerializeToStreamAsync (stream, context);
			}
开发者ID:carrie901,项目名称:mono,代码行数:7,代码来源:StreamContentTest.cs

示例5: WriteToStreamAsync

        public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
        {
            return Task.Factory.StartNew(() =>
            {
                XmlWriter writer = new XmlTextWriter(writeStream, Encoding.UTF8);
                // todo: klopt het dat Bundle wel en <?xml ...> header heeft een Resource niet?
                // follow up: is now ticket in FhirApi. Check later.

                if (type == typeof(OperationOutcome)) 
                {
                    Resource resource = (Resource)value;
                    FhirSerializer.SerializeResource(resource, writer);
                }
                else if (type == typeof(ResourceEntry))
                {
                    ResourceEntry entry = (ResourceEntry)value;
                    FhirSerializer.SerializeResource(entry.Resource, writer);
                    
                    content.Headers.SetFhirTags(entry.Tags);
                }

                else if (type == typeof(Bundle))
                {
                    FhirSerializer.SerializeBundle((Bundle)value, writer);
                }
                else if (type == typeof(TagList))
                {
                    FhirSerializer.SerializeTagList((TagList)value, writer); 
                }
                
                writer.Flush();
            });
        }
开发者ID:TonyAbell,项目名称:spark,代码行数:33,代码来源:XmlFhirFormatter.cs

示例6: SerializeToStreamAsync

        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            if (HasNoData())
                return new CompletedTask<bool>(true);

            using ( var undisposableStream = new UndisposableStream(stream) )
            using ( var bufferedStream = new BufferedStream(undisposableStream))
            {
                var writer = new StreamWriter(bufferedStream, DefaultEncoding);
                if (string.IsNullOrEmpty(Jsonp) == false)
                {
                    writer.Write(Jsonp);
                    writer.Write("(");
                }

                Data.WriteTo(new JsonTextWriter(writer)
                {
                    Formatting = IsOutputHumanReadable ? Formatting.Indented : Formatting.None,
                }, Default.Converters);

                if (string.IsNullOrEmpty(Jsonp) == false)
                    writer.Write(")");

                writer.Flush();
            }

            return new CompletedTask<bool>(true);
        }
开发者ID:heinnge,项目名称:ravendb,代码行数:28,代码来源:JsonContent.cs

示例7: WriteToStream

        public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {
                var buffer = new byte[65536];

                using (var video = new MemoryStream(this.videoData))
                {
                    var length = (int)video.Length;
                    var bytesRead = 1;

                    while (length > 0 && bytesRead > 0)
                    {
                        bytesRead = video.Read(buffer, 0, Math.Min(length, buffer.Length));
                        await outputStream.WriteAsync(buffer, 0, bytesRead);
                        length -= bytesRead;
                    }
                }
            }
            catch (Exception ex)
            {
                return;
            }
            finally
            {
                outputStream.Close();
            }
        }
开发者ID:KitKare,项目名称:KitKareService,代码行数:28,代码来源:VideoStream.cs

示例8: WriteToStream

        async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {
                var buffer = new byte[_chunkSize];
                using (var inputStream = OpenInputStream())
                {
                    var length = (int)inputStream.Length;
                    var bytesRead = 1;

                    while (length > 0 && bytesRead > 0)
                    {
                        bytesRead = inputStream.Read(buffer, 0, Math.Min(length, buffer.Length));
                        await outputStream.WriteAsync(buffer, 0, bytesRead);
                        length -= bytesRead;
                    }
                }
            }
            catch (HttpException)
            {
            }
            finally
            {
                outputStream.Close();
                outputStream.Dispose();
            }
        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:27,代码来源:HttpPushContentStream.cs

示例9: OnWriteToStreamAsync

        protected override Task OnWriteToStreamAsync(Type type, object value, Stream stream,
                                                     HttpContentHeaders contentHeaders,
                                                     FormatterContext formatterContext,
                                                     TransportContext transportContext)
        {
            var serializer = JsonSerializer.Create(jsonSerializerSettings);
            var tcs = new TaskCompletionSource<object>();

            try
            {
                using (var streamWriter = new StreamWriter(stream, Encoding))
                {
                    using (var jsonTextWriter = new JsonTextWriter(streamWriter))
                    {
                        serializer.Serialize(jsonTextWriter, value);
                        tcs.SetResult(null);
                    }
                }
            }
            catch (Exception ex)
            {
                tcs.SetException(ex);
            }

            return tcs.Task;
        }
开发者ID:rmueller,项目名称:WebAPIContrib,代码行数:26,代码来源:JsonNetFormatter.cs

示例10: WriteToStreamAsync

 public override async Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext)
 {
     using (stream)
     {
         Encoding encoding = SelectCharacterEncoding(content.Headers);
         using (var writer = new StreamWriter(stream, encoding))
         {
             var individuals = value as IEnumerable<Individual>;
             if (individuals != null)
             {
                 foreach (var individu in individuals)
                 {
                     await writer.WriteLineAsync(String.Format("{0,-10};{1,-10};{2,-10}", individu.Id, individu.FirstName, individu.LastName));
                 }
                 await writer.FlushAsync();
             }
             var individual = value as Individual;
             if (individual != null)
             {
                 await writer.WriteLineAsync(String.Format("{0,-10};{1,-10};{2,-10}", individual.Id, individual.FirstName, individual.LastName));
                 await writer.FlushAsync();
             }
         }
     }
 }
开发者ID:Redenil,项目名称:RDAcademy,代码行数:25,代码来源:CsvTextMediaFormatter.cs

示例11: WriteToStream

        public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {

              var channelBinding=   context.GetChannelBinding(ChannelBindingKind.Endpoint);

                var buffer = new byte[65536];
                using (var video = File.Open(_filename, FileMode.Open, FileAccess.Read))
                {
                    var length = (int)video.Length;
                    var bytesRead = 1;
                    while (length > 0 && bytesRead > 0)
                    {
                        bytesRead = video.Read(buffer, 0, Math.Min(length, buffer.Length));
                        await outputStream.WriteAsync(buffer, 0, bytesRead);
                        length -= bytesRead;
                    }
                }
            }
            catch (HttpResponseException ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
            finally
            {
                outputStream.Close();
            }
        }
开发者ID:wjkhappy14,项目名称:aspnetwebstack,代码行数:29,代码来源:VideoStream.cs

示例12: OnStreamAvailable1

        public static void OnStreamAvailable1(Stream stream, HttpContent headers, TransportContext context)
        {
            StreamWriter streamwriter = new StreamWriter(stream);
            //_streammessage.TryAdd(_streammessage.Count+1,streamwriter);

            StartWriting(streamwriter);
        }
开发者ID:ruhveen,项目名称:Site,代码行数:7,代码来源:ChartController.cs

示例13: WriteToStreamAsync

 public override Task WriteToStreamAsync(Type type, object value, Stream output, HttpContent content, TransportContext transportContext)
 {
     var writer = new StreamWriter(output);
     JSON.Serialize(value, writer, _options);
     writer.Flush();
     return Done;
 }
开发者ID:austinejei,项目名称:sidekick,代码行数:7,代码来源:JilMediaTypeFormatter.cs

示例14: SerializeToStreamAsync

 /// <summary>
 /// Serialize the HTTP content to a stream as an asynchronous operation.
 /// </summary>
 /// <param name="stream">The target stream.</param>
 /// <param name="context">Information about the transport (channel binding token, for example). This parameter may be null.</param>
 /// <returns>
 /// Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.
 /// </returns>
 protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
 {
     using (Stream compressedStream = new GZipStream(stream, CompressionMode.Compress, true))
     {
         await this._originalContent.CopyToAsync(compressedStream);
     }
 }
开发者ID:ni3bobade,项目名称:.net-sdk,代码行数:15,代码来源:GzippedContent.cs

示例15: WriteToStreamAsync

 public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)
 {
     return Task.Factory.StartNew(() =>
     {
         WriteHTMLOutput(type, value, writeStream);
     });
 }
开发者ID:Condeti,项目名称:spark,代码行数:7,代码来源:HtmlFhirFormatter.cs


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