Пример #1
0
        public void Respond(MessageQueue responseQueue, MessageQueueTransaction transaction, string correlationId)
        {
            var largeMessage = new LargeMessage(DataBuffer, null, _msmqCapacity, correlationId, null);
            var ttrqPo       = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.PO_TTRQ));
            var ttbrPo       = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.PO_TTBR));

            largeMessage.EncodeExtension(new[] { _id, DateTime.Now.ToBinary().ToString(), false.ToString() });
            largeMessage.Send(responseQueue, transaction, ttrqPo, ttbrPo);
        }
Пример #2
0
        protected override void DistributeMSMQ(KissTransactionMode mode, bool remove,
                                               string[] filter, LargeMessage largeMessage)
        {
            List <MessageQueue>     allQueues       = null;
            MessageQueueTransaction msmqTransaction = null;
            var ttrqPo = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.PO_TTRQ));
            var ttbrPo = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.PO_TTBR));

            try
            {
                largeMessage.EncodeExtension(new[] { _id, DateTime.Now.ToBinary().ToString(), remove.ToString() });
                allQueues = new Neighborhood(_sql, FORMAT_PO_POSTFIX).GetAllQueues(filter);

                if (allQueues.Count > 0)
                {
                    if (mode == KissTransactionMode.MSMQ)
                    {
                        msmqTransaction = new MessageQueueTransaction();
                        msmqTransaction.Begin();
                    }

                    foreach (var queue in allQueues)
                    {
                        largeMessage.Send(queue, msmqTransaction, ttrqPo, ttbrPo);
                    }

                    if (mode == KissTransactionMode.MSMQ)
                    {
                        msmqTransaction.Commit();
                    }
                }
            }
            catch
            {
                if (msmqTransaction != null && mode == KissTransactionMode.MSMQ)
                {
                    msmqTransaction.Abort();
                }

                throw;
            }
            finally
            {
                if (msmqTransaction != null)
                {
                    msmqTransaction.Dispose();
                }

                if (allQueues != null)
                {
                    foreach (var queue in allQueues)
                    {
                        queue.Dispose();
                    }
                }
            }
        }
Пример #3
0
        protected override void DistributeMSMQ(KissTransactionMode mode, bool remove,
                                               string[] filter, LargeMessage largeMessage)
        {
            object   sequenceNumber;
            string   bundleSentChar;
            DateTime bundleSent;
            MessageQueueTransaction msmqTransaction = null;
            List <MessageQueue>     othersQueues    = null;
            var ttrqBundle     = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_TTRQ));
            var ttbrBundle     = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_TTBR));
            var dialogLifetime = Kiss.GetTimeout(KissTimeout.BUNDLE_SSSB);
            var dtctoBundle    = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_DTC_DISTRIBUTION));

            if (remove)
            {
                throw new NotSupportedException("remove");
            }

            try
            {
                othersQueues = new Neighborhood(_sql, FORMAT_BUNDLE_POSTFIX).GetOthersQueues(filter);

                using (var scope = new TransactionScope(TransactionScopeOption.Required, dtctoBundle))
                {
                    bundleSent     = DateTime.Now;
                    bundleSentChar = bundleSent.ToString(FORMAT_BUNDLE_SENT, DateTimeFormatInfo.InvariantInfo);

                    Process(PROCEDURE_BUNDLE_PROCESSING,
                            new[] { new SqlParameter("@client_id", _clientId),
                                    new SqlParameter("@bundle_sent", bundleSent),
                                    new SqlParameter("@bundle_sent_char", bundleSentChar),
                                    new SqlParameter("@dialog_lifetime", dialogLifetime) },
                            "@bundle", out sequenceNumber);

                    largeMessage.EncodeExtension(new[] { sequenceNumber.ToString(),
                                                         _clientId, bundleSent.ToBinary().ToString() });

                    if (mode == KissTransactionMode.DTC)
                    {
                        foreach (var queue in othersQueues)
                        {
                            largeMessage.Send(queue, null, ttrqBundle, ttbrBundle);
                        }
                    }
                    else
                    {
                        using (var suppress = new TransactionScope(TransactionScopeOption.Suppress))
                        {
                            msmqTransaction = new MessageQueueTransaction();
                            msmqTransaction.Begin();

                            foreach (var queue in othersQueues)
                            {
                                largeMessage.Send(queue, msmqTransaction, ttrqBundle, ttbrBundle);
                            }

                            suppress.Complete();
                        }
                    }

                    scope.Complete();
                }

                _id = (long)sequenceNumber;
                SetOutputHeader(string.Format(FORMAT_TO_STRING, _id, _clientId));

                if (mode != KissTransactionMode.DTC)
                {
                    msmqTransaction.Commit();
                }
            }
            catch
            {
                if (msmqTransaction != null && mode == KissTransactionMode.MSMQ)
                {
                    msmqTransaction.Abort();
                }

                throw;
            }
            finally
            {
                if (msmqTransaction != null)
                {
                    msmqTransaction.Dispose();
                }

                if (othersQueues != null)
                {
                    foreach (var queue in othersQueues)
                    {
                        queue.Dispose();
                    }
                }
            }
        }