Beispiel #1
0
        private void Form3_Load(object sender, EventArgs e)
        {
            int lenght = connectform2.getDBBackedUp.Length;
            StringBuilder databases = new StringBuilder();
            for(int i = 0; i < lenght; i++)
            {
                if (i == lenght - 1)
                {
                    if ((i % 2 == 0) && (i != 0))
                    {
                        flag = true;
                        databases.Append( "\n" + "                        " + connectform2.getDBBackedUp[i]);
                    }
                    else
                    {
                        if (flag)
                        {
                            databases.Append(connectform2.getDBBackedUp[i]);
                        }
                        else
                        {
                            databases.Append(connectform2.getDBBackedUp[i]);
                        }
                    }
                }
                else
                {
                    if ((i % 2 == 0) && (i != 0))
                    {
                        flag = true;
                        databases.Append( "\n" + "                        " + connectform2.getDBBackedUp[i] +",");
                    }
                    else
                    {
                        if (flag)
                        {
                            databases.Append(connectform2.getDBBackedUp[i]);
                        }
                        else
                        {
                            databases.Append(connectform2.getDBBackedUp[i]+",");
                        }
                    }
                }
            }
            if (connectform2.getConnection)
            {

                label1.Text = "Hostname: " + connectform2.getHostname + "\n" +
                              "Username: "******"\n" +
                             "DataBase(s): "+Convert.ToString(databases) + "\n" + "Day: " + connectform2.getDate + "\n" + "Time: " + connectform2.getTime+"\n"+
                             "---------------------------------------------------------------------";
            }
            else
            {
                label1.Text = "Hostname: " + connectform2.getHostname2 + "\n" +
                              "Username: "******"\n" +
                             "DataBase(s): " + Convert.ToString(databases) + "\n" + "Day: "+connectform2.getDate + "\n" + "Time: " + connectform2.getTime + "\n" +
                             "---------------------------------------------------------------------";
            }

            if (connectform2.getConnection)
            {

                savelogfile = new Save(label1.Text);
                savelogfile.logFile(logfile);
            }else if (connectform2.getConnection2)
            {
                savelogfile = new Save(label1.Text);
                savelogfile.logFile(logfile);
            }
        }
Beispiel #2
0
 //gia to Save otan to remember me einai pathmeno
 private void SaveCheckBox_CheckedChanged(object sender, EventArgs e)
 {
     if (SaveCheckBox.Checked)
     {
         Save save = new Save(hostnametextbox.Text, porttextbox.Text, usernametextbox.Text, passwordtextbox.Text);
         save.SaveME();
         if (save.Exist())
         {
             savedlabel.Text = "Already Exist";
             wheresaved.Text = save.PathToShow();
         }
         else if (save.Saved())
         {
             savedlabel.Text = "Saved To ->";
             wheresaved.Text = save.PathToShow();
         }
         else
             SaveCheckBox.Checked = false;
     }
 }
