示例#1
0
 public Boolean createBackupJob(BackupJob backupJob)
 {
     //Console.WriteLine(File.Exists(pathToJsonDB) ? "File exists." : "File does not exist.");
     if (!File.Exists(pathToJsonDB))
     {
         // We create a file and add the json string in and indexed way
         FileStream stream = File.Create(pathToJsonDB);
         TextWriter tw     = new StreamWriter(stream);
         BackupJobList.Add(backupJob);
         String stringjson = JsonConvert.SerializeObject(BackupJobList, Formatting.Indented);
         tw.WriteLine(stringjson);
         tw.Close();
         return(true);
     }
     else
     {
         // The file already exists so we had another backup job
         string json = File.ReadAllText(pathToJsonDB);
         //Console.WriteLine(json);
         BackupJobList = JsonConvert.DeserializeObject <List <BackupJob> >(json);
         FileStream stream = File.Create(pathToJsonDB);
         TextWriter tw     = new StreamWriter(stream);
         // We add the job
         BackupJobList.Add(backupJob);
         String stringjson = JsonConvert.SerializeObject(BackupJobList, Formatting.Indented);
         tw.WriteLine(stringjson);
         tw.Close();
         return(true);
     }
 }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            addIsValid       = true;
            errorMessage_add = "";

            if (add_full.Checked == false && add_differential.Checked == false)
            {
                addIsValid       = false;
                errorMessage_add = Properties.Resources.error_message1;
            }
            else if (add_full.Checked == true)
            {
                backupType = "full";
            }
            else
            {
                backupType = "differential";
            }

            if (add_name.Text == "")
            {
                addIsValid       = false;
                errorMessage_add = Properties.Resources.error_message2;
            }

            if (add_sourceFolder.Length < 2)
            {
                addIsValid       = false;
                errorMessage_add = Properties.Resources.error_message3;
            }

            if (add_destinationFolder.Length < 2)
            {
                addIsValid       = false;
                errorMessage_add = Properties.Resources.error_message4;
            }

            if (addIsValid)
            {
                // add the backup
                BackupJob backupJob = new BackupJob(add_name.Text, add_sourceFolder, add_destinationFolder, (backupType == "full"), parseUserInputAsList(add_extension.Text));
                if (this.controller.Model.createBackupJob(backupJob))
                {
                    MessageBox.Show(Properties.Resources.success, Properties.Resources.information, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    reloadListView();
                }
                else
                {
                    MessageBox.Show(errorMessage_add, Properties.Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(errorMessage_add, Properties.Resources.information, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private void Add(String name, String source, String destination, bool full, List <string> extToCrypt)
        {
            addIsValid       = true;
            errorMessage_add = "";


            if (name == "")
            {
                editIsValid  = false;
                errorMessage = Properties.Resources.error_message2;
            }

            if (source.Length < 2 || source == "Source")
            {
                editIsValid  = false;
                errorMessage = Properties.Resources.error_message3;
            }

            if (destination.Length < 2 || destination == "Destination")
            {
                editIsValid  = false;
                errorMessage = Properties.Resources.error_message4;
            }

            if (addIsValid)
            {
                // add the backup
                BackupJob backupJob = new BackupJob(name, source, destination, full, extToCrypt);
                if (this.controller.Model.createBackupJob(backupJob))
                {
                    MessageBox.Show(Properties.Resources.success, Properties.Resources.information, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DelegRefresh();
                }
                else
                {
                    MessageBox.Show(errorMessage_add, Properties.Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(errorMessage_add, Properties.Resources.information, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }