Пример #1
0
 internal void SetEditorCommands(List <TextEditorCommand> editorCommands)
 {
     currentCommand      = null;
     this.editorCommands = editorCommands;
     ComposeBackgroundVisual();
     ComposeForegroundVisual();
 }
        public void TestMethodName()
        {
            TextEditorCommand textEditorCommand1 = null;

            textEditorCommand1 = new TextEditorCommand(TextEditorCommand.Method.Run);

            Assert.AreEqual(TextEditorCommand.Method.Run, textEditorCommand1.MethodName);
        }
Пример #3
0
        private void OnDispatchTimerTick(object sender, EventArgs e)
        {
            if (streamReader == null)
            {
                // All files are done
                if (madTypingCurrentFile == fileList.Length)
                {
                    dispatchTimer.Stop();
                    textEditorCore.EnableRegularCommands = true;
                    return;
                }
                else
                {
                    // Get next file
                    string testFile = fileList.ElementAt(madTypingCurrentFile++);
                    streamReader = new StreamReader(testFile);
                    // Create new script
                    command = new TextEditorCommand(TextEditorCommand.Method.CreateNewScript);
                    textEditorCore.PlaybackCommand(command);
                    // Activate script
                    textEditorControl.SetupTabInternal(null);
                    command = new TextEditorCommand(TextEditorCommand.Method.ChangeScript);
                    command.AppendArgument(0);
                    textEditorCore.PlaybackCommand(command);
                    textEditorControl.HandleScriptActivation();
                    textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
                    textEditorControl.UpdateCaretPosition();
                }
            }

            if (streamReader.Peek() >= 0)
            {
                // Insert characters
                command = new TextEditorCommand(TextEditorCommand.Method.InsertText);
                command.AppendArgument((char)streamReader.Read());
                textEditorCore.PlaybackCommand(command);
            }
            else
            {
                // Close script
                command = new TextEditorCommand(TextEditorCommand.Method.CloseScript);
                command.AppendArgument(0);
                textEditorCore.PlaybackCommand(command);
                textEditorControl.PlaybackCloseTab(0);
                command = new TextEditorCommand(TextEditorCommand.Method.ChangeScript);
                command.AppendArgument(0);
                textEditorCore.PlaybackCommand(command);
                textEditorControl.HandleScriptActivation();
                streamReader = null;
            }

            textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
            textEditorControl.UpdateCaretPosition();
            random = new Random();
            dispatchTimer.Interval = TimeSpan.FromMilliseconds(random.Next(minTime, maxTime));
        }
Пример #4
0
        private bool IsRepeatable(TextEditorCommand command)
        {
            switch (command.MethodName)
            {
            case TextEditorCommand.Method.SetMouseMovePosition:
                return(true);
            }

            return(false);
        }
        internal void HandleScriptActivation()
        {
            //Check if its in playback mode, as it should be treated differently due to blocking
            if (player == null)
            {
                if (textCore.ChangeScript(ScriptTabControl.CurrentTab))
                {
                    CheckTabControlVisibility(false);
                }
                else
                {
                    return;
                }
            }
            else
            {
                CheckTabControlVisibility(false);
                TextEditorCommand command = new TextEditorCommand(TextEditorCommand.Method.ChangeScript);
                command.AppendArgument(ScriptTabControl.CurrentTab);
                textCore.PlaybackCommand(command);
            }

            // Resize canvas to fit the next script.
            //if (numSlider != null)
            //    numSlider.Visibility = Visibility.Collapsed;
            UpdateCanvasDimension();

            IExecutionSession session = Solution.Current.ExecutionSession;

            UpdateScriptDisplay(Solution.Current.ActiveScript);
            UpdateCaretPosition(false);
            textCanvas.BreakpointsUpdated();

            if (null != session)
            {
                CodeRange executionCursor = new CodeRange();
                if (session.GetExecutionCursor(ref executionCursor))
                {
                    textCanvas.SetExecutionCursor(executionCursor);
                }
            }

            if (null != textEditorControl.textCore.CurrentTextBuffer)
            {
                textCanvas.ScrollOwner.ScrollToVerticalOffset(
                    textEditorControl.textCore.VerticalScrollPosition);
            }
        }
