當前位置: 首頁>>代碼示例>>C#>>正文


C# BrokeredMessage.Dispose方法代碼示例

本文整理匯總了C#中BrokeredMessage.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# BrokeredMessage.Dispose方法的具體用法?C# BrokeredMessage.Dispose怎麽用?C# BrokeredMessage.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BrokeredMessage的用法示例。


在下文中一共展示了BrokeredMessage.Dispose方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SendMessage

        public JsonResult SendMessage(string topicName, string message, bool messageIsUrgent, bool messageIsImportant)
        {
            TopicClient topicClient = this.messagingFactory.CreateTopicClient(topicName);
            var customMessage = new CustomMessage() { Body = message, Date = DateTime.Now };
            bool success = false;
            BrokeredMessage bm = null;

            try
            {
                bm = new BrokeredMessage(customMessage);
                bm.Properties["Urgent"] = messageIsUrgent ? "1" : "0";
                bm.Properties["Important"] = messageIsImportant ? "1" : "0";
                bm.Properties["Priority"] = "Low";
                topicClient.Send(bm);
                success = true;
            }
            catch (Exception)
            {
                // TODO: do something
            }
            finally
            {
                if (bm != null)
                {
                    bm.Dispose();
                }
            }

            return this.Json(success, JsonRequestBehavior.AllowGet);
        }
開發者ID:kirpasingh,項目名稱:MicrosoftAzureTrainingKit,代碼行數:30,代碼來源:HomeController.cs

示例2: SendMessage

        public JsonResult SendMessage(string queueName, string message)
        {
            QueueClient queueClient = this.messagingFactory.CreateQueueClient(queueName);
            var customMessage = new CustomMessage() { Date = DateTime.Now, Body = message };
            long? messagesInQueue = null;
            BrokeredMessage bm = null;

            try
            {
                bm = new BrokeredMessage(customMessage);
                bm.Properties["Urgent"] = "1";
                bm.Properties["Priority"] = "High";
                queueClient.Send(bm);
                messagesInQueue = this.GetMessageCount(queueName);
            }
            catch
            {
                // TODO: do something
            }
            finally
            {
                if (bm != null)
                {
                    bm.Dispose();
                }
            }

            return this.Json(messagesInQueue, JsonRequestBehavior.AllowGet);
        }
開發者ID:kirpasingh,項目名稱:MicrosoftAzureTrainingKit,代碼行數:29,代碼來源:HomeController.cs

示例3: SendMessage

        public void SendMessage(string queueName, string messageBody)
        {
            QueueClient queueClient = this.messagingFactory.CreateQueueClient(queueName);
            var customMessage = new CustomMessage() { Date = DateTime.Now, Body = messageBody };
            BrokeredMessage bm = null;

            try
            {
                bm = new BrokeredMessage(customMessage);
                bm.Properties["Urgent"] = "1";
                bm.Properties["Priority"] = "High";
                queueClient.Send(bm);
            }
            catch
            {
                // TODO: do something
            }
            finally
            {
                if (bm != null)
                {
                    bm.Dispose();
                }
            }
        }
開發者ID:kirpasingh,項目名稱:MicrosoftAzureTrainingKit,代碼行數:25,代碼來源:HomeController.cs

示例4: SendMessage

        public void SendMessage(string topicName, string messageBody, bool isUrgent, bool isImportant)
        {
            TopicClient topicClient = this.messagingFactory.CreateTopicClient(topicName);
            var customMessage = new CustomMessage() { Body = messageBody, Date = DateTime.Now };
            var bm = new BrokeredMessage(customMessage);
            bm.Properties["Urgent"] = isUrgent ? "1" : "0";
            bm.Properties["Important"] = isImportant ? "1" : "0";

            // Force message priority to "Low". Subscription filters will change the value automatically if applies
            bm.Properties["Priority"] = "Low";
            topicClient.Send(bm);

            if (bm != null)
            {
                bm.Dispose();
            }
        }
開發者ID:kirpasingh,項目名稱:MicrosoftAzureTrainingKit,代碼行數:17,代碼來源:HomeController.cs

