protected override void OnProcessMessage(KissTransactionMode mode, MessageQueue queue, Guid conversation)
        {
            long id,
                 maxId = ID_NO_VALUE;
            string clientId,
                   recoveryClient;
            Message bundleControl;
            MessageQueueTransaction transaction = null;
            var convMessages = LargeMessage.GetMessagesOfConversation(queue, conversation);
            var allBundleIds = Bundle.RetrieveAll(_sql);
            var ttrqBundle   = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_TTRQ));
            var ttbrBundle   = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_TTBR));
            var timeout      = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_CONTROL_RECEIVE_TIMEOUT));

            if (mode == KissTransactionMode.DTC)
            {
                throw new NotSupportedException("DTC");
            }

            try
            {
                transaction = new MessageQueueTransaction();
                transaction.Begin();

                bundleControl  = queue.ReceiveById(convMessages[0], timeout, transaction);
                recoveryClient = (string)bundleControl.Body;

                foreach (var bundleId in allBundleIds)
                {
                    id       = long.Parse(bundleId.Split(SEPARATOR_BUNDLE_IDS)[0]);
                    clientId = bundleId.Split(SEPARATOR_BUNDLE_IDS)[1];

                    if (clientId == recoveryClient && id > maxId)
                    {
                        maxId = id;
                    }
                }

                using (var msg = new Message(maxId)
                {
                    CorrelationId = bundleControl.Id,
                    Formatter = bundleControl.Formatter,
                    TimeToReachQueue = ttrqBundle,
                    TimeToBeReceived = ttbrBundle,
                    Extension = LargeMessage.ToMessageExtension(Guid.NewGuid())
                })
                {
                    bundleControl.ResponseQueue.Send(msg, transaction);
                }

                transaction.Commit();
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Dispose();
                }
            }
        }
        protected override void OnProcessMessage(KissTransactionMode mode, MessageQueue queue, Guid conversation)
        {
            Message                 poControl;
            PersistentObject        po;
            MessageQueueTransaction transaction = null;
            var convMessages = LargeMessage.GetMessagesOfConversation(queue, conversation);
            var allPoIds     = PersistentObject.RetrieveAll(_sql);
            var timeout      = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.PO_CONTROL_RECEIVE_TIMEOUT));

            if (mode == KissTransactionMode.DTC)
            {
                throw new NotSupportedException("DTC");
            }

            try
            {
                transaction = new MessageQueueTransaction();
                transaction.Begin();

                poControl = queue.ReceiveById(convMessages[0], timeout, transaction);

                foreach (var poId in allPoIds)
                {
                    po = new PersistentObject(_sql, poId, _msmqCapacity);
                    po.Retrieve();
                    po.Respond(poControl.ResponseQueue, transaction, poControl.Id);
                }

                transaction.Commit();
            }
            finally
            {
                if (transaction != null)
                {
                    transaction.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        protected override void OnProcessMessage(KissTransactionMode mode, MessageQueue queue, Guid conversation)
        {
            string[] extension;
            MessageQueueTransaction msmqTransaction = null;
            var convMessages = LargeMessage.GetMessagesOfConversation(queue, conversation);
            var largeMessage = new LargeMessage(_msmqCapacity, null);
            var dtctoPo      = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.PO_DTC_STORAGE));
            var sqltoPo      = Kiss.GetTimeout(KissTimeout.PO_SQL_STORAGE);

            try
            {
                using (var scope = new TransactionScope(TransactionScopeOption.Required, dtctoPo))
                    using (var kiss = new SqlConnection(Kiss.GetConnection(_sql)))
                        using (var poStorage =
                                   new SqlCommand(PROCEDURE_PO_STORAGE, kiss)
                        {
                            CommandTimeout = sqltoPo,
                            CommandType = CommandType.StoredProcedure
                        })
                            using (var poRemoval =
                                       new SqlCommand(PROCEDURE_PO_REMOVAL, kiss)
                            {
                                CommandTimeout = sqltoPo,
                                CommandType = CommandType.StoredProcedure
                            })
                            {
                                if (mode == KissTransactionMode.DTC)
                                {
                                    largeMessage.Receive(queue, null, convMessages,
                                                         Kiss.GetTimeout(KissTimeout.PO_RECEIVE_TIMEOUT));
                                }
                                else
                                {
                                    using (var suppress = new TransactionScope(TransactionScopeOption.Suppress))
                                    {
                                        msmqTransaction = new MessageQueueTransaction();
                                        msmqTransaction.Begin();

                                        largeMessage.Receive(queue, msmqTransaction, convMessages,
                                                             Kiss.GetTimeout(KissTimeout.PO_RECEIVE_TIMEOUT));

                                        suppress.Complete();
                                    }
                                }

                                extension = largeMessage.DecodeExtension();
                                kiss.Open();

                                if (bool.Parse(extension[2]))
                                {
                                    poRemoval.Parameters.AddWithValue("@po_id", extension[0]);
                                    poRemoval.ExecuteNonQuery();
                                }
                                else
                                {
                                    poStorage.Parameters.AddWithValue("@po_id", extension[0]);
                                    poStorage.Parameters.AddWithValue("@po_sent", DateTime.FromBinary(long.Parse(extension[1])));
                                    poStorage.Parameters.AddWithValue("@po_received", DateTime.Now);
                                    poStorage.Parameters.AddWithValue("@po", largeMessage.DataBuffer);

                                    poStorage.ExecuteNonQuery();
                                }

                                kiss.Close();
                                scope.Complete();
                            }

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

                throw;
            }
            finally
            {
                if (msmqTransaction != null)
                {
                    msmqTransaction.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnProcessMessage(KissTransactionMode mode, MessageQueue queue, Guid conversation)
        {
            string[] extension;
            string   bundleSentChar;
            DateTime bundleSent;
            MessageQueueTransaction msmqTransaction = null;
            var convMessages = LargeMessage.GetMessagesOfConversation(queue, conversation);
            var largeMessage = new LargeMessage(_msmqCapacity, null);
            var dtctoBundle  = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_DTC_STORAGE));
            var sqltoBundle  = Kiss.GetTimeout(KissTimeout.BUNDLE_SQL_STORAGE);

            try
            {
                using (var scope = new TransactionScope(TransactionScopeOption.Required, dtctoBundle))
                    using (var kiss = new SqlConnection(Kiss.GetConnection(_sql)))
                        using (var bundleStorage =
                                   new SqlCommand(PROCEDURE_BUNDLE_STORAGE, kiss)
                        {
                            CommandTimeout = sqltoBundle,
                            CommandType = CommandType.StoredProcedure
                        })
                        {
                            if (mode == KissTransactionMode.DTC)
                            {
                                largeMessage.Receive(queue, null, convMessages,
                                                     Kiss.GetTimeout(KissTimeout.BUNDLE_RECEIVE_TIMEOUT));
                            }
                            else
                            {
                                using (var suppress = new TransactionScope(TransactionScopeOption.Suppress))
                                {
                                    msmqTransaction = new MessageQueueTransaction();
                                    msmqTransaction.Begin();

                                    largeMessage.Receive(queue, msmqTransaction, convMessages,
                                                         Kiss.GetTimeout(KissTimeout.BUNDLE_RECEIVE_TIMEOUT));

                                    suppress.Complete();
                                }
                            }

                            extension = largeMessage.DecodeExtension();

                            bundleSent     = DateTime.FromBinary(long.Parse(extension[2]));
                            bundleSentChar = bundleSent.ToString(FORMAT_BUNDLE_SENT, DateTimeFormatInfo.InvariantInfo);

                            bundleStorage.Parameters.AddWithValue("@bundle_id", long.Parse(extension[0]));
                            bundleStorage.Parameters.AddWithValue("@client_id", extension[1]);
                            bundleStorage.Parameters.AddWithValue("@bundle_sent", bundleSent);
                            bundleStorage.Parameters.AddWithValue("@bundle_received", DateTime.Now);
                            bundleStorage.Parameters.AddWithValue("@bundle_sent_char", bundleSentChar);
                            bundleStorage.Parameters.AddWithValue("@bundle", largeMessage.DataBuffer);

                            kiss.Open();
                            bundleStorage.ExecuteNonQuery();
                            kiss.Close();

                            scope.Complete();
                        }

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

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