public void Record(ScopeContext context, object record) { if (IsRecording(context)) { _records.Add(record); } }
public RecordingPausedScope PauseRecording(ScopeContext context) { var result = new RecordingPausedScope(context, this); context.Set(result); return(result); }
protected virtual bool OnBeginScope(ScopeContext context) { var result = true; if (_aspects != null) { foreach (var aspect in _aspects) { result &= aspect.Begin(context); } } return(result); }
public async Task <object> StartAsync() { var context = new ScopeContext(this, _parentContext); CurrentScopeContext = context; var result = true; try { if (_asyncAction != null) { if (result = OnBeginScope(context)) { await _asyncAction(context); } } else { await Task.Run(() => { if (result = OnBeginScope(context)) { _action(context); } }); } ResultStatus = ScopeResult.Success; return(LastResult); } catch (OperationCanceledException) { ResultStatus = ScopeResult.Canceled; } catch (Exception ex) { _observers.ForEach(x => x.OnError(ex)); ResultStatus = ScopeResult.Failed; throw; } finally { OnEndScope(context, result); Dispose(); } return(LastResult); }
public TInheritor ScopedTo(ScopeContext parentContex) { _parentContext = parentContex; return(this as TInheritor); }
protected virtual void OnEndScope(ScopeContext context, bool result) => _aspects.Reverse <IScopeAspect>().ForEach(aspect => aspect.End(context, result));
public static RecordingPausedScope PauseRecording(this ScopeContext context) => context.TryGetValue(nameof(ScopeRecorder), out var recorder) ? (recorder as ScopeRecorder)?.PauseRecording(context) : null;
public RecordingPausedScope(ScopeContext context, ScopeRecorder recorder) { _context = context; _recorder = recorder; }
public bool IsRecording(ScopeContext context) => !context.ContainsKey(nameof(RecordingPausedScope));
internal void ResumeRecording(ScopeContext context) => context.Remove(nameof(RecordingPausedScope));
public override void End(ScopeContext context, bool result) { }
internal ScopeContext(IScopeTask owner, ScopeContext parentContext) { _owner = owner; Parent = parentContext; }