示例5: SendMessage

        public void SendMessage(string queueName, string messageBody, bool isUrgent, bool isFollowUp)
        {
            MessageSender sender = this.messagingFactory.CreateMessageSender(queueName);
            var customMessage = new CustomMessage() { Date = DateTime.Now, Body = messageBody };
            BrokeredMessage bm = null;

            try
            {
                bm = new BrokeredMessage(customMessage.ToDictinary());
                bm.Properties["Urgent"] = "1";
                bm.Properties["Priority"] = "High";
                sender.Send(bm);
            }
            catch 
            { 
            }
            finally
            {
                if (bm != null)
                {
                    bm.Dispose();
                }
            }
        }
開發者ID:kirpasingh,項目名稱:MicrosoftAzureTrainingKit,代碼行數:24,代碼來源:HomeController.cs

示例6: SendMessage

        /// <summary>
        /// This method can be used to send a message to a queue or a topic.
        /// </summary>
        /// <param name="messageSender">A MessageSender object used to send messages.</param>
        /// <param name="message">The message to send.</param>
        /// <param name="taskId">The sender task id.</param>
        /// <param name="isBinary">Indicates if the body is binary or not.</param>
        /// <param name="useWcf">Indicates whether to send messages to a WCF receiver.</param>
        /// <param name="logging">Indicates whether logging of message content and properties is enabled.</param>
        /// <param name="verbose">Indicates whether verbose logging is enabled.</param>
        /// <param name="elapsedMilliseconds">The time spent to send the message.</param>
        public void SendMessage(MessageSender messageSender,
                                BrokeredMessage message,
                                int taskId,
                                bool isBinary,
                                bool useWcf,
                                bool logging,
                                bool verbose,
                                out long elapsedMilliseconds)
        {
            if (messageSender == null)
            {
                throw new ArgumentNullException(MessageSenderCannotBeNull);
            }

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

            var stopwatch = new Stopwatch();

            try
            {
                Stream bodyStream = null;
                if (logging && verbose)
                {
                    bodyStream = message.Clone().GetBodyStream();
                }
                var builder = new StringBuilder();
                try
                {
                    stopwatch.Start();
                    messageSender.Send(message);
                }
                finally
                {
                    stopwatch.Stop();
                }
                elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
                if (logging)
                {
                    builder.AppendLine(string.Format(CultureInfo.CurrentCulture, MessageSuccessfullySent,
                                                     taskId,
                                                     string.IsNullOrWhiteSpace(message.MessageId) ? NullValue : message.MessageId,
                                                     string.IsNullOrWhiteSpace(message.SessionId) ? NullValue : message.SessionId,
                                                     string.IsNullOrWhiteSpace(message.Label) ? NullValue : message.Label,
                                                     message.Size));
                    if (verbose)
                    {
                        builder.AppendLine(SentMessagePayloadHeader);
                        var messageText = GetMessageText(bodyStream, isBinary);
                        if (useWcf)
                        {
                            messageText = XmlHelper.Indent(messageText);
                        }
                        builder.AppendLine(string.Format(MessageTextFormat, messageText.Contains('\n') ? messageText : messageText.Substring(0, Math.Min(messageText.Length, 128)) + (messageText.Length >= 128 ? "..." : "")));
                        if (message.Properties.Any())
                        {
                            builder.AppendLine(SentMessagePropertiesHeader);
                            foreach (var p in message.Properties)
                            {
                                builder.AppendLine(string.Format(MessagePropertyFormat,
                                                                    p.Key,
                                                                    p.Value));
                            }
                        }
                    }
                    var traceMessage = builder.ToString();
                    WriteToLog(traceMessage.Substring(0, traceMessage.Length - 1));
                }
            }
            finally
            {
                message.Dispose();
            }
        }
開發者ID:abombss,項目名稱:ServiceBusExplorer,代碼行數:87,代碼來源:ServiceBusHelper.cs

示例7: DoBeginSendMessage

 protected virtual void DoBeginSendMessage(BrokeredMessage message, AsyncCallback ac)
 {
     try
     {
         this.topicClient.BeginSend(message, ac, message);
     }
     catch
     {
         message.Dispose();
         throw;
     }
 }
開發者ID:pebblecode,項目名稱:EducationPathways,代碼行數:12,代碼來源:TopicSender.cs

