/// <summary>
        ///     Gets or create the instance out of the process name.
        /// </summary>
        /// <param name="processname">The process name</param>
        /// <returns></returns>
        public static SmartProcess Get(string processname)
        {
            if (string.IsNullOrEmpty(processname))
            {
                throw new ArgumentNullException(nameof(processname));
            }

            var local = sporcs.ToArray();
            var @out  = local.FirstOrDefault(sp => sp.ProcessName.Equals(processname));

            if (@out == null)
            {
                var ogproc = Process.GetProcessesByName(processname);
                if (ogproc.Length > 1)
                {
                    throw new IndexOutOfRangeException($"Too many processes behold the name '{processname}'. Failed to get SmartProcess.");
                }
                if (ogproc.Length == 0)
                {
                    throw new IndexOutOfRangeException($"No process beholds the name '{processname}'. Failed to get SmartProcess.");
                }
                @out = new SmartProcess(ogproc[0]);
                sporcs.Add(@out);
            }
            return(@out);
        }
 private Window(SmartProcess process, HWND handle)
 {
     Process            = process;
     Handle             = handle;
     Mouse              = new RelativeMouseEmulator(this);
     KeyboardController = new KeyboardControllerEmulator(handle);
 }
        public static Window Create(SmartProcess process, HWND handle)
        {
            var wnd   = new Window(process, handle);
            var title = wnd.Title;

            if (wnd.ProcessName == "explorer")
            {
                if (title == "Start")   //start window
                {
                    wnd.Type = WindowType.Windows;
                }
                else if (title == "Run")
                {
                    wnd.Type = WindowType.Run;
                }
                else
                {
                    var ie = _explorer_monitor.Object.FirstOrDefault(_ie => _ie.hWnd == handle);
                    if (ie != null)
                    {
                        wnd.Type = WindowType.Explorer;
                        wnd.Data.Add("Path", ie.Location);
                    }
                }
            }
            else if (wnd.ProcessName == "chrome" || wnd.ProcessName == "firefox" || wnd.ProcessName == "opera" || wnd.ProcessName == "iexplorer")
            {
                wnd.Type = WindowType.Explorer;
            }

            return(wnd);
        }
        /// <summary>
        ///     Gets or create the instance out of the process object.
        /// </summary>
        /// <param name="process">The process to smart.</param>
        /// <returns></returns>
        public static SmartProcess Get(Process process)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            var local = sporcs.ToArray();
            var @out  = local.FirstOrDefault(sp => sp.OGProcess.Id == process.Id && sp.OGProcess.ProcessName == process.ProcessName);

            if (@out == null)
            {
                @out = new SmartProcess(process);
                sporcs.Add(@out);
            }
            return(@out);
        }
Esempio n. 5
0
        /// <summary>
        ///     Gets or create the instance out of the process object.
        /// </summary>
        /// <param name="process">The process to smart.</param>
        /// <returns></returns>
        public static SmartProcess Get(Process process) {
            if (process==null)
                throw new ArgumentNullException(nameof(process));

            var local = sporcs.ToArray();
            var @out = local.FirstOrDefault(sp => sp.OGProcess.Id== process.Id && sp.OGProcess.ProcessName==process.ProcessName);
            if (@out == null) {
                @out = new SmartProcess(process);
                sporcs.Add(@out);
            }
            return @out;
        }
Esempio n. 6
0
        /// <summary>
        ///     Gets or create the instance out of the process name.
        /// </summary>
        /// <param name="processname">The process name</param>
        /// <returns></returns>
        public static SmartProcess Get(string processname) {
            if (string.IsNullOrEmpty(processname))
                throw new ArgumentNullException(nameof(processname));

            var local = sporcs.ToArray();
            var @out = local.FirstOrDefault(sp => sp.ProcessName.Equals(processname));
            if (@out == null) {
                var ogproc = Process.GetProcessesByName(processname);
                if (ogproc.Length > 1) {
                    throw new IndexOutOfRangeException($"Too many processes behold the name '{processname}'. Failed to get SmartProcess.");
                } if (ogproc.Length == 0) {
                    throw new IndexOutOfRangeException($"No process beholds the name '{processname}'. Failed to get SmartProcess.");
                }
                @out = new SmartProcess(ogproc[0]);
                sporcs.Add(@out);
            }
            return @out;
        }
Esempio n. 7
0
File: Window.cs Progetto: Nucs/nlib
 private Window(SmartProcess process, HWND handle) {
     Process = process;
     Handle = handle;
     Mouse = new RelativeMouseEmulator(this);
     Keyboard = new KeyboardEmulator();
 }
Esempio n. 8
0
File: Window.cs Progetto: Nucs/nlib
        public static Window Create(SmartProcess process, HWND handle) {
            var wnd = new Window(process, handle);
            var title = wnd.Title;
            if (wnd.ProcessName == "explorer") {
                if (title == "Start") { //start window
                    wnd.Type = WindowType.Windows;
                } else if (title == "Run") {
                    wnd.Type = WindowType.Run;
                } else {
                    var ie = _explorer_monitor.Object.FirstOrDefault(_ie => _ie.hWnd == handle);
                    if (ie != null) {
                        wnd.Type = WindowType.Explorer;
                        wnd.Data.Add("Path", ie.Location);
                    }
                }
            } else if (wnd.ProcessName == "chrome" || wnd.ProcessName == "firefox" || wnd.ProcessName == "opera" || wnd.ProcessName == "iexplorer") {
                wnd.Type = WindowType.Explorer;
            }

            return wnd;
        }
 /// <summary>
 ///     Gets all the windows in the smart proc
 /// </summary>
 public static List <Window> GetWindows(this SmartProcess sproc)
 {
     return(OpenWindowGetter.GetOpenWindows(sproc.Id).Select(hwnd => Window.Create(sproc, hwnd)).ToList());
 }