Пример #1
0
        /// <summary>
        /// Opens a file picker and imports the DB from the selected path.
        /// </summary>
        public static async Task ImportDBAsync()
        {
            // Get the source file:
            StorageFile sourceFile = await GetTargetOpenPathAsync();

            if (sourceFile is null)
            {
                Logger.Info("Importing DB canceled.");
                return;
            }
            Logger.Info("Started importing DB to: " + sourceFile.Path);

            // Close the DB connection:
            dB.Close();

            // Delete all existing DB files:
            await DeleteDBFilesAsync();

            // Import DB:
            StorageFile dbFile = await StorageFile.GetFileFromPathAsync(DB_PATH);

            try
            {
                await sourceFile.CopyAndReplaceAsync(dbFile);

                Logger.Info("Imported DB successfully from:" + sourceFile.Path);
            }
            catch (Exception e)
            {
                Logger.Error("Error during importing DB", e);
            }

            // Open the new DB:
            dB = new TSSQLiteConnection(DB_PATH);
        }
Пример #2
0
 /// <summary>
 /// Deletes the whole db and recreates an empty one.
 /// Only for testing use resetDB() instead!
 /// </summary>
 protected void DeleteDB()
 {
     try
     {
         dB.Close();
         File.Delete(DB_PATH);
     }
     catch (Exception e)
     {
         Logger.Error("Unable to close or delete the DB", e);
     }
     dB = new TSSQLiteConnection(DB_PATH);
 }