Exemplo n.º 1
0
        private void copyOperators(Server destserver)
        {
            foreach (Operator op in sourceserver.JobServer.Operators)
            {
                string     opname = op.Name;
                ItemToCopy item   = itemsToCopy.Find(x => x.Name == opname);
                if (item.IsChecked)
                {
                    if (DBChecks.OperatorExists(destserver, opname))
                    {
                        showOutput.displayOutput(string.Format("Operator {0} already exists in destination. Skipping.", opname));
                        continue;
                    }

                    try
                    {
                        StringCollection sql = op.Script();
                        destserver.ConnectionContext.ExecuteNonQuery(sql);
                        destserver.JobServer.Refresh();

                        showOutput.displayOutput(string.Format("Copied operator {0} to {1}", opname, destserver.Name));
                    }
                    catch (Exception ex)
                    {
                        showOutput.displayOutput(ex.Message);
                        continue;
                    }
                }
            }
        }
Exemplo n.º 2
0
        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;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void copyServerTriggers(Server destserver, bool disableonsource, bool disableondest, bool dropdest)
        {
            ServerDdlTriggerCollection desttriggers = destserver.Triggers;

            foreach (ServerDdlTrigger trigger in sourceserver.Triggers)
            {
                string     triggername = trigger.Name;
                ItemToCopy item        = itemsToCopy.Find(x => x.Name == triggername);
                if (item.IsChecked)
                {
                    if (desttriggers[triggername] != null)
                    {
                        if (!dropdest)
                        {
                            showOutput.displayOutput(string.Format("Trigger {0} already exists in destination. Skipping.", triggername));
                            continue;
                        }
                        try
                        {
                            showOutput.displayOutput(string.Format("Dropping trigger {0}.", triggername));
                            ServerDdlTrigger desttrigger = desttriggers[triggername];
                            desttriggers[triggername].Drop();
                            desttriggers.Refresh();
                        }
                        catch (Exception ex)
                        {
                            showOutput.displayOutput(ex.Message);
                            continue;
                        }
                    }

                    try
                    {
                        StringCollection sql = trigger.Script();
                        destserver.ConnectionContext.ExecuteNonQuery(sql);
                        destserver.Triggers.Refresh();
                        showOutput.displayOutput(string.Format("Copied trigger {0} to {1}", triggername, destserver.Name));

                        if (disableonsource)
                        {
                            trigger.IsEnabled = false;
                            trigger.Alter();
                        }

                        if (disableondest)
                        {
                            destserver.Triggers[triggername].IsEnabled = false;
                            destserver.Triggers[triggername].Alter();
                            desttriggers.Refresh();
                        }
                    }
                    catch (Exception ex)
                    {
                        showOutput.displayOutput(string.Format("Error copying trigger {0} to {1}", triggername, destserver.Name));
                        showOutput.displayOutput(ex.Message);
                        continue;
                    }
                }
            }
        }
Exemplo n.º 4
0
        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));
                }
            }
        }
Exemplo n.º 5
0
        private void copyAccounts(Server destserver, bool dropDest)
        {
            MailAccountCollection sourceaccounts = sourceserver.Mail.Accounts;
            MailAccountCollection destaccounts   = destserver.Mail.Accounts;
            SqlMail sm;

            sm = destserver.Mail;
            try
            {
                foreach (MailAccount account in sourceaccounts)
                {
                    string     accountname = account.Name;
                    ItemToCopy item        = itemsToCopy.Find(x => x.Name == accountname);
                    if (item.IsChecked)
                    {
                        if (destaccounts.Contains(accountname))
                        {
                            if (!dropDest)
                            {
                                showOutput.displayOutput(string.Format("Account {0} already exists on destination. Skipping", accountname));
                                continue;
                            }

                            destaccounts[accountname].Drop();
                            destaccounts.Refresh();
                        }

                        MailAccount newAccount = default(MailAccount);
                        newAccount = new MailAccount(sm, account.Name, account.Description, account.DisplayName, account.EmailAddress);
                        newAccount.ReplyToAddress = account.ReplyToAddress;
                        newAccount.Create();
                        newAccount.MailServers[0].Rename(account.MailServers[0].Name);
                        newAccount.Alter();

                        showOutput.displayOutput(string.Format("Copied mail account {0}", accountname));
                    }
                }
            }
            catch (Exception ex)
            {
                showOutput.displayOutput("Failed to copy account");
                showOutput.displayOutput(ex.Message, true);
            }
        }
