Пример #1
0
 public CachedQueryInvalidatorInterceptor(CommandExecutionDelegate next, IHostApplicationLifetime applicationLifetime, ICache cache, Type[]?queryTypes,
                                          ILogger <CachedQueryInvalidatorInterceptor>?logger)
 {
     _next = next ?? throw new ArgumentNullException(nameof(next));
     _applicationLifetime = applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime));
     Cache       = cache ?? throw new ArgumentNullException(nameof(cache));
     _queryTypes = queryTypes ?? Type.EmptyTypes;
     _logger     = logger ?? (ILogger)NullLogger.Instance;
 }
Пример #2
0
        public override ValueTask <int> DispatchAsync(CommandDispatchContext ctx)
        {
            var filters = FilterHelper.GetFilters <ICommandFilter>(ctx.Command.Method, _serviceProvider);

            CommandExecutionDelegate next = (ctx2) => Next(ctx);

            foreach (var filter in filters)
            {
                var next_ = next;
                next = (ctx2) => filter.OnCommandExecutionAsync(ctx2, next_);
            }

            return(next(new CoconaCommandExecutingContext(ctx.Command, ctx.ParsedCommandLine, ctx.CommandTarget)));
        }
Пример #3
0
 public async ValueTask <int> OnCommandExecutionAsync(CoconaCommandExecutingContext ctx, CommandExecutionDelegate next)
 {
     _logger.LogInformation($"[SampleCommandFilterWithDI] Before Command: {ctx.Command.Name}");
     try
     {
         return(await next(ctx));
     }
     catch (Exception ex)
     {
         _logger.LogInformation($"[SampleCommandFilterWithDI] Exception: {ex.GetType().FullName}: {ex.Message}");
         throw;
     }
     finally
     {
         _logger.LogInformation($"[SampleCommandFilterWithDI] End Command: {ctx.Command.Name}");
     }
 }
Пример #4
0
 public override async ValueTask <int> OnCommandExecutionAsync(CoconaCommandExecutingContext ctx, CommandExecutionDelegate next)
 {
     Console.WriteLine($"[SampleCommandFilter({_label})] Before Command: {ctx.Command.Name}");
     try
     {
         return(await next(ctx));
     }
     catch (Exception ex)
     {
         Console.WriteLine($"[SampleCommandFilter({_label})] Exception: {ex.GetType().FullName}: {ex.Message}");
         throw;
     }
     finally
     {
         Console.WriteLine($"[SampleCommandFilter({_label})] End Command: {ctx.Command.Name}");
     }
 }
Пример #5
0
 public ValueTask <int> OnCommandExecutionAsync(CoconaCommandExecutingContext ctx, CommandExecutionDelegate next)
 {
     throw new NotImplementedException();
 }
 public CommandPerformanceLoggerInterceptor(CommandExecutionDelegate next, IGuidProvider guidProvider, ILogger <CommandPerformanceLoggerInterceptor>?logger)
 {
     _next         = next ?? throw new ArgumentNullException(nameof(next));
     _guidProvider = guidProvider ?? throw new ArgumentNullException(nameof(guidProvider));
     _logger       = logger ?? (ILogger)NullLogger.Instance;
 }
Пример #7
0
 public CommandDataAnnotationsValidatorInterceptor(CommandExecutionDelegate next)
 {
     _next = next ?? throw new ArgumentNullException(nameof(next));
 }
Пример #8
0
 public GetCachedUserInfoQueryInvalidatorInterceptor(CommandExecutionDelegate next, IHostApplicationLifetime applicationLifetime, ICache cache, Type[]?queryTypes,
                                                     ILogger <CachedQueryInvalidatorInterceptor>?logger)
     : base(next, applicationLifetime, cache, queryTypes, logger)
 {
 }
Пример #9
0
 public ValueTask <int> OnCommandExecutionAsync(CoconaCommandExecutingContext ctx, CommandExecutionDelegate next)
 {
     return(next(ctx));
 }
Пример #10
0
 public abstract ValueTask <int> OnCommandExecutionAsync(CoconaCommandExecutingContext ctx, CommandExecutionDelegate next);
Пример #11
0
        public override async ValueTask <int> OnCommandExecutionAsync(CoconaCommandExecutingContext ctx, CommandExecutionDelegate next)
        {
            var tcs = new TaskCompletionSource <bool>();

            _mutexAcquireThread.Start(tcs);

            try
            {
                var acquired = await tcs.Task;
                if (!acquired)
                {
                    Console.Error.WriteLine("Error: The application is already running.");
                    return(1);
                }

                return(await next(ctx));
            }
            finally
            {
                _waitForExit.Set();
                _mutexAcquireThread.Join();
            }
        }