Пример #6
0
        public void Record(TextEditorCommand newCommand)
        {
            if (null == outputXmlFile)
            {
                CreateNewRecordSession();
            }

            bool recordPreviousCommand = false;

            if (null != previousCommand) // If there was a previous command...
            {
                // If we have associated any assertions to the previous
                // command, then we need to persist that information.
                if (null != previousCommand.Asserts)
                {
                    recordPreviousCommand = true;
                }
                else if (newCommand.MethodName != previousCommand.MethodName)
                {
                    recordPreviousCommand = true;
                }
                else
                {
                    // Same command, but not repeatable.
                    if (IsRepeatable(previousCommand) == false)
                    {
                        recordPreviousCommand = true;
                    }
                }
            }

            if (false != recordPreviousCommand)
            {
                SerializeCommand(previousCommand);
            }

            previousCommand = newCommand;
            if (newCommand.MethodName == TextEditorCommand.Method.CloseScript)
            {
                if (Solution.Current.ScriptCount == 1) // Closing the final script.
                {
                    SerializeCommand(newCommand);
                    previousCommand = null;
                    FinalizeRecordSession();
                }
            }
        }
Пример #7
0
        private void MadTypistBeingMad()
        {
            textEditorCore.EnableRegularCommands = false;
            // Close the default script that is open
            command = new TextEditorCommand(TextEditorCommand.Method.CloseScript);
            command.AppendArgument(0);
            textEditorCore.PlaybackCommand(command);
            textEditorControl.PlaybackCloseTab(0);
            command = new TextEditorCommand(TextEditorCommand.Method.ChangeScript);
            command.AppendArgument(0);
            textEditorCore.PlaybackCommand(command);
            textEditorControl.HandleScriptActivation();
            dispatchTimer       = new DispatcherTimer();
            dispatchTimer.Tick += new EventHandler(OnDispatchTimerTick);

            fileList = Directory.GetFiles(filePath,
                                          "*.ds", SearchOption.AllDirectories);
            dispatchTimer.Start();
        }
Пример #8
0
        private void SerializeCommand(TextEditorCommand command)
        {
            if (null == command)
            {
                return;
            }

            command.IntervalTime  = CommandTimer();        // Update command time.
            command.CommandNumber = currentCommandIndex++; // Assign a unique index.

            StringWriter writer = new StringWriter();

            commandSerializer.Serialize(writer, command);
            writer.Close();

            string serializedContent = writer.ToString();
            int    begin             = serializedContent.IndexOf(" CommandNumber");
            string processed         = "\n<TextEditorCommand" + serializedContent.Substring(begin);

            Logger.LogInfo("RecorderXML-SC", processed);
            AccumulatedLog.Append(processed);
            xmlStreamWriter.Write(processed);
            xmlStreamWriter.Flush();
        }
Пример #9
0
 internal void SetBaseState()
 {
     SerializeCommand(previousCommand);
     previousCommand = null;
     FinalizeRecordSession();
 }
Пример #10
0
 internal void SetCurrentCommand(TextEditorCommand command)
 {
     PlaybackProgress.Text = string.Format("Current command: {0} ({1})",
                                           command.MethodName.ToString(), command.CommandNumber.ToString());
     checkerboard.SetCurrentCommand(command);
 }
