public void FiltersOutMissingProcesses() { var processes = new[] { Process.Start("cmd.exe"), Process.Start("cmd.exe"), }; try { var processHelper = new ProcessHelper(); var processIds = processes.Select(p => p.Id).ToList(); processIds.Add(1); var result = processHelper.GetProcesses(processes.Select(p => p.Id)); Assert.Collection(result, x => Assert.Equal(processes[0].Id, x.Id), x => Assert.Equal(processes[1].Id, x.Id) ); } finally { foreach (var p in processes) p.Kill(); } }
void InitiatizeCategory() { try { var counters = new[] { ConsumerThreadCount, ReceiveThreadCount, ReceiveRate, PublishRate, SendRate, ReceiveCount, PublishCount, SentCount, ConsumerDuration, ConsumerDurationBase, ReceiveDuration, ReceiveDurationBase, PublishDuration, PublishDurationBase, }; if (!PerformanceCounterCategory.Exists(CategoryName)) { PerformanceCounterCategory.Create( CategoryName, CategoryHelp, PerformanceCounterCategoryType.MultiInstance, new CounterCreationDataCollection(counters.Select(x => (CounterCreationData) x).ToArray())); return; } int missing = counters .Where(counter => !PerformanceCounterCategory.CounterExists(counter.Name, CategoryName)) .Count(); if (missing > 0) { PerformanceCounterCategory.Delete(CategoryName); PerformanceCounterCategory.Create( CategoryName, CategoryHelp, PerformanceCounterCategoryType.MultiInstance, new CounterCreationDataCollection(counters.Select(x => (CounterCreationData) x).ToArray())); } } catch (SecurityException) { //swallow the exception because having these is NOT critical var msg = "Unable to create performance counter category (Category: {0})" + "\nTry running the program in the Administrator role to set these up." + "\n**Hey, this just means you aren't admin or don't have/want perf counter support**" .FormatWith(CategoryName); _log.Warn(msg); } }
void InitiatizeCategory() { try { var counters = new[] { ConsumerThreadCount, ReceiveThreadCount, ReceiveRate, PublishRate, SendRate, ReceiveCount, PublishCount, SentCount, ConsumerDuration, ConsumerDurationBase, ReceiveDuration, ReceiveDurationBase, PublishDuration, PublishDurationBase, }; if (!PerformanceCounterCategory.Exists(CategoryName)) { PerformanceCounterCategory.Create( CategoryName, CategoryHelp, PerformanceCounterCategoryType.MultiInstance, new CounterCreationDataCollection(counters.Select(x => (CounterCreationData) x).ToArray())); return; } int missing = counters .Where(counter => !PerformanceCounterCategory.CounterExists(counter.Name, CategoryName)) .Count(); if (missing > 0) { PerformanceCounterCategory.Delete(CategoryName); PerformanceCounterCategory.Create( CategoryName, CategoryHelp, PerformanceCounterCategoryType.MultiInstance, new CounterCreationDataCollection(counters.Select(x => (CounterCreationData) x).ToArray())); } } catch (SecurityException ex) { _log.Error("Unable to create performance counter category (Category: {0})\nTry running the program in the Administrator role to set these up.".FormatWith(CategoryName), ex); } }
public void ReturnsProcesses() { var processes = new [] { Process.Start("cmd.exe"), Process.Start("cmd.exe"), }; try { var processHelper = new ProcessHelper(); var result = processHelper.GetProcesses(processes.Select(p => p.Id)); Assert.Collection(result, x => Assert.Equal(processes[0].Id, x.Id), x => Assert.Equal(processes[1].Id, x.Id) ); } finally { foreach (var p in processes) p.Kill(); } }