private void copyAlerts(Server destserver) { foreach (Alert alert in sourceserver.JobServer.Alerts) { string alertname = alert.Name; ItemToCopy item = itemsToCopy.Find(x => x.Name == alertname); if (item.IsChecked) { if (DBChecks.AlertExists(destserver, alertname)) { showOutput.displayOutput(string.Format("Alert {0} already exists in destination. Skipping.", alertname)); continue; } if (DBChecks.CategoryExists(destserver, alert.CategoryName)) { showOutput.displayOutput(string.Format("Category {0} does not exist. Skipping copy of alert {1}.", alert.CategoryName, alertname)); continue; } try { StringCollection sql = alert.Script(); destserver.ConnectionContext.ExecuteNonQuery(sql); destserver.JobServer.Refresh(); showOutput.displayOutput(string.Format("Copied alert {0} to {1}", alertname, destserver.Name)); } catch (Exception ex) { showOutput.displayOutput(ex.Message); continue; } } } }
private void copyCategories(Server destserver) { foreach (JobCategory cat in sourceserver.JobServer.JobCategories) { string categoryname = cat.Name; ItemToCopy item = itemsToCopy.Find(x => x.Name == categoryname); if (item.IsChecked) { if (DBChecks.CategoryExists(destserver, categoryname)) { showOutput.displayOutput(string.Format("Category {0} already exists in destination. Skipping.", categoryname)); continue; } try { JobCategory destcat = new JobCategory(); destcat.Name = categoryname; destcat.Parent = destserver.JobServer; destcat.CategoryType = cat.CategoryType; destcat.Create(); } catch (Exception ex) { showOutput.displayOutput(ex.Message); continue; } showOutput.displayOutput(string.Format("Copied category {0} to destination", categoryname)); } } }