示例#1
0
 private void Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         Message             message   = messageQueue.Receive(TimeSpan.FromSeconds(2), MessageQueueTransactionType.None);
         XmlMessageFormatter formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
         var intArray = formatter.Read(message);
         messageProcessor.Publish(JsonConvert.DeserializeObject <List <int> >(intArray.ToString()));
     }
     catch (MessageQueueException ex)
     {
         Console.WriteLine(ex);
     }
 }
示例#2
0
        private static void HandleReceivedMSCDMessages()
        {
            MessageQueue        m_msgSenderQueue = new MessageQueue(string.Format(@"Formatname:DIRECT=TCP:{0}\private$\{1}", m_MCSDresponseQueueIP, m_MCSDresponseQueueName));
            XmlMessageFormatter formatter        = new XmlMessageFormatter(new Type[] { typeof(McdrTestReq), typeof(AllocRes) });

            while (true)
            {
                try
                {
                    System.Messaging.Message msg = (System.Messaging.Message)m_msgSenderQueue.Receive();
                    if (msg == null)
                    {
                        continue;
                    }

                    object recievedMsg = formatter.Read(msg);

                    if (recievedMsg.GetType() == typeof(McdrTestReq))
                    {
                        try
                        {
                            IMcdrToAdmin msgTo = new McdrTestRes()
                            {
                                TestKey = ((McdrTestReq)recievedMsg).TestKey
                            };
                            m_clientMcsd.HandleMsg(msgTo);
                        }
                        catch (Exception ex)
                        {
                            Console.Write(ex.ToString());
                        }
                    }
                    else if (recievedMsg.GetType() == typeof(AllocRes))
                    {
                        AllocRes respMsg = (AllocRes)recievedMsg;
                        m_mcsdRouter.PushMessage(respMsg);
                    }
                }
                catch (Exception exp)
                {
                    SystemLogger.LogErrorAsync("Error while handling MCSD Message. Error : " + exp.ToString());
                    continue;
                }
            }
        }
