Esempio n. 1
0
        public CodeWatcher(CodeRunnerParameters parameters)
        {
            _parameters = parameters;

            _workQueue = new BlockingCollection <string>();

            if (_parameters.ForceInitialRun)
            {
                ForceInitialRun();
            }

            _debouncerWithProjection = new DebouncerWithProjection <FileSystemEventArgs, string>(
                actionToDebounce: evt =>
            {
                Console.WriteLine($"INFO: {Path.GetFileName(evt.FullPath)} changed detected !", Color.SaddleBrown);
                _workQueue.Add(evt.FullPath);
            },
                debounceBy: evt => evt.FullPath,
                delay: 100.Milliseconds());

            _fsw = new FileSystemWatcher
            {
                Path = _parameters.Directory,
                IncludeSubdirectories = true,
                Filter              = "*.cs",
                NotifyFilter        = NotifyFilters.LastWrite | NotifyFilters.Security,
                EnableRaisingEvents = true,
            };

            _fsw.Changed += OnSourceFileChanged;

            Console.WriteLine($"INFO: Running and watching for change in {_parameters.Directory}", Color.SaddleBrown);

            StartConsumingTask();
        }
Esempio n. 2
0
        public void MustDebounceCallWithTheSameProjectionValueWhenTheDelayBetweenCallIsLowerThanDebouncerDelay()
        {
            var debouncer = new DebouncerWithProjection <string, char>(_ => _counter++, x => x.First(), 20.Milliseconds());

            debouncer.DebouncedActionFor("a1");
            debouncer.DebouncedActionFor("a2");
            debouncer.DebouncedActionFor("a3");

            Thread.Sleep(50.Milliseconds());

            Check.That(_counter).IsEqualTo(1);
        }