Exemplo n.º 1
0
        public void MainTest()
        {
            // Sample Initialization
            string FilesExamplePath = AHelper.BASE_PATH + @"\FilesExample", ExampleFileName = "demoFile.txt";

            Directory.CreateDirectory(FilesExamplePath);
            using (StreamWriter streamWriter = new StreamWriter(FilesExamplePath + @"\" + ExampleFileName, false))
            {
                streamWriter.WriteLine("Hello Alterful!");
            }
            AFile.Add("demo", FilesExamplePath + @"\" + ExampleFileName);

            // ----Instruction Sample----
            // new AInstruction_Startup("demo demo-f").Execute();
            // new AInstruction_Macro("@new a.txt b.txt").Execute();
            // new AInstruction_Macro(@"@add f f:\").Execute();
            // new AInstruction_Macro("f").Execute();
            // new AInstruction_Macro(@"@del f").Execute();
            // -----Demo End-----

            // ----Sample For fun----
            string yourChromePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";

            AInstruction.GetInstruction("@add chrome " + yourChromePath).Execute();
            AInstruction.GetInstruction("@add #fy chrome-o/https://fanyi.baidu.com/#zh/en/").Execute();
            AInstruction.GetInstruction("#fy+键盘增强").Execute();
            // ----Sample For fun----
        }
Exemplo n.º 2
0
 /// <summary>
 /// 执行指令
 /// </summary>
 /// <param name="instruction">欲执行的指令</param>
 /// <returns></returns>
 private string ExecuteInstruction(string instruction)
 {
     if ("~" == instruction)
     {
         Close();
     }
     try { return(AInstruction.GetInstruction(instruction).Execute()); }
     catch (Exception exception) { return(exception.Message); }
 }
Exemplo n.º 3
0
 public static InstructionType GetInstructionCompletionPartType(string instructionPart)
 {
     if (string.IsNullOrEmpty(instructionPart))
     {
         return(InstructionType.STARTUP);
     }
     if (AInstruction.SYMBOL_CONST == instructionPart[0])
     {
         return(InstructionType.CONST);
     }
     return(AInstruction.GetType(instructionPart));
 }
Exemplo n.º 4
0
        public void Decode(object sender, AInstruction instruction)
        {
            switch (instruction)
            {
            case AInstruction.INST:
                break;

            case AInstruction.MOV:
                break;

            case AInstruction.CMP:
                break;

            case AInstruction.STR:
                break;

            case AInstruction.STR12:
                break;

            case AInstruction.LOAD:
                break;

            case AInstruction.LOAD12:
                break;

            case AInstruction.SLT:
                break;

            case AInstruction.SRT:
                break;

            case AInstruction.GET:
                break;

            case AInstruction.PUT:
                break;

            case AInstruction.BREAK:
                break;

            case AInstruction.HALT:
                break;

            case AInstruction.JMP:
                break;

            case AInstruction.JMPL:
                break;

            case AInstruction.JMPX:
                break;

            case AInstruction.JE:
                break;

            case AInstruction.JNE:
                break;

            case AInstruction.JB:
                break;

            case AInstruction.JBE:
                break;

            case AInstruction.JA:
                break;

            case AInstruction.JAE:
                break;

            case AInstruction.ADD:
                break;

            case AInstruction.SUB:
                break;

            case AInstruction.MAX:
                break;

            case AInstruction.MIN:
                break;

            case AInstruction.MXNOT:
                break;

            case AInstruction.MNNOT:
                break;
            }
        }
Exemplo n.º 5
0
 public void GetTypeTest(string instruction, InstructionType excepted)
 {
     Assert.AreEqual(excepted, AInstruction.GetType(instruction));
 }
Exemplo n.º 6
0
        /// <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();
        }
Exemplo n.º 7
0
        public void AInstruction_InstantiateWithValidAddress_BinaryInstructionIsCorrect()
        {
            AInstruction aInstruction = new AInstruction("4578");

            Assert.AreEqual("0001000111100010", aInstruction.GetInstructionAsMachineCode());
        }