示例#3
0
        static void Method(string json, TypeNameHandling param)
        {
            //Unsafe 2
            var data = JsonConvert.DeserializeObject <Model>(json, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects
            });
            var serializeSettings = new JsonSerializerSettings();

            serializeSettings.TypeNameHandling = TypeNameHandling.All;
            serializeSettings.TypeNameHandling = (TypeNameHandling)2;
            serializeSettings = new JsonSerializerSettings
            {
                TypeNameHandling = param
            };
            serializeSettings.TypeNameHandling = GetHandling("");

            // Unsafe 5
            BinaryMessageFormatter binaryMessage = new System.Messaging.BinaryMessageFormatter();

            binaryMessage.Read(new Message());


            // Unsafe 7
            System.Web.UI.ObjectStateFormatter formatter = new System.Web.UI.ObjectStateFormatter();
            formatter.Deserialize("");
            formatter.Deserialize(new MemoryStream());

            // Unsafe 8
            XmlObjectSerializer xmlObjectSerializer = null;

            xmlObjectSerializer.ReadObject(new MemoryStream());

            // Unsafe 11
            DataContractJsonSerializer dataContractJsonSerializer = new DataContractJsonSerializer(typeof(InsecureDeserialize));

            dataContractJsonSerializer.ReadObject(new MemoryStream());
            dataContractJsonSerializer.ReadObject(XmlDictionaryReader.Create(""));
            dataContractJsonSerializer.ReadObject(XmlDictionaryReader.Create(""), false);
            dataContractJsonSerializer.ReadObject(XmlReader.Create(""));
            dataContractJsonSerializer.ReadObject(XmlReader.Create(""), false);

            // Unsafe 12
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(InsecureDeserialize));

            xmlSerializer.Deserialize(new MemoryStream());
            xmlSerializer.Deserialize(TextReader.Null);
            xmlSerializer.Deserialize(XmlReader.Create(""));
            xmlSerializer.Deserialize(XmlReader.Create(""), "\"");
            xmlSerializer.Deserialize(XmlReader.Create(""), new System.Xml.Serialization.XmlDeserializationEvents());
            xmlSerializer.Deserialize(XmlReader.Create(""), "\"", new System.Xml.Serialization.XmlDeserializationEvents());

            // Unsafe 13
            System.Messaging.XmlMessageFormatter xmlMessageFormatter = new XmlMessageFormatter();
            xmlMessageFormatter.Read(new System.Messaging.Message());

            // Unsafe 14
            System.Resources.ResourceReader resourceReader = new System.Resources.ResourceReader("");
            resourceReader = new System.Resources.ResourceReader(new MemoryStream());

            // Unsafe 15
            fastJSON.JSON.ToObject("");

            // Unsafe 16
            ServiceStack.Text.JsonSerializer.DeserializeFromString("", typeof(InsecureDeserialize));
            ServiceStack.Text.JsonSerializer.DeserializeFromReader(TextReader.Null, typeof(InsecureDeserialize));
            ServiceStack.Text.JsonSerializer.DeserializeFromStream(typeof(InsecureDeserialize), new MemoryStream());

            ServiceStack.Text.TypeSerializer.DeserializeFromString("", typeof(InsecureDeserialize));
            ServiceStack.Text.TypeSerializer.DeserializeFromReader(TextReader.Null, typeof(InsecureDeserialize));
            ServiceStack.Text.TypeSerializer.DeserializeFromStream(typeof(InsecureDeserialize), new MemoryStream());

            ServiceStack.Text.CsvSerializer.DeserializeFromString(typeof(InsecureDeserialize), "");
            ServiceStack.Text.CsvSerializer.DeserializeFromReader <InsecureDeserialize>(TextReader.Null);
            ServiceStack.Text.CsvSerializer.DeserializeFromStream(typeof(InsecureDeserialize), new MemoryStream());

            ServiceStack.Text.XmlSerializer.DeserializeFromString("", typeof(InsecureDeserialize));
            ServiceStack.Text.XmlSerializer.DeserializeFromReader <InsecureDeserialize>(TextReader.Null);
            ServiceStack.Text.XmlSerializer.DeserializeFromStream(typeof(InsecureDeserialize), new MemoryStream());
        }
