/// <summary> /// /// </summary> public bool RegisterOperation(OperationInformation operationInfo, bool assignId) { if (assignId && string.IsNullOrEmpty(operationInfo.Id) == false) { SystemMonitor.Warning("Id of operation already assigned."); return(false); } if (assignId) { operationInfo.Id = GetNextOperationCustomID().ToString(); } lock (this) { if (_pendingOperations.ContainsKey(operationInfo.Id)) { SystemMonitor.Error("An operation for this order id already running."); return(false); } // Register now to be sure, that whenever responce and OrderResponce come they will be handled OK. _pendingOperations.Add(operationInfo.Id, operationInfo); operationInfo.OperationCompleteEvent += new OperationInformation.OperationUpdateDelegate(operationInfo_OperationCompleteEvent); } return(true); }
/// <summary> /// Helper baseMethod. /// </summary> public bool PerformOperation <ResultType>(OperationInformation operationInfo, TimeSpan?timeOut, bool assignId, out ResultType result) where ResultType : class { result = null; if (PlaceOperation(operationInfo, assignId) == false) { return(false); } return(operationInfo.WaitResult <ResultType>(timeOut.HasValue ? timeOut.Value : this.DefaultTimeOut, out result)); }
void operationInfo_OperationCompleteEvent(OperationInformation operation) { lock (this) { // Remove operation from pending operation, timed out or not. _pendingOperations.Remove(operation.Id); } if (OperationCompleteEvent != null) { OperationCompleteEvent(this, operation); } }
/// <summary> /// If implementation is null, it will only register the operation. /// </summary> public bool PlaceOperation(OperationInformation operationInfo, bool assignId) { if (RegisterOperation(operationInfo, assignId) == false) { return(false); } if (_implementation != null && _implementation.StartOperation(operationInfo) == false) { SystemMonitor.OperationWarning("Operation [" + _implementation.GetType().Name + ", " + operationInfo.Id + "] failed to start."); return(false); } return(true); }