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


C# EventData.Clone方法代码示例

本文整理汇总了C#中EventData.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# EventData.Clone方法的具体用法?C# EventData.Clone怎么用?C# EventData.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EventData的用法示例。


在下文中一共展示了EventData.Clone方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AfterReceiveMessage

 public EventData AfterReceiveMessage(EventData eventData, WriteToLogDelegate writeToLog = null)
 {
     if (eventData == null)
     {
         return null;
     }
     var stream = eventData.Clone().GetBody<Stream>();
     if (stream == null)
     {
         return null;
     }
     if (stream.CanSeek)
     {
         stream.Seek(0, SeekOrigin.Begin);
     }
     return eventData.Clone(Decompress(stream));
 } 
开发者ID:abombss,项目名称:ServiceBusExplorer,代码行数:17,代码来源:ZipEventDataInspector.cs

示例2: BeforeSendMessage

 public EventData BeforeSendMessage(EventData eventData, WriteToLogDelegate writeToLog = null)
 {
     if (eventData == null)
     {
         return null;
     }
     var stream = eventData.Clone().GetBodyStream();
     if (stream == null)
     {
         return null;
     }
     if (stream.CanSeek)
     {
         stream.Seek(0, SeekOrigin.Begin);
     }
     return eventData.Clone(Compress(stream));
 }
开发者ID:sscctech,项目名称:ServiceBusExplorer,代码行数:17,代码来源:ZipEventDataInspector.cs

示例3: GetMessageAndProperties

        /// <summary>
        /// Gets the eventData body and properties.
        /// </summary>
        /// <param name="builder">The string builder object used to accumulate the trace event data.</param>
        /// <param name="inboundMessage">The inbound event data.</param>
        public void GetMessageAndProperties(StringBuilder builder, EventData inboundMessage)
        {
            string eventDataText = null;
            Stream stream = null;

            if (inboundMessage == null)
            {
                return;
            }
            
            try
            {
                var eventDataClone = inboundMessage.Clone();
                stream = eventDataClone.GetBody<Stream>();
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream))
                    {
                        eventDataText = reader.ReadToEnd();
                    }
                }
            }
            catch (Exception)
            {
                try
                {
                    if (stream != null)
                    {
                        try
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            var serializer = new CustomDataContractBinarySerializer(typeof(string));
                            eventDataText = serializer.ReadObject(stream) as string;
                        }
                        catch (Exception)
                        {
                            try
                            {
                                stream.Seek(0, SeekOrigin.Begin);
                                using (var reader = new StreamReader(stream))
                                {
                                    eventDataText = reader.ReadToEnd();
                                }
                            }
                            catch (Exception)
                            {
                                eventDataText = UnableToReadMessageBody;
                            }
                        }
                    }
                    else
                    {
                        eventDataText = UnableToReadMessageBody;
                    }
                }
                catch (Exception)
                {
                    eventDataText = UnableToReadMessageBody;
                }
            }
            builder.AppendLine();
            builder.AppendLine(ReceivedMessagePayloadHeader);
            builder.AppendLine(string.Format(MessageTextFormat, eventDataText));
            if (inboundMessage.Properties.Any())
            {
                builder.AppendLine(ReceivedMessagePropertiesHeader);
                foreach (var p in inboundMessage.Properties)
                {
                    builder.AppendLine(string.Format(MessagePropertyFormat,
                                                     p.Key,
                                                     p.Value));
                }
            }
        }
开发者ID:abombss,项目名称:ServiceBusExplorer,代码行数:79,代码来源:ServiceBusHelper.cs

