protected internal void ExecCompleted(int progressAtCompletion, Exception ex, string mssg) { WorkerStatus = FxWorkerStatus.Completed; Status = FxStatus.Complete; ExecComplete(progressAtCompletion, false, ex, mssg); }
protected internal void ExecError(int progressAtCompletion, bool isCancelled, Exception ex, string mssg) { if (ex == null) ex = new FxExecutionErrorException(Properties.Resources.MssgFxExceptionIsNull); WorkerStatus = FxWorkerStatus.Error; Status = FxStatus.Error; ExecComplete(progressAtCompletion, isCancelled, ex, mssg); }
public void ExecuteAsync(IParamMgr paramMgr, IInputPortMgr inPortMgr, ISimpleSettingsMgr settings, IOutputPortMgr outPortMgr) { if (IsBusy) { CancelAsync(); Reset(); } IsAsynch = true; WorkerStatus = FxWorkerStatus.ExecutingAsynch; CompletionCalled = false; PercentProgress = 0; AsynchOp = AsyncOperationManager.CreateOperation(null); new ExecDelegate(ExecWorker).BeginInvoke(paramMgr, inPortMgr, settings, outPortMgr, null, null); }
public void Reset() { if (!IsBusy) { AsynchOp = null; IsAsynch = false; WorkerStatus = FxWorkerStatus.Uninitialized; PercentProgress = 0; CompletionCalled = false; IsValidContinue = false; OutputException = null; OutputMssg = null; // just change status, the transition on Reset is from a rest state to another rest staten, no notifications involved Status = FxStatus.UnInitialized; #region Log _logger.Debug(string.Format("Reset() end")); #endregion } else { throw new InvalidOperationException(Properties.Resources.MssgFxResetException); } // Reset any internal variables or state here; }
public void CancelAsync() { if (IsAsynch && IsBusy) { WorkerStatus = FxWorkerStatus.CancellationPending; #region Log _logger.Debug(string.Format("CancelAsync()")); #endregion } }
public void Execute(IParamMgr paramMgr, IInputPortMgr inPortMgr, ISimpleSettingsMgr settings, IOutputPortMgr outPortMgr) { IsAsynch = false; WorkerStatus = FxWorkerStatus.ExecutingSynch; CompletionCalled = false; PercentProgress = 0; ExecWorker(paramMgr, inPortMgr, settings, outPortMgr); }
public void Reset() { if (!IsBusy) { AsynchOp = null; IsAsynch = false; WorkerStatus = FxWorkerStatus.Uninitialized; PercentProgress = 0; CompletionCalled = false; // just change status, the transition on Reset is from a rest state to another rest staten, no notifications involved Status = FxStatus.UnInitialized; #region Log _Logger.Debug("Reset() end"); #endregion } else { throw new InvalidOperationException(Properties.Resources.MssgFxResetException); } }
public void IsCancelled_Returns_True_If_WorkerStatus_Is_CancellationPending(FxWorkerStatus status, bool expectedResult) { //Arrange _fx = new SimpleFxBaseTestClass(Guid.NewGuid()); //Act _fx.WorkerStatus = status; //Assert Assert.Equal(expectedResult, _fx.IsCancelled); }
/// <summary> /// Sends out completion notifications. !!!Important: you must set the <see cref="Status"/> before calling /// this method. /// </summary> /// <param name="progressAtCompletion"></param> /// <param name="isCancelled"></param> /// <param name="ex"></param> /// <param name="mssg"></param> internal virtual void ExecComplete(FxWorkerStatus workerStatus, int progressAtCompletion, bool isCancelled, Exception ex, string mssg) { FxCompletedEventArgs arg = null; string logTitle = null; string logMssg = mssg; if (workerStatus == FxWorkerStatus.Error) { if (ex != null) { logTitle = BlueSpider.Common.Constants.LogEntryTitle_Exception; logMssg = ex.Message; arg = new FxCompletedEventArgs(progressAtCompletion, mssg, ex, false); OnExecuteCompleted(arg); } else { throw new InvalidOperationException(Properties.Resources.MssgFxExceptionIsNull); } } else if (isCancelled) { logTitle = BlueSpider.Common.Constants.LogEntryTitle_Cancelled; arg = new FxCompletedEventArgs(progressAtCompletion, mssg, ex, true); OnExecuteCompleted(arg); } else if (workerStatus == FxWorkerStatus.Completed) { logTitle = BlueSpider.Common.Constants.LogEntryTitle_End; arg = new FxCompletedEventArgs(progressAtCompletion, mssg, ex, false); OnExecuteCompleted(arg); } else if (workerStatus == FxWorkerStatus.Uninitialized) { logTitle = BlueSpider.Common.Constants.LogEntryTitle_End; arg = new FxCompletedEventArgs(progressAtCompletion, mssg, ex, false); OnExecuteCompleted(arg); } else { throw new InvalidOperationException(Properties.Resources.MssgFxInvalidWorkerStatusFormat(workerStatus)); } #region Log _Logger.Info("ExecComplete() end"); #endregion AsynchOp = null; }
public void CancelAsync() { if (IsAsynch && IsBusy) { WorkerStatus = FxWorkerStatus.CancellationPending; #region Log _Logger.Debug("CancelAsync() end"); #endregion } }
public void Reset() { if (!IsBusy) { AsynchOp = null; IsAsynch = false; WorkerStatus = FxWorkerStatus.Uninitialized; PercentProgress = 0; // just change status, the transition on Reset is from a rest state to another rest staten, no notifications involved Status = FxStatus.UnInitialized; #region Log _Logger.Info("Reset() end"); #endregion } else { // TODO log this???? throw new InvalidOperationException(BlueSpider.Element.Standard.Properties.Resources.MssgFxResetException); } }
public void CancelAsync() { if (IsAsynch && AsynchOp != null) { WorkerStatus = FxWorkerStatus.CancellationPending; #region Log _Logger.Info("CancelAsync() end"); #endregion } }
public void IsError_Returns_True_If_WorkerStatus_Is_Error(FxWorkerStatus status, bool expectedResult) { //Arrange _fx = new SimpleFxBaseTestClass(Guid.NewGuid()); //Act _fx.WorkerStatus = status; //Assert Assert.Equal(expectedResult, _fx.IsError); }
/// <summary> /// Called to clean up the worker when an exception is caught when executing async /// </summary> /// <param name="ex">The exception that was caught</param> internal void ExecWorkerCleanUp(Exception ex) { if (ex == null) throw new InvalidOperationException(Properties.Resources.MssgFxExceptionIsNull); WorkerStatus = FxWorkerStatus.Error; Status = FxStatus.Error; if (IsAsynch) { Exception x2 = ex; ExecComplete(PercentProgress, false, x2, Properties.Resources.MssgFxExecError); } else throw new FxExecutionErrorException(Properties.Resources.MssgFxSynchronousExecError, ex); }
internal void WrapUp(bool isValidContinue, INetwork outputNet0, IOutputPortMgr outPortMgr, Exception ex) { if (isValidContinue && !IsCancelled) { IOutputNetworkPort oPort0 = outPortMgr[0] as IOutputNetworkPort; oPort0.OutputNetwork = outputNet0; // --- set status's to completed when all is done WorkerStatus = FxWorkerStatus.Completed; Status = FxStatus.Complete; ExecComplete(PercentProgress, false, ex, FormatMessage(outputNet0)); } else if (IsCancelled) { Status = FxStatus.UnInitialized; ExecComplete(PercentProgress, IsCancelled, ex, Properties.Resources.MssgFxExecCancel); } else { // ex cannot be null if an error occured if (ex == null) ex = new FxExecutionErrorException(Properties.Resources.MssgFxExceptionIsNull); WorkerStatus = FxWorkerStatus.Error; Status = FxStatus.Error; ExecComplete(PercentProgress, IsCancelled, ex, Properties.Resources.MssgFxExecError); } }
internal void WrapUp(IOutputPortMgr outPortMgr) { if (IsValidContinue && !IsCancelled) { // --- set status's to completed when all is done WorkerStatus = FxWorkerStatus.Completed; Status = FxStatus.Complete; ExecComplete(PercentProgress, false, OutputException, OutputMssg); } else if (IsCancelled) { Status = FxStatus.UnInitialized; ExecComplete(PercentProgress, IsCancelled, OutputException, Properties.Resources.MssgFxExecCancel); } else { // ex cannot be null if an error occured if (OutputException == null) OutputException = new FxExecutionErrorException(Properties.Resources.MssgFxExceptionIsNull); WorkerStatus = FxWorkerStatus.Error; Status = FxStatus.Error; ExecComplete(PercentProgress, IsCancelled, OutputException, string.IsNullOrEmpty(OutputMssg) ? Properties.Resources.MssgFxExecError : OutputMssg); } }
public void IsBusy_Return_When_IsAsynch_Is_False_Is_Based_On_WorkerStatus(FxWorkerStatus status, bool expectedResult) { //Arrange _fx = new SimpleFxBaseTestClass(Guid.NewGuid()); _fx.IsAsynch = false; _fx.WorkerStatus = status; //Act bool result = _fx.IsBusy; //Assert Assert.Equal(expectedResult, result); }