public MainWindow() { int delay = 500; bool boolRunningFromHome = false; var window = new Window() //make sure the window is invisible { Width = 0, Height = 0, Left = -2000, WindowStyle = WindowStyle.None, ShowInTaskbar = false, ShowActivated = false, }; // Create a timer and set a two millisecond interval. aTimer.Interval = 2; // Alternate method: create a Timer with an interval argument to the constructor. //aTimer = new System.Timers.Timer(2000); // Create a timer with a two millisecond interval. aTimer = new System.Timers.Timer(2); // Hook up the Elapsed event for the timer. aTimer.Elapsed += OnTimedEvent; // Have the timer fire repeated events (true is the default) aTimer.AutoReset = true; // Start the timer aTimer.Enabled = true; spaceBarPressed = false; window.Show(); myActions.ScriptStartedUpdateStats(); InitializeComponent(); this.Hide(); string strWindowTitle = myActions.PutWindowTitleInEntity(); if (strWindowTitle.StartsWith("ExecuteWithBreakpointTrace")) { myActions.TypeText("%(\" \"n)", 1000); // minimize visual studio } myListControlEntity = new List <ControlEntity>(); myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Heading; myControlEntity.ID = "lbl"; myControlEntity.Text = "ExecuteWithBreakpointTrace"; myControlEntity.RowNumber = intRowCtr; myControlEntity.ColumnNumber = 0; myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Label; myControlEntity.ID = "lbl"; myControlEntity.Text = "" + "1. Click on visual studio to debug \r\n"; myControlEntity.ToolTipx = ""; myControlEntity.RowNumber = intRowCtr; myControlEntity.Width = 272; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 0; myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Label; myControlEntity.ID = "lbl"; myControlEntity.Text = "" + "2. Close this window to start debugging \r\n"; myControlEntity.ToolTipx = ""; myControlEntity.RowNumber = intRowCtr; myControlEntity.Width = 312; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 0; myListControlEntity.Add(myControlEntity.CreateControlEntity()); intRowCtr++; myControlEntity.ControlEntitySetDefaults(); myControlEntity.ControlType = ControlType.Label; myControlEntity.ID = "lbl"; myControlEntity.Text = "" + "3. PRESS Ctrl-Space to stop debugger \r\n"; myControlEntity.ToolTipx = ""; myControlEntity.RowNumber = intRowCtr; myControlEntity.Width = 312; myControlEntity.ColumnNumber = 0; myControlEntity.ColumnSpan = 0; myListControlEntity.Add(myControlEntity.CreateControlEntity()); strButtonPressed = myActions.WindowMultipleControls(ref myListControlEntity, 300, 624, 0, 0); if (strButtonPressed == "btnCancel") { myActions.MessageBoxShow("Okay button not pressed - Script Cancelled"); goto myExit; } // TODO: In IdealAutomateCore, create another PutAll override that does not ask if you want an alternative image when it cannot find image string firstLine = ""; string currentLine = ""; string currentLineNumber = ""; string firstFileName = ""; string currFileName = ""; string firstLineNumber = ""; myActions.TypeText("{F11}", 1000); // compile program and go to first breakpoint int intCtr = 0; TryToFindYellowArrow: intCtr++; ImageEntity myImage = new ImageEntity(); if (boolRunningFromHome) { myImage.ImageFile = "Images\\imgYellowArrow.PNG"; } else { myImage.ImageFile = "Images\\imgYellowArrow.PNG"; } myImage.Sleep = 200; myImage.Attempts = 1; myImage.RelativeX = 10; myImage.RelativeY = 10; myImage.Tolerance = 60; int[,] myArray = myActions.PutAll(myImage); if (myArray.Length == 0 && intCtr < 50) { goto TryToFindYellowArrow; } if (myArray.Length == 0) { myActions.MessageBoxShow("I could not find image of YellowArrow"); } else { // myActions.MessageBoxShow("Found Yellow Arrow"); } myActions.TypeText("^(c)", delay); currentLine = myActions.PutClipboardInEntity(); firstLine = currentLine; LineOfCode myLine = new LineOfCode(); myLine.TextOfCode = currentLine; // get line number myActions.TypeText("^(g)", delay); myActions.TypeText("^(a)", delay); myActions.TypeText("^(c)", delay); currentLineNumber = myActions.PutClipboardInEntity(); firstLineNumber = currentLineNumber; myLine.LineNumber = currentLineNumber; myActions.TypeText("{ESCAPE}", delay); // get filename myActions.TypeText("%(f)", delay); myActions.TypeText("a", delay); myActions.TypeText("^(c)", delay); currFileName = myActions.PutClipboardInEntity(); myLine.FileName = currFileName; firstFileName = currFileName; myActions.TypeText("{ESCAPE}", delay); // add the line to list listExecutedCode.Add(myLine); LineOfCode prevLine = myLine; GetNextLine: if (spaceBarPressed) { goto EndOfExecution; } // get next line myActions.TypeText("{F11}", delay); // next breakpoint myActions.TypeText("^(c)", delay); currentLine = myActions.PutClipboardInEntity(); myLine = new LineOfCode(); myLine.TextOfCode = currentLine; // get line number myActions.TypeText("^(g)", delay); myActions.TypeText("^(a)", delay); myActions.TypeText("^(c)", delay); currentLineNumber = myActions.PutClipboardInEntity(); firstLineNumber = currentLineNumber; myLine.LineNumber = currentLineNumber; myActions.TypeText("{ESCAPE}", delay); // get filename myActions.TypeText("%(f)", delay); myActions.TypeText("a", delay); myActions.TypeText("^(c)", delay); currFileName = myActions.PutClipboardInEntity(); myLine.FileName = currFileName; firstFileName = currFileName; myActions.TypeText("{ESCAPE}", delay); // add the line to list listExecutedCode.Add(myLine); if (myLine != prevLine) { prevLine = myLine; goto GetNextLine; } EndOfExecution: myActions.MessageBoxShow("Successfully Reached End of Execution"); string strOutFile = @"C:\Data\ExecutedCode.txt"; if (File.Exists(strOutFile)) { File.Delete(strOutFile); } using (System.IO.StreamWriter file = new System.IO.StreamWriter(strOutFile)) { // Write list to text file so I can look at it foreach (LineOfCode item in listExecutedCode) { file.WriteLine(item.FileName + " " + item.LineNumber + " " + item.TextOfCode); } } string strExecutable = @"C:\Windows\system32\notepad.exe"; myActions.RunSync(strExecutable, strOutFile); // We found output completed and now want to copy the results // to notepad myExit: aTimer.Enabled = false; aTimer.Stop(); aTimer.Close(); myActions.Sleep(1000); myActions.ScriptEndedSuccessfullyUpdateStats(); Application.Current.Shutdown(); }
private void OpenLineInNotepad() { myActions.TypeText("{RIGHT}", 500); myActions.TypeText("{HOME}", 500); myActions.TypeText("+({END})", 500); myActions.TypeText("^(c)", 500); myActions.Sleep(500); string strCurrentLine = ""; RunAsSTAThread( () => { strCurrentLine = myActions.PutClipboardInEntity(); }); List <string> myBeginDelim = new List <string>(); List <string> myEndDelim = new List <string>(); myBeginDelim.Add("\""); myEndDelim.Add("\""); FindDelimitedTextParms delimParms = new FindDelimitedTextParms(myBeginDelim, myEndDelim); string myQuote = "\""; delimParms.lines[0] = strCurrentLine; myActions.FindDelimitedText(delimParms); int intLastSlash = delimParms.strDelimitedTextFound.LastIndexOf('\\'); if (intLastSlash < 1) { myActions.MessageBoxShow("Could not find last slash in in EditPlusLine - aborting"); return; } string strPathOnly = delimParms.strDelimitedTextFound.SubstringBetweenIndexes(0, intLastSlash); string strFileNameOnly = delimParms.strDelimitedTextFound.Substring(intLastSlash + 1); string strFullFileName = delimParms.strDelimitedTextFound; myBeginDelim.Clear(); myEndDelim.Clear(); myBeginDelim.Add("("); myEndDelim.Add(","); delimParms = new FindDelimitedTextParms(myBeginDelim, myEndDelim); delimParms.lines[0] = strCurrentLine; myActions.FindDelimitedText(delimParms); string strLineNumber = delimParms.strDelimitedTextFound; string strExecutable = @"C:\Program Files (x86)\Notepad++\notepad++.exe"; string strContent = strFullFileName; Process.Start(strExecutable, string.Concat("", strContent, "")); myActions.TypeText("^(g)", 2000); myActions.TypeText(strLineNumber, 500); myActions.TypeText("{ENTER}", 500); myActions.TypeText("^(f)", 500); string strFindWhatToUse = strFindWhat; string blockText = strFindWhatToUse; strFindWhatToUse = ""; char[] specialChars = { '{', '}', '(', ')', '+', '^' }; foreach (char letter in blockText) { bool _specialCharFound = false; for (int i = 0; i < specialChars.Length; i++) { if (letter == specialChars[i]) { _specialCharFound = true; break; } } if (_specialCharFound) { strFindWhatToUse += "{" + letter.ToString() + "}"; } else { strFindWhatToUse += letter.ToString(); } } myActions.TypeText(strFindWhatToUse, 500); myActions.TypeText("{ENTER}", 500); myActions.TypeText("{ESC}", 500); boolStopEvent = false; }