Esempio n. 1
0
        //测试函数 定义类提供服务的方法
        public bool AddtoMsgQue(string msg)
        {
            bool returnValue;

            returnValue = false;
            string Path = ".\\Private$\\RMS";

            if (System.Messaging.MessageQueue.Exists(Path))
            {
                System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(Path);
                if (!queue.Transactional)
                {
                    queue.Send(msg);
                    returnValue = true;
                }
            }
            else
            {
                System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(Path);
                queue = System.Messaging.MessageQueue.Create(Path);
                queue.Send(msg);
                returnValue = true;
            }
            return(returnValue);
        }
Esempio n. 2
0
		//传菜
		public bool TransFood(string FoodCode, string TableType, string Tableno, string PsnCount, string billno, string FoodName, string TypeName, string DeptName, string unit, string quantity, string operandi, string taste, string operatorid, string barcode, int OperateCode, string CancelRsn)
		{
			bool returnValue;
			returnValue = false;
			string queuePath = ".\\Private$\\RMS";
			EnsureQueueExists(queuePath);
			
			System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(queuePath);
			queue.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] {typeof(AppExt.CAppExt.FoodInfo)});
			
			AppExt.CAppExt.FoodInfo orderRequest = new AppExt.CAppExt.FoodInfo();
			
			orderRequest.FoodCode = FoodCode;
			orderRequest.TableType = TableType;
			orderRequest.Tableno = Tableno;
			orderRequest.PsnCount = PsnCount;
			orderRequest.Billno = billno;
			orderRequest.FoodName = FoodName;
			orderRequest.TypeName = TypeName;
			orderRequest.DeptName = DeptName;
			orderRequest.unit = unit;
			orderRequest.quantity = quantity;
			orderRequest.operandi = operandi;
			orderRequest.taste = taste;
			orderRequest.operatorid = operatorid;
			orderRequest.BarCode = barcode;
			orderRequest.OperateCode = OperateCode; //OperateCode = 0 传菜 OperateCode = 1 催菜 OperateCode = 2 缓菜 OperateCode = 3 退菜
			orderRequest.CancelRsn = CancelRsn;
			
			queue.Send(orderRequest);
			returnValue = true;
			return returnValue;
		}
Esempio n. 3
0
        public string Ping2(int value)
        {
            var txstatus = TransactionStatus.InDoubt;
            if (Transaction.Current != null)
                txstatus = Transaction.Current.TransactionInformation.Status;

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\n[tid={0}, tx={1}]  *** PING_2 Service: {2} ***\n", Thread.CurrentThread.GetHashCode(), txstatus, value);
            Console.ResetColor();

            var retval = string.Format("[{0}, {1}, Hello from tid={2}]", DateTime.Now.ToShortTimeString(), value, Thread.CurrentThread.GetHashCode());          

            //using (DependentTransaction dtx = Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete))
            {
                // for test purpose we are using MSMQ resource manager
                var mq = new System.Messaging.MessageQueue(strQueueName);
                mq.Send(retval, value.ToString(), System.Messaging.MessageQueueTransactionType.Automatic);

                //throw new Exception("M A N U A L L Y  A B O R T E D");
                //dtx.Complete();
            }

            //Thread.Sleep(62000);

            return retval;
        }
Esempio n. 4
0
        public static void Write(Log log) {

            switch (Foundation.Common.Util.ConfigUtil.GetAppSetting("Logging.Destination").ToLower()) {
                case Logger.DATABASE_LOGSINK:
                    LoggingService.Save(log);
                    break;
                case Logger.MSMQ_LOGSINK:
                    string destinationQ = Foundation.Common.Util.ConfigUtil.GetAppSetting("Logging.MSMQ.Queue.Path");

                    // publish the request to the appropriate message queue
                    System.Messaging.MessageQueue mq = new System.Messaging.MessageQueue(destinationQ);

                    System.Messaging.Message msg = new System.Messaging.Message();
                    msg.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(blogEngine.Shared.Logging.Log) });
                    msg.Body = log;
                    msg.Priority = System.Messaging.MessagePriority.Normal;
                    msg.Recoverable = true;
                    msg.Label = log.LogType.GetType().Name;
                    mq.Send(msg);
                    break;
                default:
                    LoggingService.Save(log);
                    break;
            }
        }
