/// <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); }
private void Step11_Load(object sender, EventArgs e) { Wizard.ButtonClose.Text = ResHelper.GetString("Wizard_Finish"); // Handle events Wizard.StepLoadedEvent += Wizard_StepLoadedEvent; Wizard.SetWaitState(true, ResHelper.GetString("Step11_ImportInProgress")); // Perform CMS import CMSImport.ImportAsync(ADProvider, CurrentLog, FinishImport); }
/// <summary> /// Performs all necessary actions before validating connection. /// </summary> /// <returns>True if connecting should continue</returns> private bool PrepareConnectionValidation() { // Setup import profile ImportProfile.SQLServerAddress = cmbSQLServerAddress.Text; ImportProfile.SQLServerUsername = txtUsername.Text; ImportProfile.SQLServerPassword = txtPassword.Text; ImportProfile.SQLUseTrustedConnection = radUseTrustedConnection.Checked; if (ValidateFields()) { // Change app.config CMSImport.ConfigureApplicationSettings(); // Setup UI Wizard.SetWaitState(true, ResHelper.GetString("Step2_TryingToConnect")); Enabled = false; Wizard.ButtonNext.Enabled = false; return(true); } else { return(false); } }
/// <summary> /// Ends local threads. /// </summary> public override void EndThreads() { CMSImport.CancelImport(); }
private static void Main(string[] args) { string profileName = string.Empty; // Create new instance of AD provider ImportProfile.OnDirectoryControllerChanged += () => PrincipalProvider.ClearContext(); // If there are some arguments specified if (args.Length != 0) { // Try to attach console if (!AttachConsole(-1)) { // Create new console AllocConsole(); } // For each argument for (int i = 0; i < args.Length; i++) { string arg = args[i]; // If argument specifies profile if ((arg == "/profile") || (arg == "-profile")) { // Get profile name if ((i + 1) < args.Length) { if (profileName == string.Empty) { profileName = args[i + 1].Trim(); } } } if ((arg == "/h") || (arg == "-h") || (arg == "--help") || (arg == "-?") || (arg == "/?")) { // Write help Console.Write(ResHelper.GetString("Console_Help").Replace("\\n", "\n").Replace("\\r", "\r")); return; } } // If there was profile specified if (profileName != string.Empty) { // If there is no such file if (!File.Exists(profileName)) { Console.WriteLine(ResHelper.GetString("Error_ProfileDoesNotExist", profileName)); } else { // Try to get file info FileInfo fi = FileInfo.New(profileName); Console.WriteLine(ResHelper.GetString("Console_SelectedImportProfile", fi.FullName)); // Initialize import profile string validationError = ImportProfile.InitializeImportProfile(profileName); if (!String.IsNullOrEmpty(validationError)) { Console.WriteLine(ResHelper.GetString("Error_ProfileIsNotValid")); Console.WriteLine(validationError); } else { // Application is in console mode ImportProfile.UsesConsole = true; // Check permissions string permissionsCheckResult = PrincipalProvider.CheckPermissions(); if (!string.IsNullOrEmpty(permissionsCheckResult)) { Console.WriteLine(permissionsCheckResult); } else { // Initialize principal provider bool providerInitialized = ValidatePrincipalProvider(PrincipalProvider); bool databaseValid = ValidateDatabase(); if (providerInitialized && databaseValid) { // Initialize CMS connection CMSImport.ConfigureApplicationSettings(); // Perform CMS import CMSImport.Import(PrincipalProvider, MessageLog); } } } } } else { // Write message Console.WriteLine(ResHelper.GetString("Console_SpecifyProfile")); } } // Launch windows form application else { // Preinitialize CMS context CMSApplication.PreInit(); // Initialize application Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ADWizard(PrincipalProvider)); } }
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); }