示例#4
0
        public void StartRecievingMsgs()
        {
            MessageQueue        m_msgSenderQueue = new MessageQueue(@".\private$\client");
            XmlMessageFormatter formatter        = new XmlMessageFormatter(new Type[] { typeof(Fix_OrderAcceptedResponse), typeof(SubscriberInitializationInfo), typeof(AreYouAlive), typeof(SubscriptionStatus), typeof(Fix_OrderRejectionResponse), typeof(Fix_ExecutionReport), typeof(LogOutResponse), typeof(LogOutResponse), typeof(Fix_BusinessMessageReject), typeof(Fix_OrderReplaceCancelReject) });

            if (!m_msgSenderQueue.CanRead)
            {
                // warning
            }
            while (true)
            {
                try
                {
                    //MessageQueueTransaction mqt = new MessageQueueTransaction();
                    //mqt.Begin();
                    System.Messaging.Message msg = (System.Messaging.Message)m_msgSenderQueue.Receive();
                    if (msg == null)
                    {
                        continue;
                    }

                    object recievedMsg = formatter.Read(msg);
                    if (recievedMsg.GetType() == typeof(SubscriptionStatus))
                    {
                        SubscriptionStatus status = (SubscriptionStatus)recievedMsg;
                        if (status.IsSubscribed)
                        {
                            clientKey = status.ClientKey;
                            this.BeginInvoke(new Action(() =>
                            {
                                lblSub.ForeColor = Color.Green;
                                lblSub.Text      = "Subscribed";
                                btnSub.BackColor = Color.Red;
                                btnSub.Text      = "Unsubscribe";
                                isSubscribed     = true;
                                btnSub.Enabled   = true;
                            }
                                                        ));
                        }
                        else
                        {
                            this.BeginInvoke(new Action(() =>
                            {
                                lblSub.ForeColor = Color.Red;
                                lblSub.Text      = "Unsubscribed";
                                btnSub.BackColor = Color.Green;
                                btnSub.Text      = "Subscribe";
                                isSubscribed     = false;
                                btnSub.Enabled   = true;
                            }
                                                        ));
                            //using (OrdersProxy proxy = new OrdersProxy())
                            //{
                            //    string path = string.Format(@"Formatname:DIRECT=TCP:{0}", SystemConfigurations.GetAppSetting("ResponseQueue"));
                            //    proxy.SubscribeSession(path);
                            //}
                        }
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_OrderAcceptedResponse))
                    {
                        Fix_OrderAcceptedResponse resp = (Fix_OrderAcceptedResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} accepted", resp.RequesterOrderID), Color.Green)));
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_ExecutionReport))
                    {
                        Fix_ExecutionReport resp = (Fix_ExecutionReport)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} TotalExecuted: {1}, TradeExecuted: {2}, Remaining {3}, Status : {4}", resp.RequesterOrderID, resp.TotalExecutedQuantity, resp.TradeExecutedQuantity, resp.RemainingQuantity, resp.OrderStatus), Color.Blue)));
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_OrderSuspensionResponse))
                    {
                        Fix_OrderSuspensionResponse resp = (Fix_OrderSuspensionResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} suspended : {1}", resp.RequesterOrderID, resp.Message), Color.Red)));
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_OrderRejectionResponse))
                    {
                        Fix_OrderRejectionResponse resp = (Fix_OrderRejectionResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} rejected : {1}", resp.RequesterOrderID, resp.RejectionReason), Color.Red)));
                    }
                    else if (recievedMsg.GetType() == typeof(AreYouAlive))
                    {
                        AreYouAlive resp = (AreYouAlive)recievedMsg;
                        //m_msgSenderQueue.Send(new AmAlive() { ClientKey = clientKey });
                        using (OrdersProxy proxy = new OrdersProxy())
                        {
                            proxy.HandleRequest(new AmAlive()
                            {
                                ClientKey = clientKey
                            });
                        }
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_OrderReplacedResponse))
                    {
                        Fix_OrderReplacedResponse replace = (Fix_OrderReplacedResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} replaced : Quantity {1} price {2}", replace.RequesterOrderID, replace.Quantity, replace.Price), Color.DarkOrange)));
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error Sending Msg: " + ex.ToString());
                    Console.ResetColor();
                }
            }
        }
        public void StartRecievingMsgs()
        {
            // MessageQueue m_msgSenderQueue = new MessageQueue(string.Format(@"{0}\private$\{1}", SystemConfigurations.GetAppSetting("ResponseQueueIP"), SystemConfigurations.GetAppSetting("ResponseQueueName")));
            MessageQueue m_msgSenderQueue = new MessageQueue(string.Format(@"Formatname:DIRECT=TCP:{0}\private$\{1}", SystemConfigurations.GetAppSetting("ResponseQueueIP"), SystemConfigurations.GetAppSetting("ResponseQueueName")));
            //List<Type> types = System.Reflection.Assembly.Load("Beltone.Services.Fix.Contract").GetTypes().Where(x=>x.IsClass).ToList();
            //types.Add(typeof(Dictionary<string, object>));
            //XmlMessageFormatter formatter = new XmlMessageFormatter(types.ToArray());

            XmlMessageFormatter formatter = new XmlMessageFormatter
                                                (new Type[] { typeof(Fix_OrderReplaceRefusedByService), typeof(FixAdminMsg), typeof(FixAdmin_TestRequest),
                                                              typeof(Fix_OrderAcceptedResponse), typeof(Fix_OrderRejectionResponse), typeof(Fix_ExecutionReport),
                                                              typeof(LogOutResponse), typeof(LogOutResponse), typeof(Fix_BusinessMessageReject), typeof(Fix_OrderReplaceCancelReject),
                                                              typeof(Fix_OrderReplacedResponse),
                                                              typeof(Fix_PendingReplaceResponse), typeof(Fix_OrderRefusedByService), typeof(Fix_PendingNewResponse), typeof(Fix_PendingCancelResponse),
                                                              typeof(Fix_OrderCanceledResponse) });

            //if (!m_msgSenderQueue.CanRead)
            //{
            //    // warning
            //}
            while (true)
            {
                try
                {
                    //MessageQueueTransaction mqt = new MessageQueueTransaction();
                    //mqt.Begin();
                    System.Messaging.Message msg = (System.Messaging.Message)m_msgSenderQueue.Receive();
                    if (msg == null)
                    {
                        continue;
                    }

                    object recievedMsg = formatter.Read(msg);

                    this.BeginInvoke(new Action(() => SetReport(string.Format("Recieved {0}", recievedMsg.GetType().ToString()), Color.DarkGray)));

                    if (recievedMsg.GetType() == typeof(FixAdmin_TestRequest))
                    {
                        try
                        {
                            IToAdminMsg msgTo = new FixAdmin_TestResponse()
                            {
                                TestKey = ((FixAdmin_TestRequest)recievedMsg).TestKey
                            };
                            _client.HandleMsg(msgTo);
                            //_client.HandleRequest(new FixAdmin_TestResponse() { TestKey = "" });
                        }
                        catch (Exception ex)
                        {
                            this.BeginInvoke(new Action(() => MessageBox.Show(ex.Message)));
                        }
                        this.BeginInvoke(new Action(() => SetReport("sent FixAdmin_TestResponse", Color.DarkGray)));
                    }
                    if (recievedMsg.GetType() == typeof(Fix_OrderAcceptedResponse))
                    {
                        Fix_OrderAcceptedResponse resp = (Fix_OrderAcceptedResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} accepted", resp.ReqOrdID), Color.Green)));
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_ExecutionReport))
                    {
                        Fix_ExecutionReport resp = (Fix_ExecutionReport)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} TotalExecuted: {1}, TradeExecuted: {2}, Remaining {3}, Status : {4}", resp.RequesterOrderID, resp.TotalExecutedQuantity, resp.TradeExecutedQuantity, resp.RemainingQuantity, resp.OrderStatus), Color.Blue)));
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_OrderSuspensionResponse))
                    {
                        Fix_OrderSuspensionResponse resp = (Fix_OrderSuspensionResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} suspended : {1}", resp.RequesterOrderID, resp.Message), Color.Red)));
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_OrderRejectionResponse))
                    {
                        Fix_OrderRejectionResponse resp = (Fix_OrderRejectionResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} rejected : {1}", resp.RequesterOrderID, resp.RejectionReason), Color.Red)));
                    }
                    else if (recievedMsg.GetType() == typeof(Fix_OrderReplacedResponse))
                    {
                        Fix_OrderReplacedResponse replace = (Fix_OrderReplacedResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} replaced : Quantity {1} price {2}", replace.ReqOrdID, replace.Qty, replace.Prc), Color.DarkGreen)));
                    }

                    else if (recievedMsg.GetType() == typeof(Fix_OrderRefusedByService))
                    {
                        Fix_OrderRefusedByService refuseMsg = (Fix_OrderRefusedByService)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} refused by service : msessage : {1} ", refuseMsg.RequesterOrderID, refuseMsg.RefuseMessage), Color.DarkOrange)));
                    }

                    else if (recievedMsg.GetType() == typeof(Fix_OrderCanceledResponse))
                    {
                        Fix_OrderCanceledResponse msgCanceled = (Fix_OrderCanceledResponse)recievedMsg;
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order : {0} canceld successfully ! ", msgCanceled.RequesterOrderID), Color.DarkOrange)));
                    }


                    else if (recievedMsg.GetType() == typeof(Fix_PendingNewResponse) || recievedMsg.GetType() == typeof(Fix_PendingReplaceResponse) || recievedMsg.GetType() == typeof(Fix_PendingCancelResponse))
                    {
                        this.BeginInvoke(new Action(() => SetReport(string.Format("order pending"), Color.DarkOrange)));
                    }
                }
                catch (Exception ex)
                {
                    this.BeginInvoke(new Action(() => SetReport(string.Format("Error : {0}", ex.Message), Color.Red)));
                    Thread.Sleep(2000);
                }
            }
        }