示例#1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string backupName        = tbDatabaseName.Text;
            string backupDescription = tbDatabaseDescription.Text;

            if (String.IsNullOrWhiteSpace(backupName))
            {
                MessageBox.Show("Please enter a Database name for your backup!");
                return;
            }
            string dbFolderPath = Utils.GetBackupFolder();

            if (Directory.Exists(dbFolderPath + selectedGPVersion + "\\" + backupName + ".zip"))
            {
                MessageBox.Show("A backup called \"" + backupName + "\" already exists! Please enter a unique backup name to continue.");
                return;
            }

            List <string> listOfBadChars = new List <string>();
            StringBuilder builder        = new StringBuilder();

            string[] badChars = { @"\", @"/", ":", "*", "?", "\"", "<", ">", "|" };
            foreach (string character in badChars)
            {
                if (backupName.Contains(character))
                {
                    listOfBadChars.Add(character);
                }
            }
            foreach (string str in listOfBadChars)
            {
                builder.Append(str.ToString()).AppendLine();
            }
            if (listOfBadChars.Count > 0)
            {
                string            Message = "The following invalid characters are in the Database Backup name and are invalid. Please remove them: \n\n" + builder.ToString();
                string            Caption = "";
                MessageBoxButtons Button  = MessageBoxButtons.OK;
                MessageBoxIcon    Icon    = MessageBoxIcon.Error;
                DialogResult      Result;

                Result = MessageBox.Show(Message, Caption, Button, Icon);
                return;
            }

            SettingsModel settingsModel  = JsonConvert.DeserializeObject <SettingsModel>(File.ReadAllText(defaultSettingsFile));
            string        dbPath         = settingsModel.BackupDirectory + selectedGPVersion + "\\" + backupName;
            string        dynamicsDB     = settingsModel.DynamicsDBName;
            string        nonMBDB        = settingsModel.NonMBDBName;
            string        mbDB           = settingsModel.MBDBName;
            string        dynamicsScript = @"BACKUP DATABASE " + dynamicsDB + @" TO DISK='" + dbPath + "\\" + dynamicsDB + ".bak' WITH INIT";
            string        nonMBScript    = @"BACKUP DATABASE " + nonMBDB + @" TO DISK='" + dbPath + "\\" + nonMBDB + ".bak' WITH INIT";
            string        mbScript       = @"BACKUP DATABASE " + mbDB + @" TO DISK='" + dbPath + "\\" + mbDB + ".bak' WITH INIT";

            Directory.CreateDirectory(dbPath);
            this.Close();

            Thread newDBBak = new Thread(() => NewBackupThread(dynamicsScript, nonMBScript, mbScript, dbPath, backupName, backupDescription));

            newDBBak.Start();
            return;
        }
示例#2
0
        public static string GetBackupFolder()
        {
            SettingsModel settingsModel = JsonConvert.DeserializeObject <SettingsModel>(File.ReadAllText(defaultSettingsFile));

            return(settingsModel.BackupDirectory);
        }