示例8: ReleaseMessage

 private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
 {
     switch (releaseAction.Kind)
     {
         case MessageReleaseActionKind.Complete:
             msg.SafeCompleteAsync(
                 this.subscription,
                 success =>
                 {
                     msg.Dispose();
                     this.instrumentation.MessageCompleted(success);
                     if (success)
                     {
                         this.dynamicThrottling.NotifyWorkCompleted();
                     }
                     else
                     {
                         this.dynamicThrottling.NotifyWorkCompletedWithError();
                     }
                 },
                 processingElapsedMilliseconds,
                 schedulingElapsedMilliseconds,
                 roundtripStopwatch);
             break;
         case MessageReleaseActionKind.Abandon:
             msg.SafeAbandonAsync(
                 this.subscription,
                 success => { msg.Dispose(); this.instrumentation.MessageCompleted(false); this.dynamicThrottling.NotifyWorkCompletedWithError(); },
                 processingElapsedMilliseconds,
                 schedulingElapsedMilliseconds,
                 roundtripStopwatch);
             break;
         case MessageReleaseActionKind.DeadLetter:
             msg.SafeDeadLetterAsync(
                 this.subscription,
                 releaseAction.DeadLetterReason,
                 releaseAction.DeadLetterDescription,
                 success => { msg.Dispose(); this.instrumentation.MessageCompleted(false); this.dynamicThrottling.NotifyWorkCompletedWithError(); },
                 processingElapsedMilliseconds,
                 schedulingElapsedMilliseconds,
                 roundtripStopwatch);
             break;
         default:
             break;
     }
 }
開發者ID:hoangvv1409,項目名稱:codebase,代碼行數:46,代碼來源:SubscriptionReceiver.cs

示例9: ProcessMessageAsync

        internal async Task ProcessMessageAsync(BrokeredMessage message, CancellationToken cancellationToken)
        {
            if (message == null)
            {
                Trace.TraceWarning("ProcessMessageAsync was called with a null BrokeredMessage");
                return;
            }

            if (cancellationToken.IsCancellationRequested == false)
            {
                Trace.TraceInformation("Receiving BrokeredMessage with Correlation Id {0}", message.CorrelationId);
                try
                {
                    // Do actual processing of the message
                    var topicMessage = message.GetBody<TopicMessageModel>();
                    var context = GlobalHost.ConnectionManager.GetHubContext<MessageHub>();
                    context.Clients.All.addMessage(topicMessage.Sender, topicMessage.Message, topicMessage.Disco);
                    Trace.TraceInformation("Processing message for {0}, sent by {1}, disco? {2}", topicMessage.Message, topicMessage.Sender, topicMessage.Disco);

                    // Complete the message
                    await message.CompleteAsync();
                }
                catch (MessageLockLostException e)
                {
                    Trace.TraceError("Completing a BrokeredMessage in ProcessMessageAsync throw a MessageLockLostException");
                }
                catch (MessagingException e)
                {
                    Trace.TraceError("Completing a BrokeredMessage in ProcessMessageAsync throw a MessagingException");
                }
                catch (Exception e)
                {
                    Trace.TraceError("An exception occured while trying to process a deployment request message");
                }

                message.Dispose();
            }
        }
開發者ID:mikkelhm,項目名稱:UnicornWeb,代碼行數:38,代碼來源:NotificationProcessor.cs

