コード例 #1
0
ファイル: Startup.cs プロジェクト: VB6Hobbyst7/CNCLib
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
        {
            Services = app.ApplicationServices;

            CNCLibContext.InitializeDatabase2();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();
            app.UseHttpsRedirection();

            app.UseCors(CorsAllowAllName);

            app.UseAuthentication();
            app.UseAuthorization();

            void callback(object x)
            {
                Hub.Clients.All.SendAsync("heartbeat");
            }

            var timer = new Timer(callback);

            timer.Change(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30));

            app.UseSwagger();
            app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "CNCLib API V1"); });

            app.UseEndpoints(
                endpoints =>
            {
                endpoints.MapHub <CNCLibHub>("/cncLibSignalR");
                endpoints.MapDefaultControllerRoute();
            });

            app.UseSpa(
                spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: yazici/CNCLib
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            // Open Database here

            CNCLibContext.InitializeDatabase2(false, false);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "CNCLib API V1"); });

            app.UseCors("AllowAll");
            app.UseMvc();
        }
コード例 #3
0
ファイル: App.xaml.cs プロジェクト: yazici/CNCLib
        private void AppStartup(object sender, StartupEventArgs e)
        {
            string connectString = SqlServerDatabaseTools.ConnectString;

            GlobalDiagnosticsContext.Set("logDir", $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/CNCLib.Sql/logs");
            GlobalDiagnosticsContext.Set("connectionString", connectString);

            try
            {
#if DEBUG
                LogManager.ThrowExceptions = true;
#endif
                NLog.Logger logger = LogManager.GetLogger("foo");

                _logger.Info(@"Starting ...");
#if DEBUG
                LogManager.ThrowExceptions = false;
#endif
            }
            catch (SqlException)
            {
                // ignore Sql Exception
            }

            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            var userContext = new CNCLibUserContext();

            Dependency.Initialize(new LiveDependencyProvider())
            .RegisterFrameWorkTools()
            .RegisterFrameWorkLogging()
            .RegisterRepository(SqlServerDatabaseTools.OptionBuilder)
            .RegisterLogic()
            .RegisterLogicClient()
            .RegisterSerialCommunication()
            .RegisterServiceAsLogic()
            .RegisterCNCLibWpf()
            .RegisterMapper(
                new MapperConfiguration(
                    cfg =>
            {
                cfg.AddProfile <LogicAutoMapperProfile>();
                cfg.AddProfile <WpfAutoMapperProfile>();
                cfg.AddProfile <GCodeGUIAutoMapperProfile>();
            }))
            .RegisterInstance((ICNCLibUserContext)userContext);

            // Open Database here

            try
            {
                CNCLibContext.InitializeDatabase2(false, false);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);

                MessageBox.Show("Cannot connect to database" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Current.Shutdown();
            }

            var task = Task.Run(async() => await userContext.InitUserContext());
            while (!task.IsCompleted)
            {
                Task.Yield();
            }
        }
コード例 #4
0
ファイル: TestDataImporter.cs プロジェクト: lulzzz/CNCLib
 public TestDataImporter(CNCLibContext context) : base(context)
 {
     CsvDir = $@"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\Repository\TestData";
 }
コード例 #5
0
ファイル: App.xaml.cs プロジェクト: lulzzz/CNCLib
        private void AppStartup(object sender, StartupEventArgs e)
        {
            var localizationCollector = new LocalizationCollector();
            var moduleInit            = new InitializationManager();

            moduleInit.Add(new Framework.Tools.ModuleInitializer());
            moduleInit.Add(new Framework.Arduino.SerialCommunication.ModuleInitializer());
            moduleInit.Add(new Framework.Logic.ModuleInitializer()
            {
                MapperConfiguration =
                    new MapperConfiguration(
                        cfg =>
                {
                    cfg.AddProfile <LogicAutoMapperProfile>();
                    cfg.AddProfile <WpfAutoMapperProfile>();
                    cfg.AddProfile <GCodeGUIAutoMapperProfile>();
                })
            });
            moduleInit.Add(new CNCLib.Logic.ModuleInitializer());
            moduleInit.Add(new CNCLib.Logic.Client.ModuleInitializer());
            moduleInit.Add(new CNCLib.Repository.ModuleInitializer()
            {
                OptionsAction = SqlServerDatabaseTools.OptionBuilder
            });
            moduleInit.Add(new CNCLib.Service.Logic.ModuleInitializer());
            moduleInit.Add(new CNCLib.WpfClient.ModuleInitializer());

            string connectString = SqlServerDatabaseTools.ConnectString;

            GlobalDiagnosticsContext.Set("logDir", $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/CNCLib.Sql/logs");
            GlobalDiagnosticsContext.Set("connectionString", connectString);

            try
            {
#if DEBUG
                LogManager.ThrowExceptions = true;
#endif
                NLog.Logger logger = LogManager.GetLogger("foo");

                _logger.Info(@"Starting ...");
#if DEBUG
                LogManager.ThrowExceptions = false;
#endif
            }
            catch (SqlException)
            {
                // ignore Sql Exception
            }

            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            var userContext = new CNCLibUserContext(CNCLibConst.AdminUser);

            AppService.ServiceCollection = new ServiceCollection();
            AppService.ServiceCollection
            .AddTransient <ILoggerFactory, LoggerFactory>()
            .AddTransient(typeof(ILogger <>), typeof(Logger <>))
            .AddSingleton((ICNCLibUserContext)userContext);

            moduleInit.Initialize(AppService.ServiceCollection, localizationCollector);

            AppService.BuildServiceProvider();

            // Open Database here

            try
            {
                CNCLibContext.InitializeDatabase(AppService.ServiceProvider);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);

                MessageBox.Show("Cannot connect to database" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Current.Shutdown();
            }

            var task = Task.Run(async() => await userContext.InitUserContext());
            while (!task.IsCompleted)
            {
                Task.Yield();
            }
        }
コード例 #6
0
 public CRUDTestContext(CNCLibContext dbContext, IUnitOfWork uow, TIRepository repository)
 {
     DbContext  = dbContext;
     UnitOfWork = uow;
     Repository = repository;
 }
コード例 #7
0
ファイル: Startup.cs プロジェクト: lulzzz/CNCLib
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider)
        {
            var applicationLifetime = app.ApplicationServices.GetRequiredService <IHostApplicationLifetime>();

            applicationLifetime.ApplicationStopping.Register(OnShutdown);

            Services = app.ApplicationServices;

            CNCLibContext.InitializeDatabase(Services);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();
            app.UseHttpsRedirection();

            app.UseCors(CorsAllowAllName);

            app.UseAuthentication();
            app.UseAuthorization();

            void callback(object x)
            {
                Hub.Clients.All.HeartBeat();
            }

            var timer = new Timer(callback);

            timer.Change(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30));

            app.UseSwagger();
            app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "CNCLib API V1"); });

            app.UseEndpoints(
                endpoints =>
            {
                endpoints.MapHub <CNCLibHub>("/cncLibSignalR");
                endpoints.MapDefaultControllerRoute();
            });

            app.UseSpa(
                spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });

            void SetJobExecutor(IJobExecutor executor, object param)
            {
                // executor.ParamContainer = typeof(JobParamContainer); => this is default
                //executor.JobName  = xxx => default is Classname
                executor.Param = param;
            }

            var scheduler = Services.GetRequiredService <IJobScheduler>();

            scheduler.Daily <IDailyJob>(TimeSpan.Parse("02:00"), executor => SetJobExecutor(executor, "Hallo from daily"));

            _flushCallStatisticsJob = scheduler.Periodic <IFlushCallStatisticJob>(_flushStatisticsTime);

            scheduler.Start();
        }
