Example #1
0
        public async Task InstallAsync()
        {
            InstalledApps = new List <Installable>();

            string tenant = TenantConvention.GetTenant(this.Url);

            InstallerLog.Verbose($"Creating database {tenant}.");
            var db = new DbInstaller(tenant);
            await db.InstallAsync().ConfigureAwait(false);

            InstallerLog.Verbose("Getting installables.");
            var installables = GetInstallables(tenant);

            foreach (var installable in installables)
            {
                try
                {
                    InstallerLog.Verbose($"Installing module {installable.ApplicationName}.");
                    await new AppInstaller(tenant, tenant, installable).InstallAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    InstallerLog.Error(ex.Message);
                    InstallerLog.Error($"Could not install module {installable.ApplicationName}.");
                }
            }
        }
Example #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            DbInstaller.Install(Configuration, services);
            MVCInstaller.Install(services);
        }
Example #3
0
        /// <summary>
        /// Adds a custom database connection that can later be resolved by dependency <see cref="IDbFactory{TConnection}"/>.
        /// </summary>
        /// <typeparam name="TConnection">The specific connection to register.</typeparam>
        public DatabaseConfiguration AddConnection <TConnection>(TConnection connection)
            where TConnection : Connection
        {
            _connections[typeof(TConnection)] = new DbInstaller <TConnection>(connection);

            return(this);
        }
Example #4
0
        public async Task InstallAsync()
        {
            InstalledApps = new List<Installable>();

            string tenant = TenantConvention.GetTenant(this.Url);
            InstallerLog.Verbose($"Creating database {tenant}.");
            var db = new DbInstaller(tenant);
            await db.InstallAsync().ConfigureAwait(false);

            InstallerLog.Verbose("Getting installables.");
            var installables = GetInstallables(tenant);

            foreach (var installable in installables)
            {
                try
                {
                    InstallerLog.Verbose($"Installing module {installable.ApplicationName}.");
                    await new AppInstaller(tenant, tenant, installable).InstallAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    InstallerLog.Error(ex.Message);
                    InstallerLog.Error($"Could not install module {installable.ApplicationName}.");
                }
            }
        }
Example #5
0
        /// <summary>
        /// Extends <see cref="IServiceCollection"/> to allow chained database installation
        /// </summary>
        /// <param name="services">DI container</param>
        /// <param name="connectionString">Db connection string</param>
        /// <returns>Passed DI container to allow chaining</returns>
        public static IServiceCollection ConfigureDatabase(this IServiceCollection services, string connectionString)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            return(DbInstaller.ConfigureDatabase(services, connectionString));
        }
Example #6
0
        private static void BeforeInstall(ILogger logger)
        {
            // When building this project, copy libs/*.dll to output directory.
            logger.Debug("Dll installs.");
            new DLLInstaller(logger).Install();

            logger.Debug("Database installs.");
            DbInstaller.Install();
        }
Example #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            MvcInstaller mvcInstaller = new MvcInstaller();

            mvcInstaller.InstallServices(services, Configuration);

            DbInstaller dbInstaller = new DbInstaller();

            dbInstaller.InstallServices(services, Configuration);
        }
Example #8
0
        public InstallDatabase(string migrationsPath)
        {
            var migrationsDirectory      = new DirectoryInfo(HostingEnvironment.MapPath(migrationsPath));
            IList <Migration> migrations = new MigrationLoader()
                                           .GetDatabaseMigrations(migrationsDirectory);

            IInstallerLoggingService logging = new SitecoreInstallerLoggingService();

            InstallationConnectionStringLocator locator = new SitecoreInstallationConnectionStringLocator();

            _command = new DbInstallerCore(locator, migrations, logging);
        }
Example #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var db = new DbInstaller();

            db.InstallServices(services, Configuration);
            var mvc = new MvcInstaller();

            mvc.InstallServices(services, Configuration);
            services.AddAutoMapper(typeof(Startup));
            var swagger = new SwaggerInstaller();

            swagger.InstallServices(services, Configuration);
            var cache = new CacheInstaller();

            cache.InstallServices(services, Configuration);
        }
