Esempio n. 1
0
        /// <summary>
        /// triggered when the load todolist button is clicked
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        private void loadTodoListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            //set the filter to only .todo files
            ofd.Filter = "Todo-Lists|*.todo|Old Xml TodoList|*.xml";

            //set the initial directory to the path where the executeable is
            ofd.InitialDirectory = Path.GetDirectoryName(Application.ExecutablePath);
            ofd.Multiselect      = false;
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    ToDoList = DbVersionManager.ReadToDoList(ofd.FileName);

                    loadedDB = Path.GetFullPath(ofd.FileName);
                    AddRecentFile(loadedDB);
                }
                catch (Exception)
                {
                    MessageBox.Show("This database is corrupted!");
                }
                UpdateList();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Load a database from the given path
 /// </summary>
 /// <param name="path">The from where you want to load the database</param>
 private void LoadDatabase(string path)
 {
     loadedDB = path;
     ToDoList = new ToDoList();
     if (File.Exists(path))
     {
         try
         {
             ToDoList = DbVersionManager.ReadToDoList(path);
         }
         catch
         {
             MessageBox.Show("Database corrupted");
         }
     }
 }
Esempio n. 3
0
        private static bool RunDbUpdate(
            string dbName,
            string versionFieldName,
            string updatesFolderPath,
            string connectionString)
        {
            IDbVersionManager dbVersionManager = new DbVersionManager(dbName, connectionString);

            int?dbVersion = dbVersionManager.GetVersionAsync(versionFieldName).Result;

            if (dbVersion.HasValue)
            {
                dbVersion++;
            }
            else
            {
                dbVersion = 0;
            }

            IUpdateScriptManager updateScriptManager = new UpdateScriptManager(updatesFolderPath);
            IDbUpdateRunner      dbUpdateRunner      = new DbUpdateRunner(dbName, connectionString);

            bool isUpdated = false;

            foreach (string updateContent in updateScriptManager.GetUpdatesContent(dbVersion.Value))
            {
                isUpdated = true;

                dbUpdateRunner.RunUpdateAsync(updateContent).Wait();
                dbVersionManager.SetVersionAsync(dbVersion.Value, versionFieldName).Wait();

                Console.WriteLine("{0} -> {1} updated to version {2}", dbName, versionFieldName, dbVersion);

                dbVersion++;
            }

            if (!isUpdated)
            {
                Console.WriteLine("Database {0} has not been updated because it is up to date.", dbName);
            }

            return(isUpdated);
        }