//Here we will process the rejected messages and see if that's ok or not
        protected void ProcessReject(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper rejectWrapper = (Wrapper)param;

                    string key  = (string)rejectWrapper.GetField(RejectFields.KEY);
                    string text = (string)rejectWrapper.GetField(RejectFields.Text);

                    if (TimeoutOrders.ContainsKey(key))
                    {
                        TimeoutOrders.Remove(key);
                    }

                    //Implement rejects
                    if (OrdersSent.ContainsKey(key))
                    {
                        DoLog(string.Format("<{0}>-Received reject message for Cl. Order Id {1}:{2}", Configuration.Name, key, text), Constants.MessageType.AssertFailed);
                        OrdersSent.Remove(key);
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("{0}-Critical error processing a reject:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error);
            }
        }
示例#2
0
        //Here we will process the rejected messages and see if that's ok or not
        protected void ProcessReject(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper rejectWrapper = (Wrapper)param;

                    string key  = (string)rejectWrapper.GetField(RejectFields.KEY);
                    string text = (string)rejectWrapper.GetField(RejectFields.Text);

                    if (TimeoutOrders.ContainsKey(key))
                    {
                        TimeoutOrders.Remove(key);
                    }

                    //Implement rejects

                    if (OrdersSent.ContainsKey(key))
                    {
                        //Validar que el error es por Extra Tags
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("{0}-Critical error processing a reject:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error);
            }
        }
        //Here we will process the rejected messages and see if that's ok or not
        protected void ProcessReject(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper rejectWrapper = (Wrapper)param;

                    string key  = (string)rejectWrapper.GetField(RejectFields.KEY);
                    string text = (string)rejectWrapper.GetField(RejectFields.Text);

                    if (TimeoutOrders.ContainsKey(key))
                    {
                        TimeoutOrders.Remove(key);
                    }

                    if (MessageOk.ContainsKey(key))
                    {
                        string refTag = (string)rejectWrapper.GetField(RejectFields.RefTagID);
                        //We expected the message to be ok but it was ejected
                        DoLog(string.Format("<{0}>-Test case FAILED for Order ClOrdId = {1}. We expected the order to be ok but it was rejected. Reason={2} Tag={3}", Configuration.Name, key, text, refTag != null ? refTag : "??"),
                              Constants.MessageType.AssertFailed);
                    }

                    if (MissingTags.ContainsKey(key))
                    {
                        string refTag = (string)rejectWrapper.GetField(RejectFields.RefTagID);
                        if (MissingTags[key] == refTag)
                        {
                            DoLog(string.Format("<{0}>-Test case OK for ClOrdId ={1}. Expected to have a message rejected for  missing tag ={2} and it was rejected for that tag", Configuration.Name, key, refTag), Constants.MessageType.AssertOk);
                        }
                        else
                        {
                            DoLog(string.Format("<{0}>-Test case FAILED for ClOrdId ={1}. Expected to have a message rejected for  missing tag ={2} but it was rejected for tag {3}", Configuration.Name, key, MissingTags[key], refTag), Constants.MessageType.AssertFailed);
                        }
                    }

                    if (ExtraTags.ContainsKey(key))
                    {
                        //Validar que el error es por Extra Tags
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("{0}-Critical error processing a reject:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error);
            }
        }
        protected void ProcessTimeouts(object param)
        {
            try
            {
                while (true)
                {
                    lock (TimeoutOrders)
                    {
                        List <string> toRemove = new List <string>();
                        foreach (string key in TimeoutOrders.Keys)
                        {
                            TimeSpan elapsed = DateTime.Now - TimeoutOrders[key];

                            if (elapsed.TotalSeconds > Configuration.TimeoutInSeconds)
                            {
                                string received = "(none)";
                                if (LastProcessedCounter.ContainsKey(key))
                                {
                                    received = LastProcessedCounter[key].ToString();
                                }

                                DoLog(string.Format("<{0}>- TIMEOUT waiting for ERs for ClOrdId {1}. Received {2} - Expected {3}",
                                                    Configuration.Name, key, received, Configuration.ExecutionReportsPerOrder),
                                      Constants.MessageType.AssertFailed);

                                toRemove.Add(key);
                            }
                        }

                        toRemove.ForEach(x => TimeoutOrders.Remove(x));
                    }

                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("<{0}>- Critical error cleaning timedout Execution Reports:{1}",
                                    Configuration.Name, ex.Message),
                      Constants.MessageType.AssertFailed);
            }
        }
        protected void ProcessExecutionReport(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper erWrapper = (Wrapper)param;

                    string key = (string)erWrapper.GetField(ExecutionReportFields.KEY);


                    if (TimeoutOrders.ContainsKey(key))
                    {
                        TimeoutOrders.Remove(key);
                    }

                    if (MessageOk.ContainsKey(key))
                    {
                        //We expected the message to be ok but it was ejected
                        DoLog(string.Format("<{0}>-Test case OK for Order ClOrdId = {1}. We expected a valid ER and that was received.", Configuration.Name, key), Constants.MessageType.AssertOk);
                    }

                    if (MissingTags.ContainsKey(key))
                    {
                        DoLog(string.Format("<{0}>-Test case FAILED for ClOrdId ={1}. Expected a missing tag {2} but received an Ok Execution Report", Configuration.Name, key, MissingTags[key]), Constants.MessageType.AssertFailed);
                    }

                    if (ExtraTags.ContainsKey(key))
                    {
                        DoLog(string.Format("<{0}>-Test case FAILED for ClOrdId ={1}. Expected an extra tag {2} but received an Ok Execution Report", Configuration.Name, key, ExtraTags[key]), Constants.MessageType.AssertFailed);
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("{0}-Critical error processing a execution report:{1}", Configuration.Name, ex.Message), Constants.MessageType.Error);
            }
        }
        protected void ProcessExecutionReport(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper erWrapper = (Wrapper)param;

                    string key = (string)erWrapper.GetField(ExecutionReportFields.KEY);

                    string orderId   = (string)erWrapper.GetField(ExecutionReportFields.OrderID);
                    string clOrderId = (string)erWrapper.GetField(ExecutionReportFields.ClOrdID);

                    if (MessageOk.ContainsKey(key))
                    {
                        ExecutionReportsReceived[key]++;

                        if (ExecutionReportsReceived[key] == Configuration.ResponsesToArrive)
                        {
                            TimeoutOrders.Remove(key);
                            DoLog(string.Format("<{0}>- Received {1} ERs with order id {2}", Configuration.Name, ExecutionReportsReceived[key], orderId), Constants.MessageType.AssertOk);
                        }
                        else if (ExecutionReportsReceived[key] > Configuration.ResponsesToArrive)
                        {
                            DoLog(string.Format("<{0}>- Received {1} ERs for ClOrdId {2}. This is more than expected (max {3})!!!!",
                                                Configuration.Name, ExecutionReportsReceived[key], clOrderId, Configuration.ResponsesToArrive),
                                  Constants.MessageType.AssertFailed);
                        }
                    }
                    //This must be an order we don't manage or that we have already rejected so the counter is considered to be not working
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("<{0}>-Critical error processing a execution report:{1}", Configuration.Name, ex.Message), Constants.MessageType.AssertFailed);
            }
        }
 private void ClearOrderTracking(string clOrderId)
 {
     TimeoutOrders.Remove(clOrderId);
     LastProcessedCounter.Remove(clOrderId);
     OrdersSent.Remove(clOrderId);
 }
