public async Task SaveLocalBackup(SettingsV3Model settings)
        {
            Logger.Log(LogLevel.Debug, "Settings local backup save operation started");

            await semaphore.WaitAndRelease(async() =>
            {
                await FileSerializerHelper.SerializeToFile(settings.SettingsLocalBackupFilePath, settings);
            });

            Logger.Log(LogLevel.Debug, "Settings local backup save operation finished");
        }
 public async Task Save()
 {
     try
     {
         await FileSerializerHelper.SerializeToFile(ApplicationSettingsFileName, this);
     }
     catch (Exception ex)
     {
         Logger.Log(ex);
     }
 }
#pragma warning restore CS0612 // Type or member is obsolete

        public async Task Save(SettingsV3Model settings)
        {
            Logger.Log(LogLevel.Debug, "Settings save operation started");

            await semaphore.WaitAndRelease(async() =>
            {
                settings.CopyLatestValues();
                await FileSerializerHelper.SerializeToFile(settings.SettingsFilePath, settings);
                await settings.SaveDatabaseData();
            });

            Logger.Log(LogLevel.Debug, "Settings save operation finished");
        }
        protected override async Task OnLoadedInternal()
        {
            this.ImportActionsCommand = this.CreateCommand(async() =>
            {
                try
                {
                    await this.ImportActionsFromCommand(await CommandEditorWindowViewModelBase.ImportCommandFromFile(CommandEditorWindowViewModelBase.OpenCommandFileBrowser()));
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToImportCommand + ": " + ex.ToString());
                }
            });

            this.ExportActionsCommand = this.CreateCommand(async() =>
            {
                try
                {
                    IEnumerable <Result> results = await this.ActionEditorList.ValidateActions();
                    if (results.Any(r => !r.Success))
                    {
                        await DialogHelper.ShowFailedResults(results.Where(r => !r.Success));
                        return;
                    }

                    CustomCommandModel command = new CustomCommandModel(this.Name);
                    command.Actions.AddRange(await this.ActionEditorList.GetActions());

                    string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(this.Name + CommandEditorWindowViewModelBase.MixItUpCommandFileExtension);
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        await FileSerializerHelper.SerializeToFile(fileName, command);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToExportCommand + ": " + ex.ToString());
                }
            });

            foreach (ActionModelBase subAction in subActions)
            {
                await this.ActionEditorList.AddAction(subAction);
            }
            subActions.Clear();

            await base.OnLoadedInternal();
        }
示例#5
0
        public static async Task <bool> ExportCommandToFile(CommandModelBase command)
        {
            if (command != null)
            {
                string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(command.Name + MixItUpCommandFileExtension);
                if (!string.IsNullOrEmpty(fileName))
                {
                    await FileSerializerHelper.SerializeToFile(fileName, command);

                    return(true);
                }
            }
            return(false);
        }
示例#6
0
 private async void ExportButton_Click(object sender, RoutedEventArgs e)
 {
     await this.window.RunAsyncOperation(async() =>
     {
         CommandBase command = await this.GetNewCommand();
         if (command != null)
         {
             string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(command.Name + ".mixitupc");
             if (!string.IsNullOrEmpty(fileName))
             {
                 await FileSerializerHelper.SerializeToFile(fileName, command);
             }
         }
     });
 }
示例#7
0
        public async Task SaveLocalBackup(SettingsV3Model settings)
        {
            if (settings != null)
            {
                Logger.Log(LogLevel.Debug, "Settings local backup save operation started");

                if (ChannelSession.Services.FileService.GetFileSize(settings.SettingsFilePath) == 0)
                {
                    Logger.Log(LogLevel.Debug, "Main settings file is empty, aborting local backup settings save operation");
                    return;
                }

                await semaphore.WaitAndRelease(async() =>
                {
                    await FileSerializerHelper.SerializeToFile(settings.SettingsLocalBackupFilePath, settings);
                });

                Logger.Log(LogLevel.Debug, "Settings local backup save operation finished");
            }
        }
示例#8
0
        public CommandEditorWindowViewModelBase(CommandTypeEnum type)
        {
            this.Type = type;

            this.SaveCommand = this.CreateCommand(async(parameter) =>
            {
                CommandModelBase command = await this.ValidateAndBuildCommand();
                if (command != null)
                {
                    if (!command.IsEmbedded)
                    {
                        ChannelSession.Settings.SetCommand(command);
                        await ChannelSession.SaveSettings();
                    }
                    await this.SaveCommandToSettings(command);
                    this.CommandSaved(this, command);
                }
            });

            this.TestCommand = this.CreateCommand(async(parameter) =>
            {
                if (!await this.CheckForResultErrors(await this.ValidateActions()))
                {
                    IEnumerable <ActionModelBase> actions = await this.GetActions();
                    if (actions != null)
                    {
                        await CommandModelBase.RunActions(actions, CommandParametersModel.GetTestParameters(this.GetTestSpecialIdentifiers()));
                    }
                }
            });

            this.ExportCommand = this.CreateCommand(async(parameter) =>
            {
                CommandModelBase command = await this.ValidateAndBuildCommand();
                if (command != null)
                {
                    string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(this.Name + MixItUpCommandFileExtension);
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        await FileSerializerHelper.SerializeToFile(fileName, command);
                    }
                }
            });

            this.ImportCommand = this.CreateCommand(async(parameter) =>
            {
                try
                {
                    CommandModelBase command = await CommandEditorWindowViewModelBase.ImportCommandFromFile();
                    if (command != null)
                    {
                        // TODO Check if the imported command type matches the currently edited command. If so, import additional information.
                        foreach (ActionModelBase action in command.Actions)
                        {
                            await this.AddAction(action);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToImportCommand);
                }
            });
        }