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); }
// 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); } } }
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); }
/// <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)); }
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; }
/// <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); }
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); }
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); }
public INeedPolicies Handlers(IHandlerConfiguration handlerConfiguration) { if (handlerConfiguration == null) { throw new ArgumentNullException(nameof(handlerConfiguration)); } _handlerConfiguration = handlerConfiguration; return(this); }
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)); }
bool IGrandOutputHandler.ApplyConfiguration(IActivityMonitor m, IHandlerConfiguration c) { TextGrandOutputHandlerConfiguration config = c as TextGrandOutputHandlerConfiguration; if (config != null) { _config = config; return(true); } return(false); }
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)); }
/// <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)); }
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"); } }
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>(); }
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); }
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"); } }
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); }
public bool ApplyConfiguration(IActivityMonitor activityMonitor, IHandlerConfiguration configuration) { return(false); }
public static IHandlerConfiguration DisableConventionalDiscovery(this IHandlerConfiguration handlers) { handlers.Discovery(x => x.DisableConventionalDiscovery()); return(handlers); }
public static IHandlerConfiguration IncludeType(this IHandlerConfiguration handlers, Type handlerType) { handlers.Discovery(x => x.IncludeType(handlerType)); return(handlers); }
/// <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)); }
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)); }
public INeedAQueryContext Handlers(IHandlerConfiguration handlerConfiguration) { _handlerConfiguration = handlerConfiguration ?? throw new ArgumentNullException(nameof(handlerConfiguration)); return(this); }