コード例 #1
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));
        }
コード例 #2
0
        private void OnRecentFileClick(object sender, MouseButtonEventArgs e)
        {
            string            filePath          = null;
            TextEditorControl textEditorControl = TextEditorControl.Instance;

            if (null != lstRecentFiles.SelectedItem)
            {
                filePath = ((RecentFile)lstRecentFiles.SelectedItem).FilePath;
            }

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            if (!System.IO.File.Exists(filePath))
            {
                // @TODO(Ananya): Ask if the user wants to remove the file from list.
                string           message          = string.Format("File '{0}' cannot be found! Do you want to remove the file from the Recent file list", filePath);
                MessageBoxResult messageBoxResult = MessageBox.Show(message, " ", MessageBoxButton.YesNo);
                if (messageBoxResult.Equals(MessageBoxResult.Yes))
                {
                    textEditorControl.TextCore.Data.RemoveFromRecentFileList(((RecentFile)lstRecentFiles.SelectedItem).FilePath);
                }

                recentFileList.Clear();
                recentFileList.AddRange(textEditorControl.TextCore.Data.RecentFiles);
                recentFileList.Reverse();

                lstRecentFiles.Items.Refresh();

                return;
            }

            if (textEditorControl.TextCore.LoadScriptFromFile(filePath))
            {
                textEditorControl.SetupTabInternal(filePath);
            }
            else
            {
                int index = Solution.Current.GetScriptIndexFromPath(filePath);
                if (index >= 0)
                {
                    textEditorControl.ScriptTabControl.ActivateTab(index);
                }
                else
                {
                    MessageBox.Show(Configurations.UnsupportedFileType);
                    return;
                }
            }

            textEditorControl.HandleScriptActivation();
            textEditorControl.grid.UpdateLayout();
            CommandManager.InvalidateRequerySuggested();
            textEditorControl.textCanvas.Focus();
        }
コード例 #3
0
        private void OnSampleFileClick(object sender, MouseButtonEventArgs e)
        {
            string            filePath          = null;
            TextEditorControl textEditorControl = TextEditorControl.Instance;

            if (null != InternalTreeView.SelectedItem)
            {
                filePath = ((SampleFileProperty)InternalTreeView.SelectedItem).FilePath;
            }

            if (string.IsNullOrEmpty(filePath) || !filePath.Contains(".ds"))
            {
                return;
            }

            if (!System.IO.File.Exists(filePath))
            {
                MessageBox.Show(string.Format("File '{0}' cannot be found!", filePath));
                return;
            }

            // @TODO(Ben): PRIORITY: Consolidate all these.
            if (textEditorControl.TextCore.LoadScriptFromFile(filePath))
            {
                textEditorControl.SetupTabInternal(filePath);
            }
            else
            {
                int index = Solution.Current.GetScriptIndexFromPath(filePath);
                if (index < 0)
                {
                    return;
                }

                textEditorControl.ScriptTabControl.ActivateTab(index);
            }

            textEditorControl.HandleScriptActivation();
            textEditorControl.grid.UpdateLayout();
            CommandManager.InvalidateRequerySuggested();
            textEditorControl.textCanvas.Focus();
        }
コード例 #4
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);
        }