/// <summary> /// Método acionado quando o status estiver sendo alterado. /// </summary> /// <param name="status"></param> /// <returns></returns> protected bool BeginStatusChange(ServiceHostStatus status) { bool flag = false; lock (_hostPropertiesLock) { try { flag = this.SetHostStatus(status); } catch (ServiceException) { if (status != ServiceHostStatus.Stopping) { throw; } flag = true; } if (flag) { Status = status; } return(flag); } }
/// <summary> /// Triggered when the application host is ready to start the service. /// </summary> /// <param name="cancellationToken">Indicates that the start process has been aborted.</param> /// <returns>Task.</returns> /// <autogeneratedoc /> public Task StartAsync(CancellationToken cancellationToken) { ServiceHostStatus = ServiceHostStatus.StartPending; LocalNetworkDevice = DiscoverLocalNetworkDevice(); _logger?.LogInformation("NetworkMap Service Started on Primary Network: {PrimaryIPAddressSubnet}", LocalNetworkDevice?.LocalNetworks?.PrimaryNetwork?.NetworkIPAddressSubnet); ServiceHostStatus = ServiceHostStatus.Running; return(Task.CompletedTask); }
/// <summary> /// Triggered when the application host is ready to start the service. /// </summary> /// <param name="cancellationToken">Indicates that the start process has been aborted.</param> /// <returns>Task.</returns> /// <autogeneratedoc /> public Task StartAsync(CancellationToken cancellationToken) { ServiceHostStatus = ServiceHostStatus.StartPending; var tasks = new List <Task> { CommonServices.StartAsync(cancellationToken), PingService.StartAsync(cancellationToken), ArpService.StartAsync(cancellationToken) }; return(tasks.WaitForTasks(cancellationToken, (t) => { if (t.IsCompleted && t.Status == TaskStatus.RanToCompletion) { ServiceHostStatus = ServiceHostStatus.Running; } }, Logger)); }
/// <summary> /// Triggered when the application host is performing a graceful shutdown. /// </summary> /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param> /// <returns>Task.</returns> /// <autogeneratedoc /> public Task StopAsync(CancellationToken cancellationToken) { var tasks = new List <Task> { ArpService.StopAsync(cancellationToken), PingService.StopAsync(cancellationToken), CommonServices.StopAsync(cancellationToken) }; ServiceHostStatus = ServiceHostStatus.StopPending; var logger = CommonServices?.LoggerFactory?.CreatePureLogger <CommonNetworkServices>(); return(tasks.WaitForTasks(cancellationToken, (t) => { if (t.IsCompleted) { ServiceHostStatus = ServiceHostStatus.Stopped; } } , logger)); }
/// <summary> /// Triggered when the application host is performing a graceful shutdown. /// </summary> /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param> /// <returns>Task.</returns> /// <autogeneratedoc /> public Task StopAsync(CancellationToken cancellationToken) { ServiceHostStatus = ServiceHostStatus.Stopped; return(Task.CompletedTask); }
/// <summary> /// Triggered when the application host is ready to start the service. /// </summary> /// <param name="cancellationToken">Indicates that the start process has been aborted.</param> /// <returns>Task.</returns> /// <autogeneratedoc /> public Task StartAsync(CancellationToken cancellationToken) { ServiceHostStatus = ServiceHostStatus.Running; return(Task.CompletedTask); }
/// <summary> /// Define a situação do host. /// </summary> /// <param name="status"></param> /// <returns></returns> protected override bool SetHostStatus(ServiceHostStatus status) { return(true); }
/// <summary> /// Define o status do host. /// </summary> /// <param name="newStatus"></param> /// <returns></returns> protected abstract bool SetHostStatus(ServiceHostStatus newStatus);