public void ConstInstructionFileNameParseTest() { ConstInstruction item = AConstInstruction.ConstInstructionFileNameParse("test(param1,param2)", false); Assert.AreEqual("test", item.constInstructionName); Assert.AreEqual(2, item.parameterList.Count); Assert.AreEqual("param1", item.parameterList[0]); Assert.AreEqual("param2", item.parameterList[1]); }
public void GetFileNameFromConstInstructionTest() { ConstInstruction ci = new ConstInstruction { constInstructionName = "test", parameterList = new List <string> { "param1", "param2" } }; string actual = AConstInstruction.GetFileNameFromConstInstruction(ci); Assert.AreEqual("test(param1,param2)", actual); }
/// <summary> /// 执行指令,启动失败的启动项在ReportInfo中查看 /// </summary> /// <exception cref="ConstInstructionParameterParseException"></exception> public override string Execute() { ReportInfo.Clear(); AHelper.InstructionHistory.Insert(0, Instruction); ConstInstruction ci = new ConstInstruction(); if (AConstInstruction.GetConstInstructionFrame(Instruction, ref ci)) { bool allRight = true; try { foreach (string instructionLine in ci.instructionLines) { // Instruction here firstly need to be parse (const quote / parameter parse). // Const quote parse. string instructionLine_cqp = AConstQuote.ConstQuoteParse(instructionLine); // Parameter parse ConstInstruction instructionAttribute = AConstInstruction.ConstInstructionFileNameParse(Instruction, false); string instructionLine_cpq_pp = AConstInstruction.ConstInstructionParameterParse(ci, instructionLine_cqp, instructionAttribute.parameterList); // Execute AInstruction.GetInstruction(instructionLine_cpq_pp).Execute(); if (reportType != ReportType.OK) { allRight = false; } } } catch (Exception exception) { throw exception; } finally { if (!allRight) { reportType = ReportType.WARNING; } } return(AInstruction.MSG_EXECUTE_SUCCESSFULLY); } else { reportType = ReportType.ERROR; throw new ConstInstructionNotFoundException(Instruction); } }
public void ConstInstructionParameterParseTest() { ConstInstruction ci = new ConstInstruction { constInstructionName = "test", instructionLines = new List <string> { "param1 param2 param3" }, parameterList = new List <string> { "param1", "param2" } }; List <string> valueList = new List <string> { "a", "b" }; string parseAcutual = AConstInstruction.ConstInstructionParameterParse(ci, "param1 param2 param3", valueList); Assert.AreEqual("a b param3", parseAcutual); }
/// <summary> /// 执行指令框中的指令 /// </summary> private void ExecuteTextBoxInstrution() { UpdateMaxWidth(InstructionTextBox.Text); // Execute instruction. string retnInfo = ExecuteInstruction(InstructionTextBox.Text); InitializeGUI(ATheme.GetThemeConfig()); if (AInstruction.ADD_CONST_INSTRUCTION == retnInfo) { constInstructionInputMode = true; TestRichTextbox.IsReadOnly = false; InstructionTextBox.IsEnabled = false; //AppendRTBLine(TestRichTextbox, "确认编辑: Alt + S / 取消编辑: Alt + Esc", themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning); AppendRTBLine(TestRichTextbox, "Confirm: Alt + S / Cancel: Alt + Esc", themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning); TestRichTextbox.BorderThickness = new Thickness(1); // Content Start TestRichTextbox.CaretPosition = TestRichTextbox.Document.ContentEnd; constInstructionContentRange.ContentStart = TestRichTextbox.CaretPosition.Paragraph.ContentStart; TestRichTextbox.CaretPosition.Paragraph.IsEnabled = false; // If ci already exist string constInstruction = AInstruction_Const.GetConstInstructionFromMacroInstruction(InstructionTextBox.Text); if (AConstInstruction.Exist(constInstruction)) { ConstInstruction ci = new ConstInstruction(); if (AConstInstruction.GetConstInstructionFrame(constInstruction, ref ci)) { OldConstInstructionFileName = AConstInstruction.GetFileNameFromConstInstruction(ci); foreach (string insLine in ci.instructionLines) { AppendRTBLine(TestRichTextbox, insLine, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput); UpdateMaxWidth(insLine); } } } // Set CaretPosition. TestRichTextbox.CaretPosition = TestRichTextbox.Document.ContentEnd; //UpdateMaxWidth("确认编辑: Alt + S / 取消编辑: Alt + Esc"); UpdateMaxWidth("Confirm: Alt + S / Cancel: Alt + Esc"); Resize(true, constInstructionInputWidthBias); TestRichTextbox.Focus(); showOutput = true; return; } else if (AInstruction.UPDATE_INSTRUCTION == retnInfo) { UpdateMaxWidth(InstructionTextBox.Text); AppendRTBLine(TestRichTextbox, InstructionTextBox.Text, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput); showOutput = true; InstructionTextBox.Text = ""; Resize(); AHelper.AppendString appendString = delegate(string content, AInstruction.ReportType type) { // InstructionTextBox 被主线程占用,利用 Dispatcher 进行操作 TestRichTextbox.Dispatcher.BeginInvoke((Action)(() => { switch (type) { case AInstruction.ReportType.NONE: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput); break; case AInstruction.ReportType.WARNING: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning); break; case AInstruction.ReportType.OK: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputOk, themeConfig.BackgroundOutputOk); break; case AInstruction.ReportType.ERROR: AppendRTBLine(TestRichTextbox, content, themeConfig.ForegroundOutputError, themeConfig.BackgroundOutputError); break; } InstructionTextBox.Text = ""; UpdateMaxWidth(content); Resize(); })); }; new Thread(AUpdate.UpdateAndRestart).Start(appendString); return; } // Append instruction line. AppendRTBLine(TestRichTextbox, InstructionTextBox.Text, themeConfig.ForegroundOutput, themeConfig.BackgroundOutput); // Print report. foreach (var reportInfo in AInstruction.ReportInfo) { AppendRTBLine(TestRichTextbox, reportInfo, themeConfig.ForegroundOutputWarning, themeConfig.BackgroundOutputWarning); UpdateMaxWidth(reportInfo); // If have reportInfo, then show outputBox. showOutput = true; } // Print return information. SolidColorBrush bgcolor; SolidColorBrush fgcolor; switch (AInstruction.reportType) { case AInstruction.ReportType.OK: bgcolor = themeConfig.BackgroundOutputOk; fgcolor = themeConfig.ForegroundOutputOk; if (AInstruction.ReportInfo.Count == 0) { showOutput = false; } break; case AInstruction.ReportType.WARNING: bgcolor = themeConfig.BackgroundOutputWarning; fgcolor = themeConfig.ForegroundOutputWarning; showOutput = true; break; case AInstruction.ReportType.ERROR: bgcolor = themeConfig.BackgroundOutputError; fgcolor = themeConfig.ForegroundOutputError; showOutput = true; break; default: bgcolor = themeConfig.BackgroundOutputWarning; fgcolor = themeConfig.ForegroundOutputWarning; break; } if (retnInfo != "") { AppendRTBLine(TestRichTextbox, retnInfo.Trim(), fgcolor, bgcolor); } if (AInstruction.GetType(InstructionTextBox.Text) == InstructionType.CMD) { InstructionTextBox.Text = "> "; showOutput = true; } else { InstructionTextBox.Text = ""; if (AInstruction.ReportType.OK == AInstruction.reportType && 0 == AInstruction.ReportInfo.Count) { Visibility = Visibility.Hidden; } } InstructionTextBox.SelectionStart = InstructionTextBox.Text.Length; // Update width and resize. UpdateMaxWidth(retnInfo); Resize(); }