Exemplo n.º 1
0
        public override Task <CommandModelBase> CreateNewCommand()
        {
            var command = new WebhookCommandModel(this.Name);

            // Link the cloud webhook with the local command ID
            command.ID = this.webhookID;

            return(Task.FromResult <CommandModelBase>(command));
        }
Exemplo n.º 2
0
        private void CommandButtons_EditClicked(object sender, RoutedEventArgs e)
        {
            WebhookCommandModel command = ((CommandListingButtonsControl)sender).GetCommandFromCommandButtons <WebhookCommandModel>();

            if (command != null)
            {
                CommandEditorWindow window = CommandEditorWindow.GetCommandEditorWindow(command);
                window.Closed += Window_Closed;
                window.ForceShow();
            }
        }
Exemplo n.º 3
0
 public WebhookCommandEditorWindowViewModel(WebhookCommandModel existingCommand) : base(existingCommand)
 {
     this.webhookID = existingCommand.ID;
     JSONParameters.Clear();
     foreach (var param in existingCommand.JSONParameters)
     {
         JSONParameters.Add(new WebhookJSONParameterViewModel(this)
         {
             JSONParameterName = param.JSONParameterName, SpecialIdentifierName = param.SpecialIdentifierName
         });
     }
 }
Exemplo n.º 4
0
 private async void CommandButtons_DeleteClicked(object sender, RoutedEventArgs e)
 {
     await this.Window.RunAsyncOperation(async() =>
     {
         try
         {
             WebhookCommandModel command = ((CommandListingButtonsControl)sender).GetCommandFromCommandButtons <WebhookCommandModel>();
             if (command != null)
             {
                 ChannelSession.Services.Command.WebhookCommands.Remove(command);
                 ChannelSession.Settings.RemoveCommand(command);
                 await ChannelSession.Services.WebhookService.DeleteWebhook(command.ID);
                 await this.viewModel.RefreshCommands();
                 await ChannelSession.SaveSettings();
             }
         }
         catch (Exception ex)
         {
             Logger.Log(ex);
         }
     });
 }
Exemplo n.º 5
0
 public WebhookCommandItemViewModel(Webhook webhook, WebhookCommandModel command)
 {
     this.Webhook = webhook;
     this.Command = command;
 }
Exemplo n.º 6
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);
                }
            });
        }