Example #1
0
        private void AppStartup(object sender, StartupEventArgs e)
        {
            string userprofilepath = Environment.GetEnvironmentVariable(@"USERPROFILE");

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

            string dbfile = userprofilepath + @"\CNCLib.db";

            GlobalDiagnosticsContext.Set("connectionString", $"Data Source={dbfile}");

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

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

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

            Dependency.Initialize(new LiveDependencyProvider());

            Dependency.Container.RegisterFrameWorkTools();
            Dependency.Container.RegisterRepository();
            Dependency.Container.RegisterLogic();
            Dependency.Container.RegisterLogicClient();
            Dependency.Container.RegisterSerialCommunication();
            Dependency.Container.RegisterServiceAsLogic();
            Dependency.Container.RegisterCNCLibWpf();
            Dependency.Container.RegisterMapper(new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <LogicAutoMapperProfile>();
                cfg.AddProfile <WpfAutoMapperProfile>();
                cfg.AddProfile <GCodeGUIAutoMapperProfile>();
            }));

            var userContext = new CNCLibUserContext();

            Dependency.Container.RegisterInstance((ICNCLibUserContext)userContext);

            // Open Database here

            try
            {
                Repository.SqLite.MigrationCNCLibContext.InitializeDatabase(dbfile, false, false);
            }
            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();
            }
        }
Example #2
0
        private void AppStartup(object sender, StartupEventArgs e)
        {
            GlobalDiagnosticsContext.Set("connectionString", MigrationCNCLibContext.ConnectString);

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

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

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

            Dependency.Initialize(new LiveDependencyProvider());

            Dependency.Container.RegisterFrameWorkTools();
            Dependency.Container.RegisterRepository();
            Dependency.Container.RegisterLogic();
            Dependency.Container.RegisterLogicClient();
            Dependency.Container.RegisterSerialCommunication();
            Dependency.Container.RegisterServiceAsLogic();
            Dependency.Container.RegisterCNCLibWpf();
            Dependency.Container.RegisterMapper(new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <LogicAutoMapperProfile>();
                cfg.AddProfile <WpfAutoMapperProfile>();
                cfg.AddProfile <GCodeGUIAutoMapperProfile>();
            }));

            var userContext = new CNCLibUserContext();

            Dependency.Container.RegisterInstance((ICNCLibUserContext)userContext);

            //	        string sqlconnectstring = @"Data Source = (LocalDB)\MSSQLLocalDB; Initial Catalog = CNCLib; Integrated Security = True";
            string sqlconnectstring = null;

            // Open Database here

            try
            {
                Repository.SqlServer.MigrationCNCLibContext.InitializeDatabase(sqlconnectstring, 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();
            }
        }
Example #3
0
        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();
            }
        }
Example #4
0
        private void AppStartup(object sender, StartupEventArgs e)
        {
            var userContextRW = new CNCLibUserContext();
            ICNCLibUserContext userContext = userContextRW;

            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 <WpfAutoMapperProfile>();
                    cfg.AddProfile <GCodeGUIAutoMapperProfile>();
                })
            });
            moduleInit.Add(new CNCLib.Logic.Client.ModuleInitializer());
            moduleInit.Add(new CNCLib.WpfClient.ModuleInitializer());
            moduleInit.Add(new CNCLib.Service.WebAPI.ModuleInitializer()
            {
                ConfigureHttpClient = httpClient =>
                {
                    HttpClientHelper.PrepareHttpClient(httpClient, @"https://cnclib.azurewebsites.net");
                    httpClient.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue(
                            "Basic", Base64Helper.StringToBase64($"{userContextRW.UserName}:{userContextRW.Password}"));
                }
            });

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

            _logger.Info(@"Starting ...");
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

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

            moduleInit.Initialize(AppService.ServiceCollection, localizationCollector);

            AppService.BuildServiceProvider();

            // Open WebAPI Connection
            //
            bool ok = Task.Run(
                async() =>
            {
                try
                {
                    await userContextRW.InitUserContext(userContextRW.UserName);

                    using (var scope = AppService.ServiceProvider.CreateScope())
                    {
                        var controller = scope.ServiceProvider.GetRequiredService <IMachineService>();
                        var m          = await controller.Get(1000000);

                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Cannot connect to WebAPI: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Current.Shutdown();
                    return(false);
                }
            }).ConfigureAwait(true).GetAwaiter().GetResult();
        }
Example #5
0
        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();
            }
        }
Example #6
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();
            }
        }