Example #1
0
        // Protected methods

        protected virtual void Notify(TimeSpan delay = default)
        {
            using var _ = ExecutionContextEx.SuppressFlow();
            if (delay == default)
            {
                Task.Run(NotifyAsync);
            }
            else
            {
                Task.Delay(delay).ContinueWith(_ => NotifyAsync());
            }
        }
Example #2
0
        public Task RunAsync(
            CommandContext context, bool isolate,
            CancellationToken cancellationToken = default)
        {
            if (!isolate)
            {
                return(RunInternalAsync(context, cancellationToken));
            }

            using var _ = ExecutionContextEx.SuppressFlow();
            return(Task.Run(() => RunInternalAsync(context, cancellationToken), default));
        }
Example #3
0
        public Task <CommandContext> RunAsync(ICommand command, bool isolate, CancellationToken cancellationToken = default)
        {
            CommandContext?context;

            CommandContext ContextFactory()
            {
                context = CommandContext.New(this, command);
                return(context);
            }

            using var _ = isolate ? ExecutionContextEx.SuppressFlow() : default;
            return(RunAsync(ContextFactory, command, cancellationToken));
        }
Example #4
0
        public CommandContext Start(ICommand command, bool isolate, CancellationToken cancellationToken = default)
        {
            CommandContext context = null !;

            CommandContext ContextFactory()
            {
                context = CommandContext.New(this, command);
                return(context);
            }

            using var _ = isolate ? ExecutionContextEx.SuppressFlow() : default;
            RunAsync(ContextFactory, command, cancellationToken).Ignore();
            return(context);
        }
Example #5
0
 protected virtual void Dispose(bool disposing)
 {
     if (IsDisposed || !disposing)
     {
         return;
     }
     IsDisposed  = true;
     using var _ = ExecutionContextEx.SuppressFlow();
     Task.Run(async() => {
         using (await AsyncLock.LockAsync()) {
             var dbContext = DbContext;
             if (dbContext != null)
             {
                 await dbContext.DisposeAsync();
             }
         }
     }).Ignore();
 }
Example #6
0
        public Task OnOperationCompleted(IOperation operation)
        {
            if (operation.AgentId != AgentInfo.Id.Value) // Only local commands require notification
            {
                return(Task.CompletedTask);
            }
            var commandContext = CommandContext.Current;

            if (commandContext != null)   // It's a command
            {
                var operationScope = commandContext.Items.TryGet <DbOperationScope <TDbContext> >();
                if (operationScope == null || !operationScope.IsUsed) // But it didn't change anything related to TDbContext
                {
                    return(Task.CompletedTask);
                }
            }
            // If it wasn't command, we pessimistically assume it changed something
            using var _ = ExecutionContextEx.SuppressFlow();
            Task.Run(Notify);
            return(Task.CompletedTask);
        }
Example #7
0
 protected virtual void OnStateChanged(IState <AuthState> state, StateEventKind eventKind)
 {
     using var _ = ExecutionContextEx.SuppressFlow();
     Task.Run(() =>
              NotifyAuthenticationStateChanged(Task.FromResult((AuthenticationState)state.LastValue))).Ignore();
 }