private void Button_Click(object sender, RoutedEventArgs e)
        {
            DatabasesViewModel databasesViewModel = Globals.DatabasesViewModel;

            DatabaseInfo dbInfo = new DatabaseInfo();
            dbInfo.Host = hostTextBox.Text;
            dbInfo.DatabaseName = databaseTextBox.Text;
            dbInfo.User = userTextBox.Text;
            dbInfo.Password = passwordTextBox.Password;

            string[] startTimeSplit = startTime.Text.Split(':');
            dbInfo.StartTimeHour = Convert.ToInt32(startTimeSplit[0]);
            dbInfo.StartTimeMinute = Convert.ToInt32(startTimeSplit[1]);

            databasesViewModel.addDatabase(dbInfo);

            ResetTextBoxfields();

            ModernDialog.ShowMessage(string.Format("The database '{0}' has been added!", dbInfo.DatabaseName), "Success", MessageBoxButton.OK);
            dbInfo = null;
            NavigationCommands.GoToPage.Execute(new Uri("/Pages/DatabasesPage.xaml", UriKind.Relative), FirstFloor.ModernUI.Windows.Navigation.NavigationHelper.FindFrame(null, this));
        }
        public void onDebug()
        {
            if (library.RetrieveAllDatabaseNodes().Count > 0)
            {
                foreach (DatabaseInfo dbNode in library.RetrieveAllDatabaseNodes())
                {
                    library.RemoveDatabaseNode(dbNode.DatabaseName);
                }
            }

            DatabaseInfo dbInfo = new DatabaseInfo();
            dbInfo.DatabaseName = "movstreamdb";
            dbInfo.Host = "localhost";
            dbInfo.User = "******";
            dbInfo.Password = "******";
            int minute = DateTime.Now.Minute;
            int hour = DateTime.Now.Hour;
            if (minute + 1 > 59)
            {
                dbInfo.StartTimeMinute = 0;
                hour++;
                if (hour > 23)
                {
                    dbInfo.StartTimeHour = 0;
                }
                else
                {
                    dbInfo.StartTimeHour = hour;
                }
            }
            else
            {
                dbInfo.StartTimeHour = hour;
                dbInfo.StartTimeMinute = minute + 1;
            }
            library.InsertDatabaseNode(dbInfo);

            this.OnStart(null);
        }
        public void RetrieveAllDatabaseNodesTest()
        {
            Library lib = new Library();
            DatabaseInfo dbInfo = new DatabaseInfo();
            dbInfo.Host = "localhost";
            dbInfo.User = "******";
            dbInfo.Password = "******";
            dbInfo.DatabaseName = "TestDatabase";
            dbInfo.StartTimeHour = 4;
            dbInfo.StartTimeMinute = 30;

            lib.InsertDatabaseNode(dbInfo);
            dbInfo.DatabaseName = "NewDatabase";
            lib.InsertDatabaseNode(dbInfo);

            Assert.AreEqual(2, lib.RetrieveAllDatabaseNodes().Count);

            lib.RemoveDatabaseNode(dbInfo.DatabaseName);
            lib.RemoveDatabaseNode("TestDatabase");
            lib = null;
        }
        public void UpdateSpecificDatabaseNodeTest()
        {
            Library lib = new Library();
            DatabaseInfo dbInfo = new DatabaseInfo();
            dbInfo.Host = "localhost";
            dbInfo.User = "******";
            dbInfo.Password = "******";
            dbInfo.DatabaseName = "TestDatabase";
            dbInfo.StartTimeHour = 4;
            dbInfo.StartTimeMinute = 30;

            lib.InsertDatabaseNode(dbInfo);

            //modify the dbInfo start time
            dbInfo.StartTimeHour = 22;
            dbInfo.StartTimeMinute = 59;

            lib.UpdateDatabaseNode(dbInfo);

            Assert.AreEqual("22:59:00", dbInfo.StartTime.ToString());

            lib.RemoveDatabaseNode(dbInfo.DatabaseName);
        }
        public void RetrieveSpecificDatabaseNodeTest()
        {
            Library lib = new Library();
            DatabaseInfo dbInfo = new DatabaseInfo();
            dbInfo.Host = "localhost";
            dbInfo.User = "******";
            dbInfo.Password = "******";
            dbInfo.DatabaseName = "TestDatabase";
            dbInfo.StartTimeHour = 4;
            dbInfo.StartTimeMinute = 30;

            lib.InsertDatabaseNode(dbInfo);

            DatabaseInfo dbInfo2 = lib.RetrieveDatabaseNode(dbInfo.DatabaseName);

            Assert.AreEqual("testdatabase", dbInfo2.DatabaseName);

            lib.RemoveDatabaseNode(dbInfo2.DatabaseName);
            lib = null;
        }
        public void RemoveSpecificDatabaseNodeTest()
        {
            Library lib = new Library();
            DatabaseInfo dbInfo = new DatabaseInfo();
            dbInfo.Host = "localhost";
            dbInfo.User = "******";
            dbInfo.Password = "******";
            dbInfo.DatabaseName = "TestDatabase";
            dbInfo.StartTimeHour = 4;
            dbInfo.StartTimeMinute = 30;

            lib.InsertDatabaseNode(dbInfo);
            lib.RemoveDatabaseNode(dbInfo.DatabaseName);

            XmlDocument document = new XmlDocument();
            document.Load(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\MySQLBackup\Configuration\Databases.xml");
            XmlNode databaseNode = document.SelectSingleNode("Databases/Database[@Name='" + dbInfo.DatabaseName + "']");

            Assert.IsNull(databaseNode);
            lib = null;
        }
        public void InsertNewDatabaseNodeToDatabasesXMLFileTest()
        {
            Library lib = new Library();
            DatabaseInfo dbInfo = new DatabaseInfo();
            dbInfo.Host = "localhost";
            dbInfo.User = "******";
            dbInfo.Password = "******";
            dbInfo.DatabaseName = "test_database";
            dbInfo.StartTimeHour = 4;
            dbInfo.StartTimeMinute = 30;

            lib.InsertDatabaseNode(dbInfo);

            XmlDocument document = new XmlDocument();
            document.Load(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\MySQLBackup\Configuration\Databases.xml");
            XmlNode databaseNode = document.SelectSingleNode("Databases/Database");
            string databaseNameAttr = databaseNode.Attributes["Name"].Value;

            Assert.AreEqual("test_database", databaseNameAttr);

            //remove the database node we just created
            databaseNode.ParentNode.RemoveChild(databaseNode);
            document.Save(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\MySQLBackup\Configuration\Databases.xml");

            lib = null;
        }
 /**
  * Insert a new Database node to the Databases.xml file
  */
 public void InsertDatabaseNode(DatabaseInfo databaseInfo)
 {
     databasesHandler.InsertNewDatabaseNode(databaseInfo);
 }
 /**
  * Restore a specific database, from a backup dump file.
  */
 public void RestoreDatabase(System.Diagnostics.Process process, string dumpFilePath, DatabaseInfo dbInfo)
 {
     RestoreDatabaseProcess restoreProcess = new RestoreDatabaseProcess(this, dumpFilePath, dbInfo);
     restoreProcess.RestoreDatabase(process);
 }
 /**
  * Update an existing database node. Database Name is the only thing, which can't be updated.
  * If this is the case create a new database node instead.
  */
 public void UpdateDatabaseNode(DatabaseInfo dbInfo)
 {
     databasesHandler.UpdateDatabaseNode(dbInfo);
 }
 /**
  * Add a Database Info object to the collection
  */
 public void addDatabase(DatabaseInfo dbInfo)
 {
     this.databases.Add(dbInfo);
     library.InsertDatabaseNode(dbInfo);
     library.LogMessage("INFO", string.Format("The database {0} is now ready for backup", dbInfo.DatabaseName));
 }