Пример #11
0
        internal string ToolTipTextFromPoint(System.Windows.Point cursor)
        {
            int x     = (int)Math.Floor(cursor.X / (dimension + margin));
            int y     = (int)Math.Floor(cursor.Y / (dimension + margin));
            int index = (y * boxesPerRow) + x;

            if (null == commandIndices || (index == mouseOverIndex))
            {
                return(string.Empty); // No change, skip all processing!
            }
            mouseOverIndex = index;
            if (index < 0 || (index >= commandIndices.Count))
            {
                return(null); // If there's a tool-tip, hide it.
            }
            // If a command has the associated assertions, then they will all
            // show up right after the command itself. For an example:
            //
            //   [3][4][5][5][5][5][6][7]...
            //
            // If the mouse hovers over the 3rd '5' for example, 'index' would
            // have been '4'. Here we need to back trace to the first '5',
            // which would have at position '2'. In such case, 'startIndex'
            // will point to '2' and the 'index' will be '5'.
            //
            int startIndex = index;

            while (startIndex > 0)
            {
                if (commandIndices[startIndex - 1] != commandIndices[index])
                {
                    break;
                }
                startIndex = startIndex - 1;
            }

            int globalIndex = commandIndices[index];

            if (globalIndex < 0 || (globalIndex >= editorCommands.Count))
            {
                return(null); // If there's a tool-tip, hide it.
            }
            string toolTipText = string.Empty;

            if (startIndex == index) // This is a command node.
            {
                TextEditorCommand command   = editorCommands[globalIndex];
                string            arguments = string.Empty;

                int currentArgument = 1;
                if (null != command.Arguments)
                {
                    foreach (object obj in command.Arguments)
                    {
                        arguments += string.Format("Argument {0}: {1}\n",
                                                   currentArgument++, obj.ToString());
                    }
                }

                toolTipText = string.Format("Command index: {0}\nCommand name: {1}\n{2}",
                                            command.CommandNumber, command.MethodName.ToString(), arguments);
            }
            else // This appears to be an assert node.
            {
                int assertIndex           = index - startIndex - 1;
                TextEditorCommand command = editorCommands[globalIndex];

                List <CommandAssert> asserts = command.Asserts;
                if (assertIndex < 0 || (assertIndex >= asserts.Count)) // Invalid index?!
                {
                    toolTipText = string.Format("Houston, we have a problem! " +
                                                "The index of assertion '{0}' for command '{1}' is invalid!",
                                                assertIndex, command.CommandNumber);
                }
                else
                {
                    CommandAssert assertion = asserts[assertIndex];
                    toolTipText = string.Format("Assert property: {0} ({1})\n" +
                                                "Status: {2}\nExpected value: {3}", assertion.PropertyName,
                                                assertion.AssertNumber, assertion.Passed ? "Passed" : "Failed",
                                                assertion.PropertyValue);
                }
            }

            return(toolTipText);
        }
Пример #12
0
 internal void SetCurrentCommand(TextEditorCommand command)
 {
     currentCommand = command;
     ComposeBackgroundVisual();
 }
Пример #13
0
        private void OnDispatchTimer()
        {
            using (BinaryReader binaryReader = new BinaryReader(File.Open(currentFilePath, FileMode.Open)))
            {
                int pos          = 0;
                int streamLength = (int)binaryReader.BaseStream.Length;

                while (pos < streamLength)
                {
                    Action.ActionType actionType = (Action.ActionType)binaryReader.ReadInt32();
                    int    actionLength          = binaryReader.ReadInt32();
                    byte[] actionData            = binaryReader.ReadBytes(actionLength);
                    int    lengthOfOneAction     = sizeof(Action.ActionType) + sizeof(int) + actionLength;

                    switch (actionType)
                    {
                    case Action.ActionType.OpenFile:
                        string filePath = Encoding.UTF8.GetString(actionData);
                        command = new TextEditorCommand(TextEditorCommand.Method.LoadScriptFromFile);
                        command.AppendArgument(filePath);
                        textEditorCore.PlaybackCommand(command);
                        textEditorControl.SetupTabInternal(filePath);
                        break;

                    case Action.ActionType.InsertKeyword:
                        string keyword = Encoding.UTF8.GetString(actionData);
                        command = new TextEditorCommand(TextEditorCommand.Method.InsertText);
                        command.AppendArgument(keyword);
                        textEditorCore.PlaybackCommand(command);
                        break;

                    case Action.ActionType.InsertSymbol:
                        char symbol = BitConverter.ToChar(actionData, 0);
                        command = new TextEditorCommand(TextEditorCommand.Method.InsertText);
                        command.AppendArgument(symbol);
                        textEditorCore.PlaybackCommand(command);
                        break;

                    case Action.ActionType.InsertUnicode:
                        string unicodeChar = Encoding.UTF8.GetString(actionData);
                        command = new TextEditorCommand(TextEditorCommand.Method.InsertText);
                        command.AppendArgument(unicodeChar);
                        textEditorCore.PlaybackCommand(command);
                        break;

                    case Action.ActionType.Navigate:
                        Key navigationKey = (Key)BitConverter.ToInt32(actionData, 0);
                        command = new TextEditorCommand(TextEditorCommand.Method.DoNavigation);
                        command.AppendArgument(navigationKey);
                        textEditorCore.PlaybackCommand(command);
                        break;

                    case Action.ActionType.Delete:
                        Key deletionKey = (Key)BitConverter.ToInt32(actionData, 0);
                        command = new TextEditorCommand(TextEditorCommand.Method.DoControlCharacter);
                        command.AppendArgument(deletionKey);
                        textEditorCore.PlaybackCommand(command);
                        break;
                    }

                    pos += lengthOfOneAction;
                }

                textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
                textEditorControl.UpdateCaretPosition();
            }
        }
