/// <summary> /// Execution starts here /// </summary> /// <param name="args"> Two agruments would be passed 1. Recovery file path 2. Sheet name for popup file. 3. Invoking Parent Process ID </param> static void Main(string[] args) { try { string filePath = args[0].ToString(); Console.WriteLine("FilePath" + filePath); _applicationPath = Application.ExecutablePath; int applicationFilePath = _applicationPath.LastIndexOf("\\", StringComparison.Ordinal); string workingDirectory = string.Empty; if (applicationFilePath >= 0) { workingDirectory = _applicationPath.Substring(0, applicationFilePath + 1); } DataSet dataset = GetDataSet(filePath); try { //Generate Autoit object. _objAutoit = new AutoItX3Lib.AutoItX3(); //Setting AutoIt Title match to Exact match. _objAutoit.AutoItSetOption("WinTitleMatchMode", 4); _parentProcessId = args[2]; } catch (Exception e) { KryptonException.Writeexception(e); } //Starting Infinite loop. //loop should run as long as parent process is running while (_isParentProcessRunning) { //Getting all windows beforehand. dynamic windowsList = _objAutoit.WinList("[REGEXPTITLE:^.*$]"); int winListCount = (int)windowsList[0, 0]; // List[0,0] give the count of windows. var windowTitleList = new List <string>(); //Populating non empty titles to windowTitleList. for (int j = 1; j <= winListCount; j++) { string title = (string)windowsList[0, j]; if (!string.IsNullOrEmpty(title)) { windowTitleList.Add(title); } } if (dataset.Tables.Count > 0) { for (int i = 0; i < dataset.Tables[0].Rows.Count; i++) { //First thing first, check if parent process is running //If parent process (Krypton.exe) is not running, exits from here try { Process.GetProcessById(int.Parse(_parentProcessId)); } catch (Exception e) { //Exception will occur only when parent process is not running _isParentProcessRunning = false; return; } //Get IE popup Title. string popupName = dataset.Tables[0].Rows[i]["PopUpTitle"].ToString().Trim(); //Get IE popup Title. string buttonName = dataset.Tables[0].Rows[i]["ButtonName"].ToString().Trim(); //Get the action need to be done. string action = dataset.Tables[0].Rows[i]["Action"].ToString().Trim(); //Populate data if provided. var data = dataset.Tables[0].Rows[i]["Data"].ToString().Trim(); if (windowTitleList.Contains(popupName)) { //Switching control based on action given. switch (action.ToLower()) { case "click": BtnClick(popupName, buttonName); break; case "keypress": KeyPress(popupName, data); break; case "close": _objAutoit.WinClose(popupName); break; case "run": case "execute": if (!File.Exists(_applicationPath + data)) { data = data + ".exe"; } //Create process information and assign data using (Process specialScriptProcess = new Process()) { specialScriptProcess.StartInfo.CreateNoWindow = false; specialScriptProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; specialScriptProcess.StartInfo.UseShellExecute = false; specialScriptProcess.StartInfo.FileName = data; specialScriptProcess.StartInfo.WorkingDirectory = workingDirectory; specialScriptProcess.StartInfo.ErrorDialog = false; // Start the process specialScriptProcess.Start(); specialScriptProcess.WaitForExit(10000); } break; } } System.Threading.Thread.Sleep(10); } System.Threading.Thread.Sleep(2000); } } } catch (System.Runtime.InteropServices.COMException) { Console.WriteLine(ConsoleMessages.REGISTER_AUTOIT); } catch (IndexOutOfRangeException) { Console.WriteLine(ConsoleMessages.INVALID_ARGUMNETS); } catch (Exception e) { Console.WriteLine(ConsoleMessages.PARALLEL_rECOVERY + e.Message + e.StackTrace); } }
public void Close() { autoIT.WinClose(application_title); }
/// <summary> /// Execution starts here /// </summary> /// <param name="args"> Two agruments would be passed 1. Recovery file path 2. Sheet name for popup file. 3. Invoking Parent Process ID </param> static void Main(string[] args) { try { string filePath = args[0].ToString(); Console.WriteLine("FilePath" + filePath); _applicationPath = Application.ExecutablePath; int applicationFilePath = _applicationPath.LastIndexOf("\\", StringComparison.Ordinal); string workingDirectory = string.Empty; if (applicationFilePath >= 0) { workingDirectory = _applicationPath.Substring(0, applicationFilePath + 1); } DataSet dataset = GetDataSet(filePath); try { //Generate Autoit object. _objAutoit = new AutoItX3Lib.AutoItX3(); //Setting AutoIt Title match to Exact match. _objAutoit.AutoItSetOption("WinTitleMatchMode", 4); _parentProcessId = args[2]; } catch (Exception e) { KryptonException.Writeexception(e); } //Starting Infinite loop. //loop should run as long as parent process is running while (_isParentProcessRunning) { //Getting all windows beforehand. dynamic windowsList = _objAutoit.WinList("[REGEXPTITLE:^.*$]"); int winListCount = (int)windowsList[0, 0]; // List[0,0] give the count of windows. var windowTitleList = new List<string>(); //Populating non empty titles to windowTitleList. for (int j = 1; j <= winListCount; j++) { string title = (string)windowsList[0, j]; if (!string.IsNullOrEmpty(title)) { windowTitleList.Add(title); } } if (dataset.Tables.Count > 0) { for (int i = 0; i < dataset.Tables[0].Rows.Count; i++) { //First thing first, check if parent process is running //If parent process (Krypton.exe) is not running, exits from here try { Process.GetProcessById(int.Parse(_parentProcessId)); } catch (Exception e) { //Exception will occur only when parent process is not running _isParentProcessRunning = false; return; } //Get IE popup Title. string popupName = dataset.Tables[0].Rows[i]["PopUpTitle"].ToString().Trim(); //Get IE popup Title. string buttonName = dataset.Tables[0].Rows[i]["ButtonName"].ToString().Trim(); //Get the action need to be done. string action = dataset.Tables[0].Rows[i]["Action"].ToString().Trim(); //Populate data if provided. var data = dataset.Tables[0].Rows[i]["Data"].ToString().Trim(); if (windowTitleList.Contains(popupName)) { //Switching control based on action given. switch (action.ToLower()) { case "click": BtnClick(popupName, buttonName); break; case "keypress": KeyPress(popupName, data); break; case "close": _objAutoit.WinClose(popupName); break; case "run": case "execute": if (!File.Exists(_applicationPath + data)) { data = data + ".exe"; } //Create process information and assign data using (Process specialScriptProcess = new Process()) { specialScriptProcess.StartInfo.CreateNoWindow = false; specialScriptProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; specialScriptProcess.StartInfo.UseShellExecute = false; specialScriptProcess.StartInfo.FileName = data; specialScriptProcess.StartInfo.WorkingDirectory = workingDirectory; specialScriptProcess.StartInfo.ErrorDialog = false; // Start the process specialScriptProcess.Start(); specialScriptProcess.WaitForExit(10000); } break; } } System.Threading.Thread.Sleep(10); } System.Threading.Thread.Sleep(2000); } } } catch (System.Runtime.InteropServices.COMException) { Console.WriteLine(ConsoleMessages.REGISTER_AUTOIT); } catch (IndexOutOfRangeException) { Console.WriteLine(ConsoleMessages.INVALID_ARGUMNETS); } catch (Exception e) { Console.WriteLine(ConsoleMessages.PARALLEL_rECOVERY + e.Message + e.StackTrace); } }