示例10: SendMessage

        /// <summary>
        /// This method can be used to send a message to a queue or a topic.
        /// </summary>
        /// <param name="messageSender">A MessageSender object used to send messages.</param>
        /// <param name="outboundMessage">The message to send.</param>
        /// <param name="messageText">The message text.</param>
        /// <param name="taskId">The sender task id.</param>
        /// <param name="useWcf">Indicates whether to send messages to a WCF receiver.</param>
        /// <param name="logging">Indicates whether logging of message content and properties is enabled.</param>
        /// <param name="verbose">Indicates whether verbose logging is enabled.</param>
        /// <param name="elapsedMilliseconds">The time spent to send the message.</param>
        public void SendMessage(MessageSender messageSender,
                                BrokeredMessage outboundMessage,
                                string messageText,
                                int taskId,
                                bool useWcf,
                                bool logging,
                                bool verbose,
                                out long elapsedMilliseconds)
        {
            if (messageSender == null)
            {
                throw new ArgumentNullException(MessageSenderCannotBeNull);
            }

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

            var stopwatch = new Stopwatch();

            try
            {
                var builder = new StringBuilder();
                try
                {
                    stopwatch.Start();
                    messageSender.Send(outboundMessage);
                }
                finally
                {
                    stopwatch.Stop();
                }
                elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
                if (logging)
                {
                    builder.AppendLine(string.Format(CultureInfo.CurrentCulture, MessageSuccessfullySent,
                                                     taskId,
                                                     string.IsNullOrEmpty(outboundMessage.MessageId) ? NullValue : outboundMessage.MessageId,
                                                     string.IsNullOrEmpty(outboundMessage.SessionId) ? NullValue : outboundMessage.SessionId,
                                                     string.IsNullOrEmpty(outboundMessage.Label) ? NullValue : outboundMessage.Label,
                                                     outboundMessage.Size));
                    if (verbose)
                    {
                        builder.AppendLine(SentMessagePayloadHeader);
                        if (useWcf)
                        {
                            var stringBuilder = new StringBuilder();
                            using (var reader = XmlReader.Create(new StringReader(messageText)))
                            {
                                // The XmlWriter is used just to indent the XML message
                                var settings = new XmlWriterSettings { Indent = true };
                                using (var writer = XmlWriter.Create(stringBuilder, settings))
                                {
                                    writer.WriteNode(reader, true);
                                }
                            }
                            messageText = stringBuilder.ToString();
                        }
                        builder.AppendLine(string.Format(MessageTextFormat, messageText));
                        builder.AppendLine(SentMessagePropertiesHeader);
                        foreach (var p in outboundMessage.Properties)
                        {
                            builder.AppendLine(string.Format(MessagePropertyFormat,
                                                                p.Key,
                                                                p.Value));
                        }
                    }
                    var traceMessage = builder.ToString();
                    WriteToLog(traceMessage.Substring(0, traceMessage.Length - 1));
                }
            }
            finally
            {
                outboundMessage.Dispose();
            }
        }
開發者ID:ssuing8825,項目名稱:ServiceBusExplorer,代碼行數:88,代碼來源:ServiceBusHelper.cs

示例11: ReleaseMessage

        private void ReleaseMessage(BrokeredMessage msg, MessageReleaseAction releaseAction, Action completeReceive, Action onReleaseError, CountdownEvent countdown, long processingElapsedMilliseconds, long schedulingElapsedMilliseconds, Stopwatch roundtripStopwatch)
        {
            switch (releaseAction.Kind)
            {
                case MessageReleaseActionKind.Complete:
                    msg.SafeCompleteAsync(
                        this.subscription,
                        operationSucceeded =>
                        {
                            msg.Dispose();
                            this.OnMessageCompleted(operationSucceeded, countdown);
                            if (operationSucceeded)
                            {
                                completeReceive();
                            }
                            else
                            {
                                onReleaseError();
                            }
                        },
                        processingElapsedMilliseconds,
                        schedulingElapsedMilliseconds,
                        roundtripStopwatch);
                    break;
                case MessageReleaseActionKind.Abandon:
                    this.dynamicThrottling.Penalize();
                    msg.SafeAbandonAsync(
                        this.subscription,
                        operationSucceeded =>
                        {
                            msg.Dispose();
                            this.OnMessageCompleted(false, countdown);

                            onReleaseError();
                        },
                        processingElapsedMilliseconds,
                        schedulingElapsedMilliseconds,
                        roundtripStopwatch);
                    break;
                case MessageReleaseActionKind.DeadLetter:
                    this.dynamicThrottling.Penalize();
                    msg.SafeDeadLetterAsync(
                        this.subscription,
                        releaseAction.DeadLetterReason,
                        releaseAction.DeadLetterDescription,
                        operationSucceeded =>
                        {
                            msg.Dispose();
                            this.OnMessageCompleted(false, countdown);

                            if (operationSucceeded)
                            {
                                completeReceive();
                            }
                            else
                            {
                                onReleaseError();
                            }
                        },
                        processingElapsedMilliseconds,
                        schedulingElapsedMilliseconds,
                        roundtripStopwatch);
                    break;
                default:
                    break;
            }
        }
開發者ID:TiagoTerra,項目名稱:cqrs-journey,代碼行數:67,代碼來源:SessionSubscriptionReceiver.cs


注:本文中的BrokeredMessage.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。