コード例 #1
0
        /// <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;
        }
コード例 #2
0
 public MyProcessManager(ISimpleLogger simpleLogger, IProcessWatcher processWatcher, IProcessAdapter processAdapter)
 {
     this.simpleLoger    = simpleLogger;
     this.processWatcher = processWatcher;
     this.processAdapter = processAdapter;
     processList         = new List <IProcessItem>();
 }
コード例 #3
0
ファイル: QuestService.cs プロジェクト: rasyidf/KFlearning
 public QuestService(IPersistanceStorage storage, IProcessWatcher watcher, IPathManager path)
 {
     _storage = storage;
     _watcher = watcher;
     _path    = path;
     Load();
 }
コード例 #4
0
        /// <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;
        }
コード例 #5
0
        /// <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;
        }
コード例 #6
0
        public void GivenWatchJob_WhenStartWatch_ThenItRegistersHandler()
        {
            IProcessWatcher watchdog = GivenProcessWatcher();

            watchdog.StartCapture();

            Assert.True(JobTimerRunning);
            Assert.NotNull(WatchJobHandler);
        }
コード例 #7
0
 void DoWork()
 {
     processWatcher              = new MyProcessWatcher();
     simpleLogger                = new MySimpleLogger();
     processAdapeter             = new MyProcessAdapter();
     processManager              = new MyProcessManager(simpleLogger, processWatcher, processAdapeter);
     processManager.ListChanged += HandleListChanged;
     processManager.Load();
     processManager.StartWatch();
 }
コード例 #8
0
ファイル: ActivityInfoProcessor.cs プロジェクト: deweyvm/prod
        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;
        }
コード例 #9
0
        public KeyboardDominanceWatcher(
            IProcessWatcher processWatcher,
            ILogger logger)
        {
            this.processWatcher = processWatcher;
            this.logger         = logger;

            communicator = new HookHostCommunicator();

            SetUpProcessWatcher();
        }
コード例 #10
0
ファイル: Setup.cs プロジェクト: DeaTh-G/Reloaded-II
        /// <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));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
 /// <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;
 }
コード例 #15
0
        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);
        }
コード例 #16
0
    /// <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));
    }
コード例 #17
0
        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());
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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();
        }
コード例 #20
0
        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);
        }
コード例 #21
0
ファイル: CpuLimiter.cs プロジェクト: KBurov/WandererLib
        /// <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;
                }
            }
        }
コード例 #22
0
ファイル: MongoDbRunner.cs プロジェクト: nickmkk/Mongo2Go
 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));
 }
コード例 #23
0
        /* 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;
            }
        }
コード例 #24
0
ファイル: CpuLimiter.cs プロジェクト: KBurov/WandererLib
        /// <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;
                }
            }
        }
コード例 #25
0
 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));
 }
コード例 #26
0
        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;
        }
コード例 #27
0
 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;
 }
コード例 #28
0
ファイル: MongoDbRunner.cs プロジェクト: srasch/Mongo2Go
        /// <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;
        }
コード例 #29
0
        /// <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;
        }
コード例 #30
0
ファイル: HttpScheduler.cs プロジェクト: pszmyd/Dryad
 public IProcess NewProcess(IProcessWatcher watcher, string commandLine)
 {
     ISchedulerProcess process = scheduler.NewProcess();
     return new Process(process, watcher, commandLine, logger);
 }
コード例 #31
0
        public IProcess NewProcess(IProcessWatcher watcher, string commandLine, string commandLineArguments)
        {
            ISchedulerProcess process = scheduler.NewProcess();

            return(new Process(process, watcher, commandLine, commandLineArguments, logger));
        }
コード例 #32
0
 public ProcessWatcherTests()
 {
     _sut = new ProcessWatcher();
 }
コード例 #33
0
ファイル: ProcessWatcher.cs プロジェクト: KBurov/WandererLib
 public bool Equals(IProcessWatcher other)
 {
     return(WatchedProcess.Process.Id == other?.WatchedProcess.Process.Id);
 }
コード例 #34
0
 internal static MongoDbRunner StartForDebuggingUnitTest(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter)
 {
     return new MongoDbRunner(processWatcher, portWatcher, fileSystem, processStarter, MongoDbDefaults.DataDirectory);
 }
コード例 #35
0
ファイル: Process.cs プロジェクト: knowledgehacker/Dryad
 /// <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;
 }
コード例 #36
0
 /* Construction */
 public AutoInjector(MainPageViewModel mainPageViewModel)
 {
     _mainPageViewModel            = mainPageViewModel;
     _processWatcher               = App.IsElevated ? (IProcessWatcher) new WmiProcessWatcher() : ProcessWatcher.Instance;
     _processWatcher.OnNewProcess += ProcessWatcherOnOnNewProcess;
 }
コード例 #37
0
 public ProcessWatcherServiceImpl(IProcessProxy processProxy, IProcessWatcher processWatcher)
 {
     logger.Info("Constructing Process Watching Service");
      this.processProxy = processProxy;
      this.processWatcher = processWatcher;
 }
コード例 #38
0
    /* Construction */

    /// <summary/>
    public AutoInjector(ApplicationConfigService configService)
    {
        _configService  = configService;
        _processWatcher = IoC.GetConstant <IProcessWatcher>();
        _processWatcher.OnNewProcess += ProcessWatcherOnOnNewProcess;
    }
コード例 #39
0
 public static MongoDbRunner StartForDebuggingUnitTest(IProcessWatcher processWatcher, IPortWatcher portWatcher, IFileSystem fileSystem, IMongoDbProcessStarter processStarter, IMongoBinaryLocator mongoBin)
 {
     return new MongoDbRunner(processWatcher, portWatcher, fileSystem, processStarter, mongoBin, MongoDbDefaults.DataDirectory);
 }