示例#8
0
        protected void ProcessExecutionReport(object param)
        {
            try
            {
                lock (TimeoutOrders)
                {
                    Wrapper erWrapper = (Wrapper)param;

                    string key = (string)erWrapper.GetField(ExecutionReportFields.KEY);

                    string orderId   = (string)erWrapper.GetField(ExecutionReportFields.OrderID);
                    string clOrderId = (string)erWrapper.GetField(ExecutionReportFields.ClOrdID);


                    if (TimeoutOrders.ContainsKey(key))
                    {
                        TimeoutOrders.Remove(key);
                    }

                    if (OrdersSent.ContainsKey(key))
                    {
                        if (orderId.Contains("_"))
                        {
                            DoLog(string.Format("<{0}>- Received order id {1}", Configuration.Name, orderId), Constants.MessageType.AssertOk);

                            string strCount = orderId.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries)[1];


                            try
                            {
                                int count = Convert.ToInt32(strCount);

                                //We validate that it's lower. No that it has a specific number
                                if (LastProcessedCounter.HasValue && LastProcessedCounter.Value < count)
                                {
                                    DoLog(string.Format("<{0}>- Recevied an orderId counter {1} which is bigger than the number we had in memory. The count seems ok",
                                                        Configuration.Name, count, LastProcessedCounter.HasValue ? LastProcessedCounter.Value.ToString() : "-"), Constants.MessageType.AssertOk);
                                    LastProcessedCounter = count;
                                }
                                else
                                {
                                    if (LastProcessedCounter.HasValue)
                                    {
                                        DoLog(string.Format("<{0}>- Recevied an orderId counter {1} which is LOWER than the number we had in memory. What happened with the counter?",
                                                            Configuration.Name, count, LastProcessedCounter.HasValue ? LastProcessedCounter.Value.ToString() : "-"), Constants.MessageType.AssertFailed);

                                        OrdersSent.Remove(key);
                                    }
                                    else
                                    {
                                        LastProcessedCounter = count;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                DoLog(string.Format("<{0}>- Received an order Id with a counter that doesn't seem to be an int value: {1}", Configuration.Name, strCount), Constants.MessageType.AssertFailed);
                                OrdersSent.Remove(key);
                            }
                        }
                        else
                        {
                            DoLog(string.Format("<{0}>- Received an order Id whose format doesn't match the exepected one: {1}", Configuration.Name, orderId), Constants.MessageType.AssertFailed);
                            OrdersSent.Remove(key);
                        }
                    }
                    //This must be an order we don't manage or that we have already rejected so the counter is considered to be not working
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("<{0}>-Critical error processing a execution report:{1}", Configuration.Name, ex.Message), Constants.MessageType.AssertFailed);
            }
        }