HostFactory.New(x =>
{
// 可以定义不需要接口依赖性的服务,这只是为了
//在此示例中显示并未使用。
x.Service<SampleSansInterfaceService>(s =>
{
s.ConstructUsing(() => new SampleSansInterfaceService());
s.WhenStarted(v => v.Start());
s.WhenStopped(v => v.Stop());
});
});
HostFactory.Run(x =>
{
x.UseLog4Net("log4net.config");
x.UseAssemblyInfoForServiceInfo();
bool throwOnStart = false;
bool throwOnStop = false;
bool throwUnhandled = false;
x.Service(settings => new SampleService(throwOnStart, throwOnStop, throwUnhandled), s =>
{
s.BeforeStartingService(_ => Console.WriteLine("BeforeStart"));
s.BeforeStoppingService(_ => Console.WriteLine("BeforeStop"));
});
x.SetStartTimeout(TimeSpan.FromSeconds(10));
x.SetStopTimeout(TimeSpan.FromSeconds(10));
x.EnableServiceRecovery(r =>
{
r.RestartService(3);
r.RunProgram(7, "ping google.com");
r.RestartComputer(5, "message");
r.OnCrashOnly();
r.SetResetPeriod(2);
});
x.AddCommandLineSwitch("throwonstart", v => throwOnStart = v);
x.AddCommandLineSwitch("throwonstop", v => throwOnStop = v);
x.AddCommandLineSwitch("throwunhandled", v => throwUnhandled = v);
x.OnException((exception) =>
{
Console.WriteLine("Exception thrown - " + exception.Message);
});
});
public static Host New(Action<HostConfigurator> configureCallback)
{
try
{
if (configureCallback == null)
throw new ArgumentNullException("configureCallback");
var configurator = new HostConfiguratorImpl();
Type declaringType = configureCallback.Method.DeclaringType;
if (declaringType != null)
{
string defaultServiceName = declaringType.Namespace;
if (!string.IsNullOrEmpty(defaultServiceName))
configurator.SetServiceName(defaultServiceName);
}
configureCallback(configurator);
configurator.ApplyCommandLine();
ConfigurationResult result = ValidateConfigurationResult.CompileResults(configurator.Validate());
if (result.Message.Length > 0)
{
HostLogger.Get(typeof(HostFactory))
.InfoFormat("Configuration Result:\n{0}", result.Message);
}
return configurator.CreateHost();
}
catch (Exception ex)
{
HostLogger.Get(typeof(HostFactory)).Error("An exception occurred creating the host", ex);
HostLogger.Shutdown();
throw;
}
}
public static TopshelfExitCode Run(Action<HostConfigurator> configureCallback)
{
try
{
return New(configureCallback)
.Run();
}
catch (Exception ex)
{
HostLogger.Get(typeof(HostFactory))
.Error("The service terminated abnormally", ex);
HostLogger.Shutdown();
return TopshelfExitCode.AbnormalExit;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有