private void stopWatch_EventArrived(object sender, EventArrivedEventArgs e)
        {
            try
            {
                var pName = Path.GetFileNameWithoutExtension(e.NewEvent.Properties["ProcessName"].Value.ToString());
                var pId   = uint.Parse(e.NewEvent.Properties["ProcessId"].Value.ToString());

                if (pName.ToLower().Contains(_processName.ToLower()))
                {
                    Console.WriteLine($"Process stopped: {pName} [{pId}]", pName);

                    lock (_locker)
                    {
                        var processToRemove = _runningProcesses.FirstOrDefault(process => process.Id == pId);

                        if (processToRemove != null)
                        {
                            _runningProcesses.Remove(processToRemove);
                            OnEventArrived?.Invoke(ProcessEventType.Stop, pId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        private void startWatch_EventArrived(object sender, EventArrivedEventArgs e)
        {
            try
            {
                var pName = Path.GetFileNameWithoutExtension(e.NewEvent.Properties["ProcessName"].Value.ToString());
                var pId   = uint.Parse(e.NewEvent.Properties["ProcessId"].Value.ToString());

                if (pName.ToLower().Contains(_processName.ToLower()))
                {
                    Console.WriteLine($"Process started: {pName} [{pId}]", pName);
                    var process = Process.GetProcessById((int)pId);
                    lock (_locker)
                    {
                        _runningProcesses.Add(process);
                        OnEventArrived?.Invoke(ProcessEventType.Start, pId);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 3
0
 public Task <Result> HandleAsync(RabbitEvent domainEvent, IEventContext context = null)
 {
     OnEventArrived?.Invoke(domainEvent);
     return(Result.Ok());
 }