Пример #1
0
        public void Run(int hWndMain, Automate automate, KConnection connection, KConnection destination, Form parent)
        {
            do
            {
                int hWnd = Automate.WinWait("KCMLMasterForm_32", "Enter host details", Automate.WinMatchMode.Start, 5);
                int ret;

                if (hWnd == 0)
                {
                    break;
                }

                uint procID     = WinApi.GetWindowThreadProcessId(hWnd, 0);
                uint currThread = WinApi.GetCurrentThreadId();
                bool lret       = WinApi.AttachThreadInput(currThread, procID, true);

                WinApi.SetForegroundWindow(hWnd);
                ret = Automate.SetFocus(hWnd);

                int hCtrlHost = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 1);
                ret = Automate.SetFocus(hCtrlHost);

                Automate.SendString(hCtrlHost, destination.Host);
                Thread.Sleep(500);

                int hCtrlUserID = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 2);
                ret = Automate.SetFocus(hCtrlUserID);

                Automate.SendString(hCtrlUserID, destination.User);
                Thread.Sleep(500);

                int hCtrlPassword = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 3);
                ret = Automate.SetFocus(hCtrlPassword);

                Automate.SendString(hCtrlPassword, destination.Password);
                Thread.Sleep(500);

                int hCtrlHome = Automate.ControlGetHandle(hWnd, "KCMLEdit32", 4);
                ret = Automate.SetFocus(hCtrlHome);

                Automate.SendString(hCtrlHome, destination.Home);
                Thread.Sleep(500);
            } while (false);
        }
Пример #2
0
        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()
 {
     try
     {
         m_oListener.Start();
         //.Listen(config.Default.CONNECTION_QUEUE_SIZE);
         //CDevices.Initialize();
         //CMClients.Initialize();
         while (m_bRun)
         {
             LogFile.writeLog(LOG_OPTIONS.INFO, "Waiting for client connection...");
             TcpClient oClientSocket = m_oListener.AcceptTcpClient();
             //Socket oSocket = m_oListener.Accept();
             LogFile.writeLog(LOG_OPTIONS.INFO, "Connection receieved, and Processing started...");
             KSocketConnection oConnection = new KSocketConnection();
             LogFile.writeLog(LOG_OPTIONS.DEBUG, "Handler object creating...");
             KConnection oClientConnection = new KConnection(oClientSocket);
             LogFile.writeLog(LOG_OPTIONS.DEBUG, "Handler object created");
             LogFile.writeLog(LOG_OPTIONS.DEBUG, "Creating handling thread...");
             Thread oClientThread = new Thread(new ThreadStart(oClientConnection.run));
             LogFile.writeLog(LOG_OPTIONS.DEBUG, "Handling thread created");
             oConnection.m_oHandler = oClientConnection;
             oConnection.m_oThread  = oClientThread;
             LogFile.writeLog(LOG_OPTIONS.DEBUG, "Connection storing in list...");
             m_oaConnectionList.Add(oConnection);
             LogFile.writeLog(LOG_OPTIONS.DEBUG, "Connection stored.");
             oClientThread.Start();
             LogFile.writeLog(LOG_OPTIONS.DEBUG, "Handling thread started.");
             clearConnections();
         }
     }
     catch (Exception oEx)
     {
         LogFile.writeLog(LOG_OPTIONS.ERROR, "initialization failed");
         LogFile.writeLog(LOG_OPTIONS.ERROR, "Exception error: " + oEx.Message);
         LogFile.writeLog(LOG_OPTIONS.ERROR, "Exception trace: " + oEx.StackTrace);
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }