本文整理汇总了C#中HostControl类的典型用法代码示例。如果您正苦于以下问题:C# HostControl类的具体用法?C# HostControl怎么用?C# HostControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HostControl类属于命名空间,在下文中一共展示了HostControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public bool Start(HostControl hc)
{
mqtt.MqttConnect(serveur, clientid);
mqtt = new Mqttclient_handler();
foreach (var tokv in topicsStr.Split(';'))
{
string topicname = tokv.Split('=')[0];
string topicvalue = tokv.Split('=')[1];
mqtt.subscribe(topicvalue, 0);
// topicNames.Add(topicvalue, topicname);
}
t = new Timer(WriteMessages, null, 10000, 10 * 60000);
// Console.WriteLine("mqtt isconnected : {0}", mqtt.IsConnected);
mqtt.OnMessageArrived += (Mqttclient_handler sender, MessPublishEventArgs e) =>
{
Console.WriteLine("at {0} from {1} : {2}", e.Message.Date, e.Message.Topic, e.Message.GetStringMessage());
if (!messagesByTopic.ContainsKey(e.Message.Topic))
messagesByTopic.Add(e.Message.Topic, new List<MqttMessage>());
messagesByTopic[e.Message.Topic].Add(e.Message);
if (messagesByTopic[e.Message.Topic].Count > 20)
{
SaveMessages(messagesByTopic[e.Message.Topic], e.Message.Topic, FileType.csv);
messagesByTopic[e.Message.Topic].Clear();
}
};
return true;
/* do
{
Thread.Sleep(50);
} while (true);*/
}
示例2: Start
public bool Start(HostControl hostControl)
{
_log.Info("SampleService Starting...");
hostControl.RequestAdditionalTime(TimeSpan.FromSeconds(10));
Thread.Sleep(1000);
if(_throwOnStart)
{
_log.Info("Throwing as requested");
throw new InvalidOperationException("Throw on Start Requested");
}
ThreadPool.QueueUserWorkItem(x =>
{
Thread.Sleep(3000);
if(_throwUnhandled)
throw new InvalidOperationException("Throw Unhandled In Random Thread");
_log.Info("Requesting stop");
hostControl.Stop();
});
_log.Info("SampleService Started");
return true;
}
示例3: Stop
public bool Stop(HostControl hostControl)
{
if (app != null)
app.Dispose();
return true;
}
示例4: Start
/// <summary>
/// Starts the specified host control.
/// </summary>
/// <param name="hostControl">The host control.</param>
/// <returns></returns>
public virtual bool Start(HostControl hostControl)
{
ShutdownWatcher.Token.Register(hostControl.Stop);
JobHost.Start();
return true;
}
示例5: Stop
public bool Stop(HostControl hostControl)
{
_log.Info("stop service");
_serviceHost.Close();
_serviceHost = null;
return true;
}
示例6: Start
public bool Start(HostControl hostControl)
{
Log.Info("Starting Service...");
var Config = Configuration.LoadFromFile("Jobs.xml");
foreach (var config in Config.Jobs)
{
if (!config.Enabled) continue;
var job = config.GenerateJob();
var trigger = TriggerBuilder.Create()
.ForJob(job)
.WithCronSchedule(config.CronTrigger)
.StartNow()
.Build();
this.scheduler.ScheduleJob(job, trigger);
}
this.scheduler.Start();
return true;
}
示例7: Stop
public bool Stop(HostControl hostControl)
{
OnStopping(hostControl);
Logger.Get(GetType())
.InfoFormat("Stopping {0} Service Buses for hosted service: {1}", _instances.Length, _serviceName);
try
{
Parallel.ForEach(_instances, instance => instance.Dispose());
_disposed = true;
OnStopped(hostControl);
Logger.Get(GetType())
.InfoFormat("Stopped {0} Service Buses for hosted service: {1}", _instances.Length, _serviceName);
}
catch (Exception ex)
{
OnStopFailed(hostControl, ex);
throw;
}
return true;
}
示例8: Start
public bool Start(HostControl hostControl)
{
try
{
_bus = ServiceBusFactory.New(x =>
{
// just support everything by default
x.UseMsmq();
x.UseRabbitMq();
x.UseJsonSerializer();
// move this to app.config
x.ReceiveFrom(_controlQueueUri);
x.SetConcurrentConsumerLimit(_consumerLimit);
x.Subscribe(s =>
{
s.Consumer(() => new ScheduleMessageConsumer(_scheduler));
s.Consumer(() => new CancelScheduledMessageConsumer(_scheduler));
});
});
_scheduler.JobFactory = new MassTransitJobFactory(_bus);
}
catch (Exception)
{
_scheduler.Shutdown();
throw;
}
_scheduler.Start();
return true;
}
示例9: Start
public void Start(HostControl hostControl)
{
isRunning = true;
this.hostControl = hostControl;
channel.BeginReceive(new TimeSpan(0, 0, 0, ConfigurationSettings.PollingTimeout));
Console.WriteLine("Service started");
}
示例10: Start
public bool Start(HostControl hostControl)
{
OnStarting(hostControl);
Logger.Get(GetType())
.InfoFormat("Creating {0} Service Buses for hosted service: {1}", _instances.Length, _serviceName);
try
{
Parallel.ForEach(_instances, instance => instance.Start(_transportConfigurator));
OnStarted(hostControl);
Logger.Get(GetType())
.InfoFormat("Created {0} Service Buses for hosted service: {1}", _instances.Length, _serviceName);
return true;
}
catch (Exception ex)
{
Parallel.ForEach(_instances, instance => instance.Dispose());
OnStartFailed(hostControl, ex);
throw;
}
}
示例11: Start
public bool Start(HostControl hostControl)
{
_log.Info("Creating bus...");
_sagaRepository = GetSagaRepository();
ITrackingEventWriter writer = GetTrackingEventWriter();
_busControl = Bus.Factory.CreateUsingRabbitMq(x =>
{
var host = x.Host(GetHostAddress(), h =>
{
h.Username(ConfigurationManager.AppSettings["RabbitMQUsername"]);
h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]);
});
x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["BookingStateQueueName"], e =>
{
e.StateMachineSaga(_stateMachine, _sagaRepository);
});
x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["EventTrackingQueueName"], e =>
{
e.Consumer(() => new EventTrackingConsumer(writer));
});
});
_log.Info("Starting bus...");
_busHandle = _busControl.Start();
TaskUtil.Await(() => _busHandle.Ready);
return true;
}
示例12: Start
public bool Start(HostControl hostControl)
{
this.startHostControl = hostControl;
myCallback = new Win32.ServiceControlHandlerEx(ServiceControlHandler);
var serviceStatusHandle = Win32.RegisterServiceCtrlHandlerEx(DummyService.ServiceName,
myCallback,
IntPtr.Zero);
var deviceInterface = new Win32.DEV_BROADCAST_DEVICEINTERFACE();
int size = Marshal.SizeOf(deviceInterface);
deviceInterface.dbcc_size = size;
deviceInterface.dbcc_devicetype = Win32.DBT_DEVTYP_DEVICEINTERFACE;
IntPtr buffer = default(IntPtr);
buffer = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(deviceInterface, buffer, true);
deviceEventHandle = Win32.RegisterDeviceNotification(serviceStatusHandle,
buffer,
Win32.DEVICE_NOTIFY_SERVICE_HANDLE |
Win32.DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
if (deviceEventHandle == IntPtr.Zero)
{
// TODO handle error
}
return true;
}
示例13: Stop
public bool Stop(HostControl hc)
{
mqtt.Dispose();
t.Dispose();
t = null;
return true;
}
示例14: WatchForExitKey
void WatchForExitKey(HostControl hostControl)
{
while (!_terminate)
{
Thread.Sleep(TimeSpan.FromMilliseconds(1));
char ch;
try
{
if (!Console.KeyAvailable)
continue;
var tmp = Console.ReadKey();
ch = tmp.KeyChar;
}
catch (InvalidOperationException)
{
// console input is redirected
var tmp = Console.In.Read();
if (tmp == -1)
continue;
ch = (char)tmp;
}
if (ch == 'q')
{
Stop(hostControl);
Environment.Exit(0);
}
}
}
示例15: Start
public bool Start(HostControl hostControl)
{
if (string.IsNullOrEmpty(TestConfig.Instance.ServerUrl))
{
throw new Exception("Url为空 无法启动服务器");
}
Pioneer.WxSdk.SdkSetup.MessageTokenGetter = (dic) =>
{
PublicAccount pa = new PublicAccount();
pa.EncryptionKey = TestConfig.Instance.EncryptionKey;
pa.MessageToken = TestConfig.Instance.Token;
pa.AppId = TestConfig.Instance.AppId;
return pa;
};
SdkSetup.RegisterListener(new WxSdk.Message.DefaultMessageListener());
StartOptions so = new StartOptions();
so.Urls.Add(TestConfig.Instance.ServerUrl);
innerHost = WebApp.Start(so, builder =>
{
builder.Use(new MessageModel().ProcessRequest);
});
logger.Info("监听地址:" + TestConfig.Instance.ServerUrl);
logger.Info("启动成功");
return true;
}