public void getData(out ScheduleJob.ScheduleData scheduleDataOut) { getDataFromForm(); Sql.ScheduleJob.BuildDescription(ref m_scheduleData); scheduleDataOut = m_scheduleData; }
private static void AddJobToRepository(Repository repository, ScheduleJob.ScheduleData scheduleData, string connectionName) { try { scheduleData.SetDefaults(); Guid jobID = ScheduleJob.AddJob(repository.ConnectionString, connectionName, repository.Instance, scheduleData, false); // Update Registered Server with new jobID repository.GetServer(connectionName).SetJobId(jobID); } catch (Exception ex) { logX.loggerX.Error(ex.Message); throw; } }
public void setData(ScheduleJob.ScheduleData scheduleDataLocal) { m_scheduleData = scheduleDataLocal; loadData(); }
public static bool ImportItem(ImportItem itemToImport, Repository repository, ImportSettings settings) { using (logX.loggerX.InfoCall()) { string sqlServerVersion, machine, instance, connectionName, edition; var errorList = new List <string>(); if (itemToImport.HasErrors()) { settings.ChangeStatus(ImportStatusIcon.Warning, string.Format("Skipped due to errors: {0}", itemToImport.GetErrors())); return(false); } settings.ChangeStatus(ImportStatusIcon.Importing, "Importing"); var serverNameParts = itemToImport.ServerName.Split(','); var serverPort = serverNameParts.Length > 1 ? Convert.ToInt32(serverNameParts[1]) : (int?)null; ScheduleJob.ScheduleData scheduleData = new ScheduleJob.ScheduleData(); //Validation of instance connection credentials OperationResult <bool> operationResult = ValidateCredentials(itemToImport, out sqlServerVersion, out machine, out instance, out connectionName, out edition); if (!operationResult.Value) { settings.ChangeStatus(ImportStatusIcon.Error, string.Format("Not imported. {0}", operationResult.GetEventAllMessagesString())); return(false); //Skip importing of server } // SQLsecure 3.1 (Anshul) - Validate server edition based on server type. // SQLsecure 3.1 (Anshul) - SQLSECU-1775 - Azure VM : Register a Server as Azure DB by selecting Server type as Azure VM. if (!SqlHelper.ValidateServerEdition(itemToImport.ServerType, edition)) { settings.ChangeStatus(ImportStatusIcon.Error, string.Format("Not imported. {0}", itemToImport.ServerType == ServerType.AzureSQLDatabase ? ErrorMsgs.IncorrectServerTypeAzureSQLDBImportMsg : ErrorMsgs.IncorrectServerTypeSQLServerImportMsg)); return(false); //Skip importing of server } //Validation of server acces credentials (using WindowsCredentials) //Add operation error if not successful but continue import operation operationResult = CheckServerAccess(itemToImport, machine); if (!operationResult.Value) { errorList.AddRange(operationResult.GetEventMessagesStringList()); } ; var parsedSqlServerVersion = SqlHelper.ParseVersion(sqlServerVersion); ServerInfo serverInfo = new ServerInfo(parsedSqlServerVersion, (itemToImport.AuthType == SqlServerAuthenticationType.WindowsAuthentication || itemToImport.AuthType == SqlServerAuthenticationType.AzureADAuthentication), itemToImport.UserName, itemToImport.Password, connectionName, SqlServer.GetValueByName(itemToImport.ServerType)); try { if (repository.RegisteredServers.Find(connectionName) != null) { UpdateCredentials(itemToImport, repository, connectionName); if (errorList.Count > 0) { settings.ChangeStatus(ImportStatusIcon.Warning, string.Format("Updated with warnings: {0}", string.Join("\n", errorList.ToArray()))); } else { settings.ChangeStatus(ImportStatusIcon.Imported, "Updated"); } return(true); } string serverType = itemToImport.ServerType == ServerType.OnPremise ? "OP" : (itemToImport.ServerType == ServerType.SQLServerOnAzureVM ? "AVM" : "ADB"); RegisteredServer.AddServer(repository.ConnectionString, connectionName, serverPort, machine, instance, (itemToImport.AuthType == SqlServerAuthenticationType.WindowsAuthentication || itemToImport.AuthType == SqlServerAuthenticationType.AzureADAuthentication) ? "W" : "S", itemToImport.UserName, itemToImport.Password, itemToImport.UseSameCredentials ? itemToImport.UserName : itemToImport.WindowsUserName, itemToImport.UseSameCredentials ? itemToImport.Password : itemToImport.WindowsUserPassword, sqlServerVersion, 0, new string[0], serverType); repository.RefreshRegisteredServers(); } catch (Exception ex) { errorList.Add(ex.Message); logX.loggerX.Error(ex.Message); return(false); } var server = repository.RegisteredServers.Find(connectionName); //Add email notification try { int providerId = Program.gController.Repository.NotificationProvider.ProviderId; RegisteredServerNotification rSN = new RegisteredServerNotification(SQLCommandTimeout.GetSQLCommandTimeoutFromRegistry()); rSN.RegisteredServerId = server.RegisteredServerId; rSN.ProviderId = providerId; rSN.Recipients = string.Empty; rSN.SnapshotStatus = RegisteredServerNotification.SnapshotStatusNotification_Never; rSN.PolicyMetricSeverity = (int)RegisteredServerNotification.MetricSeverityNotificaiton.Never; rSN.AddNotificationProvider(repository.ConnectionString); } catch (Exception ex) { errorList.Add(ex.Message); } // Add rules to the repository. try { AddRulesToRepository(repository, instance, serverInfo); } catch (Exception ex) { errorList.Add(ex.Message); } // Add job to repository try { AddJobToRepository(repository, scheduleData, connectionName); } catch (Exception ex) { errorList.Add(ex.Message); } try { AddServerToTags(server.RegisteredServerId); } catch (Exception ex) { errorList.Add(ex.Message); } var errorMessage = string.Join("\n", errorList.ToArray()); if (string.IsNullOrEmpty(errorMessage)) { settings.ChangeStatus(ImportStatusIcon.Imported, "Imported"); } else { settings.ChangeStatus(ImportStatusIcon.Warning, string.Format("Imported with warnings: {0}", errorMessage)); } return(true); } }