/// <summary> /// usage: local debugging /// </summary> private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin, int port, string dataDirectory = null, bool singleNodeReplSet = false, string additionalMongodArguments = null) { _fileSystem = fileSystem; _mongoBin = mongoBin; _port = port; MakeMongoBinarysExecutable(); ConnectionString = singleNodeReplSet? "mongodb://127.0.0.1:{0}/?connect=direct&replicaSet=singleNodeReplSet&readPreference=primary".Formatted(_port) : "mongodb://127.0.0.1:{0}/".Formatted(_port); if (processWatcher.IsProcessRunning(MongoDbDefaults.ProcessName) && !portWatcher.IsPortAvailable(_port)) { State = State.AlreadyRunning; return; } if (!portWatcher.IsPortAvailable(_port)) { throw new MongoDbPortAlreadyTakenException("MongoDB can't be started. The TCP port {0} is already taken.".Formatted(_port)); } if (dataDirectory == null) { dataDirectory = CreateTemporaryDataDirectory(); } _fileSystem.CreateFolder(dataDirectory); _fileSystem.DeleteFile("{0}{1}{2}".Formatted(dataDirectory, Path.DirectorySeparatorChar.ToString(), MongoDbDefaults.Lockfile)); _mongoDbProcess = processStarter.Start(_mongoBin.Directory, dataDirectory, _port, true, singleNodeReplSet, additionalMongodArguments); State = State.Running; }
public MyProcessManager(ISimpleLogger simpleLogger, IProcessWatcher processWatcher, IProcessAdapter processAdapter) { this.simpleLoger = simpleLogger; this.processWatcher = processWatcher; this.processAdapter = processAdapter; processList = new List <IProcessItem>(); }
public QuestService(IPersistanceStorage storage, IProcessWatcher watcher, IPathManager path) { _storage = storage; _watcher = watcher; _path = path; Load(); }
/// <summary> /// usage: local debugging /// </summary> private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin, string dataDirectory) { _fileSystem = fileSystem; _port = MongoDbDefaults.DefaultPort; _mongoBin = mongoBin; MakeMongoBinarysExecutable(); ConnectionString = "mongodb://*****:*****@"{0}{1}{2}".Formatted(dataDirectory, System.IO.Path.DirectorySeparatorChar.ToString(), MongoDbDefaults.Lockfile)); _mongoDbProcess = processStarter.Start(_mongoBin.Directory, dataDirectory, _port, true); State = State.Running; }
public void GivenWatchJob_WhenStartWatch_ThenItRegistersHandler() { IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.StartCapture(); Assert.True(JobTimerRunning); Assert.NotNull(WatchJobHandler); }
void DoWork() { processWatcher = new MyProcessWatcher(); simpleLogger = new MySimpleLogger(); processAdapeter = new MyProcessAdapter(); processManager = new MyProcessManager(simpleLogger, processWatcher, processAdapeter); processManager.ListChanged += HandleListChanged; processManager.Load(); processManager.StartWatch(); }
public ActivityInfoProcessor() { this.monitor = new WindowsActivityMonitor(); this.watcher = new WindowsProcessWatcher(monitor, queue); myTimer = new Timer {Interval = 1000}; myTimer.Tick += watcher.Handle; consumeTimer = new Timer {Interval = 100}; consumeTimer.Tick += consume; }
public KeyboardDominanceWatcher( IProcessWatcher processWatcher, ILogger logger) { this.processWatcher = processWatcher; this.logger = logger; communicator = new HookHostCommunicator(); SetUpProcessWatcher(); }
/// <summary> /// Sets up services which can be used by the various viewmodels. /// </summary> private static void SetupServices() { var config = IoC.Get <LoaderConfig>(); SynchronizationContext synchronizationContext = null; ActionWrappers.ExecuteWithApplicationDispatcher(() => synchronizationContext = SynchronizationContext.Current); IoC.Kernel.Rebind <IProcessWatcher>().ToConstant(IProcessWatcher.Get()); IoC.Kernel.Rebind <ApplicationConfigService>().ToConstant(new ApplicationConfigService(config, synchronizationContext)); IoC.Kernel.Rebind <ModConfigService>().ToConstant(new ModConfigService(config, synchronizationContext)); }
public void GivenConfigFile_WhenGettingInitialProcessToWatch_ThenItReturnsProperProcessWatch() { IProcessWatcher watchdog = GivenProcessWatcher(); IEnumerable <IProcessWatch> initialTargets = watchdog.GetProcessUnderWatch(); var processWatches = initialTargets as IProcessWatch[] ?? initialTargets.ToArray(); Assert.Single(processWatches); Assert.Contains(INITIAL_TARGET, processWatches.Single().ProcessName); }
public void GivenNotRunningProcess_WhenAddProcessWatch_ProcessIsNotRunning() { const string processName = "NOT_A_PROCESS"; IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.AddProcessToWatchList(processName, false); IEnumerable <IProcessWatch> processWatches = watchdog.GetProcessUnderWatch(); IProcessWatch processWatch = processWatches.SingleOrDefault(pw => pw.ProcessName.Equals(processName)); Assert.False(processWatch?.IsRunning); }
public void GivenAddedProcessWatchWithNoCapture_WhenStartCapture_CaptureDeviceFilterDoesntChange() { Process runningProcess = ProcessWatchTestHelper.GivenFirstRunningProcess(); IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.AddProcessToWatchList(runningProcess.ProcessName, false); watchdog.StartCapture(); WatchJobHandler.Invoke(null, new EventArgs() as ElapsedEventArgs); Assert.Equal(string.Empty, CaptureDeviceFilter); }
/// <summary> /// construct a new object to represent the lifecycle of a process being scheduled /// </summary> public Process(ISchedulerProcess p, IProcessWatcher w, string cmd, ILogger l) { schedulerProcess = p; state = State.Initializing; commandLine = cmd; watcher = w; cancelTask = new TaskCompletionSource <bool>(); directory = null; statusVersion = 0; statusString = ""; logger = l; }
public void GivenUpdateProcessWatchToNoCapture_WhenStartCapture_ThenItRemovesProcessPortsFromWatchList() { Process runningProcess = ProcessWatchTestHelper.GivenFirstRunningProcess(); IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.AddProcessToWatchList(runningProcess.ProcessName, true); watchdog.UpdateProcessCaptureInWatchList(runningProcess.ProcessName, false); watchdog.StartCapture(); WatchJobHandler.Invoke(null, new EventArgs() as ElapsedEventArgs); Assert.Equal(string.Empty, CaptureDeviceFilter); }
/// <summary> /// Sets up services which can be used by the various viewmodels. /// </summary> private static void SetupServices() { var config = IoC.Get <LoaderConfig>(); var synchronizationContext = Actions.SynchronizationContext; IoC.BindToConstant(IProcessWatcher.Get()); IoC.BindToConstant(new ApplicationConfigService(config, synchronizationContext)); var modConfigService = new ModConfigService(config, synchronizationContext); IoC.BindToConstant(modConfigService); IoC.BindToConstant(new ModUserConfigService(config, modConfigService, synchronizationContext)); }
public void GivenRunningProcess_WhenAddProcessWatch_ProcessIsRunning() { IProcessWatcher watchdog = GivenProcessWatcher(); Process runningProcess = ProcessWatchTestHelper.GivenFirstRunningProcess(); watchdog.AddProcessToWatchList(runningProcess.ProcessName, false); IEnumerable <IProcessWatch> processWatches = watchdog.GetProcessUnderWatch(); IProcessWatch processWatch = processWatches.SingleOrDefault(pw => pw.ProcessName.Equals(runningProcess.ProcessName)); Assert.True(processWatch?.IsRunning); Assert.Equal(2, processWatches.Count()); }
public void GivenWatchJob_WhenStopWatch_ThenItUnregistersHandler() { WatchJobHandler = null; JobTimerRunning = false; CaptureDeviceOpen = true; IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.StartCapture(); watchdog.StopCapture(); Assert.False(JobTimerRunning); Assert.Null(WatchJobHandler); Assert.False(CaptureDeviceOpen); }
public ComputerMonitoringManager(IEventAggregator eventHub, IHardwareManager hardwareManager, IProcessWatcher watchDog, IRepository repository, ITimer refreshCounter) : base(eventHub) { _monitoringRefreshCounter = refreshCounter; _hardwareManager = hardwareManager; _monitoringTargets = new List <MonitoringTarget>(); _processWatcher = watchDog; _repository = repository; SetInitialMonitoringTargets(); SubscribeToEvents(); }
public void GivenProcessUnderWatch_WhenRemoveProcess_ThenItRemovesProperly() { Process runningProcess = ProcessWatchTestHelper.GivenFirstRunningProcess(); IProcessWatcher watchdog = GivenProcessWatcher(); watchdog.AddProcessToWatchList(runningProcess.ProcessName, false); IEnumerable <IProcessWatch> processWatches = watchdog.GetProcessUnderWatch(); Assert.Equal(2, processWatches.Count()); watchdog.RemoveProcessFromWatchList(runningProcess.ProcessName); processWatches = watchdog.GetProcessUnderWatch(); Assert.Single(processWatches); }
/// <summary> /// Add process to list of controlled processes. /// </summary> /// <param name="processWatcher"><see cref="IProcessWatcher"/></param> public void AddProcessToWatchList(IProcessWatcher processWatcher) { Contract.Requires<ArgumentNullException>(processWatcher != null, "processWatcher cannot be null"); using (_watchListLocker.GetWriteLock()) { if (_watchList.Contains(processWatcher)) { _watchList.Remove(processWatcher); } _watchList.Add(processWatcher); if (_watchList.Count > 0 && !_watchingTimer.Enabled) { _watchingTimer.Enabled = true; } } }
public static MongoDbRunner StartForDebuggingUnitTest( IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin, string dataDirectory = null) { return(new MongoDbRunner( processWatcher, portWatcher, fileSystem, processStarter, mongoBin, dataDirectory)); }
/* Class Setup and Teardown */ public ApplicationInstanceTracker(string applicationPath, CancellationToken token = default) { if (String.IsNullOrEmpty(applicationPath)) { throw new ArgumentException(Errors.PathNullOrEmpty()); } _applicationPath = Path.GetFullPath(applicationPath); BuildInitialProcesses(token); if (!token.IsCancellationRequested) { _processWatcher = IoC.Get <IProcessWatcher>(); _processWatcher.OnNewProcess += ProcessWatcherOnOnNewProcess; _processWatcher.OnRemovedProcess += ProcessWatcherOnOnRemovedProcess; } }
/// <summary> /// Add process to list of controlled processes. /// </summary> /// <param name="processWatcher"><see cref="IProcessWatcher"/></param> public void AddProcessToWatchList(IProcessWatcher processWatcher) { Contract.Requires <ArgumentNullException>(processWatcher != null, "processWatcher cannot be null"); using (_watchListLocker.GetWriteLock()) { if (_watchList.Contains(processWatcher)) { _watchList.Remove(processWatcher); } _watchList.Add(processWatcher); if (_watchList.Count > 0 && !_watchingTimer.Enabled) { _watchingTimer.Enabled = true; } } }
public static MongoDbRunner StartForDebuggingUnitTest( IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin, string dataDirectory = null, string additionalMongodArguments = null) { return(new MongoDbRunner( processWatcher, portWatcher, fileSystem, processStarter, mongoBin, MongoDbDefaults.DefaultPort, dataDirectory, additionalMongodArguments: additionalMongodArguments)); }
private RedisRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IRedisProcessStarter processStarter) { Port = RedisDefaults.DefaultPort; if (processWatcher.IsProcessRunning(RedisDefaults.ProcessName) && !portWatcher.IsPortAvailable(Port)) { State = State.AlreadyRunning; return; } if (!portWatcher.IsPortAvailable(Port)) { throw new PortTakenException(String.Format("Redis can't be started. The TCP port {0} is already taken.", this.Port)); } _redisProcess = processStarter.Start(Port); State = State.Running; }
public GameSettingsProcessWatcher( Plugins plugins, string communicationAddress, ushort communicationPort, ComponentAssembler assembler, IDirectoryRepository directoryRepository, IGameRepository gameRepository, IInjectionService injectionService, ILogger logger, IProcessWatcher processWatcher) { _plugins = plugins; _communicationAddress = communicationAddress; _communicationPort = communicationPort; _assembler = assembler; _directoryRepository = directoryRepository; _injectionService = injectionService; _gameRepository = gameRepository; _logger = logger; _processWatcher = processWatcher; }
/// <summary> /// usage: local debugging /// </summary> private MongoDbRunner(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter) { _fileSystem = fileSystem; _port = MongoDbDefaults.DefaultPort; ConnectionString = "mongodb://*****:*****@"{0}\{1}".Formatted(MongoDbDefaults.DataDirectory, MongoDbDefaults.Lockfile)); _mongoDbProcess = processStarter.Start(BinariesDirectory, MongoDbDefaults.DataDirectory, _port, true); State = State.Running; }
public IProcess NewProcess(IProcessWatcher watcher, string commandLine) { ISchedulerProcess process = scheduler.NewProcess(); return new Process(process, watcher, commandLine, logger); }
public IProcess NewProcess(IProcessWatcher watcher, string commandLine, string commandLineArguments) { ISchedulerProcess process = scheduler.NewProcess(); return(new Process(process, watcher, commandLine, commandLineArguments, logger)); }
public ProcessWatcherTests() { _sut = new ProcessWatcher(); }
public bool Equals(IProcessWatcher other) { return(WatchedProcess.Process.Id == other?.WatchedProcess.Process.Id); }
internal static MongoDbRunner StartForDebuggingUnitTest(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter) { return new MongoDbRunner(processWatcher, portWatcher, fileSystem, processStarter, MongoDbDefaults.DataDirectory); }
/// <summary> /// construct a new object to represent the lifecycle of a process being scheduled /// </summary> public Process(ISchedulerProcess p, IProcessWatcher w, string cmd, string cmdLineArgs, ILogger l) { schedulerProcess = p; state = State.Initializing; CommandLine = cmd; CommandLineArguments = cmdLineArgs; watcher = w; cancelTask = new TaskCompletionSource<bool>(); directory = null; statusVersion = 0; statusString = ""; logger = l; }
/* Construction */ public AutoInjector(MainPageViewModel mainPageViewModel) { _mainPageViewModel = mainPageViewModel; _processWatcher = App.IsElevated ? (IProcessWatcher) new WmiProcessWatcher() : ProcessWatcher.Instance; _processWatcher.OnNewProcess += ProcessWatcherOnOnNewProcess; }
public ProcessWatcherServiceImpl(IProcessProxy processProxy, IProcessWatcher processWatcher) { logger.Info("Constructing Process Watching Service"); this.processProxy = processProxy; this.processWatcher = processWatcher; }
/* Construction */ /// <summary/> public AutoInjector(ApplicationConfigService configService) { _configService = configService; _processWatcher = IoC.GetConstant <IProcessWatcher>(); _processWatcher.OnNewProcess += ProcessWatcherOnOnNewProcess; }
public static MongoDbRunner StartForDebuggingUnitTest(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin) { return new MongoDbRunner(processWatcher, portWatcher, fileSystem, processStarter, mongoBin, MongoDbDefaults.DataDirectory); }