示例#1
0
        public INeedAQueryContext Handlers(IQueryHandlerRegistry handlerRegistry, IQueryHandlerFactory handlerFactory,
                                           IQueryHandlerDecoratorRegistry decoratorRegistry, IQueryHandlerDecoratorFactory decoratorFactory)
        {
            if (handlerRegistry == null)
            {
                throw new ArgumentNullException(nameof(handlerRegistry));
            }
            if (handlerFactory == null)
            {
                throw new ArgumentNullException(nameof(handlerFactory));
            }
            if (decoratorRegistry == null)
            {
                throw new ArgumentNullException(nameof(decoratorRegistry));
            }
            if (decoratorFactory == null)
            {
                throw new ArgumentNullException(nameof(decoratorFactory));
            }

            _handlerConfiguration = new HandlerConfiguration(
                handlerRegistry,
                handlerFactory,
                decoratorRegistry,
                decoratorFactory);

            return(this);
        }
示例#2
0
        // Helper to invoke any handler config attributes on this handler type or its base classes.
        private static void InvokeAttributesOnHandlerType(EventHandlerDescriptor descriptor, Type type)
        {
            Contract.Requires(descriptor != null);

            if (type == null)
            {
                return;
            }

            // Initialize base class before derived classes (same order as ctors).
            InvokeAttributesOnHandlerType(descriptor, type.BaseType);

            // Check for attribute
            object[] attrs = type.GetCustomAttributes(inherit: false);
            for (int i = 0; i < attrs.Length; i++)
            {
                object attr = attrs[i];
                IHandlerConfiguration handlerConfig = attr as IHandlerConfiguration;
                if (handlerConfig != null)
                {
                    ProcessorConfiguration originalConfig = descriptor.Configuration;
                    CommandHandlerSettings settings       = new CommandHandlerSettings(originalConfig);
                    //// handlerConfig.Initialize(settings, descriptor);
                    descriptor.Configuration = ProcessorConfiguration.ApplyHandlerSettings(settings, originalConfig);
                }
            }
        }
示例#3
0
        public INeedAQueryContext Handlers(IQueryHandlerRegistry handlerRegistry, Func <Type, IQueryHandler> handlerFactory,
                                           Action <Type> decoratorRegistry, Func <Type, IQueryHandlerDecorator> decoratorFactory)
        {
            if (handlerRegistry == null)
            {
                throw new ArgumentNullException(nameof(handlerRegistry));
            }
            if (handlerFactory == null)
            {
                throw new ArgumentNullException(nameof(handlerFactory));
            }
            if (decoratorRegistry == null)
            {
                throw new ArgumentNullException(nameof(decoratorRegistry));
            }
            if (decoratorFactory == null)
            {
                throw new ArgumentNullException(nameof(decoratorFactory));
            }

            _handlerConfiguration = new HandlerConfiguration(
                handlerRegistry,
                new FactoryFuncWrapper(handlerFactory),
                new RegistryActionWrapper(decoratorRegistry),
                new FactoryFuncWrapper(decoratorFactory));

            return(this);
        }
示例#4
0
        /// <summary>
        /// Attempts to apply configuration if possible.
        /// </summary>
        /// <param name="m">The monitor to use.</param>
        /// <param name="c">Configuration to apply.</param>
        /// <returns>True if the configuration applied.</returns>
        public ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor m, IHandlerConfiguration c)
        {
            if (c is not BinaryFileConfiguration cF || cF.Path != _config.Path)
            {
                return(ValueTask.FromResult(false));
            }

            if (_config.UseGzipCompression != cF.UseGzipCompression)
            {
                var f = new MonitorBinaryFileOutput(_config.Path, cF.MaxCountPerFile, cF.UseGzipCompression);
                // If the initialization of the new file fails (should not happen), we fail to apply the configuration:
                // this handler will be Deactivated and another one will be created... and it may work. Who knows...
                if (!f.Initialize(m))
                {
                    return(ValueTask.FromResult(false));
                }
                _file.Close();
                _file = f;
            }
            else
            {
                _file.MaxCountPerFile = cF.MaxCountPerFile;
            }
            _config = cF;
            return(ValueTask.FromResult(true));
        }
示例#5
0
        public QueryProcessor(IHandlerConfiguration handlerConfiguration, IPolicyRegistry policyRegistry, IRequestContextFactory requestContextFactory)
        {
            if (handlerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(handlerConfiguration));
            }
            if (policyRegistry == null)
            {
                throw new ArgumentNullException(nameof(policyRegistry));
            }
            if (requestContextFactory == null)
            {
                throw new ArgumentNullException(nameof(requestContextFactory));
            }

            if (handlerConfiguration.HandlerRegistry == null)
            {
                throw new ArgumentException($"{nameof(handlerConfiguration.HandlerRegistry)} must not be null", nameof(handlerConfiguration));
            }
            if (handlerConfiguration.HandlerFactory == null)
            {
                throw new ArgumentException($"{nameof(handlerConfiguration.HandlerFactory)} must not be null", nameof(handlerConfiguration));
            }
            if (handlerConfiguration.DecoratorFactory == null)
            {
                throw new ArgumentException($"{nameof(handlerConfiguration.DecoratorFactory)} must not be null", nameof(handlerConfiguration));
            }

            _handlerRegistry       = handlerConfiguration.HandlerRegistry;
            _handlerFactory        = handlerConfiguration.HandlerFactory;
            _decoratorFactory      = handlerConfiguration.DecoratorFactory;
            _policyRegistry        = policyRegistry;
            _requestContextFactory = requestContextFactory;
        }
