Ejemplo n.º 1
0
 private GenericResult EnforceTriggerStatus(OrderStateMachine.Trigger trigger, ref TriggerStatus triggerStatus)
 {
     if (IsTriggerHandlePending(trigger))
     {
         if (_workingData.PendingTrigger != null)
         {
             if (triggerStatus.IsPending())
             {
                 return(GenericResult.FailureFormat("There is already a {0} pending command. You must handle it before", _workingData.PendingTrigger));
             }
             if (trigger != _workingData.PendingTrigger)
             {
                 return(GenericResult.FailureFormat("There is a {0} pending not a {1}. You cannot {0} it", _workingData.PendingTrigger, trigger, triggerStatus));
             }
             _workingData.SetPendingTrigger(null);
         }
         else
         {
             triggerStatus = TriggerStatus.Pending;
         }
     }
     else if (triggerStatus.IsPending() || triggerStatus.IsPendingReply())
     {
         return(GenericResult.FailureFormat("The command {0} could not be {1}. No pending required", trigger, triggerStatus));
     }
     return(GenericResult.Success());
 }
Ejemplo n.º 2
0
        public static GenericResult IsValid <T>(this AbstractValidator <T> validator, T item)
        {
            Contract.Requires(item != null, "item != null");

            var result = validator.Validate(item);

            return(result.IsValid ? GenericResult.Success()
                : GenericResult.FailureFormat(result.Errors.Aggregate(new StringBuilder(), (s, v) => { s.AppendFormat("{0} : {1}", v.PropertyName, v.ErrorMessage); return s; }).ToString()));
        }
Ejemplo n.º 3
0
 private GenericResult HandlePendingReplyCommand(
     bool isAccept,
     ITriggerContext context,
     IOrderEditableData editableData = null,
     IOrderDealingData dealingData   = null,
     IOrderCoreData coreData         = null)
 {
     if (PendingTrigger == null)
     {
         return(GenericResult.FailureFormat("There is no pending command to {0}", isAccept ? "accept" : "reject"));
     }
     return(HandleCommand(PendingTrigger.Value, context, editableData, dealingData, coreData, isAccept ? TriggerStatus.Accepted : TriggerStatus.Rejected));
 }
Ejemplo n.º 4
0
        private GenericResult HandleTradeCommand(
            OrderStateMachine.Trigger trigger,
            ITriggerContext context,
            ITrade trade,
            ITradeEditableData editableData = null
            )
        {
            Contract.Requires(context != null, "context != null");

            _workingData = CurrentData.Clone();
            if (!_stateMachine.CanFireTrigger(trigger))
            {
                return(GenericResult.FailureFormat(String.Format("The commmand {0} is not allowed when the _order is in {1} state", trigger, OrderState)));
            }
            GenericResult result;

            switch (trigger)
            {
            case OrderStateMachine.Trigger.AddTrade:
                trade = new Trade {
                    Order = this
                };
                result = trade.Create(context, editableData);
                break;

            case OrderStateMachine.Trigger.TradeBooked:
                //TODO handle the booking done
                result = GenericResult.Success();
                break;

            case OrderStateMachine.Trigger.CancelTrade:
                result = trade.Cancel(context);
                break;

            case OrderStateMachine.Trigger.UpdateTrade:
            default:
                return(GenericResult.FailureFormat("The trade command {0} is not implemented", trigger));
            }
            return(result.IsSuccess() ? HandleCommand(trigger, context, dealingData: new OrderDealingEventParameter(trade)) : result);
        }