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


C# MessageQueueTransaction.Abort方法代码示例

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


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

示例1: btnAdd_Click

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            string queueName = ConfigurationManager.AppSettings["MSMQLocation"];

            MessageQueue rmTxnQ = new MessageQueue(queueName);

            rmTxnQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(ProcessMessage) });

            foreach (ListBoxItem itm in files.Items)
            {
                MessageQueueTransaction msgTx = new MessageQueueTransaction();
                msgTx.Begin();
                try
                {
                    string argument = "-i \"{0}\" -o \"{1}\" --preset \"" + ConfigurationManager.AppSettings["HandbrakePreset"] + "\"";

                    string destination = txtDestination.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(itm.ToolTip.ToString()) + ".m4v";

                    ProcessMessage p = new ProcessMessage() { CommandLine = argument, DestinationURL = destination, OrignalFileURL = itm.ToolTip.ToString() };

                    rmTxnQ.Send(p, msgTx);
                    results.Items.Insert(0, string.Format("{0} added to queue", p.OrignalFileURL));

                    msgTx.Commit();
                }
                catch (Exception ex)
                {
                    results.Items.Insert(0, ex.Message);
                    msgTx.Abort();
                }
            }
        }
开发者ID:tiernano,项目名称:HandbrakeCluster,代码行数:32,代码来源:MainWindow.xaml.cs

示例2: _orderQueue_PeekCompleted

        static void _orderQueue_PeekCompleted(object sender, PeekCompletedEventArgs e)
        {
            var orderQueue = (MessageQueue)sender;

            var transaction = new MessageQueueTransaction();
            transaction.Begin();

            Order order;

            try
            {
                var receivedMessage = orderQueue.Receive(transaction);
                receivedMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });

                order = Order.DeserializeXml(receivedMessage.Body.ToString());

                using (var db = new OrderContext())
                {
                    db.Orders.Add(order);
                    db.SaveChanges();
                }

                transaction.Commit();
            }
            catch
            {
                // TODO: Log something
                transaction.Abort();
            }
            finally
            {
                orderQueue.BeginPeek();
            }
        }
开发者ID:sconno05,项目名称:order-service,代码行数:34,代码来源:Program.cs

示例3: Run

        static void Run()
        {
            MessageQueue queue = null;
            MessageQueueTransaction trans = null;
            try
            {
                queue = new MessageQueue();
                queue.Path = Constants.QUEUE_PATH;
                queue.DefaultPropertiesToSend.Recoverable = true;

                trans = new MessageQueueTransaction();
                trans.Begin();

                MyOrder order = new MyOrder();
                order.ID = DateTime.Now.Ticks.ToString();
                order.Name = "Order_" + order.ID;

                Message msg = new Message(order);

                queue.Send(msg, trans);
                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Abort();
            }
            finally
            {
                queue.Close();
            }

            Console.WriteLine("message sent..");
        }
开发者ID:yoshiao,项目名称:WCF_Samples,代码行数:33,代码来源:Program.cs

示例4: GetMessageFromQueue

		public override void GetMessageFromQueue(string messageId, MessageQueue queue, Action<Message> processMethod)
		{
			using (var transaction = new MessageQueueTransaction())
			{
				transaction.Begin();
				Logger.DebugFormat("Transaction for {0} started.", messageId);

				Message message;
				try
				{
					message = queue.ReceiveById(messageId, TimeSpan.FromSeconds(30), transaction);
					Logger.DebugFormat("Message with id {0} received.", messageId);
				}
				catch (Exception ex)
				{
					transaction.Abort();
					Logger.Error(
						string.Concat("Failed to receive message with id ", messageId, "transactions aborted.")
						, ex);
					return;
				}

				if (message != null)
				{
					processMethod(message);
				}

				if (transaction.Status != MessageQueueTransactionStatus.Aborted)
					transaction.Commit();
			}
		}
开发者ID:mickednk,项目名称:MightyLittle.MQ,代码行数:31,代码来源:TransactionalReceive.cs

