public void Execute(T state) { lock (_syncRoot) { if (_isExecuting) { return; } _isExecuting = true; } IChainStep <T> head; if (_isFrozen && _head != null) { head = _head; } else { head = ComputeChainSequence(); if (_isFrozen) { _head = head; } } _head.Execute(state); lock (_syncRoot) _isExecuting = false; }
public void SetSteps( IChainStep previousStepIfConstructorArgumentExists, IChainStep previousStepIfNoConstructorArgumentExists, IChainStep nextStep ) { if (previousStepIfConstructorArgumentExists is null) { throw new ArgumentNullException(nameof(previousStepIfConstructorArgumentExists)); } if (previousStepIfNoConstructorArgumentExists is null) { throw new ArgumentNullException(nameof(previousStepIfNoConstructorArgumentExists)); } if (nextStep is null) { throw new ArgumentNullException(nameof(nextStep)); } _previousStepIfConstructorArgumentExists = previousStepIfConstructorArgumentExists; _previousStepIfNoConstructorArgumentExists = previousStepIfNoConstructorArgumentExists; _nextStep = nextStep; }
public ChainProcedure <T> AddStep(IChainStep <T> next) { if (firstStep == null) { firstStep = next; } lastStep?.NextStep(next); lastStep = next; return(this); }
public void RegisterStep <TStep>() where TStep : IChainStep <T> { lock (_syncRoot) { if (_isExecuting) { throw new Exception("Cannot add chainsteps while the chain is executing."); } IChainStep <T> step = _kernel.Get <TStep>(); _steps.Add(step.Name, step); } }
public void SetSteps( IChainStep previousStep //IChainStep nextStep ) { if (previousStep is null) { throw new ArgumentNullException(nameof(previousStep)); } //if (nextStep is null) //{ // throw new ArgumentNullException(nameof(nextStep)); //} _previousStep = previousStep; //_nextStep = nextStep; }
public bool UnregisterStep <TStep>() where TStep : class, IChainStep <T> { lock (_syncRoot) { if (_isExecuting) { throw new Exception("Cannot remove chainsteps while the chain is executing."); } if (_isFrozen) { throw new Exception("Cannot unregister a chainstep after the chain has been frozen."); } IChainStep <T> remove = _steps.Values.Where(step => step.GetType() == typeof(TStep)).FirstOrDefault(); return(_steps.Remove(remove.Name)); } }
public void SetSteps( IChainStep nextStepIfConstructorArgumentsExists, IChainStep nextStepIfNoConstructorArgumentsExists ) { if (nextStepIfConstructorArgumentsExists is null) { throw new ArgumentNullException(nameof(nextStepIfConstructorArgumentsExists)); } if (nextStepIfNoConstructorArgumentsExists is null) { throw new ArgumentNullException(nameof(nextStepIfNoConstructorArgumentsExists)); } _nextStepIfConstructorArgumentsExists = nextStepIfConstructorArgumentsExists; _nextStepIfNoConstructorArgumentsExists = nextStepIfNoConstructorArgumentsExists; }
public void SetSteps( IChainStep previousStep, IChainStep nextStep ) { if (previousStep is null) { throw new ArgumentNullException(nameof(previousStep)); } if (nextStep is null) { throw new ArgumentNullException(nameof(nextStep)); } _previousStep = previousStep; _nextStep = nextStep; }
public IChain <T> RegisterStep <TStep>() where TStep : class, IChainStep <T> { lock (_syncRoot) { if (_isExecuting) { throw new Exception("Cannot add chainsteps while the chain is executing."); } if (_isFrozen) { throw new Exception("Chainsteps must be registered before the chain is frozen."); } IChainStep <T> step = CreateStep <TStep>(); step.Chain = this; _steps.Add(step.Name, step); } return(this); }
public void Execute(T state) { try { lock (_syncRoot) { Guard.Assert(!_isExecuting, string.Format("Chain {0} was executed while already executing.", Name)); _isExecuting = true; } IChainStep <T> head; if (_isFrozen && _head != null) { head = _head; } else { head = ComputeChainSequence(); if (_isFrozen) { _head = head; } } if (head != null) { head.Execute(state); } } finally { lock (_syncRoot) _isExecuting = false; } }
public IChainStep <T> NextStep(IChainStep <T> next) { nextStep = next; return(nextStep); }