public static void Configure(string name, ServiceStartup startup) { if (!IsInstalled(name)) throw new Exception(string.Format(M_Service__0__is_not_installed_, name)); if (startup == ServiceStartup.Disabled) SetServiceStatus(name, ServiceStatus.Stopped); SetServiceStartup(name, startup); if (startup == ServiceStartup.Automatic) SetServiceStatus(name, ServiceStatus.Started); }
public RequestProcessorIntegrationTests() { var context = new HostBuilderContext(new Dictionary <object, object>()); context.Configuration = new ConfigurationBuilder() .AddInMemoryCollection( new Dictionary <string, string> { ["SERVICE_URI_DELIVERY"] = DeliveryUri, ["SERVICE_URI_DRONE"] = DroneSchedulerUri, ["SERVICE_URI_PACKAGE"] = PackageUri }) .AddEnvironmentVariables() .Build(); context.HostingEnvironment = Mock.Of <Microsoft.Extensions.Hosting.IHostEnvironment>(e => e.EnvironmentName == "Test"); var serviceCollection = new ServiceCollection(); ServiceStartup.ConfigureServices(context, serviceCollection); serviceCollection.AddLogging(builder => builder.AddDebug()); _testServer = new TestServer( new WebHostBuilder() .UseTestServer() .Configure(builder => { builder.Run(ctx => _handleHttpRequest(ctx)); }) .ConfigureServices(builder => { builder.AddControllers(); })); _testServer.AllowSynchronousIO = true; serviceCollection.Replace( ServiceDescriptor.Transient <HttpMessageHandlerBuilder, TestServerMessageHandlerBuilder>( sp => new TestServerMessageHandlerBuilder(_testServer))); var serviceProvider = serviceCollection.BuildServiceProvider(); _requestProcessor = serviceProvider.GetService <IRequestProcessor>(); }
public PackageServiceCallerIntegrationTests() { var context = new HostBuilderContext(new Dictionary <object, object>()); context.Configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["SERVICE_URI_PACKAGE"] = PackageUri }) .AddEnvironmentVariables() .Build(); context.HostingEnvironment = Mock.Of <Microsoft.Extensions.Hosting.IHostingEnvironment>(e => e.EnvironmentName == "Test"); var serviceCollection = new ServiceCollection(); ServiceStartup.ConfigureServices(context, serviceCollection); serviceCollection.AddLogging(builder => builder.AddDebug()); _testServer = new TestServer( new WebHostBuilder() .Configure(builder => { builder.UseMvc(); builder.Run(ctx => _handleHttpRequest(ctx)); }) .ConfigureServices(builder => { builder.AddMvc(); })); serviceCollection.Replace( ServiceDescriptor.Transient <HttpMessageHandlerBuilder, TestServerMessageHandlerBuilder>( sp => new TestServerMessageHandlerBuilder(_testServer))); var serviceProvider = serviceCollection.BuildServiceProvider(); _caller = serviceProvider.GetService <IPackageServiceCaller>(); }
static void Main(string[] args) { log.Register(new ConfigLogManager()); Cmd.Handle(args, () => { ServiceStartup ss = new ServiceStartup(); if (!Cmd.Exists("s") || Debugger.IsAttached) { ss.Begin(); log.w("Press ENTER to unload module(s) ..."); Console.ReadLine(); ss.End(); log.w("Press any key to exit ..."); Console.ReadKey(); } else { ServiceBase[] svc = { ss }; ServiceBase.Run(svc); } }); }
public DeliveryServiceCallerIntegrationTests() { var context = new StatelessServiceContext( new NodeContext(string.Empty, new NodeId(999, 111), 555, string.Empty, string.Empty), new Mock <ICodePackageActivationContext>().Object, string.Empty, new Uri("http://www.microsoft.com"), null, Guid.Empty, 0); var serviceCollection = new ServiceCollection(); ServiceStartup.ConfigureServices(context, serviceCollection); serviceCollection .AddLogging(builder => builder.AddDebug()); _testServer = new TestServer( new WebHostBuilder() .Configure(builder => { builder.UseMvc(); builder.Run(ctx => _handleHttpRequest(ctx)); }) .ConfigureServices(builder => { builder.AddMvc(); })); serviceCollection.Replace( ServiceDescriptor.Transient <HttpMessageHandlerBuilder, TestServerMessageHandlerBuilder>( sp => new TestServerMessageHandlerBuilder(_testServer))); var serviceProvider = serviceCollection.BuildServiceProvider(); _caller = serviceProvider.GetService <IDeliveryServiceCaller>(); }
static void Main() { ServiceStartup.Main(); UnixSignal[] signals = { new UnixSignal(Signum.SIGINT), new UnixSignal(Signum.SIGTERM), }; // Wait for a unix signal for (bool exit = false; !exit;) { int id = UnixSignal.WaitAny(signals); if (id >= 0 && id < signals.Length) { if (signals[id].IsSet) { exit = true; } } } }
/// <summary>Configures the dependent services.</summary> /// <param name="services">The services.</param> public void ConfigureDependentServices(IServiceCollection services) { ServiceStartup.RegisterServices(services); services .AddLogging() .UseDeepSleepPingEndpoint() .UseDeepSleepJsonNegotiation() .UseDeepSleepXmlNegotiation() .UseDeepSleepMultipartFormDataNegotiation() .UseDeepSleepFormUrlEncodedNegotiation() .UseDeepSleepOpenApi((o) => { o.V2RouteTemplate = "openapi/v2/doc"; o.V3RouteTemplate = "openapi/v3/doc"; o.XmlDocumentationFileNames.Add("Api.DeepSleep.Models.xml"); o.XmlDocumentationFileNames.Add("Api.DeepSleep.Controllers.xml"); o.XmlDocumentationFileNames.Add("deepsleep.xml"); o.XmlDocumentationFileNames.Add("deepsleep.web.xml"); }) .UseDeepSleepDataAnnotationValidations() .UseDeepSleepServices((o) => { o.DiscoveryStrategies = ServiceStartup.DiscoveryStrategies(); o.DefaultRequestConfiguration = ServiceStartup.DefaultRequestConfiguration(); o.WriteConsoleHeader = false; o.OnException = (ctx, ex) => { var context = ctx.GetContext(); if (context.Items.ContainsKey("exceptionHandlerCount")) { var count = (int)context.Items["exceptionHandlerCount"]; context.Items["exceptionHandlerCount"] = count++; } else { context.Items["exceptionHandlerCount"] = 1; } return(Task.CompletedTask); }; o.OnRequestProcessed = (ctx) => { var context = ctx.GetContext(); if (context.Items.ContainsKey("requestHandlerCount")) { var count = (int)context.Items["requestHandlerCount"]; context.Items["requestHandlerCount"] = count++; } else { context.Items["requestHandlerCount"] = 1; } return(Task.CompletedTask); }; }); if (ServicePreprocessor != null) { ServicePreprocessor(services); } }
private static bool ConsoleCtrlCheck(CtrlTypes ctrlType) { ServiceStartup.Stop(); return(false); }
public IdentityRestService(IConfiguration configuration, IHostingEnvironment environment) : base(ServiceStartup.GetConfigurationRoot(), new AggregatorServiceStartup()) { _environment = environment; }
public List <AuthorizedUser> AuthorizedUsers(string terminal = null) { Terminal = terminal ?? Terminal; return(ServiceStartup.GetAuthorized(Terminal)); }
private async Task <LoginResult> TryLoginAsync(LoginCode code, User find, string ip) { if (code == LoginCode.Ok) { // 默认单人登录 var single = (mongo.SystemConfigCollection.AsQueryable().Where(s => s.Key == $"{ip}:SingleAuth").Select(s => s.JObject).FirstOrDefault() ?? "true").Equals("true", StringComparison.OrdinalIgnoreCase); var isFirstUser = false; var primary = ServiceStartup.GetPrimaryAuthorized(ip); var token = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"); var menuId = mongo.RoleCollection.AsQueryable().FirstOrDefault(r => r.Users.Contains(find.UniqueId) && r.DefaultMenu != null)?.DefaultMenu ?? null; var menu = mongo.MenuCollection.AsQueryable().FirstOrDefault(f => f.UniqueId == menuId); var defaultMenu = menu == null ? null : $"/{menu.ParentId}/{menu.Uri}"; if (primary == null) { isFirstUser = true; primary = new AuthorizedUserCache { UniqueId = find.UniqueId, LoginId = find.LoginId, DisplayName = find.Employee?.DisplayName ?? find.LoginId, Kernel = false, Token = token, DefaultMenu = defaultMenu, }; await ServiceStartup.SetPrimaryAuthorizedAsync(ip, primary); } if (single) { await mongo.AccessJournalCollection.InsertOneAsync(new AccessJournal { Computer = ip, UserId = primary.LoginId, UserName = primary.DisplayName, }); return(new LoginResult { Code = code, Jwt = token, Menu = defaultMenu, Ip = ip, }); } if (!isFirstUser) { if (find.LoginId == primary.LoginId) { return(new LoginResult { Code = LoginCode.DuplicateLogin, Ip = ip, }); } await ServiceStartup.SetSecondaryAuthorizedAsync(ip, new AuthorizedUserCache { UniqueId = find.UniqueId, LoginId = find.LoginId, DisplayName = find.Employee?.DisplayName ?? find.LoginId, Kernel = false, Token = token, DefaultMenu = defaultMenu, }); await mongo.AccessJournalCollection.InsertOneAsync(new AccessJournal { Computer = ip, UserId = primary.LoginId, UserName = primary.DisplayName, }); await mongo.AccessJournalCollection.InsertOneAsync(new AccessJournal { Computer = ip, UserId = find.LoginId, UserName = find.DisplayName, }); return(new LoginResult { Code = code, Jwt = token, Menu = defaultMenu, Ip = ip, }); } } return(new LoginResult { Code = code, Ip = ip, }); }
public static ItemBuilder Service(this ItemBuilder dsl, string name, ServiceStartup dominate, ServiceStartup makeSubmissive) { return dsl .Setter( action => { ServiceTools.Configure(name, action == DominationAction.Dominate ? dominate : makeSubmissive); }) .Getter( () => { var configuration = ServiceTools.TryGetConfiguration(name); if (configuration == null) return (dominate == ServiceStartup.Disabled) ? DominatorState.Dominated(ServiceDoesNotExistMessage) : DominatorState.Indetermined(ServiceStateNotRecognizedMessage); if (configuration.Value.Startup == dominate) return DominatorState.Dominated(); if (configuration.Value.Startup == makeSubmissive) return DominatorState.Submissive(); return DominatorState.Indetermined(ServiceStateNotRecognizedMessage); }); }
public static void SetServiceStartup(string name, ServiceStartup startup) { Registry.SetValue(mkServiceKey(name), "Start", (int)startup, RegistryValueKind.DWord); }
public ServiceConfiguration(ServiceStartup startup, ServiceStatus status) { Startup = startup; Status = status; }