void Window_WindowBasicChanged(object sender, Public.ProcessEventArgs e) { try { ExternalToolConfig _ret = CheckProcessForEvents(e.Window.Processname, ProcessEventTyp.BasicData); if (_ret != null) { //Process exit event OnLoadedEvent(e.Window, _ret); } } catch (Exception ex) { Log.cLogger.Log(ex); } }
private bool Load(ExternalToolConfig _ExToolConfig) { try { if (_ExToolConfig != null && !string.IsNullOrEmpty(_ExToolConfig.ProcessName)) { if (myProcessToWatch == null) { myProcessToWatch = new Dictionary <string, List <ExternalToolConfig> >(); } if (myWindowsForWatching == null) { myWindowsForWatching = new List <WindowHandle.Window>(); } if (!myProcessToWatch.ContainsKey(_ExToolConfig.ProcessName)) { myProcessToWatch.Add(_ExToolConfig.ProcessName, new List <ExternalToolConfig>()); myProcessToWatch[_ExToolConfig.ProcessName].Add(_ExToolConfig); Log.cLogger.Log(string.Format("Added Processname:'{0}' to the Watching list", _ExToolConfig.ProcessName)); } else { if (myProcessToWatch[_ExToolConfig.ProcessName].Contains(_ExToolConfig)) { Log.cLogger.Log(string.Format("Process with Eventtyp already added to the Watching list, Processname:'{0}'", _ExToolConfig.ProcessName)); } else { myProcessToWatch[_ExToolConfig.ProcessName].Add(_ExToolConfig); } } return(true); } else { throw new ArgumentNullException("strProcessName"); } } catch (Exception ex) { Log.cLogger.Log(ex); return(false); } }
void myGPrc_ProcessRemoved(object sender, Public.ProcessEventArgs e) { try { if (myProcessToWatch != null && myProcessToWatch.ContainsKey(e.Window.Processname)) { ExternalToolConfig _ret = CheckProcessForEvents(e.Window.Processname, ProcessEventTyp.ProcessEnd); if (_ret != null) { //Process exit event OnLoadedEvent(e.Window, _ret); } Log.cLogger.Log(string.Format("Watcher found Process in Collection are getting removed, Processname:'{0}'", e.Window.Processname)); OnProcessFound_Removed(sender, e); } } catch (Exception ex) { Log.cLogger.Log(ex); } }
/// <summary> /// handle/execute the Event for a Window /// </summary> /// <param name="win">the Window which raised the event</param> /// <param name="exConfig">the Parameter for the execution</param> protected virtual void OnLoadedEvent(WindowHandle.Window win, ExternalToolConfig exConfig) { try { if (win != null) { Log.cLogger.Log(string.Format("Loaded event raised for Process:'{0}'", win.Processname)); switch (exConfig.ProcessEventExecuteTyp) { case ProcessEventExecuteTyp.Command: Log.cLogger.Log(string.Format("Command execute event , Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter)); System.Diagnostics.Process.Start(exConfig.ProcessStartParameter); break; case ProcessEventExecuteTyp.Position: string[] strPos = exConfig.ProcessStartParameter.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int iXCor = win.Rectangle.X; int iYCor = win.Rectangle.Y; if (strPos.Length > 0) { for (int i = 0; i < strPos.Length; i++) { if (strPos[i].StartsWith("X:")) { iXCor = Convert.ToInt32(strPos[i].Replace("X:", "").Trim()); } else if (strPos[i].StartsWith("Y:")) { iYCor = Convert.ToInt32(strPos[i].Replace("Y:", "").Trim()); } else { Log.cLogger.Log(string.Format("Position execute event has a unkown parameter, Process:'{0}' ParamString:'{1}' Current Param:'{2}'", win.Processname, exConfig.ProcessStartParameter, strPos[i])); } } Log.cLogger.Log(string.Format("Position execute event change Value (new X Cor:'{2}', new Y Cor:'{3}'), Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter, iXCor.ToString(), iYCor.ToString())); win.SetSizeLocation(iXCor, iYCor, win.Rectangle.Width, win.Rectangle.Height); } else { Log.cLogger.Log(string.Format("Position execute event has no arguments, Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter)); } break; case ProcessEventExecuteTyp.Size: string[] strSize = exConfig.ProcessStartParameter.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int iWidth = win.Rectangle.Width; int iHeight = win.Rectangle.Height; if (strSize.Length > 0) { for (int i = 0; i < strSize.Length; i++) { if (strSize[i].StartsWith("H:")) { iHeight = Convert.ToInt32(strSize[i].Replace("H:", "").Trim()); } else if (strSize[i].StartsWith("W:")) { iWidth = Convert.ToInt32(strSize[i].Replace("W:", "").Trim()); } else { Log.cLogger.Log(string.Format("Size execute event has a unkown parameter, Process:'{0}' ParamString:'{1}' Current Param:'{2}'", win.Processname, exConfig.ProcessStartParameter, strSize[i])); } } Log.cLogger.Log(string.Format("Size execute event change Value (new Width:'{2}', new Height:'{3}'), Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter, iWidth.ToString(), iHeight.ToString())); win.SetSizeLocation(win.Rectangle.X, win.Rectangle.Y, iWidth, iHeight); } else { Log.cLogger.Log(string.Format("Size execute event has no arguments, Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter)); } break; case ProcessEventExecuteTyp.Border: int iBorder = Convert.ToInt32(exConfig.ProcessStartParameter); IntPtr ipBorder = IntPtr.Zero; switch (iBorder) { case 1: ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.MAXIMIZEBOX; break; case 2: ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.OVERLAPPEDWINDOW; break; case 3: ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.SIZEFRAME; break; case 4: ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.BORDER; break; default: ipBorder = (IntPtr)WindowHandle.Enums.WindowStyles.MAXIMIZEBOX; break; } Log.cLogger.Log(string.Format("Border execute event change Value (new Bordertyp:'{2}' Border IntPtr:'{3}'), Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter, iBorder.ToString(), ipBorder.ToString())); win.SetBorderStyle(ipBorder); break; default: Log.cLogger.Log(string.Format("Command execute event , Process:'{0}' ParamString:'{1}'", win.Processname, exConfig.ProcessStartParameter)); System.Diagnostics.Process.Start(exConfig.ProcessStartParameter); break; } } else { Log.cLogger.Log("Loaded event can't raised Window data is null"); } } catch (Exception ex) { Log.cLogger.Log(ex); } }