Пример #14
0
        private bool PlaybackSingleCommand()
        {
            if (null == assertions)
            {
                assertions = new List <AssertionResult>();
            }

            commandIndex = commandIndex + 1;
            if (commandIndex >= editorCommands.Count)
            {
                if (xmlTestFiles.Count > 1) // Multi-playback mode.
                {
                    if (null == testResults)
                    {
                        testResults = new List <AutomationResult>();
                    }

                    testResults.Add(new AutomationResult(currentTestName, assertions));
                }

                playbackComplete = true;
                assertions       = null;
                return(false); // Done playing back.
            }

            TextEditorCommand command = editorCommands[commandIndex];
            int commandInterval       = (int)command.IntervalTime;

            commandInterval        = ((commandInterval > 220) ? 220 : commandInterval);
            playbackTimer.Interval = TimeSpan.FromMilliseconds(commandInterval);
            bool result = textEditorCore.PlaybackCommand(command);

            PlaybackVisualizer.Instance.SetCurrentCommand(command);

            switch (command.MethodName)
            {
            case TextEditorCommand.Method.LoadScriptFromFile:
                if (!result)
                {
                    assertions = new List <AssertionResult>();
                    assertions.Add(new AssertionResult("Fail", "0", "Invalid path! Cannot load script!"));
                    if (null == testResults)
                    {
                        testResults = new List <AutomationResult>();
                    }
                    testResults.Add(new AutomationResult(currentTestName, assertions));
                    playbackComplete = true;
                    assertions       = null;
                    TextEditorCommand closeScriptCommand = new TextEditorCommand(TextEditorCommand.Method.CloseScript);
                    closeScriptCommand.AppendArgument(0);
                    int  scriptCount       = textEditorControl.ScriptTabControl.TabCount;
                    bool closeScriptResult = textEditorCore.PlaybackCommand(closeScriptCommand);
                    while (--scriptCount != 0)
                    {
                        closeScriptResult = textEditorCore.PlaybackCommand(closeScriptCommand);
                    }
                    textEditorControl.ScriptTabControl.CloseAllTabs();
                    textEditorControl.ShowTabControls(false);

                    return(false);    // Exit playback.
                }
                textEditorControl.SetupTabInternal(command.Arguments[0] as string);
                break;

            case TextEditorCommand.Method.CreateNewScript:
                textEditorControl.SetupTabInternal(null);
                break;

            case TextEditorCommand.Method.CloseScript:
                textEditorControl.PlaybackCloseTab((int)command.Arguments[0]);
                break;

            case TextEditorCommand.Method.ChangeScript:
                textEditorControl.PlaybackSwitchTab((int)command.Arguments[0]);
                break;

            case TextEditorCommand.Method.Step:
                textEditorControl.UpdateUiForStepNext(result);
                break;

            case TextEditorCommand.Method.Run:
                textEditorControl.UpdateUiForRun(result);
                break;

            case TextEditorCommand.Method.Stop:
                textEditorControl.UpdateUiForStop(result);
                break;
            }

            textEditorControl.UpdateScriptDisplay(Solution.Current.ActiveScript);
            textEditorControl.UpdateCaretPosition();

            if (null != command.Asserts)
            {
                DoAssertions(command.Asserts);
            }

            return(true);
        }
 public void Setup()
 {
     textEditorCommand = new TextEditorCommand();
 }