예제 #1
0
 public void Record(ScopeContext context, object record)
 {
     if (IsRecording(context))
     {
         _records.Add(record);
     }
 }
예제 #2
0
        public RecordingPausedScope PauseRecording(ScopeContext context)
        {
            var result = new RecordingPausedScope(context, this);

            context.Set(result);
            return(result);
        }
예제 #3
0
        protected virtual bool OnBeginScope(ScopeContext context)
        {
            var result = true;

            if (_aspects != null)
            {
                foreach (var aspect in _aspects)
                {
                    result &= aspect.Begin(context);
                }
            }
            return(result);
        }
예제 #4
0
        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);
        }
예제 #5
0
 public TInheritor ScopedTo(ScopeContext parentContex)
 {
     _parentContext = parentContex;
     return(this as TInheritor);
 }
예제 #6
0
 protected virtual void OnEndScope(ScopeContext context, bool result)
 => _aspects.Reverse <IScopeAspect>().ForEach(aspect => aspect.End(context, result));
예제 #7
0
 public static RecordingPausedScope PauseRecording(this ScopeContext context)
 => context.TryGetValue(nameof(ScopeRecorder), out var recorder)
             ? (recorder as ScopeRecorder)?.PauseRecording(context)
             : null;
예제 #8
0
 public RecordingPausedScope(ScopeContext context, ScopeRecorder recorder)
 {
     _context  = context;
     _recorder = recorder;
 }
예제 #9
0
 public bool IsRecording(ScopeContext context)
 => !context.ContainsKey(nameof(RecordingPausedScope));
예제 #10
0
 internal void ResumeRecording(ScopeContext context)
 => context.Remove(nameof(RecordingPausedScope));
예제 #11
0
 public override void End(ScopeContext context, bool result)
 {
 }
예제 #12
0
 internal ScopeContext(IScopeTask owner, ScopeContext parentContext)
 {
     _owner = owner;
     Parent = parentContext;
 }