Esempio n. 1
0
        protected void CheckPreviousBackup()
        {
            string backupFilePath = GetSystemSettingsBackupPath();

            if (File.Exists(backupFilePath))
            {
                // backup file exists
                DateTime date    = File.GetLastWriteTime(backupFilePath);
                string   message = string.Format(Resources.CommandBase_Message_SystemSettingsAreNotRestored, date);
                bool?    answer  = Prompt(message, threeState: true);

                // process depending on answer
                //   true (Yes): restore the backup
                //   false (No): do not restore the backup, but delete it
                //   null (Cancel): do nothing
                if (answer.HasValue)
                {
                    if (answer.Value)
                    {
                        // restore the backup
                        JsonObjectData data = JsonObjectData.Load(backupFilePath, createIfNotExist: false);
                        if (data != null)
                        {
                            SystemSettingsSwitcher switcher = this.ComponentFactory.CreateSystemSettingsSwitcher(this, null);
                            switcher.Restore(data, systemSessionEnding: false);
                        }
                    }

                    // delete backup file
                    File.Delete(backupFilePath);
                }
            }

            return;
        }
Esempio n. 2
0
        protected JsonObjectData LoadSettingsFromFile(bool createIfNotExist, string settingsFilePath = null)
        {
            // argument checks
            if (settingsFilePath == null)
            {
                settingsFilePath = EnsureSettingsFilePathSet();
            }

            // load settings from the file
            return(JsonObjectData.Load(settingsFilePath, createIfNotExist));
        }