/// <summary> /// Initializes an instance of <see cref="HyperServiceHostContainer"/> with the specified <see cref="IServiceHostFactory"/> and <see cref="IServiceHostExceptionHandler"/> implementations. /// </summary> /// <param name="hostFactory">The <see cref="IServiceHostFactory"/> that is used to create the <see cref="ServiceHost"/> object to wrap.</param> /// <param name="timeoutExceptionHandler">The <see cref="IServiceHostExceptionHandler"/> implementation to use when a <see cref="TimeoutException"/> is thrown.</param> /// <param name="communicationExceptionHandler">The <see cref="IServiceHostExceptionHandler"/> implementation to use when a <see cref="CommunicationException"/> is thrown.</param> /// <param name="genericExceptionHandler">The <see cref="IServiceHostExceptionHandler"/> implementation to use when an <see cref="Exception"/> is thrown that is not a <see cref="TimeoutException"/> or a <see cref="CommunicationException"/>.</param> public HyperServiceHostContainer(IServiceHostFactory hostFactory, IServiceHostExceptionHandler timeoutExceptionHandler, IServiceHostExceptionHandler communicationExceptionHandler, IServiceHostExceptionHandler genericExceptionHandler) { if (hostFactory == null) { throw new ArgumentNullException(nameof(hostFactory)); } if (timeoutExceptionHandler == null) { throw new ArgumentNullException(nameof(timeoutExceptionHandler)); } if (communicationExceptionHandler == null) { throw new ArgumentNullException(nameof(communicationExceptionHandler)); } if (genericExceptionHandler == null) { throw new ArgumentNullException(nameof(genericExceptionHandler)); } _hostFactory = hostFactory; _timeoutExceptionHandler = timeoutExceptionHandler; _communicationExceptionHandler = communicationExceptionHandler; _genericExceptionHandler = genericExceptionHandler; // By default, this property is true, making the container a one stop shop for ServiceHost management. Users can turn the feature off if they have to though. DisposeServiceOnStop = true; }
/// <summary> /// Initializes a new instance of the <see cref="ServiceHostContainer"/> using the /// specified factory and retry settings. /// </summary> /// <param name="factory">The factory responsible for creating new service hosts.</param> /// <param name="retryTimes">A sequence of <see cref="TimeSpan"/> instances representing /// the specific times to wait between successive attempts to restart the service.</param> public ServiceHostContainer(IServiceHostFactory factory, IEnumerable<TimeSpan> retryTimes) { if (factory == null) throw new ArgumentNullException("factory"); if ((retryTimes != null) && retryTimes.Any(t => t < TimeSpan.Zero)) throw new ArgumentException("Parameter 'retryTimes' cannot contain any negative " + "time intervals."); this.factory = factory; this.retryTimes = (retryTimes ?? Enumerable.Empty<TimeSpan>()).ToList(); }
public static App Create(string[] args, IServiceHostFactory factory) { var config = ServiceConfiguration.FromArgs(args); switch (factory) { case IServiceHostFactoryWithBroker withBroker: return(new BrokerOnlyApp(config, withBroker)); case IServiceHostFactoryWithEventStore withEventStore: return(new EventStoreApp(config, withEventStore)); default: throw new ArgumentException($"Unsupported service host factory type: '{factory.GetType().FullName}'", nameof(factory)); } }
/// <summary> /// Initializes a new instance of the <see cref="ServiceHostContainer"/> using the /// specified factory and retry settings. /// </summary> /// <param name="factory">The factory responsible for creating new service hosts.</param> /// <param name="maxRetries">The maximum number of retries, after which the service will /// no longer attempt to restart.</param> /// <param name="initialRetryTime">The amount of time, in milliseconds, to wait before /// first attempting to restart the service.</param> /// <param name="retryTimeMultiplier">The amount by which to multiply the previous retry /// time to get the next retry time; a value greater than 1 indicates geometrically /// increasing time between successive attempts to restart the service.</param> /// <param name="maxRetryTime">The maximum time the container should wait before scheduling /// another restart attempt. This overrides the <paramref name="retryTimeMultiplier"/> if /// the new retry time would exceed the max time.</param> public ServiceHostContainer(IServiceHostFactory factory, uint maxRetries = 10, uint initialRetryTime = 1000, double retryTimeMultiplier = 5, uint maxRetryTime = 3600000) { if (factory == null) throw new ArgumentNullException("factory"); if (retryTimeMultiplier < 1) throw new ArgumentOutOfRangeException("retryTimeMultiplier", "Parameter 'retryTimeMultiplier' must be greater than 1."); if (maxRetryTime < initialRetryTime) throw new ArgumentException("Parameter 'maxRetryTime' cannot be less than the " + "initial retry time. For unlimited time, use UInt32.MaxValue.", "maxRetryTime"); this.factory = factory; this.retryTimes = CalculateRetryTimes(TimeSpan.FromMilliseconds(initialRetryTime), retryTimeMultiplier, maxRetries, TimeSpan.FromMilliseconds(maxRetryTime)) .ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="PluginHandler"/> class. /// </summary> /// <param name="pluginLoader">The plugin loader.</param> /// <param name="authorizer">The authorizer.</param> /// <param name="serviceFactory">The service factory.</param> public PluginHandler(IPluginLoader pluginLoader, IAuthorization authorizer, IServiceHostFactory serviceFactory) { Guard.Against(pluginLoader == null, "pluginLoader"); Guard.Against(authorizer == null, "authorizer"); Guard.Against(serviceFactory == null, "serviceFactory"); this.pluginDirectory = pluginLoader.PluginDirectory; this.pluginLoader = pluginLoader; this.authorizer = authorizer; this.serviceFactory = serviceFactory; }
public static void Run(string[] args, IServiceHostFactory factory) { var a = new App(args, factory); a.Start(); }
public App(string[] args, IServiceHostFactory factory) { _args = args; _factory = factory; }
public static void Run(string[] args, IServiceHostFactory factory) { var app = Create(args, factory); app.Start(); }
/// <summary> /// Initializes an instance of <see cref="HyperServiceHostContainer"/> with the specified <see cref="IServiceHostFactory"/> and <see cref="IServiceHostExceptionHandler"/> implementations. /// </summary> /// <param name="hostFactory">The <see cref="IServiceHostFactory"/> that is used to create the <see cref="ServiceHost"/> object to wrap.</param> /// <param name="exceptionHandler">The <see cref="IServiceHostExceptionHandler"/> implementation to use when any is thrown.</param> public HyperServiceHostContainer(IServiceHostFactory hostFactory, IServiceHostExceptionHandler exceptionHandler) : this(hostFactory, exceptionHandler, exceptionHandler, exceptionHandler) { }