示例5: ReceiveMessage

        public override async Task ReceiveMessage()
        {
            Message message = null;

            try
            {
                using (var msmqTransaction = new MessageQueueTransaction())
                {
                    msmqTransaction.Begin();

                    if (!TryReceive(msmqTransaction, out message))
                    {
                        return;
                    }

                    Dictionary<string, string> headers;

                    if (!TryExtractHeaders(message, out headers))
                    {
                        MovePoisonMessageToErrorQueue(message, msmqTransaction);

                        msmqTransaction.Commit();
                        return;
                    }

                    var shouldCommit = await ProcessMessage(msmqTransaction, message, headers).ConfigureAwait(false);

                    if (shouldCommit)
                    {
                        msmqTransaction.Commit();
                    }
                    else
                    {
                        msmqTransaction.Abort();
                    }
                }
            }
            // We'll only get here if Commit/Abort/Dispose throws which should be rare.
            // Note: If that happens the attempts counter will be inconsistent since the message might be picked up again before we can register the failure in the LRU cache.
            catch (Exception exception)
            {
                if (message == null)
                {
                    throw;
                }

                failureInfoStorage.RecordFailureInfoForMessage(message.Id, exception);
            }
        }
开发者ID:Particular,项目名称:NServiceBus,代码行数:49,代码来源:SendsAtomicWithReceiveNativeTransactionStrategy.cs

示例6: Main

        static void Main(string[] args)
        {
            string queueName = ConfigurationManager.AppSettings["MSMQLocation"];

            if (args.Count() != 4)
            {
                Console.WriteLine("needs 4 params: sourcedir sourcefiletypes dstdir dstfileformat");
                return;
            }

            try
            {
                MessageQueue rmTxnQ = new MessageQueue(queueName);

                rmTxnQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(ProcessMessage) });

                string[] files = Directory.GetFiles(args[0], args[1], SearchOption.AllDirectories);
                int count = 0;
                foreach (string s in files)
                {
                    MessageQueueTransaction msgTx = new MessageQueueTransaction();
                    msgTx.Begin();
                    try
                    {
                        string argument = "-i \"{0}\" -o \"{1}\" --preset \"" + ConfigurationManager.AppSettings["HandbrakePreset"] + "\"";

                        string destination = args[2] + "\\" + Path.GetFileNameWithoutExtension(s) + args[3];

                        ProcessMessage p = new ProcessMessage() { CommandLine = argument, DestinationUrl = destination, OrignalFileUrl = s };

                        rmTxnQ.Send(p, msgTx);
                        Console.WriteLine("Adding message for {0} to queue", s);
                        count++;
                        msgTx.Commit();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        msgTx.Abort();
                    }
                }
                Console.WriteLine("added {0} items to queue. Queue count now {1}", count, rmTxnQ.GetAllMessages().Count());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:tiernano,项目名称:HandbrakeCluster,代码行数:48,代码来源:Program.cs

示例7: Dequeue

        public IFetchedJob Dequeue(string[] queues, CancellationToken cancellationToken)
        {
            string jobId = null;
            MessageQueueTransaction transaction;
            var queueIndex = 0;

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                queueIndex = (queueIndex + 1) % queues.Length;
                var queueName = queues[queueIndex];

                transaction = new MessageQueueTransaction();

                using (var messageQueue = GetMessageQueue(queueName))
                {
                    try
                    {
                        transaction.Begin();

                        var message = queueIndex == 0
                            ? messageQueue.Receive(SyncReceiveTimeout, transaction)
                            : messageQueue.Receive(new TimeSpan(1), transaction);

                        message.Formatter = _formatter.Value;

                        jobId = (string)message.Body;

                    }
                    catch (MessageQueueException ex)
                    {
                        transaction.Abort();
                        transaction.Dispose();

                        if (ex.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
                        {
                            throw;
                        }
                    }
                }
            } while (jobId == null);

            return new MsmqFetchedJob(transaction, jobId);
        }
开发者ID:henningst,项目名称:HangFire,代码行数:45,代码来源:MsmqJobQueue.cs

示例8: Send

 public void Send(object message)
 {
     var transaction = new MessageQueueTransaction();
     try
     {
         transaction.Begin();
         _messageQueue.Send(message, transaction);
         transaction.Commit();
     }
     catch
     {
         transaction.Abort();
         throw;
     }
     finally
     {
         transaction.Dispose();
     }
 }
开发者ID:larsw,项目名称:Loom.Esb,代码行数:19,代码来源:MsmqTransport.cs

示例9: OnMessagePeeked

 private void OnMessagePeeked(object sender, PeekCompletedEventArgs e)
 {
     var transaction = new MessageQueueTransaction();
     try
     {
         transaction.Begin();
         var message = _messageQueue.Receive(transaction);
         MessageReceived(this, new MessageReceivedEventArgs(message));
     }
     catch
     {
         transaction.Abort();
         throw;
     }
     finally
     {
         transaction.Dispose();
     }
 }
开发者ID:larsw,项目名称:Loom.Esb,代码行数:19,代码来源:MsmqTransport.cs