示例#6
0
 /// <summary>
 /// Accepts any configuration that is a <see cref="ConsoleConfiguration"/>.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 /// <param name="c">The configuration.</param>
 /// <returns>True if <paramref name="c"/> is a ConsoleConfiguration.</returns>
 public ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor m, IHandlerConfiguration c)
 {
     if (c is not ConsoleConfiguration cf)
     {
         return(ValueTask.FromResult(false));
     }
     _config = cf;
     return(ValueTask.FromResult(true));
 }
        public static IHandlerConfiguration DisableConventionalDiscovery(this IHandlerConfiguration handlers, bool disabled = true)
        {
            if (disabled)
            {
                handlers.Discovery(x => x.DisableConventionalDiscovery());
            }

            return(handlers);
        }
示例#8
0
 public ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor m, IHandlerConfiguration c)
 {
     if (c is MailAlerterConfiguration newC && newC.Email == _c.Email)
     {
         _c = newC;
         return(ValueTask.FromResult(true));
     }
     return(ValueTask.FromResult(false));
 }
        public static IHandlerConfiguration OnlyType <T>(this IHandlerConfiguration handlers)
        {
            handlers.Discovery(x =>
            {
                x.DisableConventionalDiscovery();
                x.IncludeType <T>();
            });

            return(handlers);
        }
示例#10
0
 public bool ApplyConfiguration(IActivityMonitor m, IHandlerConfiguration c)
 {
     if (c is HandlerWithConfigSectionConfiguration conf)
     {
         m.Info($"Applying: {_config.Message} => {conf.Message}.");
         _config = conf;
         return(true);
     }
     return(false);
 }
示例#11
0
        public INeedPolicies Handlers(IHandlerConfiguration handlerConfiguration)
        {
            if (handlerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(handlerConfiguration));
            }

            _handlerConfiguration = handlerConfiguration;
            return(this);
        }
示例#12
0
 public ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor m, IHandlerConfiguration c)
 {
     if (c is HandlerWithConfigSectionConfiguration conf)
     {
         m.Info($"Applying: {_config.Message} => {conf.Message}.");
         _config = conf;
         return(ValueTask.FromResult(true));
     }
     return(ValueTask.FromResult(false));
 }
示例#13
0
        bool IGrandOutputHandler.ApplyConfiguration(IActivityMonitor m, IHandlerConfiguration c)
        {
            TextGrandOutputHandlerConfiguration config = c as TextGrandOutputHandlerConfiguration;

            if (config != null)
            {
                _config = config;
                return(true);
            }
            return(false);
        }
示例#14
0
        public ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor m, IHandlerConfiguration c)
        {
            var conf = c as DemoSinkHandlerConfiguration;

            if (conf != null)
            {
                m.Info("DemoSinkHandler: ApplyConfiguration!");
                Interlocked.Increment(ref ApplyConfigurationCount);
                return(ValueTask.FromResult(true));
            }
            return(ValueTask.FromResult(false));
        }
示例#15
0
 /// <summary>
 /// Attempts to apply configuration if possible.
 /// The key is the <see cref="FileConfigurationBase.Path"/>: the <paramref name="c"/>
 /// must be a <see cref="TextFileConfiguration"/> with the exact same path
 /// for this reconfiguration to be applied.
 /// </summary>
 /// <param name="m">The monitor to use.</param>
 /// <param name="c">Configuration to apply.</param>
 /// <returns>True if the configuration applied.</returns>
 public ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor m, IHandlerConfiguration c)
 {
     if (c is not TextFileConfiguration cF || cF.Path != _config.Path)
     {
         return(ValueTask.FromResult(false));
     }
     _config = cF;
     _file.MaxCountPerFile = cF.MaxCountPerFile;
     _file.Flush();
     _countFlush        = _config.AutoFlushRate;
     _countHousekeeping = _config.HousekeepingRate;
     return(ValueTask.FromResult(true));
 }
示例#16
0
 public override bool Initialize(IHandlerConfiguration config)
 {
     if (config.TryGetValue("WebhookUrl", out string url) && config.TryGetValue("OutputDir", out string dir))
     {
         WebhookUrl = url;
         OutputDir  = Path.Join(Game.StartupDirectory, dir);
         client     = new DiscordWebhookClient(url);
         Disabled   = false;
         return(true);
     }
     else
     {
         throw new ArgumentException("Initialize: needed WebhookUrl and OutputDir to be defined, aborting");
     }
 }
