public override void Execute() { // Parse the arguments and append to the file. var result = Parser.Default.ParseArguments <TriggerArguments>(CreateArgs(this.Parameters)) .WithParsed(o => { if (o.Enable && o.Disable) { this.Interpreter.Conveyor.EchoLog("You cannot both enable and disable a trigger at the same time.", Common.Models.LogType.Error); return; } // System triggers that match the ID. foreach (var t in App.SystemTriggers.Where(x => x.Identifier == o.Id)) { if (o.Enable) { t.Enabled = true; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' was enabled.", Common.Models.LogType.Success); } } if (o.Disable) { t.Enabled = false; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' was disabled.", Common.Models.LogType.Success); } } // The pattern has to be something if (!string.IsNullOrWhiteSpace(o.Pattern)) { t.Pattern = o.Pattern; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had its pattern set to {o.Pattern}.", Common.Models.LogType.Success); } } // The command only has to not be null so it can be cleared. if (o.Command != null) { t.Command = o.Command; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had its command set to {o.Command}.", Common.Models.LogType.Success); } } } bool found = false; // Update - User created triggers that match the ID. foreach (var t in App.Settings.ProfileSettings.TriggerList.Where(x => x.Identifier == o.Id)) { found = true; if (o.Enable) { t.Enabled = true; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' was enabled.", Common.Models.LogType.Success); } } if (o.Disable) { t.Enabled = false; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' was disabled.", Common.Models.LogType.Success); } } // The pattern has to be something if (!string.IsNullOrWhiteSpace(o.Pattern)) { t.Pattern = o.Pattern; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had its pattern set to {o.Pattern}.", Common.Models.LogType.Success); } } // The command only has to not be null so it can be cleared. if (o.Command != null) { t.Command = o.Command; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had its command set to {o.Command}.", Common.Models.LogType.Success); } } } // Create if (!found) { // Create the trigger. var t = new Common.Triggers.Trigger(o.Pattern, o.Command, "", false, o.Id); t.Group = o.Group ?? ""; t.VariableReplacement = o.VariableReplacement; // Enabled is default, they can force it to be created disabled. if (o.Disable) { t.Enabled = false; } // Set the Conveyor so it's usable t.Conveyor = this.Interpreter.Conveyor; // Add it to the list. App.Settings.ProfileSettings.TriggerList.Add(t); if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' has been created.", Common.Models.LogType.Success); } } }); // Display the help or error output from the parameter parsing. this.DisplayParserOutput(result); }
public override void Execute() { // Parse the arguments and append to the file. var result = Parser.Default.ParseArguments <Arguments>(CreateArgs(this.Parameters)) .WithParsed(o => { if (o.Enable && o.Disable) { this.Interpreter.Conveyor.EchoLog("You cannot both enable and disable a trigger at the same time.", Common.Models.LogType.Error); return; } // System triggers that match the ID. foreach (var t in App.InstanceGlobals.SystemTriggers.Where(x => x.Identifier == o.Id)) { if (o.Enable) { t.Enabled = true; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' was enabled.", Common.Models.LogType.Success); } } if (o.Disable) { t.Enabled = false; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' was disabled.", Common.Models.LogType.Success); } } if (!string.IsNullOrWhiteSpace(o.StopProcessing)) { t.StopProcessing = bool.Parse(o.StopProcessing); if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had stop processing set to {t.StopProcessing.ToString()}.", Common.Models.LogType.Success); } } // The pattern has to be something if (!string.IsNullOrWhiteSpace(o.Pattern)) { t.Pattern = o.Pattern; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had its pattern set to {o.Pattern}.", Common.Models.LogType.Success); } } // The command only has to not be null so it can be cleared. if (o.Command != null) { t.Command = o.Command; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had its command set to {o.Command}.", Common.Models.LogType.Success); } } } bool found = false; // Update - User created triggers that match the ID. foreach (var t in App.Settings.ProfileSettings.TriggerList.Where(x => x.Identifier == o.Id)) { found = true; if (o.Enable) { t.Enabled = true; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' was enabled.", Common.Models.LogType.Success); } } if (o.Disable) { t.Enabled = false; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' was disabled.", Common.Models.LogType.Success); } } if (!string.IsNullOrWhiteSpace(o.StopProcessing)) { t.StopProcessing = bool.Parse(o.StopProcessing); if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had stop processing set to {t.StopProcessing.ToString()}.", Common.Models.LogType.Success); } } // The pattern has to be something if (!string.IsNullOrWhiteSpace(o.Pattern)) { t.Pattern = o.Pattern; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had its pattern set to {o.Pattern}.", Common.Models.LogType.Success); } } // The command only has to not be null so it can be cleared. if (o.Command != null) { t.Command = o.Command; if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' had its command set to {o.Command}.", Common.Models.LogType.Success); } } } // Create if (!found) { // Create the trigger. var t = new Common.Triggers.Trigger(o.Pattern, o.Command ?? "", "", false, o.Id) { Group = o.Group ?? "", VariableReplacement = o.VariableReplacement }; if (!string.IsNullOrWhiteSpace(o.StopProcessing)) { t.StopProcessing = bool.Parse(o.StopProcessing); } // Enabled is default, they can force it to be created disabled. if (o.Disable) { t.Enabled = false; } // Add it to the list. BUG: This could cause a bug if a trigger is added and this has // been called from the trigger loop itself (e.g. you're adding to a collection that is being // currently enumerated. App.Settings.ProfileSettings.TriggerList.Add(t); if (o.Verbose) { this.Interpreter.Conveyor.EchoLog($"A trigger with the ID of '{o.Id}' has been created.", Common.Models.LogType.Success); } } }); // Display the help or error output from the parameter parsing. this.DisplayParserOutput(result); }