コード例 #1
0
        private static async Task Main()
        {
            // https://www.c-sharpcorner.com/UploadFile/f9f215/how-to-restrict-the-application-to-just-one-instance/
            // Restrict the application to run in just one instance
            Mutex mutex = new Mutex(true, AppConstants.AppName, out bool createdNew);

            // If it is not the first instance, means that the App is already running!
            // We need to alert the user and then exiting the application.
            if (!createdNew)
            {
                MessageBox.Show(
                    "An instance of the App is already running.",
                    AppConstants.AppName,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                // Exit
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // When in production, check if the DB folder exists. If not, create it.
            CreateDataFolderInProduction();

            // Set the options builder for our database context
            DbContextOptionsBuilder <DatabaseContext> builder = new DbContextOptionsBuilder <DatabaseContext>();

            builder.UseSqlite(IsDebug() ? AppConstants.connectionStringDev : AppConstants.connectionString);

            // Instantiate our database
            DatabaseContext DatabaseContext = new DatabaseContext(builder.Options);

            // Instantiate our repository
            IAppRepository AppRepository = new AppRepository(DatabaseContext);

            // Instantiate our services
            AppServices.ConfigureServices(AppRepository);

            // Set the application language
            AppTranslations.ConfigureLanguage(await AppServices.AppSettingsService.GetAppLanguageAsync());

            Application.Run(new MainForm());
        }
コード例 #2
0
        public TestsConfig()
        {
            // Set the Sqlite in memory database connection
            _connection = new SqliteConnection(AppConstants.connectionStringTestDB);

            // Open database connection
            _connection.Open();

            // Set the options builder for our test database context
            DbContextOptionsBuilder <DatabaseContext> builder = new DbContextOptionsBuilder <DatabaseContext>();

            builder.UseSqlite(_connection);

            // Instantiate our test database context
            DatabaseContext DatabaseContext = new DatabaseContext(builder.Options);

            // Instantiate our repository
            IAppRepository AppRepository = new AppRepository(DatabaseContext);

            // Instantiate our services
            AppServices.ConfigureServices(AppRepository);
        }