/// <summary> /// Hunts for a specific process /// </summary> /// <param name="id">The ID of the process found in Process.Id</param> public AppMonitor(FileInfo file) { if (file == null || !System.IO.File.Exists(file.FullName)) throw new ArgumentNullException(nameof(file)); var active = new ActiveProcessFiles().Enumerate(info => info.CompareTo(file)); if (active == null) { File = new FileInfo(Paths.NormalizePath(file.FullName)); Id = 0; } }
/// <summary> /// Hunts for a specific process /// </summary> /// <param name="id">The ID of the process found in Process.Id</param> public ProcessCrashMonitor(FileInfo file) { if (file == null || !System.IO.File.Exists(file.FullName)) throw new ArgumentNullException(nameof(file)); var active = new ActiveProcessFiles().Enumerate(info => info.CompareTo(file)); if (active == null) Id = 0; else { _load(active); } }
/// <summary> /// Hunts for a specific process /// </summary> /// <param name="id">The ID of the process found in Process.Id</param> /// <param name="additionalCheck"></param> public ProcessCrashMonitor(FileInfo file, Func <Process, bool> additionalCheck = null) { AdditionalCheck = additionalCheck; if (file == null || !System.IO.File.Exists(file.FullName)) { throw new ArgumentNullException(nameof(file)); } var active = new ActiveProcessFiles().Enumerate(info => info.CompareTo(file)); if (active == null) { Id = 0; } else { _load(active); } }
/// <summary> /// Pass null and it will look for it, pass the process and it will load it. /// </summary> /// <param name="foundprocess"></param> /// <returns></returns> public Process ProcessProcess(Process foundprocess = null) { Process p = foundprocess; try { if (p != null) return p; if (this.Id != 0) { p = Process.GetProcesses().FirstOrDefault(proc => proc.Id.Equals(this.Id)); if (p != null) return p; } if (this.Name != null) { p = Process.GetProcesses().FirstOrDefault(proc => proc.ProcessName.Equals(this.Name, StringComparison.InvariantCultureIgnoreCase)); if (p != null) return p; } if (this.File != null && System.IO.File.Exists(this.File.FullName)) { p = new ActiveProcessFiles().Enumerate(info => info.CompareTo(this.File)); return p; } return null; } finally { if (p != null) { if (File==null) File = new FileInfo(ProcessExecutablePath(p)); Id = p.Id; Name = p.ProcessName; } } }