Esempio n. 1
0
        /// <summary>
        /// Verifies connection credentials, database version, license.
        /// </summary>
        private Task <bool> ValidateDatabase()
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();
            bool validationResult           = false;

            try
            {
                // Change message
                Wizard.SetWaitState(null, ResHelper.GetString("Step2_CheckingLicense"));

                using (InvokeHelper ih = new InvokeHelper(cmbDBName))
                {
                    ih.InvokeMethod(() => ImportProfile.SQLServerDatabase = cmbDBName.Text);
                }

                if (!string.IsNullOrEmpty(ImportProfile.SQLServerDatabase))
                {
                    var projectVersion = GetDatabaseVersion(CMSImport.ConnectionString);

                    if (String.IsNullOrEmpty(projectVersion))
                    {
                        SetError("Step2_OtherDB");
                    }
                    else
                    {
                        Wizard.SetWaitState(null, ResHelper.GetString("Step2_CheckingVersion"));

                        // Version has to correspond with DLL version
                        if (projectVersion.EqualsCSafe(ADWizard.SupportedVersion))
                        {
                            // Set new connection string
                            CMSImport.ConfigureApplicationSettings();

                            // Initialize application to enable usage of providers
                            CMSImport.CMSInit();

                            validationResult = true;
                            SetMessage("Step2_ConnectionToDBSuccessfull");
                        }
                        else
                        {
                            SetError(ResHelper.GetString("Step2_WrongVersion", ADWizard.SupportedVersion, projectVersion));
                        }
                    }
                }
                else
                {
                    SetError("Step2_SelectDatabase");
                }
            }
            catch (SqlException)
            {
                validationResult = false;
                SetError("Step2_OtherDB");
            }
            tcs.SetResult(validationResult);
            return(tcs.Task);
        }
Esempio n. 2
0
        private static bool ValidateDatabase()
        {
            bool validationResult = false;

            try
            {
                // Change message
                Console.WriteLine(ResHelper.GetString("Step2_CheckingLicense"));

                if (!string.IsNullOrEmpty(ImportProfile.SQLServerDatabase))
                {
                    // Try to open connection
                    SqlConnection sc = new SqlConnection(CMSImport.ConnectionString);

                    // Find out whether CMS version is correct
                    SqlCommand getVersion = new SqlCommand("SELECT [KeyValue] FROM [CMS_SettingsKey] WHERE [KeyName] = 'CMSDBVersion'", sc);

                    DataSet ds = null;
                    using (SqlDataAdapter dataAdapter = new SqlDataAdapter(getVersion))
                    {
                        ds = new DataSet();
                        dataAdapter.Fill(ds);
                    }

                    // Get current project version
                    string projectVersion = null;
                    if (!DataHelper.DataSourceIsEmpty(ds))
                    {
                        projectVersion = ValidationHelper.GetString(ds.Tables[0].Rows[0]["KeyValue"], string.Empty);
                    }

                    if (string.IsNullOrEmpty(projectVersion))
                    {
                        Console.WriteLine(ResHelper.GetString("Step2_OtherDB"));
                    }
                    else
                    {
                        Console.WriteLine(ResHelper.GetString("Step2_CheckingVersion"));

                        // Version has to correspond with DLL version
                        if (projectVersion.EqualsCSafe(ADWizard.SupportedVersion))
                        {
                            // Set new connection string
                            ConnectionHelper.ConnectionString = CMSImport.ConnectionString;

                            // Initialize application to enable usage of providers
                            CMSImport.CMSInit();

                            validationResult = true;
                            Console.WriteLine(ResHelper.GetString("Step2_ConnectionToDBSuccessfull"));
                        }
                        else
                        {
                            Console.WriteLine(ResHelper.GetString("Step2_WrongVersion", ADWizard.SupportedVersion, projectVersion));
                        }
                    }
                }
                else
                {
                    Console.WriteLine(ResHelper.GetString("Step2_SelectDatabase"));
                }
            }
            catch (SqlException)
            {
                validationResult = false;
                Console.WriteLine(ResHelper.GetString("Step2_OtherDB"));
            }
            return(validationResult);
        }