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

            context.Set(result);
            return(result);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 5
0
 public TInheritor ScopedTo(ScopeContext parentContex)
 {
     _parentContext = parentContex;
     return(this as TInheritor);
 }
Esempio n. 6
0
 protected virtual void OnEndScope(ScopeContext context, bool result)
 => _aspects.Reverse <IScopeAspect>().ForEach(aspect => aspect.End(context, result));
Esempio n. 7
0
 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;
 }
Esempio n. 9
0
 public bool IsRecording(ScopeContext context)
 => !context.ContainsKey(nameof(RecordingPausedScope));
Esempio n. 10
0
 internal void ResumeRecording(ScopeContext context)
 => context.Remove(nameof(RecordingPausedScope));
Esempio n. 11
0
 public override void End(ScopeContext context, bool result)
 {
 }
Esempio n. 12
0
 internal ScopeContext(IScopeTask owner, ScopeContext parentContext)
 {
     _owner = owner;
     Parent = parentContext;
 }