Esempio n. 5
0
        public static void Connect_Server()
        {
            //connection setup
            ircconnect = new TcpClient(SetupClass.Server, SetupClass.port);
            ircstream = ircconnect.GetStream();
            PingClass ping = new PingClass();
            ping.Start();
            reader = new StreamReader(ircstream);
            writer = new StreamWriter(ircstream);

            writer.WriteLine("PING " + "irc.freenode.net");
            writer.Flush();
            writer.WriteLine("USER WPChat 8 * : WrongPlanet IRC Client");
            writer.Flush();
            writer.WriteLine("NICK " + SetupClass.Nick);
            writer.Flush();
            writer.WriteLine("JOIN " + "#wrongplanet");
            writer.Flush();

            while (true)
            {

                //if (reader.ReadLine() != null)
                {
                    System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(@".\Private$\ServerQueue");
                    queue.Send(reader.ReadLine());
                }

            }
        }
Esempio n. 6
0
        //传菜
        public bool TransFood(string FoodCode, string TableType, string Tableno, string PsnCount, string billno, string FoodName, string TypeName, string DeptName, string unit, string quantity, string operandi, string taste, string operatorid, string barcode, int OperateCode, string CancelRsn)
        {
            bool returnValue;
            returnValue = false;
            string queuePath = ".\\Private$\\RMS";
            EnsureQueueExists(queuePath);

            System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(queuePath);
            queue.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] {typeof(AppExt.CAppExt.FoodInfo)});

            AppExt.CAppExt.FoodInfo orderRequest = new AppExt.CAppExt.FoodInfo();

            orderRequest.FoodCode = FoodCode;
            orderRequest.TableType = TableType;
            orderRequest.Tableno = Tableno;
            orderRequest.PsnCount = PsnCount;
            orderRequest.Billno = billno;
            orderRequest.FoodName = FoodName;
            orderRequest.TypeName = TypeName;
            orderRequest.DeptName = DeptName;
            orderRequest.unit = unit;
            orderRequest.quantity = quantity;
            orderRequest.operandi = operandi;
            orderRequest.taste = taste;
            orderRequest.operatorid = operatorid;
            orderRequest.BarCode = barcode;
            orderRequest.OperateCode = OperateCode; //OperateCode = 0 传菜 OperateCode = 1 催菜 OperateCode = 2 缓菜 OperateCode = 3 退菜
            orderRequest.CancelRsn = CancelRsn;

            queue.Send(orderRequest);
            returnValue = true;
            return returnValue;
        }
Esempio n. 7
0
        public static void Write(Log log)
        {
            switch (ConfigurationManager.AppSettings["Logging.Destination"].ToLower()) {
                case Logger.DATABASE_LOGSINK:
                    log.Save();
                    break;
                case Logger.MSMQ_LOGSINK:
                    string destinationQ = ConfigurationManager.AppSettings["Logging.MSMQ.Queue.Path"];

                    // publish the request to the appropriate message queue
                    System.Messaging.MessageQueue mq = new System.Messaging.MessageQueue(destinationQ);

                    System.Messaging.Message msg = new System.Messaging.Message();
                    msg.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(Log) });
                    msg.Body = log;
                    msg.Priority = System.Messaging.MessagePriority.Normal;
                    msg.Recoverable = true;
                    msg.Label = log.LogType.GetType().Name;
                    mq.Send(msg);
                    break;
                default:
                    log.Save();
                    break;
            }
        }
