public bool Start(HostControl hc) { _hostControl = hc; var hostDirectory = LightBlueConfiguration.SetAsWindowsHost(_settings.ServiceTitle, _settings.Cscfg, _settings.Csdef, _settings.RoleName); Trace.TraceInformation("Worker host service LightBlue context created at directory {0}", hostDirectory); var assemblyPath = Path.IsPathRooted(_settings.Assembly) ? _settings.Assembly : Path.Combine(Environment.CurrentDirectory, _settings.Assembly); var entryPoint = Assembly.LoadFrom(assemblyPath) .GetTypes() .Single(t => typeof(RoleEntryPoint).IsAssignableFrom(t)); _role = (RoleEntryPoint)Activator.CreateInstance(entryPoint); Trace.TraceInformation("Worker host service role entry point {0} located at {1}", entryPoint.FullName, assemblyPath); if (!_role.OnStart()) { Trace.TraceError("Worker host service role entry point {0} start failed", entryPoint.FullName); _hostControl.Restart(); return(true); } Task.Run(() => { try { _role.Run(); } catch (Exception ex) { Trace.TraceError("Worker host service errored with exception: {0}", ex); _hostControl.Restart(); } }); Trace.TraceInformation("Worker host service role entry point {0} running", entryPoint.FullName); return(true); }
private void RunRole(Type roleType) { // does this also apply to web roles?? if (!roleType.Name.Contains("Worker")) { Console.WriteLine("Unable to run a non worker role"); return; } _workerRole = (RoleEntryPoint)Activator.CreateInstance(roleType); if (!_workerRole.OnStart()) { Console.WriteLine("Role failed to start for '{0}'", roleType); return; } Console.WriteLine("Role is starting for '{0}'", roleType); _workerRole.Run(); }
private void RunRole(Type workerRoleType) { _workerRole = (RoleEntryPoint)Activator.CreateInstance(workerRoleType); if (!_workerRole.OnStart()) { Trace.TraceError("Role failed to start for '{0}'", workerRoleType); return; } try { if (workerRoleType.Name.Contains("WebRole")) { Trace.TraceInformation("HostRunner: Will not call Run() on WebRole, waiting for thread control."); try { Task.Delay(-1, LightBlueThreadControl.CancellationToken).Wait(); } catch (AggregateException) { Trace.TraceError("HostRunner: Cancellation requested, terminating."); } catch (OperationCanceledException) { Trace.TraceError("HostRunner: Cancellation requested, terminating."); } } else { _workerRole.Run(); } } finally { _workerRole.OnStop(); } }