protected override async Task PerformInternal(CommandParametersModel parameters)
        {
            List <bool> results = new List <bool>();

            foreach (ConditionalClauseModel clause in this.Clauses)
            {
                results.Add(await this.Check(clause, parameters));
            }

            bool finalResult = false;

            if (this.Operator == ConditionalOperatorTypeEnum.And)
            {
                finalResult = results.All(r => r);
            }
            else if (this.Operator == ConditionalOperatorTypeEnum.Or)
            {
                finalResult = results.Any(r => r);
            }
            else if (this.Operator == ConditionalOperatorTypeEnum.ExclusiveOr)
            {
                finalResult = results.Count(r => r) == 1;
            }

            if (finalResult)
            {
                await CommandModelBase.RunActions(this.Actions, parameters);
            }
        }
Пример #2
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);
                }
            });
        }