示例4: GetMessageText

 /// <summary>
 /// Reads the content of the EventData passed as argument.
 /// </summary>
 /// <param name="eventDataToRead">The EventData to read.</param>
 /// <param name="bodyType">BodyType</param>
 /// <returns>The content of the EventData.</returns>
 public string GetMessageText(EventData eventDataToRead, out BodyType bodyType)
 {
     string eventDataText = null;
     Stream stream = null;
     bodyType = BodyType.Stream;
     if (eventDataToRead == null)
     {
         return null;
     }
     var inboundMessage = eventDataToRead.Clone();
     try
     {
         stream = inboundMessage.GetBody<Stream>();
         if (stream != null)
         {
             var element = new BinaryMessageEncodingBindingElement
             {
                 ReaderQuotas = new XmlDictionaryReaderQuotas
                 {
                     MaxArrayLength = int.MaxValue,
                     MaxBytesPerRead = int.MaxValue,
                     MaxDepth = int.MaxValue,
                     MaxNameTableCharCount = int.MaxValue,
                     MaxStringContentLength = int.MaxValue
                 }
             };
             var encoderFactory = element.CreateMessageEncoderFactory();
             var encoder = encoderFactory.Encoder;
             var stringBuilder = new StringBuilder();
             var eventData = encoder.ReadMessage(stream, MaxBufferSize);
             using (var reader = eventData.GetReaderAtBodyContents())
             {
                 // The XmlWriter is used just to indent the XML eventData
                 var settings = new XmlWriterSettings { Indent = true };
                 using (var writer = XmlWriter.Create(stringBuilder, settings))
                 {
                     writer.WriteNode(reader, true);
                 }
             }
             eventDataText = stringBuilder.ToString();
             bodyType = BodyType.Wcf;
         }
     }
     catch (Exception)
     {
         inboundMessage = eventDataToRead.Clone();
         try
         {
             stream = inboundMessage.GetBody<Stream>();
             if (stream != null)
             {
                 var element = new BinaryMessageEncodingBindingElement
                 {
                     ReaderQuotas = new XmlDictionaryReaderQuotas
                     {
                         MaxArrayLength = int.MaxValue,
                         MaxBytesPerRead = int.MaxValue,
                         MaxDepth = int.MaxValue,
                         MaxNameTableCharCount = int.MaxValue,
                         MaxStringContentLength = int.MaxValue
                     }
                 };
                 var encoderFactory = element.CreateMessageEncoderFactory();
                 var encoder = encoderFactory.Encoder;
                 var eventData = encoder.ReadMessage(stream, MaxBufferSize);
                 using (var reader = eventData.GetReaderAtBodyContents())
                 {
                     eventDataText = reader.ReadString();
                 }
                 bodyType = BodyType.Wcf;
             }
         }
         catch (Exception)
         {
             try
             {
                 if (stream != null)
                 {
                     try
                     {
                         stream.Seek(0, SeekOrigin.Begin);
                         var serializer = new CustomDataContractBinarySerializer(typeof(string));
                         eventDataText = serializer.ReadObject(stream) as string;
                         bodyType = BodyType.String;
                     }
                     catch (Exception)
                     {
                         try
                         {
                             stream.Seek(0, SeekOrigin.Begin);
                             using (var reader = new StreamReader(stream))
                             {
                                 eventDataText = reader.ReadToEnd();
                                 if (eventDataText.ToCharArray().GroupBy(c => c).
//.........这里部分代码省略.........
开发者ID:abombss,项目名称:ServiceBusExplorer,代码行数:101,代码来源:ServiceBusHelper.cs

示例5: SendEventData


//.........这里部分代码省略.........
        //                    builder.AppendLine(string.Format(MessageTextFormat, GetMessageText(eventDataPayloadList[i])));
        //                    builder.AppendLine(SentMessagePropertiesHeader);
        //                    foreach (var p in eventDataList[i].Properties)
        //                    {
        //                        builder.AppendLine(string.Format(MessagePropertyFormat,
        //                                                         p.Key,
        //                                                         p.Value));
        //                    }
        //                }
        //            }
        //            finally
        //            {
        //                eventDataList[i].Dispose();
        //            }
        //        }
        //        var traceMessage = builder.ToString();
        //        WriteToLog(traceMessage.Substring(0, traceMessage.Length - 1));
        //    }
        //    return elapsedMilliseconds;
        //}

        /// <summary>
        /// This method can be used to send an event data to an event hub.
        /// </summary>
        /// <param name="eventHubClient">A MessageSender object used to send event datas.</param>
        /// <param name="eventData">The event data to send.</param>
        /// <param name="messageNumber">The message number.</param>
        /// <param name="taskId">The sender task id.</param>
        /// <param name="logging">Indicates whether logging of event data content and properties is enabled.</param>
        /// <param name="verbose">Indicates whether verbose logging is enabled.</param>
        /// <returns>Elapsed milliseconds.</returns>
        public async Task<long> SendEventData(EventHubClient eventHubClient,
                                              EventData eventData,
                                              long messageNumber,
                                              int taskId,
                                              bool logging,
                                              bool verbose)
        {
            long elapsedMilliseconds;
            if (eventHubClient == null)
            {
                throw new ArgumentNullException(MessageSenderCannotBeNull);
            }

            if (eventData == null)
            {
                throw new ArgumentNullException(BrokeredMessageCannotBeNull);
            }

            var stopwatch = new Stopwatch();
            Stream bodyStream = null;
            try
            {
                var builder = new StringBuilder();
                try
                {
                    if (logging && verbose)
                    {
                        bodyStream = eventData.Clone().GetBodyStream();
                    }
                    stopwatch.Start();
                    await eventHubClient.SendAsync(eventData);
                }
                finally
                {
                    stopwatch.Stop();
                }
                elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
                if (logging)
                {
                    builder.AppendLine(string.Format(CultureInfo.CurrentCulture, 
                                                     EventDataSuccessfullySent,
                                                     taskId,
                                                     messageNumber,
                                                     string.IsNullOrWhiteSpace(eventData.PartitionKey) ? NullValue : eventData.PartitionKey));
                    if (verbose)
                    {
                        builder.AppendLine(SentMessagePayloadHeader);
                        builder.AppendLine(string.Format(MessageTextFormat, GetMessageText(bodyStream)));
                        if (eventData.Properties.Any())
                        {
                            builder.AppendLine(SentMessagePropertiesHeader);
                            foreach (var p in eventData.Properties)
                            {
                                builder.AppendLine(string.Format(MessagePropertyFormat,
                                                                    p.Key,
                                                                    p.Value));
                            }
                        }
                    }
                    var traceMessage = builder.ToString();
                    WriteToLog(traceMessage.Substring(0, traceMessage.Length - 1));
                }
            }
            finally
            {
                eventData.Dispose();
            }
            return elapsedMilliseconds;
        }
开发者ID:abombss,项目名称:ServiceBusExplorer,代码行数:101,代码来源:ServiceBusHelper.cs

示例6: LogEventData

 private EventData LogEventData(EventDataDirection direction, EventData eventData)
 {
     try
     {
         if (eventData != null)
         {
             messageCollection.TryAdd(new Tuple<EventDataDirection, EventData>(direction, eventData.Clone()));
         }
     }
     // ReSharper disable once EmptyGeneralCatchClause
     catch (Exception)
     {
     }
     return eventData;
 }
开发者ID:pvmraghunandan,项目名称:EventHubReader,代码行数:15,代码来源:LogEventData.cs


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