Exemplo n.º 1
0
 public ZoneRecoveryBatch(ZoneRecoveryBatchType batchType, ZoneRecoveryBatchStatus stat)
 {
     BatchNumber       = CreateBatchNr();
     ZROrdersList      = new List <ZoneRecoveryBatchOrder>();
     BatchStatus       = stat;
     BatchType         = batchType;
     ResponsesReceived = 0;
     Direction         = ZoneRecoveryDirection.Undefined;
 }
Exemplo n.º 2
0
        public void CheckBatchStatus()
        {
            switch (BatchType)
            {
            case ZoneRecoveryBatchType.PeggedStart:
                if (ResponsesReceived < 2)
                {
                    if (ZROrdersList.Max(x => x.LastUpdateReceived) < DateTime.Now.AddSeconds(-MaxWorkingDelayAllowedInSec))
                    {
                        BatchStatus = ZoneRecoveryBatchStatus.Error;
                    }

                    else
                    {
                        BatchStatus = ZoneRecoveryBatchStatus.Working;
                    }
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.New).Count() == 2)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Waiting;
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.Filled).Count() == 1)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.ReadyForNext;
                    if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.Filled).Single().Account == ZoneRecoveryAccount.A)
                    {
                        Direction = ZoneRecoveryDirection.Up;
                    }
                    else
                    {
                        Direction = ZoneRecoveryDirection.Down;
                    }
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.New).Count() == 0)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Closed;
                }
                else
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Error;
                    throw new Exception("ZoneRecoveryBatch.CheckBatchStatus: ZoneRecoveryBatchStatus.Error[1]");
                }
                break;

            case ZoneRecoveryBatchType.WindingFirst:
            case ZoneRecoveryBatchType.UnwindingLast:
                if (ResponsesReceived < 2)
                {
                    if (ZROrdersList.Max(x => x.LastUpdateReceived) < DateTime.Now.AddSeconds(-MaxWorkingDelayAllowedInSec))
                    {
                        BatchStatus = ZoneRecoveryBatchStatus.Error;
                    }

                    else
                    {
                        BatchStatus = ZoneRecoveryBatchStatus.Working;
                    }
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.New).Count() == 2)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Waiting;
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.Filled).Count() == 1)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.ReadyForNext;
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.New).Count() == 0)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Closed;
                }
                else
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Error;
                    throw new Exception("ZoneRecoveryBatch.CheckBatchStatus: ZoneRecoveryBatchStatus.Error[2]");
                }
                break;

            case ZoneRecoveryBatchType.Winding:
            case ZoneRecoveryBatchType.Unwinding:
                if (ResponsesReceived < 3)
                {
                    if (ZROrdersList.Max(x => x.LastUpdateReceived) < DateTime.Now.AddSeconds(-MaxWorkingDelayAllowedInSec))
                    {
                        BatchStatus = ZoneRecoveryBatchStatus.Error;
                    }

                    else
                    {
                        BatchStatus = ZoneRecoveryBatchStatus.Working;
                    }
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.New).Count() == 3)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Waiting;
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.Filled).Count() == 1)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.ReadyForNext;
                }
                else if (ZROrdersList.Where(x => x.CurrentStatus == ZoneRecoveryOrderStatus.New).Count() == 0)
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Closed;
                }
                else
                {
                    BatchStatus = ZoneRecoveryBatchStatus.Error;
                    throw new Exception("ZoneRecoveryBatch.CheckBatchStatus: ZoneRecoveryBatchStatus.Error[2]");
                }
                break;

            default:
                BatchStatus = ZoneRecoveryBatchStatus.Error;
                break;
            }
            var message = $"CheckBatchStatus: BatchStatus [{BatchStatus.ToString()}]";

            Console.WriteLine(message);
            Log.Verbose(message);
        }