示例#17
0
        public QueryProcessor(
            IHandlerConfiguration handlerConfiguration,
            IQueryContextFactory queryContextFactory,
            IReadOnlyDictionary <string, object> contextBagData = null)
        {
            if (handlerConfiguration == null)
            {
                throw new ArgumentNullException(nameof(handlerConfiguration));
            }

            _handlerRegistry  = handlerConfiguration.HandlerRegistry ?? throw new ArgumentException($"{nameof(handlerConfiguration.HandlerRegistry)} must not be null", nameof(handlerConfiguration));
            _handlerFactory   = handlerConfiguration.HandlerFactory ?? throw new ArgumentException($"{nameof(handlerConfiguration.HandlerFactory)} must not be null", nameof(handlerConfiguration));
            _decoratorFactory = handlerConfiguration.DecoratorFactory ?? throw new ArgumentException($"{nameof(handlerConfiguration.DecoratorFactory)} must not be null", nameof(handlerConfiguration));

            _queryContextFactory = queryContextFactory ?? throw new ArgumentNullException(nameof(queryContextFactory));
            _contextBagData      = contextBagData ?? new Dictionary <string, object>();
        }
示例#18
0
        public INeedPolicies Handlers(IQueryHandlerRegistry handlerRegistry, Func <Type, object> handlerFactory, Func <Type, object> decoratorFactory)
        {
            if (handlerRegistry == null)
            {
                throw new ArgumentNullException(nameof(handlerRegistry));
            }
            if (handlerFactory == null)
            {
                throw new ArgumentNullException(nameof(handlerFactory));
            }
            if (decoratorFactory == null)
            {
                throw new ArgumentNullException(nameof(decoratorFactory));
            }

            _handlerConfiguration = new HandlerConfiguration(handlerRegistry, new FactoryFuncWrapper(handlerFactory), new FactoryFuncWrapper(decoratorFactory));
            return(this);
        }
示例#19
0
            public override bool Initialize(IHandlerConfiguration config)
            {
                config.TryGetValue("WebhookUrl", out string WebhookUrl);

                if (!string.IsNullOrEmpty(WebhookUrl))
                {
                    client = new DiscordWebhookClient(WebhookUrl);
                }

                if (config.TryGetValue("OutputDir", out string dir))
                {
                    OutputDir = Path.Join(global::Hybrasyl.Game.StartupDirectory, dir);
                    Disabled  = false;
                    return(true);
                }
                else
                {
                    throw new ArgumentException("Initialize: OutputDir must be defined, aborting");
                }
            }
示例#20
0
 public virtual bool Initialize(IHandlerConfiguration config)
 {
     return(true);
 }
 /// <summary>
 /// Adds a handler configuration (fluent interface).
 /// </summary>
 /// <param name="config">The configuration top add.</param>
 /// <returns>This configuration object.</returns>
 public GrandOutputConfiguration AddHandler(IHandlerConfiguration config)
 {
     Handlers.Add(config);
     return(this);
 }
        public static IHandlerConfiguration IncludeType <T>(this IHandlerConfiguration handlers)
        {
            handlers.Discovery(x => x.IncludeType <T>());

            return(handlers);
        }
示例#23
0
 public bool ApplyConfiguration(IActivityMonitor activityMonitor, IHandlerConfiguration configuration)
 {
     return(false);
 }
示例#24
0
        public static IHandlerConfiguration DisableConventionalDiscovery(this IHandlerConfiguration handlers)
        {
            handlers.Discovery(x => x.DisableConventionalDiscovery());

            return(handlers);
        }
示例#25
0
        public static IHandlerConfiguration IncludeType(this IHandlerConfiguration handlers, Type handlerType)
        {
            handlers.Discovery(x => x.IncludeType(handlerType));

            return(handlers);
        }
示例#26
0
 /// <inheritdoc />
 /// <remarks>
 /// When the configuration applies to this handler, <see cref="UpdateConfiguration(IActivityMonitor, TConfiguration)"/>
 /// must be called.
 /// </remarks>
 public abstract ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor monitor, IHandlerConfiguration c);
        ValueTask <bool> IGrandOutputHandler.ApplyConfigurationAsync(IActivityMonitor m, IHandlerConfiguration c)
        {
            TextGrandOutputHandlerConfiguration config = c as TextGrandOutputHandlerConfiguration;

            if (config != null)
            {
                _config = config;
                return(ValueTask.FromResult(true));
            }
            return(ValueTask.FromResult(false));
        }
示例#28
0
 public override ValueTask <bool> ApplyConfigurationAsync(IActivityMonitor monitor, IHandlerConfiguration c)
 {
     if (c is FakeLogSenderConfiguration conf && conf.Target == Configuration.Target)
     {
         UpdateConfiguration(monitor, conf);
         return(ValueTask.FromResult(true));
     }
     return(ValueTask.FromResult(false));
 }
示例#29
0
 public INeedAQueryContext Handlers(IHandlerConfiguration handlerConfiguration)
 {
     _handlerConfiguration = handlerConfiguration ?? throw new ArgumentNullException(nameof(handlerConfiguration));
     return(this);
 }