public async Task ShouldDisposeEventScopeOnServiceDisposeIfScopeWasInitializedTest() { await _messagingService.StopAsync(CancellationToken.None); _eventScopeMock.Verify(x => x.Dispose(), Times.Never); await _messagingService.StartAsync(CancellationToken.None); await _messagingService.StopAsync(CancellationToken.None); _eventScopeMock.Verify(x => x.Dispose(), Times.Once); }
private unsafe void DeferredStop() { fixed(SERVICE_STATUS *status = &_status) { var currentState = _status.currentState; _status.checkPoint = 0; _status.waitHint = 0; _status.currentState = ServiceControllerStatus.StopPending; SetServiceStatus(_statusHandle, status); try { var source = new CancellationTokenSource(); _service.StopAsync(source.Token); _status.currentState = ServiceControllerStatus.Stopped; SetServiceStatus(_statusHandle, status); } catch (Exception ex) { XTrace.WriteException(ex); _status.currentState = currentState; SetServiceStatus(_statusHandle, status); } } }
public async Task CanComponentsStart(string componentToError, string expected) { IServiceCollection serviceCollection = this.GetServiceDescriptors(); string fromHeaders = componentToError == "from" ? "?WillError=true" : string.Empty; string toHeaders = componentToError == "to" ? "?WillError=true" : string.Empty; string actual = string.Empty; try { Kyameru.Route.From($"injectiontest:///mememe{fromHeaders}") .Process(this.processComponent.Object) .To($"injectiontest:///somewhere{toHeaders}") .Build(serviceCollection); IServiceProvider provider = serviceCollection.BuildServiceProvider(); IHostedService service = provider.GetService <IHostedService>(); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); } catch (Exception ex) { actual = ex.Message; } Assert.AreEqual(expected, actual); }
public async Task StopAsync(CancellationToken cancellationToken) { if (_next != null) { await _next.StopAsync(cancellationToken); } }
public async Task HostedServiceManager_Triggers_StopServicesAsync() { mockRpcServer.Setup(a => a.ShutdownAsync()).Returns(Task.CompletedTask); await hostedServiceManager.StopAsync(CancellationToken.None); mockRpcServer.Verify(a => a.ShutdownAsync(), Times.Once); }
public async Task CanActivateAndRun() { IServiceCollection serviceCollection = this.GetServiceDescriptors(); Routable routable = null; this.processComponent.Reset(); this.processComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); Kyameru.Route.From("injectiontest:///mememe") .Process(this.processComponent.Object) .To("injectiontest:///somewhere") .Build(serviceCollection); IServiceProvider provider = serviceCollection.BuildServiceProvider(); IHostedService service = provider.GetService <IHostedService>(); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.AreEqual("Injected Test Complete", routable?.Body); }
public async Task CanExecuteAtomic() { Component.Test.GlobalCalls.Calls.Clear(); IHostedService service = this.GetNoErrorChain(); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.AreEqual(6, this.GetCallCount()); }
public async Task AddHeaderErrors(bool secondFunction) { Component.Test.GlobalCalls.Calls.Clear(); IHostedService service = this.GetHeaderError(secondFunction); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.AreEqual(6, this.GetCallCount()); }
private async Task <bool> RunProcess(string callsContain) { Component.Test.GlobalCalls.Calls.Clear(); IHostedService service = this.GetRoute(); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); return(Kyameru.Component.Test.GlobalCalls.Calls.Contains(callsContain)); }
public async Task CanExecuteMultipleChains() { Component.Test.GlobalCalls.Calls.Clear(); IHostedService service = this.AddComponent(true); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.AreEqual(20, this.GetCallCount()); }
public IActionResult PublishWeeklyStats() { try { _timeHostedService.StopAsync(new System.Threading.CancellationToken()); _timeHostedService.StartAsync(new System.Threading.CancellationToken()); return(Ok("Published")); } catch (Exception e) { return(Ok("Not published: \n" + e.Message)); } }
public async Task <bool> StopUpdatingAsync() { if (_progress.GetIsUpdatingStarted()) { await _hostedUpdater.StopAsync(_progress.GetCurrentCalnellationToken()); return(true); } else { return(false); } }
public async Task ErrorComponentErrors() { Routable routable = null; this.errorComponent.Reset(); this.errorComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; throw new ProcessException("Manual Error", new IndexOutOfRangeException("Random index")); }); IHostedService service = this.GetHostedService(false, false, true); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.IsTrue(this.IsInError(routable, "Error Component")); }
public async Task FromException() { Routable routable = null; this.errorComponent.Reset(); this.errorComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); this.processComponent.Reset(); IHostedService service = this.GetHostedService(true); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.IsNull(routable); }
public async Task AtomicError() { Routable routable = null; this.errorComponent.Reset(); this.errorComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); this.processComponent.Reset(); IHostedService service = this.GetHostedService(false, false, true); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.IsTrue(this.IsInError(routable, "Atomic Component")); }
public async Task CanRunDIComponent() { AutoResetEvent autoResetEvent = new AutoResetEvent(false); Routable routable = null; this.diProcessor.Reset(); this.diProcessor.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); IHostedService service = this.SetupDIComponent(); await service.StartAsync(CancellationToken.None); autoResetEvent.WaitOne(TimeSpan.FromSeconds(5)); await service.StopAsync(CancellationToken.None); Assert.AreEqual("Yes", routable.Headers["ComponentRan"]); }
private async void bOperation_Click(object sender, EventArgs e) { switch (HostedServiceStatus) { case HostedServiceStatus.Starting: case HostedServiceStatus.Stopping: break; case HostedServiceStatus.Running: UpdateServiceStatus(HostedServiceStatus.Stopping); try { await bindedService.StopAsync(); } catch (Exception ex) { logError("停止服务时出错:" + ex.Message, ex); UpdateServiceStatus(HostedServiceStatus.Running, true); break; } UpdateServiceStatus(HostedServiceStatus.Stopped); break; case HostedServiceStatus.Stopped: UpdateServiceStatus(HostedServiceStatus.Starting); try { await bindedService.StartAsync(); } catch (Exception ex) { logError("启动服务时出错:" + ex.Message, ex); UpdateServiceStatus(HostedServiceStatus.Stopped, true); break; } UpdateServiceStatus(HostedServiceStatus.Running); break; default: break; } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifetime, IConsulClient consulClient, IHostedService hostedService) { loggerFactory.AddConsole(); var _logger = loggerFactory.CreateLogger <Startup>(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); app.UseSwagger(c => { c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value); }); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs"); }); lifetime.ApplicationStopping.Register(() => { _logger.LogInformation("Deregistering from Consul"); try { hostedService.StopAsync(new CancellationToken()); } catch (Exception ex) { _logger.LogError(ex, $"Deregisteration failed"); } }); app.Map("/health", appBulider => { appBulider.Run(async context => await context.Response.WriteAsync("health")); }); app.UseWelcomePage(); }
public async Task ComponentError() { Routable routable = null; this.errorComponent.Reset(); this.errorComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { routable = x; }); this.processComponent.Reset(); this.processComponent.Setup(x => x.Process(It.IsAny <Routable>())).Callback((Routable x) => { throw new Kyameru.Core.Exceptions.ProcessException("Manual Error"); }); IHostedService service = this.GetHostedService(); await service.StartAsync(CancellationToken.None); await service.StopAsync(CancellationToken.None); Assert.IsTrue(this.IsInError(routable, "Processing component")); }
public async Task StopAsync(CancellationToken cancellationToken) { var scope = _logger.BeginScope(GetScopeState()); _logger.LogInformation("Stopping..."); var stopwatch = Stopwatch.StartNew(); try { await _inner.StopAsync(cancellationToken); _logger.LogInformation($"took {stopwatch.Elapsed.TotalMilliseconds}ms to stop"); } catch (Exception ex) { _logger.LogCritical(ex, ex.Message); throw; } finally { scope.Dispose(); } }
public async Task <IActionResult> StopCounter() { await counterService.StopAsync(new CancellationToken(true)); return(Ok("Counter Service Stopped")); }
public Task StopAsync(CancellationToken cancellationToken) => _underlyingService.StopAsync(cancellationToken);
public Task StopAsync(CancellationToken cancellationToken) { return(_hostedService.StopAsync(cancellationToken)); }
/// <summary> /// Method to stop the service /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private static void StopService(object sender, ConsoleCancelEventArgs args) { _scheduledService.StopAsync(_cancellationTokenSource.Token); _cancellationTokenSource.Cancel(); }
public Task StopAsync(CancellationToken cancellationToken) => _hostedService.StopAsync(cancellationToken);
/// <inheritdoc /> public Task StopAsync(CancellationToken cancellationToken) => _hostedServiceImplementation.StopAsync(cancellationToken);