Exemplo n.º 6
0
        private void copyProfiles(Server destserver, bool dropDest)
        {
            MailProfileCollection sourceprofiles = sourceserver.Mail.Profiles;
            MailProfileCollection destprofiles   = destserver.Mail.Profiles;

            try
            {
                foreach (MailProfile profile in sourceprofiles)
                {
                    string     profilename = profile.Name;
                    ItemToCopy item        = itemsToCopy.Find(x => x.Name == profilename);
                    if (item.IsChecked)
                    {
                        if (destprofiles.Contains(profilename))
                        {
                            if (!dropDest)
                            {
                                showOutput.displayOutput(string.Format("Profile {0} already exists on destination. Skipping", profilename));
                                continue;
                            }

                            destprofiles[profilename].Drop();
                            destprofiles.Refresh();
                        }

                        StringCollection sql = profile.Script();
                        destserver.ConnectionContext.ExecuteNonQuery(sql);
                        showOutput.displayOutput(string.Format("Copied mail profile {0}", profilename));
                    }
                }
            }
            catch (Exception ex)
            {
                showOutput.displayOutput("Failed to copy profile");
                showOutput.displayOutput(ex.Message, true);
            }
        }
Exemplo n.º 7
0
        private void copyJobs(Server destserver, bool disableonsource, bool disableondest, bool dropdest)
        {
            JobCollection destjobs = destserver.JobServer.Jobs;

            foreach (Job job in sourceserver.JobServer.Jobs)
            {
                string     jobname = job.Name;
                ItemToCopy item    = itemsToCopy.Find(x => x.Name == jobname);
                if (item.IsChecked)
                {
                    if (!DBChecks.LoginExists(destserver, job.OwnerLoginName))
                    {
                        showOutput.displayOutput(string.Format("[Job: {0}] Owner {1} doesn't exist ion destination. Skipping. ", jobname, job.OwnerLoginName));
                        continue;
                    }

                    foreach (JobStep jobstep in job.JobSteps)
                    {
                        if (!DBChecks.DatabaseExists(destserver, jobstep.DatabaseName))
                        {
                            showOutput.displayOutput(string.Format("[Job: {0}] Database {1} doesn't exist on destination. Skipping. ", jobname, jobstep.DatabaseName));
                            continue;
                        }

                        if (!string.IsNullOrEmpty(jobstep.ProxyName) && !DBChecks.ProxyExists(destserver, jobstep.ProxyName))
                        {
                            showOutput.displayOutput(string.Format("[Job: {0}] Proxy {1} doesn't exist on destination. Skipping. ", jobname, jobstep.ProxyName));
                            continue;
                        }
                    }

                    if (!string.IsNullOrEmpty(job.OperatorToEmail) && !DBChecks.OperatorExists(destserver, job.OperatorToEmail))
                    {
                        showOutput.displayOutput(string.Format("[Job: {0}] Operator {1} doesn't exist on destination. Skipping. ", jobname, job.OperatorToEmail));
                        continue;
                    }

                    if (!string.IsNullOrEmpty(job.OperatorToNetSend) && !DBChecks.OperatorExists(destserver, job.OperatorToNetSend))
                    {
                        showOutput.displayOutput(string.Format("[Job: {0}] Operator {1} doesn't exist on destination. Skipping. ", jobname, job.OperatorToNetSend));
                        continue;
                    }

                    if (!string.IsNullOrEmpty(job.OperatorToPage) && !DBChecks.OperatorExists(destserver, job.OperatorToPage))
                    {
                        showOutput.displayOutput(string.Format("[Job: {0}] Operator {1} doesn't exist on destination. Skipping. ", jobname, job.OperatorToPage));
                        continue;
                    }

                    if (DBChecks.JobExists(destserver, jobname))
                    {
                        if (!dropdest)
                        {
                            showOutput.displayOutput(string.Format("Job: {0} already exists on destination server. Skipping. ", jobname));
                            continue;
                        }
                        else
                        {
                            try
                            {
                                destserver.JobServer.Jobs[jobname].Drop();
                                destserver.JobServer.Refresh();
                            }
                            catch (Exception ex)
                            {
                                showOutput.displayOutput(ex.Message);
                                continue;
                            }
                        }
                    }

                    try
                    {
                        StringCollection sql = job.Script();
                        for (int i = 0; i < sql.Count; i++)
                        {
                            sql[i] = sql[i].Replace(sourceserver.Name, destserver.Name);
                        }

                        destserver.ConnectionContext.ExecuteNonQuery(sql);

                        if (disableondest)
                        {
                            DBFunctions.ChangeJobStatus(destserver, jobname, false);
                        }

                        if (disableonsource)
                        {
                            DBFunctions.ChangeJobStatus(sourceserver, jobname, false);
                        }

                        showOutput.displayOutput(string.Format("Copied job {0} to {1}", jobname, destserver.Name));
                    }
                    catch (Exception ex)
                    {
                        showOutput.displayOutput(string.Format("Failed to copy job {0} to {1}", jobname, destserver.Name));
                        showOutput.displayOutput(ex.Message);
                        continue;
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void processLogins(Server destserver, string action)
        {
            foreach (Login sourcelogin in sourceserver.Logins)
            {
                string     username     = sourcelogin.Name;
                Login      destlogin    = destserver.Logins[username];
                string     currentlogin = sourceserver.ConnectionContext.TrueLogin;
                string     servername   = sourceserver.NetName.ToLower();
                ItemToCopy item         = new ItemToCopy();
                var        checkitem    = itemsToCopy.FirstOrDefault(x => x.Name == username);
                if (checkitem == null)
                {
                    item.IsChecked = false;
                }
                else
                {
                    item = (ItemToCopy)checkitem;
                }

                if (item.IsChecked)
                {
                    if (username.StartsWith("##") || username == "sa" || username == "distributor_admin")
                    {
                        showOutput.displayOutput(string.Format("Skipping {0}.", username));
                        continue;
                    }

                    if (currentlogin == username && action.StartsWith("Force"))
                    {
                        showOutput.displayOutput("Cannot drop login performing the migration. Skipping");
                        continue;
                    }

                    string userbase = username.Split('\\')[0].ToLower();
                    if (servername == userbase || username.StartsWith("NT ") || username.StartsWith("BUILTIN)"))
                    {
                        showOutput.displayOutput(string.Format("{0} is skipped because it is a local machine name.", username));
                        continue;
                    }

                    if (sourcelogin.LoginType != LoginType.SqlLogin && sourcelogin.LoginType != LoginType.WindowsUser && sourcelogin.LoginType != LoginType.WindowsGroup)
                    {
                        showOutput.displayOutput(string.Format("{0} logins are not support. Skipping login {1}.", sourcelogin.LoginType.ToString(), username));
                        continue;
                    }

                    if (destlogin != null && action.StartsWith("Force") && username == destserver.ServiceAccount)
                    {
                        showOutput.displayOutput(string.Format("{0} is the destiation service account. Skipping drop.", username));
                        continue;
                    }

                    if (destlogin == null && action.StartsWith("Sync"))
                    {
                        showOutput.displayOutput(string.Format("{0} does not exist on destination. Skipping sync.", username));
                        continue;
                    }

                    if (destlogin != null && action.StartsWith("Normal"))
                    {
                        showOutput.displayOutput(string.Format("{0} already exists in destination. Select Force Copy to drop and recreate.", username));
                        continue;
                    }

                    switch (action)
                    {
                    case "Normal Copy":
                        copyLogin(sourceserver, destserver, sourcelogin, destlogin);
                        syncPermissions(sourceserver, destserver, username);
                        break;

                    case "Normal Copy with Database Permission Sync":
                        copyLogin(sourceserver, destserver, sourcelogin, destlogin);
                        syncPermissions(sourceserver, destserver, username);
                        destlogin = destserver.Logins[username];
                        syncDatabasePerms(sourcelogin, destlogin, sourceserver, destserver);
                        break;

                    case "Forced Copy":
                        dropUser(destserver, destlogin, username);
                        copyLogin(sourceserver, destserver, sourcelogin, destlogin);
                        syncPermissions(sourceserver, destserver, username);
                        break;

                    case "Forced Copy with Database Permission Sync":
                        dropUser(destserver, destlogin, username);
                        copyLogin(sourceserver, destserver, sourcelogin, destlogin);
                        syncPermissions(sourceserver, destserver, username);
                        destlogin = destserver.Logins[username];
                        syncDatabasePerms(sourcelogin, destlogin, sourceserver, destserver);
                        break;

                    case "Sync Logon Permissions Only":
                        syncPermissions(sourceserver, destserver, username);
                        break;

                    case "Sync Database Permission Only":
                        syncDatabasePerms(sourcelogin, destlogin, sourceserver, destserver);
                        break;

                    default:
                        showOutput.displayOutput("No Action selected", true);
                        break;
                    }
                }
            }
        }