private void markLineAt(CommandsModule commandsModule, MarkType markType, int index) { markCommandsModule = commandsModule; this.markType = markType; markLineIndex = index; if (commandsModule != null) { if (this.markType == MarkType.COMPILE_ERROR) { // 如果是语法错误,不自动跳转到其他CommandsModule, // 因为检测到出错的位置,和当前正在编辑的位置有可能不在同一个CommandsModule if (CurrCommandsModule == markCommandsModule) { updateLineNumbers(true); } } else { LoadData(commandsModule, index); } //LoadData(commandsModule, index); } else { updateLineNumbers(true); } }
public RunnableModule(CommandsModule commandsModule, PointD origin) { this.commandsModule = commandsModule; //todo reverse this.origin.X = origin.X; this.origin.Y = origin.Y; }
public DiscordBotHandler(string [] args) { BotSettings = new BotSettings(); Configuration = new ConfigurationBuilder() .SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "Settings")) .AddJsonFile("shared.json") .AddJsonFile("bot.json") .AddJsonFile("uploader.json") .AddCommandLine(args) .Build(); Configuration.Bind(BotSettings); if (BotSettings.UseRemoteDatabase) { /* * DB = new OctoKitGameDatabase( HttpClient , Configuration ["GitUsername"] , Configuration ["GitPassword"] ) * { * InitialLoad = true , * }; */ DB = new HttpGameDatabase(HttpClient) { InitialLoad = true, }; } else { DB = new FileSystemGameDatabase(); } Configuration.Bind(DB.SharedSettings); DiscordInstance = new DiscordClient(new DiscordConfiguration() { AutoReconnect = true, TokenType = TokenType.Bot, Token = BotSettings.DiscordToken, #if DEBUG MinimumLogLevel = Microsoft.Extensions.Logging.LogLevel.Debug, #endif }); //TODO:not sure if this has to be any other way, but singleton for now will work Services = new ServiceCollection() .AddSingleton(DB) .AddSingleton(Configuration); CommandsModule = DiscordInstance.UseCommandsNext(new CommandsNextConfiguration() { Services = Services.BuildServiceProvider(), }); InteractivityModule = DiscordInstance.UseInteractivity(new InteractivityConfiguration()); CommandsModule.RegisterCommands <MatchTrackerCommands>(); }
public static ContainerBuilder AddMessageHandling(this ContainerBuilder builder, params Assembly[] assemblies) { builder .RegisterModule(CommandsModule.For(assemblies)) .RegisterModule(EventsModule.For(assemblies)) .RegisterModule(QueryModule.For(assemblies)); return(builder); }
/// <summary> /// 加载命令行 /// </summary> /// <param name="cmdLines"></param> /// <param name="scrollToIndex">加载完成后自动滚动到指定行的索引位置</param> public void LoadData(CommandsModule commandsModule, int scrollToIndex = 0) { if (commandsModule == null) { throw new Exception("commandsModule can not be null."); } if (this.commandsModule == commandsModule) { scrollTo(scrollToIndex); Log.Dprint("update LineNumbers..."); updateLineNumbers(true); Log.Dprint("update LineNumbers done!"); return; } this.commandsModule = commandsModule; Log.Dprint("update listView..."); listView1.BeginUpdate(); listView1.Items.Clear(); if (commandsModule.CmdLineList != null && commandsModule.CmdLineList.Count > 0) { for (int i = 0; i < commandsModule.CmdLineList.Count; i++) { insertListViewItem(i, commandsModule.CmdLineList[i]); } } resizeCmdColumnWidth(); scrollTo(scrollToIndex); listView1.EndUpdate(); Log.Dprint("update listView done!"); Log.Dprint("update LineNumbers..."); updateLineNumbers(true); Log.Dprint("update LineNumbers done!"); OnCommandsModuleLoadedEvent?.Invoke(commandsModule); this.UpdateDrawPanel(); }
public CommandsModuleTests() { _instance = new CommandsModule(); }
///<summary> /// Description :设置打开的命令模块和指定某一行的指令 /// Author :liyi /// Date :2019/07/23 ///</summary> public void SetCurCommandsModule(CommandsModule module) { this.curModule = module; }
/// <summary> /// 在指定的行位置标记程序运行暂停的位置 /// </summary> /// <param name="index"></param> public void MarkRunningPausedPosition(CommandsModule commandsModule, int index) { markLineAt(commandsModule, MarkType.RUNNING_PAUSED_POSITION, index); }
/// <summary> /// 在指定的行位置标记编译出错 /// </summary> /// <param name="index"></param> public void MarkCompileError(CommandsModule commandsModule, int index) { markLineAt(commandsModule, MarkType.COMPILE_ERROR, index); }
int RegisterCommandsClass(CommandEvaluationContext context, Type type, bool registerAsModule) { if (type.GetInterface(typeof(ICommandsDeclaringType).FullName) == null) { throw new Exception($"the type '{type.FullName}' must implements interface '{typeof(ICommandsDeclaringType).FullName}' to be registered as a command class"); } var comsCount = 0; object instance = Activator.CreateInstance(type, new object[] { }); var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); if (registerAsModule && _modules.ContainsKey(type.FullName)) { Errorln($"a module with same name than commands type '{type.FullName}' is already registered"); return(0); } foreach (var method in methods) { var cmd = method.GetCustomAttribute <CommandAttribute>(); if (cmd != null) { if (!method.ReturnType.HasInterface(typeof(ICommandResult))) { Errorln($"class={type.FullName} method={method.Name} wrong return type. should be of type '{typeof(ICommandResult).FullName}', but is of type: {method.ReturnType.FullName}"); } else { var paramspecs = new List <CommandParameterSpecification>(); bool syntaxError = false; var pindex = 0; foreach (var parameter in method.GetParameters()) { if (pindex == 0) { // manadatory: param 0 is CommandEvaluationContext if (parameter.ParameterType != typeof(CommandEvaluationContext)) { Errorln($"class={type.FullName} method={method.Name} parameter 0 ('{parameter.Name}') should be of type '{typeof(CommandEvaluationContext).FullName}', but is of type: {parameter.ParameterType.FullName}"); syntaxError = true; break; } } else { CommandParameterSpecification pspec = null; var paramAttr = parameter.GetCustomAttribute <ParameterAttribute>(); object defval = null; if (!parameter.HasDefaultValue && parameter.ParameterType.IsValueType) { defval = Activator.CreateInstance(parameter.ParameterType); } if (paramAttr != null) { // TODO: validate command specification (eg. indexs validity) pspec = new CommandParameterSpecification( parameter.Name, paramAttr.Description, paramAttr.IsOptional, paramAttr.Index, null, true, parameter.HasDefaultValue, (parameter.HasDefaultValue) ? parameter.DefaultValue : defval, parameter); } var optAttr = parameter.GetCustomAttribute <OptionAttribute>(); if (optAttr != null) { var reqParamAttr = parameter.GetCustomAttribute <OptionRequireParameterAttribute>(); try { pspec = new CommandParameterSpecification( parameter.Name, optAttr.Description, optAttr.IsOptional, -1, optAttr.OptionName ?? parameter.Name, optAttr.HasValue, parameter.HasDefaultValue, (parameter.HasDefaultValue) ? parameter.DefaultValue : defval, parameter, reqParamAttr?.RequiredParameterName); } catch (Exception ex) { Errorln(ex.Message); } } if (pspec == null) { syntaxError = true; Errorln($"invalid parameter: class={type.FullName} method={method.Name} name={parameter.Name}"); } else { paramspecs.Add(pspec); } } pindex++; } if (!syntaxError) { var cmdNameAttr = method.GetCustomAttribute <CommandNameAttribute>(); var cmdName = (cmdNameAttr != null && cmdNameAttr.Name != null) ? cmdNameAttr.Name : (cmd.Name ?? method.Name.ToLower()); var cmdspec = new CommandSpecification( cmdName, cmd.Description, cmd.LongDescription, cmd.Documentation, method, instance, paramspecs); bool registered = true; if (_commands.TryGetValue(cmdspec.Name, out var cmdlst)) { if (cmdlst.Select(x => x.MethodInfo.DeclaringType == type).Any()) { Errorln($"command already registered: '{cmdspec.Name}' in type '{cmdspec.DeclaringTypeFullName}'"); registered = false; } else { cmdlst.Add(cmdspec); } } else { _commands.Add(cmdspec.Name, new List <CommandSpecification> { cmdspec }); } if (registered) { _syntaxAnalyzer.Add(cmdspec); comsCount++; } } } } } if (registerAsModule) { if (comsCount == 0) { Errorln($"no commands found in type '{type.FullName}'"); } else { var descAttr = type.GetCustomAttribute <CommandsAttribute>(); var description = descAttr != null ? descAttr.Description : ""; _modules.Add(type.FullName, new CommandsModule(CommandsModule.DeclaringTypeShortName(type), description, type.Assembly, 1, comsCount, type)); } } return(comsCount); }
/// <summary> /// 事件处理:双击脚本编辑器命令行 /// 按钮标识:如果是PageJobsProgram界面的按钮,直接用传递过来的btn /// 如果点击的命令行对应按钮在本界面,则直接用对应按钮 /// </summary> private void PageJobProgram_CmdLineDoubleClicked(CommandsModule commandsModule, CmdLine cmdLine, MetroSetButtonImg btn) { if (cmdLine is MeasureHeightCmdLine) { this.addPage(new EditHeightMetro(commandsModule as Pattern, cmdLine as MeasureHeightCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is CircleCmdLine) { this.addPage(new EditCircleMetro(commandsModule as Pattern, cmdLine as CircleCmdLine)); this.selectCmdButton(btnEditCircle); } else if (cmdLine is ArcCmdLine) { this.addPage(new EditArcMetro(commandsModule as Pattern, cmdLine as ArcCmdLine)); this.selectCmdButton(btnEditArc); } else if (cmdLine is CommentCmdLine) { this.addPage(new EditCommentsMetro(cmdLine as CommentCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is StepAndRepeatCmdLine) { this.addPage(new EditPatternArrayMetro(commandsModule as Pattern, cmdLine as StepAndRepeatCmdLine)); this.selectCmdButton(btnEditPatternArray); } else if (cmdLine is DoCmdLine) { this.addPage(new EditDoPatternMetro(commandsModule as Pattern, cmdLine as DoCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is DoMultiPassCmdLine) { this.addPage(new EditDoMultipassMetro(commandsModule as Pattern, cmdLine as DoMultiPassCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is DotCmdLine) { this.addPage(new EditDotMetro(commandsModule as Pattern, cmdLine as DotCmdLine)); this.selectCmdButton(btnEditDot); } else if (cmdLine is FinishShotCmdLine) { this.addPage(new EditFinishShotMetro(commandsModule as Pattern, cmdLine as FinishShotCmdLine)); this.selectCmdButton(btnEditFinishShot); } else if (cmdLine is SnakeLineCmdLine) { this.addPage(new EditSnakelineMetro(commandsModule as Pattern, cmdLine as SnakeLineCmdLine)); this.selectCmdButton(btnEditSnakeline); } else if (cmdLine is LineCmdLine) { this.addPage(new EditLineMetro(commandsModule as Pattern, cmdLine as LineCmdLine)); this.selectCmdButton(btnEditLine); } else if (cmdLine is LoopPassCmdLine) { this.addPage(new EditLoopPassMetro(cmdLine as LoopPassCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is MarkCmdLine) { this.clearPage(); } else if (cmdLine is BadMarkCmdLine) { this.clearPage(); } else if (cmdLine is MoveAbsXyCmdLine) { this.addPage(new EditMoveAbsXyMetro(cmdLine as MoveAbsXyCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is MoveAbsZCmdLine) { this.addPage(new EditMoveAbsZMetro(cmdLine as MoveAbsZCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is MoveToLocationCmdLine) { this.addPage(new EditMoveLocMetro(this.pageJobsProgram.CurrProgram, cmdLine as MoveToLocationCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is MoveXyCmdLine) { this.addPage(new EditMoveXyMetro(cmdLine as MoveXyCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is SetHeightSenseModeCmdLine) { // TODO 测高模式第二阶段再做 } else if (cmdLine is StartPassCmdLine) { this.addPage(new EditStartPassMetro(cmdLine as StartPassCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is NormalTimerCmdLine) { this.addPage(new EditTimerMetro(cmdLine as NormalTimerCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is TimerCmdLine) { this.addPage(new EditMultipassTimerMetro(cmdLine as TimerCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is PassBlockCmdLine) { this.addPage(new EditPassBlockMetro(cmdLine as PassBlockCmdLine)); this.selectCmdButton(btn); } else if (cmdLine is NozzleCheckCmdLine) { this.clearPage(); } }
public ModifyCompForm(CommandsModule commandsModule) { InitializeComponent(); this.commandsModule = commandsModule; this.StartPosition = FormStartPosition.CenterScreen; }