Esempio n. 1
0
            public override async Task WriteMessageAsync(Message message, Stream stream)
            {
                if (message == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
                }
                if (stream == null)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(stream)), message);
                }
                ThrowIfMismatchedMessageVersion(message);

                message.Properties.Encoder = this;
                XmlDictionaryWriter xmlWriter = TakeStreamedWriter(stream);

                if (optimizeWriteForUTF8)
                {
                    await message.WriteMessageAsync(xmlWriter);
                }
                else
                {
                    xmlWriter.WriteStartDocument();
                    await message.WriteMessageAsync(xmlWriter);

                    xmlWriter.WriteEndDocument();
                }

                await xmlWriter.FlushAsync();

                ReturnStreamedWriter(xmlWriter);
            }
 private async Task AppendToTextFileAsync(string fileLocation, T data)
 {
     try
     {
         using (var stream = new FileStream(fileLocation, FileMode.Create, FileAccess.Write))
         {
             using (XmlDictionaryWriter writer = JsonReaderWriterFactory.CreateJsonWriter(
                        stream, Encoding.UTF8, true, true, "  "))
             {
                 var serializer = new DataContractJsonSerializer(data.GetType());
                 serializer.WriteObject(writer, data);
                 await writer.FlushAsync();
             }
         }
     }
     catch (IOException ex) when((ex.HResult & 0xFFFF) == 0x27 || (ex.HResult & 0xFFFF) == 0x70)
     {
         Logger.Error("TumblrJsonDownloader:AppendToTextFile: {0}", ex);
         shellService.ShowError(ex, Resources.DiskFull);
         crawlerService.StopCommand.Execute(null);
     }
     catch
     {
     }
 }
Esempio n. 3
0
            public override async Task WriteMessageAsync(Message message, Stream stream)
            {
                if (message == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(message)));
                }

                if (stream == null)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(stream)), message);
                }

                ThrowIfMismatchedMessageVersion(message);

                EventTraceActivity eventTraceActivity = null;

                if (WcfEventSource.Instance.TextMessageEncodingStartIsEnabled())
                {
                    eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                    WcfEventSource.Instance.TextMessageEncodingStart(eventTraceActivity);
                }

                message.Properties.Encoder = this;
                XmlDictionaryWriter xmlWriter = TakeStreamedWriter(stream);

                if (_optimizeWriteForUTF8)
                {
                    await message.WriteMessageAsync(xmlWriter);
                }
                else
                {
                    xmlWriter.WriteStartDocument();
                    await message.WriteMessageAsync(xmlWriter);

                    xmlWriter.WriteEndDocument();
                }

                await xmlWriter.FlushAsync();

                ReturnStreamedWriter(xmlWriter);

                if (WcfEventSource.Instance.StreamedMessageWrittenByEncoderIsEnabled())
                {
                    WcfEventSource.Instance.StreamedMessageWrittenByEncoder(eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message));
                }

                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
                }
            }
Esempio n. 4
0
        private async Task <XDocument> GetMessageEnvelope(MessageBuffer buffer)
        {
            using (var stream = new MemoryStream())
            {
                var msg = buffer.CreateMessage();
                XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream);
                msg.WriteMessage(writer);
                await writer.FlushAsync();

                stream.Seek(0, SeekOrigin.Begin);
                XDocument doc = XDocument.Load(stream);
                return(doc);
            }
        }
Esempio n. 5
0
        private async Task WriteMessageInternalAsync(Message message, Stream stream, string startInfo, string boundary, string startUri, bool writeMessageHeaders)
        {
            if (message == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(message)));
            }
            if (stream == null)
            {
                throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(stream)), message);
            }
            ThrowIfMismatchedMessageVersion(message);

            EventTraceActivity eventTraceActivity = null;

            if (WcfEventSource.Instance.MtomMessageEncodingStartIsEnabled())
            {
                eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(message);
                WcfEventSource.Instance.MtomMessageEncodingStart(eventTraceActivity);
            }

            message.Properties.Encoder = this;
            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportSend);
            }
            XmlDictionaryWriter xmlWriter = _factory.TakeStreamedWriter(stream, startInfo, boundary, startUri, writeMessageHeaders);

            if (_writeEncoding.WebName == "utf-8")
            {
                await message.WriteMessageAsync(xmlWriter);
            }
            else
            {
                await xmlWriter.WriteStartDocumentAsync();

                await message.WriteMessageAsync(xmlWriter);

                await xmlWriter.WriteEndDocumentAsync();
            }

            await xmlWriter.FlushAsync();

            _factory.ReturnStreamedWriter(xmlWriter);

            if (WcfEventSource.Instance.StreamedMessageWrittenByEncoderIsEnabled())
            {
                WcfEventSource.Instance.StreamedMessageWrittenByEncoder(eventTraceActivity ?? EventTraceActivityHelper.TryExtractActivity(message));
            }
        }