Beispiel #3
0
        private void Runbutton_Click(object sender, EventArgs e)
        {
            if ((((this.connectForm.getConnection) || (this.connectForm.getConnection2))))
                {
                string path2 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+"\\CurrentFile.txt";
                string path =(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName +@"\sqlBackup\ScheduleFile\");
               StreamWriter write = new StreamWriter(path2);
                write.Write(path);
               write.Close();
                try
                    {
                        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++;
                        }

                        if (SchedulecheckBox.Checked)
                        {
                            TimeSpan time = ScheduleTime.Value.TimeOfDay;

                            if (this.connectForm.getConnection)
                            {
                                saveschedulefile = new Save(time, this.connectForm.getHostname, this.connectForm.getPort, connectForm.getUsername, connectForm.getPassword, this.FTPHost, this.FTPusername, this.FTPpasswd, emailtextBox.Text, dbForBackup);
                                saveschedulefile.ScheduleFile(schedulefile);
                                ErrorScheduleLabel.Text = "Schedule completed sucessfully";
                            }
                            else if (this.connectForm.getConnection2)
                            {
                                saveschedulefile = new Save(time, this.connectForm.getHostname2, this.connectForm.getPort2, this.connectForm.getUsername2, this.connectForm.getPassword2, this.FTPHost, this.FTPusername, this.FTPpasswd, emailtextBox.Text, dbForBackup);
                                saveschedulefile.ScheduleFile(schedulefile);
                                ErrorScheduleLabel.Text = "Schedule completed sucessfully";

                            }
                        }

                    }
                    catch (Exception x)
                    {
                        ErrorScheduleLabel.Text = "Choose a database first";
                    }

                try
                {

                    //MessageBox.Show(Convert.ToString(IsUserAdministrator()));
                    TimeSpan time = ScheduleTime.Value.TimeOfDay;
                    using (TaskService ts = new TaskService())
                    {
                        TaskDefinition td = ts.NewTask();

                        //δημηουργια ονοματος και description για το schedule
                        td.RegistrationInfo.Description = "This task will backup the database that the user has chosen ";
                        td.Principal.DisplayName = "sqlBckup" + counter;
                        td.Principal.RunLevel = TaskRunLevel.Highest;

                        //δημιουργια triiger ο οποίος θα τρέχει κάθε μέρα
                        DailyTrigger dt = new DailyTrigger();
                        dt.StartBoundary = DateTime.Today + TimeSpan.FromHours(Convert.ToDouble(time.Hours)) + TimeSpan.FromMinutes(Convert.ToDouble(time.Minutes));
                        dt.DaysInterval = 1;
                        dt.Enabled = true;

                        td.Triggers.Add(dt);

                        //προσθεση ρυθμiσeων για το πως θα τρέχει το schedule
                        td.Settings.MultipleInstances = TaskInstancesPolicy.Parallel;
                        td.Settings.ExecutionTimeLimit = TimeSpan.FromHours(23);
                        td.Settings.DisallowStartIfOnBatteries = false;
                        td.Settings.WakeToRun = true;
                        td.Settings.Hidden = true;
                        td.Settings.StartWhenAvailable = true;
                        td.Settings.Priority = ProcessPriorityClass.High;

                        //προσθηκη exe action που δείχνει πιο exe θα τρεχει οταν ερθει η ωρα του schedule
                        td.Actions.Add(new ExecAction(schedulerexe, null, null));

                        //ExecAction et = new ExecAction(schedulerexe, null, null);
                        //td.Actions.Add(et);

                        //δημιουργία του schedule

                        ts.RootFolder.RegisterTaskDefinition("sqlBackup" + counter, td);

                        counter++;

                        ErrorScheduleLabel.Text = "Schedule sucessfull created";
                    }
                }
                catch (Exception exk) {
                    MessageBox.Show(exk.Source);
                    MessageBox.Show(exk.Message);
                    MessageBox.Show(exk.StackTrace);
                }

            }
        }
Beispiel #4
0
        private void Form3_Load(object sender, EventArgs e)
        {
            int           lenght    = connectform2.getDBBackedUp.Length;
            StringBuilder databases = new StringBuilder();

            for (int i = 0; i < lenght; i++)
            {
                if (i == lenght - 1)
                {
                    if ((i % 2 == 0) && (i != 0))
                    {
                        flag = true;
                        databases.Append("\n" + "                        " + connectform2.getDBBackedUp[i]);
                    }
                    else
                    {
                        if (flag)
                        {
                            databases.Append(connectform2.getDBBackedUp[i]);
                        }
                        else
                        {
                            databases.Append(connectform2.getDBBackedUp[i]);
                        }
                    }
                }
                else
                {
                    if ((i % 2 == 0) && (i != 0))
                    {
                        flag = true;
                        databases.Append("\n" + "                        " + connectform2.getDBBackedUp[i] + ",");
                    }
                    else
                    {
                        if (flag)
                        {
                            databases.Append(connectform2.getDBBackedUp[i]);
                        }
                        else
                        {
                            databases.Append(connectform2.getDBBackedUp[i] + ",");
                        }
                    }
                }
            }
            if (connectform2.getConnection)
            {
                label1.Text = "Hostname: " + connectform2.getHostname + "\n" +
                              "Username: "******"\n" +
                              "DataBase(s): " + Convert.ToString(databases) + "\n" + "Day: " + connectform2.getDate + "\n" + "Time: " + connectform2.getTime + "\n" +
                              "---------------------------------------------------------------------";
            }
            else
            {
                label1.Text = "Hostname: " + connectform2.getHostname2 + "\n" +
                              "Username: "******"\n" +
                              "DataBase(s): " + Convert.ToString(databases) + "\n" + "Day: " + connectform2.getDate + "\n" + "Time: " + connectform2.getTime + "\n" +
                              "---------------------------------------------------------------------";
            }

            if (connectform2.getConnection)
            {
                savelogfile = new Save(label1.Text);
                savelogfile.logFile(logfile);
            }
            else if (connectform2.getConnection2)
            {
                savelogfile = new Save(label1.Text);
                savelogfile.logFile(logfile);
            }
        }