Example #10
0
        public void InitDatabase()
        {
            DbInstaller.Install();

            _logger = new LoggerConfiguration()
                      .MinimumLevel.Debug()
                      .WriteTo.File("./log.txt").CreateLogger();
            HostLogger.UseLogger(new SerilogLogWriterFactory.SerilogHostLoggerConfigurator(_logger));

            mock = new Mock <IWebApiConnector>();
            mock.Setup(api => api.FindProjectWorkerByFaceId("2", GlobalConfig.ProjectCode)).ReturnsAsync("2222222");
            mock.Setup(api => api.CheckIn(GlobalConfig.ProjectCode, "2222222", new DateTime(2018, 1, 13, 8, 11, 30), "gate01")).ReturnsAsync(true);
            mock.Setup(api => api.CheckIn(GlobalConfig.ProjectCode, "2222222", new DateTime(2018, 1, 13, 12, 11, 30), "gate01")).ReturnsAsync(false);
            mock.Setup(api => api.CheckOut(GlobalConfig.ProjectCode, "2222222", new DateTime(2018, 1, 13, 10, 11, 30))).ReturnsAsync(true);
            mock.Setup(api => api.CheckOut(GlobalConfig.ProjectCode, "2222222", new DateTime(2018, 1, 13, 14, 11, 30))).ReturnsAsync(false);
        }
Example #11
0
        public async Task InstallAsync()
        {
            InstalledApps = new List <Installable>();

            string tenant = TenantConvention.GetTenant(this.Url);

            this.Notify($"Creating database {tenant}.");
            var db = new DbInstaller(tenant);

            db.Notification += delegate(object sender, string message)
            {
                this.Notify(sender, message);
            };

            await db.InstallAsync().ConfigureAwait(false);

            this.Notify("Getting installables.");
            var installables = Installables.GetInstallables(tenant);

            foreach (var installable in installables)
            {
                try
                {
                    var installer = new AppInstaller(tenant, tenant, this.WithoutSample, installable);

                    installer.Notification += delegate(object sender, string message)
                    {
                        this.Notify(sender, message);
                    };

                    await installer.InstallAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    this.Notify("Error: " + ex.Message);
                    this.Notify($"Error: Could not install module {installable.ApplicationName}.");
                }
            }

            this.Notify("OK");
        }
Example #12
0
        public void InitDb()
        {
            DbInstaller.Install();

            _connector = new SqliteConnector();
        }
Example #13
0
        static void Main(string[] args)
        {
            var logger = new LoggerConfiguration()
                         .ReadFrom.AppSettings()
                         .WriteTo.RollingFile(Path.Combine(ZKTecoConfig.AppRootFolder, "logs", "info{Date}.log"), retainedFileCountLimit: 10)
                         .CreateLogger();

            HostFactory.Run(cfg =>
            {
                cfg.UseSerilog(logger);

                cfg.UseNinject(new ZKTecoModule());

                cfg.BeforeInstall(_ =>
                {
                    // When building this project, copy libs/*.dll to output directory.
                    logger.Information("RegisterDLLs starts...");
#if x64
                    //x64
                    RegisterDLLs("sdk_install", "x64", logger);
#else
                    //x86
                    RegisterDLLs("sdk_install", "x86", logger);
#endif
                    logger.Information("RegisterDLLs ends.");

                    logger.Information("InstallSyncDatabase starts...");

                    DbInstaller.Install();

                    logger.Information("InstallSyncDatabase ends.");
                });

                cfg.AfterUninstall(() =>
                {
                    logger.Information("UnregisterDLLs starts...");
#if x64
                    //x64
                    RegisterDLLs("sdk_uninstall", "x64", logger);
#else
                    //x86
                    RegisterDLLs("sdk_uninstall", "x86", logger);
#endif
                    logger.Information("UnregisterDLLs ends.");
                });

                cfg.Service <ZKTecoServiceControl>(x =>
                {
                    x.ConstructUsingNinject();
                    x.WhenStarted((s, h) => s.Start(h));
                    x.WhenStopped((s, h) => s.Stop(h));

                    // retry failed attendance logs.
                    x.UseQuartzNinject();
                    x.ScheduleQuartzJob(q =>
                    {
                        q.WithJob(() =>
                        {
                            return(JobBuilder.Create <ResendAttendancesJob>().WithIdentity("retryJob", "syncbackend").Build());
                        }).AddTrigger(() =>
                        {
                            return(TriggerBuilder.Create()
                                   .WithIdentity("retryTrigger", "syncbackend")
                                   .StartNow()
                                   .WithSimpleSchedule(b => b.WithIntervalInHours(1).RepeatForever())
                                   .Build());
                        });
                    });
                });

                cfg.RunAsLocalService();
                cfg.StartAutomatically();

                cfg.SetServiceName("ZKTeco-SyncBackendService");
                cfg.SetDisplayName("ZKTeco Sync Backend Service");
                cfg.SetDescription("ZKTeco Synchronize attendance log to CTMS.");

                cfg.OnException(ex =>
                {
                    logger.Error("OnException: {@ex}", ex);
                });
            });
        }