public override void Execute(params object[] executeArgs) { //Check the condition, if success, the execute `if` block //If failed, then search the SubCommands, find the `elseif` block and check one by one //If no matched the `elseif` block, the find the `else` block and execute if (CheckCondition()) { var commands = SubCommands.Where(o => !(o is ElseIfScriptCommand) && !(o is ElseScriptCommand)); foreach (var command in commands) { command.Execute(executeArgs); } } else { var elseIfCommands = SubCommands.Where(o => o is ElseIfScriptCommand); foreach (var command in elseIfCommands) { if ((command as ConditionalScriptCommand).CheckCondition()) { command.Execute(executeArgs); return; } } var elseCommand = SubCommands.Where(o => o is ElseScriptCommand).FirstOrDefault(); if (elseCommand != null) { elseCommand.Execute(executeArgs); } } }
private void DoMove(CharacterData character, string argument, int command, SubCommands subcommand) { DirectionTypes direction = DirectionTypes.Index; switch (subcommand) { case SubCommands.North: direction = DirectionTypes.North; break; case SubCommands.South: direction = DirectionTypes.South; break; case SubCommands.East: direction = DirectionTypes.East; break; case SubCommands.West: direction = DirectionTypes.West; break; case SubCommands.Up: direction = DirectionTypes.Up; break; case SubCommands.Down: direction = DirectionTypes.Down; break; } PerformMove(character, direction, false); }
public override void NotifyOfPropertyChange(string propertyName = "") { base.NotifyOfPropertyChange(propertyName); switch (propertyName) { case "SliderValue": int curIdx = findViewMode(ViewModes, SliderValue); string viewMode; int step; int itemHeight; parseViewMode(ViewModes[curIdx], out viewMode, out step, out itemHeight); ViewModeStepCommandModel commandModel = SubCommands .Where(c => c is ViewModeStepCommandModel) .First(c => (c as ViewModeStepCommandModel).SliderStep == step) as ViewModeStepCommandModel; if (commandModel != null) { this.HeaderIconExtractor = commandModel.HeaderIconExtractor; } if (_flvm.Parameters.ItemSize != SliderValue) { updateViewMode(_flvm, commandModel.Header, SliderValue); //Debug.WriteLine(commandModel.Header + SliderValue.ToString()); } break; } }
public CommandInfo (string command, PositionTypes min_position, CommandHandler pointer, int min_level, SubCommands subcmd) { Command = command; MinimumPosition = min_position; CommandPointer = pointer; MinimumLevel = min_level; SubCommand = subcmd; }
public override string ReportInternal(int tabsCount, VerbosityLevel verbosity) { string whitespace = CommonExtensions.NewLineWithTabs(tabsCount); return($"{whitespace}TreatUnmatchedTokensAsErrors:{TreatUnmatchedTokensAsErrors}" + $"{whitespace}SubCommands:{string.Join("", SubCommands.Select(x => x.Report(tabsCount + 1, verbosity)))}" + $"{whitespace}Options:{string.Join("", Options.Select(x => x.Report(tabsCount + 1, verbosity)))}" + $"{whitespace}Arguments:{string.Join("", Arguments.Select(x => x.Report(tabsCount + 1, verbosity)))}"); }
public CommandViewModel(ICommandModel commandModel, IParameterDicConverter parameterDicConverter, ICommandViewModel parentCommandViewModel = null) { CommandModel = commandModel; _parentCommandViewModel = parentCommandViewModel; _parameterDicConverter = parameterDicConverter; if (CommandModel != null) { if (CommandModel is IRoutedCommandModel && (CommandModel as IRoutedCommandModel).RoutedCommand != null) { CommandBinding = ScriptCommandBinding.ForRoutedUICommand((CommandModel as IRoutedCommandModel).RoutedCommand); } else { CommandBinding = ScriptCommandBinding.FromScriptCommand( ApplicationCommands.NotACommand, commandModel, cm => cm.Command, parameterDicConverter, /*ParameterDicConverters.ConvertUIParameter, */ ScriptBindingScope.Local); } } CommandModel.PropertyChanged += (o, e) => { switch (e.PropertyName) { case "IsChecked": case "Symbol": case "HeaderIconExtractor": RefreshIcon(); break; case "SubCommands": SubCommands.LoadAsync(UpdateMode.Replace, true); RefreshIcon(); break; case "IsEnabled": case "IsVisibleOnMenu": case "IsVisibleOnToolbar": NotifyOfPropertyChange(() => IsVisibleOnMenu); NotifyOfPropertyChange(() => IsVisibleOnToolbar); break; } }; RefreshIcon(); if (commandModel is IDirectoryCommandModel) { IDirectoryCommandModel directoryModel = CommandModel as IDirectoryCommandModel; SubCommands = new EntriesHelper <ICommandViewModel>( (cts) => Task.Run <IEnumerable <ICommandViewModel> >( () => directoryModel.SubCommands.Select(c => (ICommandViewModel) new CommandViewModel(c, parameterDicConverter, this)))); SubCommands.LoadAsync(UpdateMode.Replace, false); } }
public NewNetNatPrerequisite(NewNetIpAddressTaskSubCommand newNetIpAddressTaskSubCommand) : base ( title: Resources.NewNatName, successMessage: Resources.NewNetSuccess, errorMessage: Resources.NewNetError, resolveText: Resources.NewNatResolve, configureText: Resources.NewNatConfigure ) { _newNetIpAddressTaskSubCommand = newNetIpAddressTaskSubCommand; SubCommands.Add(_newNetIpAddressTaskSubCommand); }
public PrivateNetworkPrerequisite(PrivateNetworkTaskSubCommand privateNetworkTaskSubCommand) : base ( title: Resources.PrivateNetworkTitle, successMessage: Resources.PrivateNetworkSuccess, errorMessage: Resources.PrivateNetworkError, resolveText: Resources.PrivateNetworkResolve, configureText: Resources.PrivateNetworkConfigure ) { _privateNetworkTaskSubCommand = privateNetworkTaskSubCommand; SubCommands.Add(_privateNetworkTaskSubCommand); }
public ClientConfigurationsPrerequisite( OpenClientConfigDirectorySubCommand openClientConfigDirectorySubCommand, ChangeClientConfigDirectorySubCommand changeClientConfigDirectorySubCommand) : base ( title: Resources.ClientConfigurations, successMessage: Resources.ClientConfigurationsSuccessMessage, errorMessage: Resources.ClientConfigurationsMissingErrorMessage, resolveText: Resources.ClientConfigurationsResolveText, configureText: Resources.ClientConfigurationsResolveText ) { SubCommands.Add(openClientConfigDirectorySubCommand); SubCommands.Add(changeClientConfigDirectorySubCommand); }
public ServerConfigurationPrerequisite( OpenServerConfigDirectorySubCommand openServerConfigDirectorySubCommand, ChangeServerConfigDirectorySubCommand changeServerConfigDirectorySubCommand) : base ( title: Resources.ServerConfiguration, successMessage: Resources.ServerConfigurationSuccessMessage, errorMessage: Resources.ServerConfigurationMissingErrorMessage, resolveText: Resources.ServerConfigurationConfigureText, configureText: Resources.ServerConfigurationConfigureText ) { SubCommands.Add(openServerConfigDirectorySubCommand); SubCommands.Add(changeServerConfigDirectorySubCommand); }
public MyCommand(TimerForm form) { this.form = form; SubCommands.Add("quit", () => { form.canclose = true; form.Close(); Application.Exit(); }); SubCommands.Add(WORK_COMMAND, new timeCommand(form, true)); SubCommands.Add(BREAK_COMMAND, new timeCommand(form, false)); SubCommands.Add(PAUSE_COMMAND, form.icon.Pause); }
public AlarmCommand(PluginInitContext context, CommandHandlerBase parent) : base(context, parent) { SubCommands.Add(new AlarmAddCommand(context, this)); SubCommands.Add(new AlarmTimerCommand(context, this)); SubCommands.Add(new AlarmListCommand(context, this)); SubCommands.Add(new AlarmEditCommand(context, this)); SubCommands.Add(new AlarmDeleteCommand(context, this)); SubCommands.Add(new AlarmStopwatchCommand(context, this)); System.Timers.Timer alarmTimer = new System.Timers.Timer(5000); alarmTimer.Elapsed += AlarmTimer_Elapsed; alarmTimer.Start(); }
/// <summary> /// Generates an invocation for the current command. /// </summary> /// <param name="tokens"></param> /// <returns></returns> /// <remarks>Useful in testing your command structure.</remarks> private Action GetAction(params string[] tokens) { var token = tokens.FirstOrDefault(); var subCommand = SubCommands.FirstOrDefault(cmd => cmd.IsIdentifiedBy(token)); if (subCommand == null) { return(GetAction(tokens, token)); } var theRest = tokens.Skip(1).ToArray(); var action = subCommand.GetAction(theRest); return(action ?? GetAction(tokens, token)); }
public Command WithSubCommand(Command sub) { if (HasArguments) { throw new InvalidOperationException("A command cannot have both arguments and sub-commands"); } if (SubCommands == null) { SubCommands = new List <Command>(); } sub._AllowAnonymous = this._AllowAnonymous; // Inherit property. sub.Parent = this; // Store referencee to parent. SubCommands.Add(sub); NumSubCommands++; return(this); }
public void Run(IPlayer player, int groupId, CmdArgs args) { string arg = args.PopWord()?.ToLowerInvariant(); if (arg != null) { if (SubCommands.ContainsKey(arg)) { SubCommands[arg].Run(player, groupId, args); return; } else { args.PushSingle(arg); } } Command.Invoke(player, groupId, args); }
private void DoReturn(CharacterData character, string argument, int command, SubCommands subcommand) { if (character.Descriptor != null && character.Descriptor.Original != null) { SendToCharacter(character, "You return to your original body.\r\n"); if (character.Descriptor.Original.Descriptor != null) { character.Descriptor.Original.Descriptor.Character = null; character.Descriptor.Original.Descriptor.ConnectState = ConnectState.Disconnect; } character.Descriptor.Character = character.Descriptor.Original; character.Descriptor.Original = null; character.Descriptor.Character.Descriptor = character.Descriptor; character.Descriptor = null; } }
public ClientChatCommandExt(ICoreClientAPI capi) { this.capi = capi; RegisterSubCommand("help", new SubCommand((a, b, c) => { string arg = c.PopWord()?.ToLowerInvariant(); if (arg != null && SubCommands.ContainsKey(arg)) { capi.ShowChatMessage(SubCommands[arg].Description); } else { if (arg == null) { capi.ShowChatMessage(string.Format("Please provide an argument you need help with. Type .help {0} for syntax.", Command)); } else { capi.ShowChatMessage(string.Format("No such argument '{0}' exists.", arg)); } } }, "Gets help for specified subcommand")); }
public void Delete() { if (Deleted || _Deleting) { return; } _Deleting = true; OnBeforeDelete(); KickAll(); EventSink.Shutdown -= InternalServerShutdown; EventSink.Logout -= InternalLogout; EventSink.Login -= InternalLogin; if (CoreTimer != null) { CoreTimer.Dispose(); CoreTimer = null; } Instances.Dungeons.Remove(Serial); OnDelete(); if (ExitPortal1 != null) { ExitPortal1.Delete(); ExitPortal1 = null; } if (ExitPortal2 != null) { ExitPortal2.Delete(); ExitPortal2 = null; } if (Loot != null) { Loot.ForEach(l => l.Free()); Loot.Free(true); } if (Zones != null) { Zones.ForEachReverse( z => { if (z != null) { z.Dungeon = null; z.Delete(); } }); Zones.Free(true); } if (MobileSpawns != null) { MobileSpawns.Where(m => m != null && !m.Deleted && !m.Player && m.Map == Map).ForEach(m => m.Delete()); MobileSpawns.Free(true); } if (ItemSpawns != null) { ItemSpawns.Where(m => m != null && !m.Deleted && m.Map == Map && m.Parent == null).ForEach(i => i.Delete()); ItemSpawns.Free(true); } if (Map != null) { if (Map.InstanceRegions.All(z => z == null || z.Deleted)) { Map.Delete(); } Map = null; } if (Logs != null) { Logs.Values.Free(true); Logs.Clear(); } if (ActiveGroup != null) { ActiveGroup.Free(true); } if (Group != null) { Group.Free(true); } if (SubCommands != null) { SubCommands.Clear(); } if (Options != null) { Options.Clear(); } Deleted = true; OnAfterDelete(); _Deleting = false; /* * Loot = null; * Zones = null; * MobileSpawns = null; * ItemSpawns = null; * Map = null; * Logs = null; * ActiveGroup = null; * Group = null; * SubCommands = null; * Options = null; */ }
public void AddSubCommand(ScriptCommand scriptCommand) { SubCommands.Add(scriptCommand); scriptCommand.ParentCommand = this; }
private SubCommands make_sub_command(string comm, int id, string desc, int i, int cmd_id) { Commands c = _ow.commands[cmd_id]; SubCommands sc = new SubCommands(){ Sub=comm, Row=id, sDescription=desc, Index=i, parentCommand=c}; return sc; }
public Command FindSubCommand(string name) => SubCommands.FirstOrDefault(sc => sc.Name == name.ToLowerInvariant() || sc.Aliases.Contains(name.ToLowerInvariant()));
public override void NotifySelectionChanged(IEntryModel[] appliedModels) { List <ICommandModel> subCommands = new List <ICommandModel>(); if (appliedModels.Length >= 1 && !(appliedModels.Any(em => em.FullPath.StartsWith("::")))) { #region Decompress - When selected archive. if (appliedModels.All(em => em is ISzsItemModel)) { bool isRoot = appliedModels.All(em => em is SzsRootModel); Func <IEntryModel, IScriptCommand, IScriptCommand> transferCommandFunc = (destModel, thenCommand) => isRoot? IOScriptCommands.DiskTransferChild(appliedModels, destModel, false, true, thenCommand) : IOScriptCommands.DiskTransfer(appliedModels, destModel, false, true, thenCommand); //Extract to ... subCommands.Add(new CommandModel( WPFScriptCommands.ShowDirectoryPicker(_initializer, null, dm => WPFScriptCommands.ShowProgress("Extract", transferCommandFunc(dm, WPFScriptCommands.HideProgress())), ResultCommand.NoError)) { Header = "Extract to ...", IsEnabled = true, IsVisibleOnMenu = true }); if (isRoot) { SzsRootModel firstRoot = appliedModels[0] as SzsRootModel; IPathHelper path = firstRoot.Profile.Path; Header = path.GetExtension(firstRoot.Name).TrimStart('.').FirstCharToUppercase(); string parentPath = path.GetDirectoryName(firstRoot.FullPath); //Extract Here subCommands.Add(new CommandModel( WPFScriptCommands.ShowProgress("Extract", transferCommandFunc(firstRoot.Parent, WPFScriptCommands.HideProgress()))) { Header = "Extract Here", IsEnabled = true, IsVisibleOnMenu = true }); if (appliedModels.Length == 1) { //Extract to \\ArchiveName subCommands.Add(new CommandModel( WPFScriptCommands.ParseOrCreatePath(firstRoot.Parent.Profile as IDiskProfile, path.Combine(parentPath, path.RemoveExtension(appliedModels[0].Name)), true, destFolder => transferCommandFunc(destFolder, WPFScriptCommands.HideProgress()))) { Header = "Extract to \\" + path.RemoveExtension(appliedModels[0].Name), IsEnabled = true, IsVisibleOnMenu = true }); } else { subCommands.Add(new CommandModel( WPFScriptCommands.ShowProgress("Extract", ScriptCommands.ForEach(appliedModels, am => WPFScriptCommands.ParseOrCreatePath(firstRoot.Parent.Profile as IDiskProfile, path.Combine(parentPath, path.RemoveExtension(am.Name)), true, destFolder => transferCommandFunc(destFolder, WPFScriptCommands.HideProgress()))))) { Header = "Extract to {ArchiveName}\\", IsEnabled = true, IsVisibleOnMenu = true }); } } } //if (appliedModels.All(em => em is SzsRootModel)) //{ // SzsRootModel firstRoot = appliedModels[0] as SzsRootModel; // IPathHelper path = firstRoot.Profile.Path; // Header = path.GetExtension(firstRoot.Name).TrimStart('.').FirstCharToUppercase(); // string parentPath = path.GetDirectoryName(firstRoot.FullPath); // //Extract to ... // subCommands.Add(new CommandModel( // ScriptCommands.ShowDirectoryPicker(_initializer, null, // dm => // ScriptCommands.ShowProgress("Extract", // ScriptCommands.ForEach(appliedModels, am => // IOScriptCommands.TransferChild(am, dm, null, false), // ScriptCommands.HideProgress())), // ResultCommand.NoError)) { Header = "Extract to ...", IsEnabled = true, IsVisibleOnMenu = true }); // //Extract Here // subCommands.Add(new CommandModel( // ScriptCommands.ShowProgress("Extract", // ScriptCommands.ForEach(appliedModels, am => // IOScriptCommands.TransferChild(am, firstRoot.Parent, null, false), // ScriptCommands.HideProgress()))) { Header = "Extract Here", IsEnabled = true, IsVisibleOnMenu = true }); // if (appliedModels.Length == 1) // { // //Extract to \\ArchiveName // subCommands.Add(new CommandModel( // ScriptCommands.ParseOrCreatePath(firstRoot.Parent.Profile as IDiskProfile, // path.Combine(parentPath, path.RemoveExtension(appliedModels[0].Name)), true, // destFolder => // ScriptCommands.ShowProgress("Extract", // IOScriptCommands.TransferChild(appliedModels[0], destFolder, null, false, // ScriptCommands.HideProgress())))) // { // Header = "Extract to \\" + path.RemoveExtension(appliedModels[0].Name), // IsEnabled = true, // IsVisibleOnMenu = true // }); // } // else // subCommands.Add(new CommandModel( // ScriptCommands.ShowProgress("Extract", // ScriptCommands.ForEach(appliedModels, am => // ScriptCommands.ParseOrCreatePath(firstRoot.Parent.Profile as IDiskProfile, // path.Combine(parentPath, path.RemoveExtension(am.Name)), true, // destFolder => // IOScriptCommands.TransferChild(am, destFolder, null, false)), // ScriptCommands.HideProgress()))) { Header = "Extract to {ArchiveName}\\", IsEnabled = true, IsVisibleOnMenu = true }); //} #endregion #region Compress if (!appliedModels.Any(em => em is SzsChildModel) && !(appliedModels.Length == 1 && appliedModels[0] is SzsRootModel)) { Header = "Compress"; IEntryModel firstEntry = appliedModels[0]; IDiskProfile firstProfile = firstEntry.Profile as IDiskProfile; if (firstProfile != null && !firstEntry.FullPath.StartsWith("::{") && firstEntry.Parent != null) { IPathHelper path = firstEntry.Profile.Path; //Header = path.GetExtension(firstEntry.Name).TrimStart('.').FirstCharToUppercase(); string parentPath = path.GetDirectoryName(firstEntry.FullPath); //e.g. C:\temp\abc.txt => C:\temp\temp.zip string parentArchiveName = path.ChangeExtension(firstEntry.Parent.Name, ".zip"); string parentArchivePath = path.Combine(firstEntry.Parent.FullPath, parentArchiveName); string firstArchiveName = path.ChangeExtension(firstEntry.Name, ".zip"); string firstArchivePath = path.Combine(firstEntry.Parent.FullPath, firstArchiveName); subCommands.Add(new CommandModel( ScriptCommands.Assign(new Dictionary <string, object>() { { "{Profile}", firstEntry.Parent.Profile }, { "{Header}", "Compress" }, { "{CompressFiles}", appliedModels }, { "{StartupPath}", firstEntry.Parent.FullPath }, { "{FileName}", firstArchiveName } }, false, IOScriptCommands.FileSave("Zip archives (.zip)|*.zip|7z archives (.7z)|*.7z", "{ArchivePath}", WPFScriptCommands.ShowProgress("Compress", IOScriptCommands.DiskParseOrCreateArchive("{Profile}", "{ArchivePath}", "{Archive}", IOScriptCommands.SzsDiskTransfer("{CompressFiles}", "{Archive}", false))), UIScriptCommands.MessageBoxOK("Compress", "Compress is canceled.")))) { Header = "Compress to ...", IsEnabled = true, IsVisibleOnMenu = true }); Action <string, string> addCompressToPath = (destName, destPath) => { subCommands.Add(new CommandModel( WPFScriptCommands.ShowProgress("Compress", IOScriptCommands.ParseOrCreateArchive(firstProfile, destPath, pm => IOScriptCommands.DiskTransfer(appliedModels, pm, false, true, null)))) { Header = "Compress to " + destName, IsEnabled = true, IsVisibleOnMenu = true }); }; addCompressToPath(firstArchiveName, firstArchivePath); addCompressToPath(parentArchiveName, parentArchivePath); } } #endregion } SubCommands = subCommands; IsVisibleOnMenu = SubCommands.Count() > 0; }
internal Command GetSubCommandByToken(string token) { return(SubCommands.FirstOrDefault(cmd => cmd.IsIdentifiedBy(token))); }