public static async Task <CommandModelBase> ImportCommandFromFile() { string fileName = ChannelSession.Services.FileService.ShowOpenFileDialog(string.Format("Mix It Up Command (*{0})|*{0},*{1}|All files (*.*)|*.*", MixItUpCommandFileExtension, MixItUpOldCommandFileExtension)); if (!string.IsNullOrEmpty(fileName)) { if (Path.GetExtension(fileName).Equals(MixItUpOldCommandFileExtension)) { #pragma warning disable CS0612 // Type or member is obsolete MixItUp.Base.Commands.CommandBase command = await FileSerializerHelper.DeserializeFromFile <MixItUp.Base.Commands.CommandBase>(fileName); ActionGroupCommandModel actionGroup = new ActionGroupCommandModel(command.Name, false); foreach (MixItUp.Base.Actions.ActionBase action in command.Actions) { actionGroup.Actions.AddRange(ActionModelBase.UpgradeAction(action)); } return(actionGroup); #pragma warning restore CS0612 // Type or member is obsolete } else { return(await FileSerializerHelper.DeserializeFromFile <CommandModelBase>(fileName)); } } return(null); }
public async Task AddAction(ActionModelBase action) { ActionEditorControlViewModelBase editorViewModel = null; switch (action.Type) { case ActionTypeEnum.Chat: editorViewModel = new ChatActionEditorControlViewModel((ChatActionModel)action); break; case ActionTypeEnum.Command: editorViewModel = new CommandActionEditorControlViewModel((CommandActionModel)action); break; case ActionTypeEnum.Conditional: editorViewModel = new ConditionalActionEditorControlViewModel((ConditionalActionModel)action); break; case ActionTypeEnum.Consumables: editorViewModel = new ConsumablesActionEditorControlViewModel((ConsumablesActionModel)action); break; case ActionTypeEnum.Counter: editorViewModel = new CounterActionEditorControlViewModel((CounterActionModel)action); break; case ActionTypeEnum.Discord: editorViewModel = new DiscordActionEditorControlViewModel((DiscordActionModel)action); break; case ActionTypeEnum.ExternalProgram: editorViewModel = new ExternalProgramActionEditorControlViewModel((ExternalProgramActionModel)action); break; case ActionTypeEnum.File: editorViewModel = new FileActionEditorControlViewModel((FileActionModel)action); break; case ActionTypeEnum.GameQueue: editorViewModel = new GameQueueActionEditorControlViewModel((GameQueueActionModel)action); break; case ActionTypeEnum.IFTTT: editorViewModel = new IFTTTActionEditorControlViewModel((IFTTTActionModel)action); break; case ActionTypeEnum.Input: editorViewModel = new InputActionEditorControlViewModel((InputActionModel)action); break; case ActionTypeEnum.Moderation: editorViewModel = new ModerationActionEditorControlViewModel((ModerationActionModel)action); break; case ActionTypeEnum.Overlay: editorViewModel = new OverlayActionEditorControlViewModel((OverlayActionModel)action); break; case ActionTypeEnum.OvrStream: editorViewModel = new OvrStreamActionEditorControlViewModel((OvrStreamActionModel)action); break; case ActionTypeEnum.Serial: editorViewModel = new SerialActionEditorControlViewModel((SerialActionModel)action); break; case ActionTypeEnum.Sound: editorViewModel = new SoundActionEditorControlViewModel((SoundActionModel)action); break; case ActionTypeEnum.SpecialIdentifier: editorViewModel = new SpecialIdentifierActionEditorControlViewModel((SpecialIdentifierActionModel)action); break; case ActionTypeEnum.StreamingSoftware: editorViewModel = new StreamingSoftwareActionEditorControlViewModel((StreamingSoftwareActionModel)action); break; case ActionTypeEnum.Streamlabs: editorViewModel = new StreamlabsActionEditorControlViewModel((StreamlabsActionModel)action); break; case ActionTypeEnum.TextToSpeech: editorViewModel = new TextToSpeechActionEditorControlViewModel((TextToSpeechActionModel)action); break; case ActionTypeEnum.Twitch: editorViewModel = new TwitchActionEditorControlViewModel((TwitchActionModel)action); break; case ActionTypeEnum.Twitter: editorViewModel = new TwitterActionEditorControlViewModel((TwitterActionModel)action); break; case ActionTypeEnum.Wait: editorViewModel = new WaitActionEditorControlViewModel((WaitActionModel)action); break; case ActionTypeEnum.WebRequest: editorViewModel = new WebRequestActionEditorControlViewModel((WebRequestActionModel)action); break; } if (editorViewModel != null) { await this.AddActionViewModel(editorViewModel); } }
#pragma warning disable CS0612 // Type or member is obsolete protected CommandModelBase(MixItUp.Base.Commands.CommandBase command) { if (command != null) { this.ID = command.ID; this.GroupName = command.GroupName; this.IsEnabled = command.IsEnabled; this.Unlocked = command.Unlocked; if (command is MixItUp.Base.Commands.PermissionsCommandBase) { MixItUp.Base.Commands.PermissionsCommandBase pCommand = (MixItUp.Base.Commands.PermissionsCommandBase)command; this.Requirements = new RequirementsSetModel(pCommand.Requirements); } foreach (MixItUp.Base.Actions.ActionBase action in command.Actions) { this.Actions.AddRange(ActionModelBase.UpgradeAction(action)); } } else { this.ID = Guid.NewGuid(); } }
public static async Task <T> ImportCommandFromFile <T>(string filePath) where T : CommandModelBase { if (!string.IsNullOrEmpty(filePath)) { if (Path.GetExtension(filePath).Equals(MixItUpOldCommandFileExtension)) { #pragma warning disable CS0612 // Type or member is obsolete MixItUp.Base.Commands.CommandBase command = await FileSerializerHelper.DeserializeFromFile <MixItUp.Base.Commands.CommandBase>(filePath); ActionGroupCommandModel actionGroup = new ActionGroupCommandModel(command.Name, false); foreach (MixItUp.Base.Actions.ActionBase action in command.Actions) { actionGroup.Actions.AddRange(ActionModelBase.UpgradeAction(action)); } return(actionGroup as T); #pragma warning restore CS0612 // Type or member is obsolete } else { return(await FileSerializerHelper.DeserializeFromFile <T>(filePath)); } } return(null); }
public SubActionContainerControlViewModel(ActionModelBase action, IEnumerable <ActionModelBase> subActions) : base(action) { foreach (ActionModelBase subAction in subActions) { this.subActions.Add(subAction); } }
public async Task DuplicateAction(ActionEditorControlViewModelBase actionViewModel) { ActionModelBase action = await actionViewModel.ValidateAndGetAction(); if (action != null) { await this.AddAction(action); } }
public async Task <ActionModelBase> GetAction() { ActionModelBase action = await this.GetActionInternal(); if (action != null) { action.Name = this.Name; action.Enabled = this.Enabled; } return(action); }
private async Task RunDirectlyInternal(CommandInstanceModel commandInstance, CommandParametersModel parameters) { CommandModelBase command = commandInstance.Command; if (command != null) { await command.PreRun(parameters); } if (command != null && command.HasCustomRun) { await commandInstance.Command.CustomRun(parameters); } else { List <ActionModelBase> actions = commandInstance.GetActions(); for (int i = 0; i < actions.Count; i++) { if (commandInstance.State == CommandInstanceStateEnum.Canceled) { return; } ActionModelBase action = actions[i]; if (action is OverlayActionModel && ChannelSession.Services.Overlay.IsConnected) { ChannelSession.Services.Overlay.StartBatching(); } await action.Perform(parameters); if (action is OverlayActionModel && ChannelSession.Services.Overlay.IsConnected) { if (i == (actions.Count - 1) || !(actions[i + 1] is OverlayActionModel)) { await ChannelSession.Services.Overlay.EndBatching(); } } } } if (commandInstance.State == CommandInstanceStateEnum.Canceled) { return; } if (command != null) { await command.PostRun(parameters); } }
public async Task <IEnumerable <ActionModelBase> > GetActions() { List <ActionModelBase> actions = new List <ActionModelBase>(); foreach (ActionEditorControlViewModelBase actionViewModel in this.Actions) { ActionModelBase action = await actionViewModel.GetAction(); if (action == null) { return(null); } actions.Add(action); } return(actions); }
protected override Task OnLoadedInternal() { this.PlayCommand = this.CreateCommand(async(parameter) => { ActionModelBase action = await this.ValidateAndGetAction(); if (action != null) { await action.TestPerform(this.actionEditorListControlViewModel.GetTestSpecialIdentifiers()); } }); this.MoveUpCommand = this.CreateCommand((parameter) => { this.actionEditorListControlViewModel.MoveActionUp(this); return(Task.FromResult(0)); }); this.MoveDownCommand = this.CreateCommand((parameter) => { this.actionEditorListControlViewModel.MoveActionDown(this); return(Task.FromResult(0)); }); this.CopyCommand = this.CreateCommand(async(parameter) => { await this.actionEditorListControlViewModel.DuplicateAction(this); }); this.HelpCommand = this.CreateCommand((parameter) => { ProcessHelper.LaunchLink("https://github.com/SaviorXTanren/mixer-mixitup/wiki/Actions#" + this.HelpLinkIdentifier); return(Task.FromResult(0)); }); this.DeleteCommand = this.CreateCommand((parameter) => { this.actionEditorListControlViewModel.DeleteAction(this); return(Task.FromResult(0)); }); return(Task.FromResult(0)); }
public static async Task RunActions(IEnumerable <ActionModelBase> actions, CommandParametersModel parameters) { List <ActionModelBase> actionsToRun = new List <ActionModelBase>(actions); for (int i = 0; i < actionsToRun.Count; i++) { ActionModelBase action = actionsToRun[i]; if (action is OverlayActionModel && ChannelSession.Services.Overlay.IsConnected) { ChannelSession.Services.Overlay.StartBatching(); } await action.Perform(parameters); if (action is OverlayActionModel && ChannelSession.Services.Overlay.IsConnected) { if (i == (actionsToRun.Count - 1) || !(actionsToRun[i + 1] is OverlayActionModel)) { await ChannelSession.Services.Overlay.EndBatching(); } } } }
public ActionEditorControlViewModelBase(ActionModelBase action) { this.Name = action.Name; this.Enabled = action.Enabled; this.IsMinimized = true; }