Esempio n. 8
0
        public string Ping2(int value)
        {
            var txstatus = TransactionStatus.InDoubt;

            if (Transaction.Current != null)
            {
                txstatus = Transaction.Current.TransactionInformation.Status;
            }

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\n[tid={0}, tx={1}]  *** PING_2 Service: {2} ***\n", Thread.CurrentThread.GetHashCode(), txstatus, value);
            Console.ResetColor();

            var retval = string.Format("[{0}, {1}, Hello from tid={2}]", DateTime.Now.ToShortTimeString(), value, Thread.CurrentThread.GetHashCode());

            //using (DependentTransaction dtx = Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete))
            {
                // for test purpose we are using MSMQ resource manager
                var mq = new System.Messaging.MessageQueue(strQueueName);
                mq.Send(retval, value.ToString(), System.Messaging.MessageQueueTransactionType.Automatic);

                //throw new Exception("M A N U A L L Y  A B O R T E D");
                //dtx.Complete();
            }

            //Thread.Sleep(62000);

            return(retval);
        }
Esempio n. 9
0
        public virtual void Publish(TEvnt eventToBePublished)
        {
            if (string.IsNullOrEmpty(this.QueuePath))
            {
                return;
            }

            Utilities.CreateIfNotExist(new MessageQueueRequest
            {
                IsTransactional = this.IsTransactional,
                QueuePath       = this.QueuePath
            });

            using (var mq = new System.Messaging.MessageQueue(this.QueuePath))
            {
                mq.Formatter = _formatter;
                if (this.Logger != null)
                {
                    this.Logger.Debug(string.Format("Sending Event '{1}' to Message Queue '{0}' with publisher '{2}'", this.QueuePath, typeof(TEvnt).Name, this.GetType().Name));
                }

                mq.Send(eventToBePublished);

                if (this.Logger != null)
                {
                    this.Logger.Debug(string.Format("Sent Event '{1}' to Message Queue '{0}' with publisher '{2}'", this.QueuePath, typeof(TEvnt).Name, this.GetType().Name));
                }

                mq.Close();
            }
        }
