private GenericResult HandleCommand( OrderStateMachine.Trigger trigger, ITriggerContext context, IOrderEditableData editableData = null, IOrderDealingData dealingData = null, IOrderCoreData coreData = null, TriggerStatus status = TriggerStatus.Done) { Contract.Requires(context != null, "context != null"); _workingData = CurrentData.Clone() .SetRoutingData(dealingData) .SetEditableData(editableData) .SetTrigger(trigger) .SetPendingTrigger(status.IsPendingReply() && this.PendingTrigger == trigger ? null : this.PendingTrigger); var result = EnforceTriggerStatus(trigger, ref status); if (result.IsFailure()) { return(result); } if (status == TriggerStatus.Rejected) { result = GenericResult.Success(); } else { var triggerSucceeded = status == TriggerStatus.Pending ? _stateMachine.CanFireTrigger(trigger) : _stateMachine.TryFireTrigger(trigger); result = triggerSucceeded ? GenericResult.Success() : GenericResult.Failure(string.Concat(_workingData.StateMachineErrorMessage, String.Format("The commmand {0} is not allowed when the order is in {1} state", trigger, OrderState))); } if (result.IsSuccess()) { _workingData.SetOrderState(_stateMachine.GetState); if (editableData != null) { if (coreData != null) { this.InsertDataFrom(coreData); } EventLogs.Add(new OrderParameterEventLog <IOrderEditableData>(context, trigger, status, _workingData.OrderState, this, editableData)); } else if (dealingData != null) { EventLogs.Add(new OrderParameterEventLog <IOrderDealingData>(context, trigger, status, _workingData.OrderState, this, dealingData)); if (dealingData.Trade != null) { _workingData.SetExecutionQuantity(ComputeExecutionQuantity(_workingData.Side)); } } else { EventLogs.Add(new OrderEventLog(context, trigger, status, _workingData.OrderState, this)); } _workingData.SetOrderStatus(ComputeOrderStatus(_workingData)); RefreshCurrentData(_workingData); } _workingData = null; return(result); }
public object Clone() { return(new Session() { InitialData = (SessionData)InitialData?.Clone(), DifferenceData = (SessionData)DifferenceData?.Clone(), CurrentData = (SessionData)CurrentData?.Clone(), SessionDate = SessionDate, Username = Username, GainedPlays = new List <OsuApiHelper.OsuPlay>(GainedPlays) }); }
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); }