예제 #1
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);
                }
            });
        }
예제 #2
0
        public CommandEditorWindowViewModelBase(CommandTypeEnum type)
        {
            this.Type = type;

            this.SaveCommand = this.CreateCommand(async() =>
            {
                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() =>
            {
                if (!await this.CheckForResultErrors(await this.ValidateActions()))
                {
                    IEnumerable <ActionModelBase> actions = await this.GetActions();
                    if (actions != null)
                    {
                        await CommandEditorWindowViewModelBase.TestCommandWithTestSpecialIdentifiers(actions, this.GetTestSpecialIdentifiers());
                    }
                }
            });

            this.ExportCommand = this.CreateCommand(async() =>
            {
                await CommandEditorWindowViewModelBase.ExportCommandToFile(await this.ValidateAndBuildCommand());
            });

            this.ImportCommand = this.CreateCommand(async() =>
            {
                try
                {
                    string filename          = CommandEditorWindowViewModelBase.OpenCommandFileBrowser();
                    CommandModelBase command = null;

                    // Check if the imported command type matches the currently edited command. If so, import additional information.
                    switch (this.Type)
                    {
                    case CommandTypeEnum.Webhook:
                        WebhookCommandModel webhookCommandModel = await CommandEditorWindowViewModelBase.ImportCommandFromFile <WebhookCommandModel>(filename);
                        command = webhookCommandModel;

                        WebhookCommandEditorWindowViewModel thisType = this as WebhookCommandEditorWindowViewModel;
                        if (webhookCommandModel != null && thisType != null)
                        {
                            // Merge JSON Mapping
                            foreach (var map in webhookCommandModel.JSONParameters)
                            {
                                if (!thisType.JSONParameters.Any(j => j.JSONParameterName == map.JSONParameterName || j.SpecialIdentifierName == map.SpecialIdentifierName))
                                {
                                    thisType.JSONParameters.Add(new WebhookJSONParameterViewModel(thisType)
                                    {
                                        JSONParameterName = map.JSONParameterName, SpecialIdentifierName = map.SpecialIdentifierName
                                    });
                                }
                            }
                        }

                        break;
                    }

                    if (command == null)
                    {
                        command = await CommandEditorWindowViewModelBase.ImportCommandFromFile(filename);
                    }

                    if (command != null)
                    {
                        foreach (ActionModelBase action in command.Actions)
                        {
                            await this.AddAction(action);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex);
                    await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToImportCommand);
                }
            });
        }