public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent) { do { int hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 5); if (hWnd == 0) { // If the main window did not become active check for a system info windows hWnd = Automate.WinWait("#32770", "System", Automate.WinMatchMode.Any, 3); if (hWnd != 0) { // System info window found, click on the button to close it int hSystemInfoButton = Automate.ControlGetHandle(hWnd, "Button", ""); if (hSystemInfoButton != 0) { Thread.Sleep(500); Automate.ControlClick(hSystemInfoButton); } else { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("System info button not found"); break; } } else { // System info window not found either, end process WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Main form not found"); break; } } Thread.Sleep(200); WinApi.SetForegroundWindow(hWnd); Thread.Sleep(500); automate.Send("^{BREAK}"); } while (false); }
public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent) { do { int hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 5); if (hWnd == 0) { break; } int hControlUtilities = Automate.ControlGetHandle(hWnd, "KCMLButton_32", "Utilities..."); if (hControlUtilities == 0) { Thread.Sleep(300); automate.Send("%(u)"); int hControlList = Automate.ControlGetHandle(hWnd, "ListBox_Class", ""); if (hControlList == 0) { break; } Thread.Sleep(200); automate.Send("c"); //Automate.SendChar(hControlList, 'c'); Thread.Sleep(200); int hControlOk = Automate.ControlGetHandle(hWnd, "KCMLButton_32", "OK"); if (hControlOk == 0) { break; } Thread.Sleep(200); Automate.ControlClick(hControlOk); } else { Automate.ControlClick(hControlUtilities); Thread.Sleep(200); int hWndUtilities = Automate.WinWait("KCMLMasterForm_32", "Select Item", Automate.WinMatchMode.Start, 5); if (hWndUtilities == 0) { break; } int hControlList = Automate.ControlGetHandle(hWndUtilities, "ListBox_Class", ""); if (hControlList == 0) { break; } Thread.Sleep(200); automate.Send("c"); //Automate.SendChar(hControlList, 'c'); Thread.Sleep(200); int hControlOk = Automate.ControlGetHandle(hWndUtilities, "KCMLButton_32", "OK"); if (hControlOk == 0) { break; } Thread.Sleep(200); Automate.ControlClick(hControlOk); } } while (false); }
public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent) { string password; do { // Open the password form PasswordForm pf = new PasswordForm(); pf.StartPosition = FormStartPosition.CenterParent; if (pf.ShowDialog() == DialogResult.OK) { password = pf.textBoxPassword.Text; } else { break; } // Wait for main window to become active int hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 3); if (hWnd == 0) { // If the main window did not become active check for a system info windows hWnd = Automate.WinWait("#32770", "System", Automate.WinMatchMode.Any, 3); if (hWnd != 0) { // System info window found, click on the button to close it int hSystemInfoButton = Automate.ControlGetHandle(hWnd, "Button", ""); if (hSystemInfoButton != 0) { automate.MediumDelay(); Automate.ControlClick(hSystemInfoButton); } else { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("System info button not found"); break; } } else { // System info window not found either, end process WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Main form not found"); break; } } WinApi.SetForegroundWindow(hWnd); automate.MediumDelay(); // At this point the Autoline library form should be displayed and we need to select "Kerridge mode" to break into code // Get the handle of the Kerridge mode button int hKerridgeModeButton = Automate.ControlGetHandle(hWnd, "KCMLButton_32", 5); if (hKerridgeModeButton == 0) { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Kerridge mode button not found"); break; } automate.ShortDelay(); Automate.ControlClick(hKerridgeModeButton); // Enter the daily password got from the password form int hPasswordCtrl = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 1); if (hPasswordCtrl == 0) { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Password control not found"); break; } automate.ShortDelay(); automate.Send(password + "{ENTER}"); automate.MediumDelay(); automate.Send("{TAB}"); automate.MediumDelay(); automate.Send("CLEARP{ENTER}"); automate.MediumDelay(); automate.Send("LOAD \"GB/MKMOD\"{ENTER}"); // This if for loading the make modules program automate.MediumDelay(); automate.Send("TRAP 'ExecuteScript{ENTER}"); // This is to stop the execution right after the module build sript has been created and before it's executed automate.MediumDelay(); automate.Send("RUN{ENTER}"); automate.LongDelay(); // At this point the Make Modules form will be displayed, now we need to press the Build button // Wait for the next form hWnd = Automate.WinWait("KCMLMasterForm_32", "", Automate.WinMatchMode.Start, 5); if (hWnd == 0) { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Build modules form not found"); break; } // Click on the button to build int hCtrlBuild = Automate.ControlGetHandle(hWnd, "KCMLButton_32", 2); if (hCtrlBuild == 0) { WinApi.SetForegroundWindow(hWndMain); MessageBox.Show("Build button not found"); break; } automate.MediumDelay(); Automate.ControlClick(hCtrlBuild); // The build modules process will start, now we need to wait for it to reach the trap // as this process can take very variable amounts of time to complete it requires it's own delay time automate.CustomDelay(); automate.Send("{TAB}"); automate.MediumDelay(); // Capture the module build script name by writing it into a known file name that we can get through FTP automate.Send( Automate.ConvertKeys("stream = OPEN $PRINTF(\"%s/%s\", ENV(\"WORKSPACE\"), \"ScriptFileName.txt\"), \"w\"") + "{ENTER}"); automate.Send( Automate.ConvertKeys("pointer = WRITE #stream, ScriptName$") + "{ENTER}"); // Get the file through FTP // Get the object used to communicate with the server. FtpWebRequest requestFile = (FtpWebRequest)WebRequest.Create( //"ftp://" + connection.Host + "/%2f" + connection.Home.Substring(1).Replace("home", "work") + "/ScriptFileName.txt"); "ftp://" + connection.Host + "/%2f" + ReplaceLastOccurrence(connection.Home.Substring(1), "home", "work") + "/ScriptFileName.txt"); requestFile.Method = WebRequestMethods.Ftp.DownloadFile; // This example assumes the FTP site uses anonymous logon. requestFile.Credentials = new NetworkCredential(connection.User, connection.Password); FtpWebResponse responseFile = (FtpWebResponse)requestFile.GetResponse(); // Get the file from the response Stream responseStreamFile = responseFile.GetResponseStream(); StreamReader readerFile = new StreamReader(responseStreamFile); string line = readerFile.ReadLine(); if (line != null) { string test = line.Substring(1); StringCollection result2 = new StringCollection(); FtpWebRequest requestFile2 = (FtpWebRequest)WebRequest.Create("ftp://" + connection.Host + "/%2f" + line.Substring(1)); requestFile2.Method = WebRequestMethods.Ftp.DownloadFile; // This example assumes the FTP site uses anonymous logon. requestFile2.Credentials = new NetworkCredential(connection.User, connection.Password); FtpWebResponse responseFile2 = (FtpWebResponse)requestFile2.GetResponse(); Stream responseStreamFile2 = responseFile2.GetResponseStream(); StreamReader readerFile2 = new StreamReader(responseStreamFile2); line = readerFile2.ReadLine(); while (line != null) { result2.Add(line); line = readerFile2.ReadLine(); } readerFile2.Close(); int firstIndex = result2.IndexOf("CLEAR P"); int lastIndex = 0; foreach (string s in result2) { if (s.Contains("SAVE <G>")) { lastIndex = result2.IndexOf(s); } } for (int index = firstIndex; index <= lastIndex; index++) { string lineCommand = result2[index]; // We now have each command ready to send to the console automate.Send(lineCommand + "{ENTER}"); automate.LongDelay(); } } readerFile.Close(); } while (false); }