Cross Platform Application to allow control with a MIDI controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

// Author: Gockner, Simon
// Created: 2021-04-23
// Copyright(c) 2021 SimonG. All Rights Reserved.
using System.Diagnostics;
using Lib.ProcessManaging.Interfaces;
namespace Lib.ProcessManaging
{
public class ObservedProcess : IObservedProcess
{
public ObservedProcess(Process process)
{
Name = process.ProcessName;
Id = process.Id;
FileName = TryGetFileName(process);
}
public string Name { get; }
public int Id { get; }
public string FileName { get; }
public bool EqualsProcess(Process process) => Id == process.Id;
public bool IsSameExecutable(IObservedProcess observedProcess) => FileName.Equals(observedProcess.FileName);
private string TryGetFileName(Process process)
{
try
{
return process.MainModule?.FileName ?? "";
}
catch
{
// ignored
}
return "";
}
}
}