示例10: DeleteMessage

        void DeleteMessage(Message message)
        {
            using (var queue = new MessageQueue(message.QueuePath))
            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();
                try
                {
                    queue.ReceiveById(message.Id, transaction);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Abort();
                    throw;
                }
            }

            Messenger.Default.Send(new MessageDeleted(message));
        }
开发者ID:rasmuskl,项目名称:Rebus,代码行数:21,代码来源:MsmqInteraction.cs

示例11: runButton_Click

        private void runButton_Click(object sender, EventArgs e)
        {
            int size = (int)sizeNumericUpDown.Value;
            byte[] data = new byte[size];

            for (int i = 0; i < size; i++)
            {
                data[i] = (byte)(i & 0xff);
            }

            int count = (int)countNumericUpDown.Value;
            string queue = queueComboBox.SelectedItem.ToString();

            MessageQueue mq = new MessageQueue(queue);
            MessageQueueTransaction transaction = new MessageQueueTransaction();

            for (int i = 0; i < count; i++)
            {
                System.Messaging.Message message = new System.Messaging.Message();

                message.Label = "Bulk " + i;
                BulkPayload payload = new BulkPayload();
                payload.Count = i;
                payload.Text = "Text " + i;
                payload.Data = data;
                message.Body = payload;

                try
                {
                    transaction.Begin();
                    mq.Send(message, transaction);
                    transaction.Commit();
                }
                finally
                {
                    if (transaction.Status == MessageQueueTransactionStatus.Pending)
                        transaction.Abort();
                }
            }
        }
开发者ID:untoldwind,项目名称:soatools,代码行数:40,代码来源:BulkMessagesForm.cs

示例12: Send

        public void Send(Message message)
        {
            if (Transactional)
            {
                using (var transaction = new MessageQueueTransaction())
                {
                    transaction.Begin();

                    try
                    {
                        Send(message, MessageQueueTransactionType.Single);
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Abort();
                    }
                }
            }
            else
                base.Send(message);
        }
开发者ID:josh28,项目名称:risen,代码行数:22,代码来源:LogMessageQueue.cs

示例13: RunInTransaction

        public void RunInTransaction(Action callback, IsolationLevel isolationLevel, TimeSpan transactionTimeout)
        {
            if (MsmqOnly)
            {
                using (var trans = new MessageQueueTransaction())
                {
                    MsmqUtilities.CurrentTransaction = trans;
                    try
                    {
                        trans.Begin();
                        callback();
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        trans.Abort();
                        throw;
                    }
                    finally
                    {
                        MsmqUtilities.CurrentTransaction = null;
                    }
                }
            }
            else
            {
                using (
                    var scope = new TransactionScope(TransactionScopeOption.Required,
                                                     new TransactionOptions
                                                         {IsolationLevel = isolationLevel, Timeout = transactionTimeout})
                    )
                {
                    callback();

                    scope.Complete();
                }
            }
        }
开发者ID:martinernst,项目名称:NServiceBus,代码行数:38,代码来源:TransactionWrapper.cs

示例14: Submit

 public void Submit()
 {
     using (var queue = new MessageQueue(@".\private$\NoSQLServer"))
     using (var message = new System.Messaging.Message())
     {
         message.Label = string.Format("{0}:{1}", ClassType.Name, aggregate.AggregateID.ToString());
         using (message.BodyStream = new MemoryStream(aggregate.ToAggregateStore().Data))
         {
             var mqTran = new MessageQueueTransaction();
             mqTran.Begin();
             try
             {
                 queue.Send(message);
                 mqTran.Commit();
             }
             catch (Exception ex)
             {
                 mqTran.Abort();
                 throw new Exception("Problem with messaging... ", ex);
             }
         }
     }
 }
开发者ID:jmeirow,项目名称:NoSQLServer,代码行数:23,代码来源:Submitter.cs

示例15: queue_PeekCompleted

        private void queue_PeekCompleted(object sender, PeekCompletedEventArgs e)
        {
            var queue = (MessageQueue)sender;

            var transaction = new MessageQueueTransaction();
            transaction.Begin();
            try
            {
                var message = queue.Receive(transaction);
                var tm = NServiceBus.Utils.MsmqUtilities.Convert(message);
                var audit = tm.To_NServiceBus_Audit_Message();
                Bus.SendLocal(audit);

                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Abort();
            }
            finally
            {
                queue.BeginPeek();
            }
        }
开发者ID:valeriob,项目名称:MessageMonitor,代码行数:24,代码来源:NServiceBus_Queue_Listener.cs


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