コード例 #1
0
        public WebhookJSONParameterViewModel(WebhookCommandEditorWindowViewModel viewModel)
        {
            this.viewModel = viewModel;

            this.DeleteJSONParameterCommand = this.CreateCommand(() =>
            {
                this.viewModel.JSONParameters.Remove(this);
            });
        }
コード例 #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);
                }
            });
        }