protected override void OnStart(string[] args) { // создаем журнал событий _eventLink = new EventLink(TsGlobalConst.GetLogDirectory()); try { _eventLink.Post(TsGlobalConst.EventSource, string.Format( "Сервис менеджера турникетов, версия {0}", VersionInfoHelper.GetVersion(Assembly.GetExecutingAssembly()))); // создаем менеджер турникетов _manager = new global::TsManager.TsManager(_eventLink); // запуск менеджера _eventLink.Post(TsGlobalConst.EventSource, "Запуск менеджера турникетов"); _manager.Start(); _eventLink.Post(TsGlobalConst.EventSource, "Сервис запущен"); } catch (Exception e) { _eventLink.Post(TsGlobalConst.EventSource, "Старт сервиса", e); Stop(); } }
public override void ConfigureServices(IServiceCollection services) { base.ConfigureServices(services); ModelAssemblyRegistry.Instance.AddModelConfigAssembly(this.GetType().Assembly); var versionInfoHelper = VersionInfoHelper.Instance(); services.AddSingleton <IVersionInfoHelper>(sp => versionInfoHelper); services.AddSingleton <VersionInfoHelper>(sp => versionInfoHelper as VersionInfoHelper); var versionInfo = versionInfoHelper.GetVersionInfo(); services.AddSingleton(sp => versionInfo); services.AddOptions <DevSetting>().Bind(Configuration.GetSection("DevSetting")); services.AddScoped(sp => sp.GetService <IOptionsSnapshot <DevSetting> >().Value); services.AddDbContext <BaseDbContext>(async(sp, optionsBuilder) => { var dbContextHelper = sp.GetRequiredService <DbContextHelper>(); var dataProvider = dbContextHelper.GetDataProviderFromConfiguration(Configuration); var fixProvider = dbContextHelper.AutoFixProvider(dataProvider); var connName = "DefaultConnection"; var databaseName = "DemoDb"; //template for non tenant var dbConn = Configuration.GetConnectionString(connName); var myDatabaseHelper = sp.GetRequiredService <DbConnConfigHelper>(); var config = myDatabaseHelper.GetDbConnConfig(connName, dataProvider); if (config == null) { //create tenant Conn from "non tenant" template Conn //eg => replace DemoDb with DemoDb_{tenant} var tenant = myDatabaseHelper.Tenant; var dbConnTenant = dbConn.Replace(databaseName, $"{databaseName}_{tenant}", StringComparison.OrdinalIgnoreCase); config = DbConnConfig.Create( connectionName: connName, dataProvider: fixProvider, connString: dbConnTenant); dbContextHelper.SetupDbContextOptionsBuilder(optionsBuilder, fixProvider, dbConnTenant); await using (var baseDbContext = new BaseDbContext(optionsBuilder.Options)) { await myDatabaseHelper.SaveDbConnConfig(config); var canConnect = await baseDbContext.Database.CanConnectAsync(); if (!canConnect) { await baseDbContext.Database.EnsureCreatedAsync(); } await myDatabaseHelper.SaveDatabaseCreated(databaseName, true); } } dbContextHelper.SetupDbContextOptionsBuilder(optionsBuilder, config.DataProvider, config.ConnectionString); }); }
private void OnAbout() { AboutBox aboutBox = new AboutBox(); aboutBox.CopyrightYear = 2008; aboutBox.ProductName = "Форинт-С: Диспетчер устройств"; aboutBox.AppName = "Менеждер турникетов"; aboutBox.Version = VersionInfoHelper.GetVersion(Application.ExecutablePath);; aboutBox.Show(false); }
/// <summary> /// Запуск сервиса /// </summary> /// <param name="args">Параметры командной строки</param> protected override void OnStart(string[] args) { // создаем журнал событий _eventLink = new EventLink(DeviceManager.GetDeviceManagerLogDirectory()); try { // версия сервиса _eventLink.Post(DeviceManager.EventSource, string.Format(serviceHello, VersionInfoHelper.GetVersion(Assembly.GetExecutingAssembly()))); // создаем и публикуем диспетчер _devmanHost = new TcpBinaryHost <DeviceManager>(new DeviceManager(_eventLink)); _devmanHost.EventLink = _devmanHost.Target.DebugInfo ? _eventLink : null; _devmanHost.Marshal(); _eventLink.Post(DeviceManager.EventSource, serviceStarted); } catch (Exception e) { _eventLink.Post(DeviceManager.EventSource, "Старт сервиса", e); // останавливаем работу сервиса Stop(); } }