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


C# EventData.Dispose方法代码示例

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


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

示例1: 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


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