Beispiel #1
0
        public void LoadFromFile()
        {
            try
            {

                StreamReader read = new StreamReader(local_path2);
                string schedulefile = null;
                string setpath = read.ReadLine();
                Directory.SetCurrentDirectory(setpath);
                string schedulefile2 = Directory.GetCurrentDirectory();
                //orismos tou path pou einai to arxeio p tha diabazoume
                string[] dirs = Directory.GetFiles(schedulefile2);
                //trexei gia osa arxeia exei o fakelos
                foreach (string dir in dirs)
                {
                    if (dbBackUp.Any()) {
                        dbBackUp.Clear();
                    }
                    stringsave = new StringBuilder();
                    schedulefile = dir;
                    tcpclnt = new TcpClient();
                    //anoigma tou areiou
                    StreamReader readfromLoad = new StreamReader(schedulefile);
                    ConnectToServer connection = new ConnectToServer();

                    //diabasma apo arxeio
                    setTime(readfromLoad.ReadLine());
                    setHostname(readfromLoad.ReadLine(), readfromLoad.ReadLine());
                    setUsername(readfromLoad.ReadLine());
                    setPassword(readfromLoad.ReadLine());
                    setFtpHostname(readfromLoad.ReadLine());
                    setFtpusername(readfromLoad.ReadLine());
                    setFtppassword(readfromLoad.ReadLine());
                    setEmail(readfromLoad.ReadLine());
                    int i = 0;
                    do{

                        setbackup(readfromLoad.ReadLine());
                        i++;
                    } while (!(readfromLoad.EndOfStream)) ;
                    tcpclnt.Connect(hostname, Convert.ToInt32(port));
                    if (tcpclnt.Connected)
                    {
                        BackupDb back = new BackupDb(getHostname(), getUsername(), getPassword(), getbackup(), @local_path, getFtphostname(), getFtpusername(), getFtppassword());
                        string respone  =  back.downloadDb();
                        if (respone.Equals("Backup completed successfully!") &&(getEmaiil()!=String.Empty))
                        {
                            mail = new SendEmail(getEmaiil(), respone);
                            mail.PrepareEmail();
                            mail.setEmail();
                        }
                        else if (getEmaiil() != String.Empty)
                        {
                            mail = new SendEmail(getEmaiil(), respone);
                            mail.PrepareEmail();
                            mail.setEmail();
                        }
                        tcpclnt.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.Source);
                Application.Exit();
            }
        }
Beispiel #2
0
        private void button_Click(object sender, EventArgs e)
        {
            if((this.connectForm.getConnection) || (this.connectForm.getConnection2))
            {
                //MessageBox.Show(local_path.ToString());

                // get number of selected databases from checklistBox
                int selectedDbNum = DatabasesCheckedListBox.CheckedItems.Count;

                //array with selected databases number length, for store all selected databases
                string[] dbForBackup = new string[selectedDbNum];
                //get names of selected databases
                int i = 0;
                foreach (object itemChecked in DatabasesCheckedListBox.CheckedItems)
                {
                    dbForBackup[i] = itemChecked.ToString();
                    i++;
                }

                // check if upload to ftp is checked and initialize the backupDB object with suitable constructor
                if (cbUploadFtp.Checked)
                {
                    if (connectForm.getConnection)
                    {
                        uploadToFTP = true;
                        backupDB = new BackupDb(connectForm.getHostname, connectForm.getUsername, connectForm.getPassword, dbForBackup, local_path, ftpHost, ftpUsername, ftpPassword);
                    }
                    else
                    {
                        uploadToFTP = true;
                        backupDB = new BackupDb(connectForm.getHostname2, connectForm.getUsername2, connectForm.getPassword2, dbForBackup, local_path, ftpHost, ftpUsername, ftpPassword);
                    }
                }
                else
                {
                    if (connectForm.getConnection)
                    {
                        uploadToFTP = false;
                        backupDB = new BackupDb(connectForm.getHostname, connectForm.getUsername, connectForm.getPassword, dbForBackup, local_path);
                    }
                    else
                    {
                        uploadToFTP = false;
                        backupDB = new BackupDb(connectForm.getHostname, connectForm.getUsername, connectForm.getPassword, dbForBackup, local_path);
                    }
                }
                //check the response of backupdb() method, if true successed, else failed
                response = backupDB.downloadDb();
                MessageBox.Show(response);

                if (response.Equals("Backup completed successfully!"))
                {
                    success = true;

                }

                if(success)
                {

                    if (emailnotcheckBox.Checked)
                    {
                        mail = new SendEmail(emailtextBox.Text,response);
                        mail.PrepareEmail();
                        mail.setEmail();
                    }

                    form3 = new Form3(this);
                    form3.Visible = true;
                }
            }
        }