Esempio n. 10
0
        public void SendLockReleaseRequest(Business.Test.AccessionOrder accessionOrder)
        {
            LockReleaseRequestMessageBody messageBody = new LockReleaseRequestMessageBody(accessionOrder.MasterAccessionNo, accessionOrder.LockAquiredByUserName, accessionOrder.LockAquiredByHostName, accessionOrder.TimeLockAquired.Value);

            System.Messaging.Message message = new System.Messaging.Message(messageBody);

            message.ResponseQueue = new System.Messaging.MessageQueue(Environment.MachineName + "\\" + LockReleaseResponseQueueName);
            System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(messageBody.LockAquiredByHostName + "\\" + LockReleaseRequestQueueName);
            queue.Send(message);

            MessageQueueMessage messageQueueMessage = new MessageQueueMessage(message, MessageDirectionEnum.Sent);

            this.m_MessageCollection.Insert(0, messageQueueMessage);
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            try
            {
                System.Messaging.MessageQueue Queue;
                Queue = new System.Messaging.MessageQueue(@"FormatName:DIRECT=TCP:172.26.230.2\ptest1");

                System.Messaging.Message Msg;
                Msg           = new System.Messaging.Message();
                Msg.Formatter = new System.Messaging.BinaryMessageFormatter();
                Msg.Body      = "Testing   3   times";
                Queue.Send(Msg);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            try
            {
                System.Messaging.MessageQueue Queue;
                Queue = new System.Messaging.MessageQueue(@"FormatName:DIRECT=TCP:172.26.230.2\ptest1");

                System.Messaging.Message Msg;
                Msg = new System.Messaging.Message();
                Msg.Formatter = new System.Messaging.BinaryMessageFormatter();
                Msg.Body = "Testing   3   times";
                Queue.Send(Msg);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 13
0
        public bool EnviarMensaje(Eventos evt, string xmlParams)
        {
            bool retVal = false;

            System.Messaging.Message msg = new System.Messaging.Message();
            msg.Body = new objMensaje(evt, xmlParams);

            try
            {
                msgQueue.Send(msg);
                retVal = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " " + ex.InnerException.Message);
            }

            return(retVal);
        }
        internal static void SendMessageToQueue(string mqPath, string mqName, string mqLabel, string mqMessage)
        {
            try
            {
                mqPath    = @mqPath;
                mqName    = @mqName;
                mqMessage = @mqMessage;

                queueCreate(mqPath, mqName);

                System.Messaging.MessageQueue mq = new System.Messaging.MessageQueue(mqPath);
                mq.DefaultPropertiesToSend.Recoverable = true;
                mq.Send(mqMessage, mqLabel);
            }
            catch (System.Exception ex)
            {
                HandleError(ex);
            }
        }
Esempio n. 15
0
        public void Ping(int value)
        {
            //Thread.Sleep(4000);
            var txstatus = TransactionStatus.InDoubt;
            if (Transaction.Current != null)
                txstatus = Transaction.Current.TransactionInformation.Status;

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\n[tid={0}, tx={1}]  *** PING Service: {2} ***\n", Thread.CurrentThread.GetHashCode(), txstatus, value);
            Console.ResetColor();

            //Thread.Sleep(5000);

            // for test purpose we are using MSMQ resource manager
            var mq = new System.Messaging.MessageQueue(strQueueName);
            mq.Send("This is a test message", value.ToString(), System.Messaging.MessageQueueTransactionType.Automatic);

            //if(state == 2)
            //throw new Exception("M A N U A L L Y  A B O R T E D");
        }
Esempio n. 16
0
 //测试函数 定义类提供服务的方法
 public bool AddtoMsgQue(string msg)
 {
     bool returnValue;
     returnValue = false;
     string Path = ".\\Private$\\RMS";
     if (System.Messaging.MessageQueue.Exists(Path))
     {
         System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(Path);
         if (! queue.Transactional)
         {
             queue.Send(msg);
             returnValue = true;
         }
     }
     else
     {
         System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(Path);
         queue = System.Messaging.MessageQueue.Create(Path);
         queue.Send(msg);
         returnValue = true;
     }
     return returnValue;
 }
Esempio n. 17
0
        public void Ping(int value)
        {
            //Thread.Sleep(4000);
            var txstatus = TransactionStatus.InDoubt;

            if (Transaction.Current != null)
            {
                txstatus = Transaction.Current.TransactionInformation.Status;
            }

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\n[tid={0}, tx={1}]  *** PING Service: {2} ***\n", Thread.CurrentThread.GetHashCode(), txstatus, value);
            Console.ResetColor();

            //Thread.Sleep(5000);

            // for test purpose we are using MSMQ resource manager
            var mq = new System.Messaging.MessageQueue(strQueueName);

            mq.Send("This is a test message", value.ToString(), System.Messaging.MessageQueueTransactionType.Automatic);

            //if(state == 2)
            //throw new Exception("M A N U A L L Y  A B O R T E D");
        }
Esempio n. 18
0
        /// <summary>
        /// For Asynchroneous Reporting...
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">     </param>
        protected internal static void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            string result = "Message sent at " + DateTime.Now.ToString();
            Type   tipo   = e.UserState.GetType();

            if (tipo.Equals(typeof(object[])))
            {
                object[] pkg = e.UserState as object[];

                System.Messaging.MessageQueue qu     = pkg[0] as System.Messaging.MessageQueue;
                System.Net.Mail.MailMessage   mail   = pkg[1] as System.Net.Mail.MailMessage;
                System.Net.Mail.SmtpClient    client = sender as System.Net.Mail.SmtpClient;

                System.Messaging.Message m = new System.Messaging.Message();
                if (e.Error != null)
                {
                    m.Body  = new Exception(e.Error.Message);
                    m.Label = "AsyncEmail FAILED";
                }
                else
                {
                    if (mail.Attachments.Count > 0)
                    {
                        Attachment           at     = mail.Attachments[0];
                        System.IO.FileStream stream = (System.IO.FileStream)at.ContentStream;
                        m.Body = stream.Name;
                        // stream.Unlock(0, stream.Length);
                        stream.Close();
                        stream.Dispose();
                        ///NOT USED BUT COULD BE

                        /*
                         * byte[] array = new byte[stream.Length];
                         * stream.Read(array, 0, (int)stream.Length);
                         * stream.Close();
                         * stream.Dispose();
                         * m.Extension = array;
                         */
                    }
                    m.Label = "AsyncEmail OK";
                }
                m.Formatter   = new System.Messaging.BinaryMessageFormatter();
                m.AppSpecific = 1;
                System.Messaging.MessageQueueTransaction mqt = new System.Messaging.MessageQueueTransaction();
                mqt.Begin();
                qu.Send(m, mqt);
                mqt.Commit();
                mqt.Dispose();
                mqt = null;
                m.Dispose();
                m = null;

                Dispose(ref client, ref mail);

                qu.BeginReceive();
            }
            else
            {
                if (e.Cancelled)
                {
                    System.Windows.Forms.MessageBox.Show(e.Error.Message, "Email Cancelled", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                }
                if (e.Error != null)
                {
                    System.Windows.Forms.MessageBox.Show(e.Error.Message, "Email NOT Sent!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
                else if (!e.Cancelled)
                {
                    System.Windows.Forms.MessageBox.Show(result, "Email Sent!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                }
            }
        }
Esempio n. 19
0
 public void Publish(byte[] message)
 {
     MSMessageQueue.Send(message);
 }
Esempio n. 20
0
        public void SendLockReleaseRequest(Business.Test.AccessionOrder accessionOrder)
        {
            LockReleaseRequestMessageBody messageBody = new LockReleaseRequestMessageBody(accessionOrder.MasterAccessionNo, accessionOrder.LockAquiredByUserName, accessionOrder.LockAquiredByHostName, accessionOrder.TimeLockAquired.Value);
            System.Messaging.Message message = new System.Messaging.Message(messageBody);

            message.ResponseQueue = new System.Messaging.MessageQueue(Environment.MachineName + "\\" + LockReleaseResponseQueueName);
            System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(messageBody.LockAquiredByHostName + "\\" + LockReleaseRequestQueueName);
            queue.Send(message);

            MessageQueueMessage messageQueueMessage = new MessageQueueMessage(message, MessageDirectionEnum.Sent);
            this.m_MessageCollection.Insert(0, messageQueueMessage);
        }
Esempio n. 21
0
 public void SubmitOrder(WorkOrder theWorkOrder)
 {
     messageQueueOrders.Send(theWorkOrder);
 }
Esempio n. 22
0
        // Handle poison message exception by moving the poison message out of the way for regular processing to continue.
        public bool HandleError(Exception error)
        {
            MsmqPoisonMessageException poisonException = error as MsmqPoisonMessageException;

            if (null != poisonException)
            {
                long lookupId = poisonException.MessageLookupId;
                Console.WriteLine(" Poisoned message -message look up id = {0}", lookupId);

                // Get MSMQ queue name from app settings in configuration.

                System.Messaging.MessageQueue orderQueue         = new System.Messaging.MessageQueue(OrderProcessorService.QueueName);
                System.Messaging.MessageQueue poisonMessageQueue = new System.Messaging.MessageQueue(OrderProcessorService.PoisonQueueName);
                System.Messaging.Message      message            = null;

                // Use a new transaction scope to remove the message from the main app queue and add it to the poison queue
                // the poison message service processes messages from the poison queue.
                using (TransactionScope txScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    int retryCount = 0;
                    while (retryCount < 3)
                    {
                        retryCount++;

                        try
                        {
                            // Look up the poison message using the look up id.
                            message = orderQueue.ReceiveByLookupId(lookupId);
                            if (message != null)
                            {
                                // send the message to the poison message queue.
                                poisonMessageQueue.Send(message, System.Messaging.MessageQueueTransactionType.Automatic);

                                // complete transaction scope
                                txScope.Complete();

                                Console.WriteLine("Moved poisoned message with look up id: {0} to poison queue: {1} ", lookupId, OrderProcessorService.PoisonQueueName);
                                break;
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            //Code for the case when the message may still not be available in the queue because of a race condition in the transaction or
                            //another node in the farm may actually have taken the message.
                            if (retryCount < 3)
                            {
                                Console.WriteLine("Trying to move poison message but message is not available, sleeping for 10 seconds before retrying");
                                Thread.Sleep(TimeSpan.FromSeconds(10));
                            }
                            else
                            {
                                Console.WriteLine("Giving up on trying to move the message");
                            }
                        }
                    }
                }

                // restart service host
                Console.WriteLine();
                Console.WriteLine("Restarting the service to process rest of the messages in the queue");
                Console.WriteLine("Press <ENTER> to stop the service");
                ThreadPool.QueueUserWorkItem(orderProcessingCallback);
                return(true);
            }

            return(false);
        }
Esempio n. 23
0
 public void SubmitForInvoicing(WorkOrder theWorkOrder)
 {
     messageQueueVehiclesToInvoice.Send(theWorkOrder);
 }
Esempio n. 24
0
        private void StartSystem(object sender, DoWorkEventArgs e)
        {
            Bot.OnCallbackQuery += BotOnCallbackQueryReceived;
            //Bot.OnInlineQuery += BotOnInlineQueryReceived;
            Bot.OnInlineResultChosen += BotOnChosenInlineResultReceived;
            Bot.OnReceiveError       += BotOnReceiveError;
            Bot.OnMessage            += BotOnMessageReceived;

            Bot.StartReceiving();


            System.Messaging.MessageQueue msgQ = new System.Messaging.MessageQueue(".\\Private$\\botshoppayment");


            EventLog.WriteEntry("BotHandler", "Queue intialized", EventLogEntryType.Warning, 240);


            Access.Queue_Payment pm_input = new Access.Queue_Payment();
            Object o = new Object();

            Type[] arrTypes = new Type[2];
            arrTypes[0]    = pm_input.GetType();
            arrTypes[1]    = o.GetType();
            msgQ.Formatter = new System.Messaging.XmlMessageFormatter(arrTypes);

            while (_Die == false)
            {
                try
                {
                    EventLog.WriteEntry("BotHandler", "Listener intialized", EventLogEntryType.Warning, 241);

                    pm_input = (Queue_Payment)msgQ.Receive().Body;

                    EventLog.WriteEntry("BotHandler", "Item receieved", EventLogEntryType.Warning, 242);

                    if (pm_input.Store != ConfigurationManager.AppSettings["StoreName"])
                    {
                        string sSource = "BotHandler";

                        EventLog.WriteEntry(sSource, "Item return to queue", EventLogEntryType.Warning, 234);

                        System.Messaging.Message msg = new System.Messaging.Message();
                        msg.Body = pm_input;
                        msgQ.Send(msg);
                        continue;
                    }
                    else
                    {
                        try
                        {
                            EventLog.WriteEntry("BotHandler", "Item handled", EventLogEntryType.Warning, 243);

                            using (Access.GoldoonEntities db = new Access.GoldoonEntities())
                            {
                                var _getOrder = db.Orders.Where(a => a.Id == pm_input.OrderId).FirstOrDefault();
                                if (_getOrder != null)
                                {
                                    _getOrder.Status        = Logic.Utilities.EnumStatus.Paid;
                                    _getOrder.Paymetn_Refid = pm_input.RefId;

                                    db.SaveChanges();

                                    var _getCart = db.Carts.Where(a => a.User_Id == _getOrder.UserId).ToList();
                                    db.Carts.RemoveRange(_getCart);
                                    db.SaveChanges();

                                    var keyboard = new InlineKeyboardMarkup(new[]
                                    {
                                        new[]
                                        {
                                            InlineKeyboardButton.WithCallbackData(Logic.Utilities.Enum.Home.Text, Logic.Utilities.Enum.Home.Command)
                                        }
                                    });

                                    var sb = new StringBuilder();
                                    sb.AppendLine("پرداخت انجام شده و سفارش شما ثبت شد، به همین زودیا بهتون خبر میدیم");
                                    sb.AppendLine("شماره پیگیری : " + pm_input.RefId);


                                    Bot.SendTextMessageAsync(_getOrder.User.Token, sb.ToString(),
                                                             replyMarkup: keyboard);


                                    string[] admin = ConfigurationManager.AppSettings["AdminToken"].Split('-');
                                    sb.Clear();
                                    sb.AppendLine("سفارش جدید");
                                    sb.AppendLine("@" + _getOrder.User.Username + "به نام " + _getOrder.User.Name);
                                    sb.AppendLine("سفارشات :");

                                    int TotalPrice = 0;
                                    foreach (var ord in _getOrder.OrderItems)
                                    {
                                        sb.AppendLine(ord.Product.Name + "-" + ord.Quantity);
                                        TotalPrice = TotalPrice + (ord.Product.Price.HasValue ? ord.Product.Price.Value : 0);
                                    }
                                    sb.AppendLine("مبلغ پرداخت شده :" + TotalPrice);
                                    sb.AppendLine("شماره پیگیری : " + pm_input.RefId);


                                    foreach (var item in admin)
                                    {
                                        Bot.SendTextMessageAsync(item, sb.ToString(),
                                                                 replyMarkup: new ReplyKeyboardRemove());
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            string sSource = "BotHandler";

                            EventLog.WriteEntry(sSource, ex.ToString(), EventLogEntryType.Warning, 236);
                        }
                    }
                }
                catch (Exception ex)
                {
                    EventLog.WriteEntry("BotHandler", ex.ToString(), EventLogEntryType.Warning, 295);
                }
            }
        }
 // Handle poison message exception by moving the offending message out of the way for regular processing to go on.
 public bool HandleError(Exception error)
 {
     MsmqPoisonMessageException poisonException = error as MsmqPoisonMessageException;
     //Note--we only want to handle poison messages coming from a durable/transacted MSMQ here.
     //So if this is not the exception type, don't do anything.  Note that errors on
     //TCP, HTTP and non-transacted (volatile) MSMQ bindings for the Trade Service will attempt,
     //on their own, to send an order to the poison queue if an exception occurs.  However, a poison
     //message in a durable queue is a special, important case that is handled here such that the
     //order message is never lost, yet is removed from the main processing queue so processing
     //is not interrupted and the queue is kept "clean."
     if (null != poisonException)
     {
         // Use a new transaction scope to remove the message from the main application queue and add it to the poison queue.
         // The poison message service processes messages from the poison queue.
         using (TransactionScope txScope = new TransactionScope(TransactionScopeOption.RequiresNew))
         {
             long lookupId = poisonException.MessageLookupId;
             ConfigUtility.writeErrorConsoleMessage(" Poisoned message: message look up id = " + lookupId + "\n",EventLogEntryType.Information,true,new Settings());
             // Get MSMQ queue name from app settings in configuration.
             if (!System.Messaging.MessageQueue.Exists(Settings.QUENAMEPOISON))
             {
                 ConfigUtility.writeErrorConsoleMessage("Creating Poison Message Queue: \n", EventLogEntryType.Information, true, new Settings());
                 ConfigUtility.writeErrorConsoleMessage(Settings.QUENAMEPOISON + "\n\n", EventLogEntryType.Information, true, new Settings());
                 System.Messaging.MessageQueue.Create(Settings.QUENAMEPOISON, true);
             }
             HostedServices opsService = Settings.hostedServices.Find(delegate(HostedServices hs) { return (hs.BindingType.Equals(ConfigUtility.NET_MSMQ_BINDING)); });
             string tempqueuenametx = @".\private$\" + opsService.VirtualPath;
             System.Messaging.MessageQueue orderQueue = new System.Messaging.MessageQueue(tempqueuenametx);
             System.Messaging.MessageQueue poisonMessageQueue = new System.Messaging.MessageQueue(Settings.QUENAMEPOISON);
             System.Messaging.Message message = null;
        
             int retryCount = 0;
             while (retryCount < 4)
             {
                 retryCount++;
                 try
                 {
                     // Look up the poison message using the look up id.
                     message = orderQueue.ReceiveByLookupId(lookupId);
                     if (message != null)
                     {
                         // Send the message to the poison message queue.
                         if (Settings.NOPOISONQUEUE)
                         {
                             ConfigUtility.writeErrorConsoleMessage("Running in /nopoisonq mode:  message is being removed and discarded!\n", EventLogEntryType.Warning, true, new Settings());
                             txScope.Complete();
                             break;
                         }
                         else
                         {
                             poisonMessageQueue.Send(message, System.Messaging.MessageQueueTransactionType.Automatic);
                             // complete transaction scope
                             txScope.Complete();
                             string writemessage = string.Format("Moved poisoned message with look up id: {0} to poison queue: {1} ", lookupId, Settings.QUENAMEPOISON);
                             ConfigUtility.writeErrorConsoleMessage(writemessage + "\n\n", EventLogEntryType.Information, true, new Settings());
                             break;
                         }
                     }
                 }
                 catch (InvalidOperationException)
                 {
                     //Code for the case when the message may still not be available in the queue because of a race in transaction or 
                     //another node in the farm may actually have taken the message.
                     if (retryCount < 2)
                     {
                         ConfigUtility.writeErrorConsoleMessage("Trying to move poison message but message is not available.  Will retry in 500 ms. \n", EventLogEntryType.Warning, true, new Settings());
                         Thread.Sleep(1000);
                     }
                     else
                     {
                        //The message will remain in the main queue in this condition. 
                         ConfigUtility.writeErrorConsoleMessage("Giving up on trying to move the message:  May have been automatically moved already to the local retry queue on Vista/Win Server 2008 depending on binding setting!\n", EventLogEntryType.Warning, true, new Settings());
                     }
                 }
             }
         }
         return true;
     }
     return false;
 }
Esempio n. 26
0
        // Handle poison message exception by moving the offending message out of the way for regular processing to go on.
        public bool HandleError(Exception error)
        {
            MsmqPoisonMessageException poisonException = error as MsmqPoisonMessageException;
            if (null != poisonException)
            {
                long lookupId = poisonException.MessageLookupId;
                Console.WriteLine(" Poisoned message -message look up id = {0}", lookupId);

                // Get MSMQ queue name from app settings in configuration.

                System.Messaging.MessageQueue orderQueue = new System.Messaging.MessageQueue(Poisoned.WcfService.Properties.Settings.Default.QueueName);
                System.Messaging.MessageQueue poisonMessageQueue = new System.Messaging.MessageQueue(Poisoned.WcfService.Properties.Settings.Default.PoisonQueueName);
                System.Messaging.Message message = null;

                // Use a new transaction scope to remove the message from the main application queue and add it to the poison queue.
                // The poison message service processes messages from the poison queue.
                using (TransactionScope txScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    int retryCount = 0;
                    while (retryCount < 3)
                    {
                        retryCount++;

                        try
                        {
                            // Look up the poison message using the look up id.
                            message = orderQueue.ReceiveByLookupId(lookupId);
                            if (message != null)
                            {
                                // Send the message to the poison message queue.
                                poisonMessageQueue.Send(message, System.Messaging.MessageQueueTransactionType.Automatic);

                                // complete transaction scope
                                txScope.Complete();

                                Console.WriteLine("Moved poisoned message with look up id: {0} to poison queue: {1} ", lookupId, Poisoned.WcfService.Properties.Settings.Default.PoisonQueueName);
                                break;
                            }

                        }
                        catch (InvalidOperationException)
                        {
                            //Code for the case when the message may still not be available in the queue because of a race condition in transaction or 
                            //another node in the farm may actually have taken the message.
                            if (retryCount < 3)
                            {
                                Console.WriteLine("Trying to move poison message but message is not available, sleeping for 10 seconds before retrying");
                                Thread.Sleep(TimeSpan.FromSeconds(10));
                            }
                            else
                            {
                                Console.WriteLine("Giving up on trying to move the message");
                            }
                        }

                    }
                }

                // Restart the service host.
                Console.WriteLine();
                Console.WriteLine("Restarting the service to process rest of the messages in the queue");
                Console.WriteLine("Press <ENTER> to stop the service");
                //ThreadPool.QueueUserWorkItem(orderProcessingCallback);
                return true;
            }

            return false;
        }
Esempio n. 27
0
 public void SubmitForAssembly(WorkOrder theWorkOrder)
 {
     messageQueueVehiclesToAssemble.Send(theWorkOrder);
 }