Esempio n. 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            System.Threading.Thread splashThread = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                splashScreen = new FormSplashFOCA(ProgramVersion);
                Application.Run(splashScreen);
                Application.ExitThread();
            }));

            splashThread.SetApartmentState(System.Threading.ApartmentState.STA);
            splashThread.Start();

            Application.DoEvents();
            //Load the FOCA
            Running = true;


            SqlConnectionStringBuilder connectionStringBuilder = null;
            bool csUpdated = false;

            try
            {
                ConnectionStringSettings csFromConfig = ConfigurationManager.ConnectionStrings[nameof(FocaContextDb)];
                //If there is no connection string configured, try with SQLEXPRESS instance
                if (csFromConfig == null || String.IsNullOrEmpty(csFromConfig.ConnectionString))
                {
                    connectionStringBuilder = new SqlConnectionStringBuilder(SQLExpressConnectionString);
                    csUpdated = true;
                }
                else
                {
                    connectionStringBuilder = new SqlConnectionStringBuilder(csFromConfig.ConnectionString);
                    if (String.IsNullOrWhiteSpace(connectionStringBuilder.InitialCatalog))
                    {
                        connectionStringBuilder.InitialCatalog = FocaDatabaseName;
                    }
                }
            }
            catch (ArgumentException)
            {
                csUpdated = true;
                connectionStringBuilder = new SqlConnectionStringBuilder(SQLExpressConnectionString);
            }

            while (!FocaContextDb.IsDatabaseAvailable(connectionStringBuilder.ToString()))
            {
                splashScreen.Invoke((MethodInvoker)(() => MessageBox.Show(splashScreen, "FOCA needs a SQL database. Please setup your connection and try again.", "Database not found", MessageBoxButtons.OK, MessageBoxIcon.Error)));

                // Display the connection dialog
                using (DataConnectionDialog dlg = new DataConnectionDialog(connectionStringBuilder))
                {
                    DialogResult connectionResult = DialogResult.Cancel;
                    splashScreen.Invoke((MethodInvoker)(() => connectionResult = dlg.ShowDialog(splashScreen)));

                    if (DialogResult.OK != connectionResult)
                    {
                        Environment.Exit(0);
                    }
                }
                csUpdated = true;
            }

            if (csUpdated)
            {
                UpdateConnectionString(connectionStringBuilder.ToString());
            }

            data                     = new Data();
            FormMainInstance         = new FormMain();
            FormMainInstance.TopMost = true;
            FormMainInstance.Shown  += FormMainInstance_Shown;

            FormOptionsInstance = new FormOptions();

            InitializeServicePointManager();

            Application.Run(FormMainInstance);
        }
Esempio n. 2
0
File: Program.cs Progetto: rdbh/FOCA
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FormSplashFOCA splashScreen = new FormSplashFOCA("Open Source");

            splashScreen.Show();
            Application.DoEvents();
            //Load the FOCA
            Running = true;

            SqlConnectionStringBuilder connectionStringBuilder = null;
            bool csUpdated = false;

            try
            {
                ConnectionStringSettings csFromConfig = ConfigurationManager.ConnectionStrings[nameof(FocaContextDb)];
                //If there is no connection string configured, try with SQLEXPRESS instance
                if (csFromConfig == null || String.IsNullOrEmpty(csFromConfig.ConnectionString))
                {
                    connectionStringBuilder = new SqlConnectionStringBuilder(SQLExpressConnectionString);
                    csUpdated = true;
                }
                else
                {
                    connectionStringBuilder = new SqlConnectionStringBuilder(csFromConfig.ConnectionString);
                    if (String.IsNullOrWhiteSpace(connectionStringBuilder.InitialCatalog))
                    {
                        connectionStringBuilder.InitialCatalog = FocaDatabaseName;
                    }
                }
            }
            catch (ArgumentException)
            {
                csUpdated = true;
                connectionStringBuilder = new SqlConnectionStringBuilder(SQLExpressConnectionString);
            }

            while (!FocaContextDb.IsDatabaseAvailable(connectionStringBuilder.ToString()))
            {
                MessageBox.Show("FOCA needs a SQL database. Please setup your connection and try again.", "Database not found", MessageBoxButtons.OK, MessageBoxIcon.Error);

                // Display the connection dialog
                using (DataConnectionDialog dlg = new DataConnectionDialog(connectionStringBuilder))
                {
                    if (DialogResult.OK != dlg.ShowDialog(splashScreen))
                    {
                        Environment.Exit(0);
                    }
                }
                csUpdated = true;
            }

            if (csUpdated)
            {
                UpdateConnectionString(connectionStringBuilder.ToString());
            }

            data                = new Data();
            FormMainInstance    = new FormMain();
            FormOptionsInstance = new FormOptions();

            splashScreen.Close();
            splashScreen.Dispose();

            Application.Run(FormMainInstance);
        }