コード例 #8
0
        private void AppStartup(object sender, StartupEventArgs e)
        {
            string userProfilePath = Environment.GetEnvironmentVariable(@"USERPROFILE");

            AppDomain.CurrentDomain.SetData("DataDirectory", userProfilePath);


            string dbFile = userProfilePath + @"\CNCLib.db";

            SqliteDatabaseTools.DatabaseFile = dbFile;
            string connectString = SqliteDatabaseTools.ConnectString;

            GlobalDiagnosticsContext.Set("logDir", $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}/CNCLib/logs");
            GlobalDiagnosticsContext.Set("connectionString", connectString);

            LogManager.ThrowExceptions = true;
            var logger = LogManager.GetLogger("foo");

            _logger.Info(@"Starting ...");
            LogManager.ThrowExceptions = false;

            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            var userContext = new CNCLibUserContext("global");

            AppService.ServiceCollection = new ServiceCollection();
            AppService.ServiceCollection
            .AddFrameWorkTools()
            .AddTransient <ILoggerFactory, LoggerFactory>()
            .AddTransient(typeof(ILogger <>), typeof(Logger <>))
            .AddRepository(SqliteDatabaseTools.OptionBuilder)
            .AddLogic()
            .AddLogicClient()
            .AddSerialCommunication()
            .AddServiceAsLogic()
            .AddCNCLibWpf()
            .AddMapper(
                new MapperConfiguration(
                    cfg =>
            {
                cfg.AddProfile <LogicAutoMapperProfile>();
                cfg.AddProfile <WpfAutoMapperProfile>();
                cfg.AddProfile <GCodeGUIAutoMapperProfile>();
            }))
            .AddSingleton((ICNCLibUserContext)userContext);

            AppService.BuildServiceProvider();
            // Open Database here

            try
            {
                CNCLibContext.InitializeDatabase2();
            }
            catch (Exception ex)
            {
                _logger.Error(ex);

                MessageBox.Show($"Cannot create/connect database in {dbFile} \n\r" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Current.Shutdown();
            }

            var task = Task.Run(async() => await userContext.InitUserContext());

            while (!task.IsCompleted)
            {
                Task.Yield();
            }
        }