Ejemplo n.º 1
0
        public void Init()
        {
            _watcher = _watcherFactory.Create();

            _watcher.Path = _settings.Dir.DirectoryWithFilesToSend;
            _watcher.EnableRaisingEvents = true;

            _watcher.Created += OnChanged;
            _watcher.Changed += OnChanged;
        }
Ejemplo n.º 2
0
        public void OnChanged_Should_NotRaiseChangedEvent_When_NewFileCreatedAlreadyDoNotExist()
        {
            bool IsRiced = false;

            var fileInfo = Substitute.For <IFileInfo>();

            fileInfo.Exists.Returns(false);
            _fileInfoFactory.Create(Arg.Any <string>()).Returns(fileInfo);

            var watcher = Substitute.For <IFileSystemWatcher>();

            _fileSystemWatcherFactory.Create().Returns(watcher);

            _directoryWatcher.Changed += (sender, info) => IsRiced = true;

            _directoryWatcher.Init();
            watcher.Created += Raise.Event <FileSystemEventHandler>(watcher, new FileSystemEventArgs(WatcherChangeTypes.Created, String.Empty, "fileName"));

            Expect(IsRiced, Is.False);
        }
Ejemplo n.º 3
0
        private void CreateWatcher(SyncRule rule, string filter)
        {
            var watcher = _watcherFactory.Create(rule.Source);

            watcher.EnableRaisingEvents = true;
            watcher.Filter = filter;
            watcher.IncludeSubdirectories = true;
            watcher.Changed   += Watcher_Changed;
            watcher.Created   += Watcher_Changed;
            watcher.Renamed   += Watcher_Changed;
            _watchers[watcher] = rule;
        }
Ejemplo n.º 4
0
        public TelemetryDataRepository(IFile fileWrapper, IDirectory directoryWrapper,
                                       IFileSystemWatcherFactory fileSystemWatcherFactory)
        {
            this.fileWrapper      = fileWrapper;
            this.directoryWrapper = directoryWrapper;

            EnsureFileExists(StorageFilePath);
            ReadFromXmlFile();

            fileWatcher                     = fileSystemWatcherFactory.Create();
            fileWatcher.Path                = Path.GetDirectoryName(StorageFilePath);
            fileWatcher.Filter              = Path.GetFileName(StorageFilePath);
            fileWatcher.NotifyFilter        = NotifyFilters.LastWrite;
            fileWatcher.EnableRaisingEvents = true;
            fileWatcher.Changed            += OnStorageFileChanged;
        }
Ejemplo n.º 5
0
        public JekyllSiteContextTests()
        {
            filename                 = @"C:\Site\Index.md";
            basePath                 = @"C:\Site\";
            eventAggregator          = Substitute.For <IEventAggregator>();
            dialogService            = Substitute.For <IDialogService>();
            fileSystem               = Substitute.For <IFileSystem>();
            fileSystemWatcherFactory = Substitute.For <IFileSystemWatcherFactory>();
            fileSystemWatcher        = Substitute.For <IFileSystemWatcher>();
            fileSystemWatcherFactory.Create(Arg.Any <string>()).Returns(fileSystemWatcher);

            jekyllContext = new JekyllSiteContext(
                eventAggregator,
                dialogService,
                fileSystem,
                fileSystemWatcherFactory,
                basePath);
        }
        public JekyllSiteContextTests()
        {
            filename = @"C:\Site\Index.md";
            basePath = @"C:\Site\";
            eventAggregator = Substitute.For<IEventAggregator>();
            dialogService = Substitute.For<IDialogService>();
            fileSystem = Substitute.For<IFileSystem>();
            fileSystemWatcherFactory = Substitute.For<IFileSystemWatcherFactory>();
            fileSystemWatcher = Substitute.For<IFileSystemWatcher>();
            fileSystemWatcherFactory.Create(Arg.Any<string>()).Returns(fileSystemWatcher);

            jekyllContext = new JekyllSiteContext(
                eventAggregator,
                dialogService,
                fileSystem,
                fileSystemWatcherFactory,
                basePath);
        }
        public SingleFileMonitor(IFileSystemWatcherFactory factory, IDirectory directoryWrapper, string filePathToMonitor, ILogger logger)
        {
            this.MonitoredFilePath = filePathToMonitor;

            EnsureDirectoryExists(filePathToMonitor, directoryWrapper, logger);

            fileWatcher              = factory.Create();
            fileWatcher.Path         = Path.GetDirectoryName(filePathToMonitor); // NB will throw if the directory does not exist
            fileWatcher.Filter       = Path.GetFileName(filePathToMonitor);
            fileWatcher.NotifyFilter = System.IO.NotifyFilters.CreationTime | System.IO.NotifyFilters.LastWrite |
                                       NotifyFilters.FileName | NotifyFilters.DirectoryName;

            fileWatcher.Changed += OnFileChanged;
            fileWatcher.Created += OnFileChanged;
            fileWatcher.Deleted += OnFileChanged;
            fileWatcher.Renamed += (s, args) => OnFileChanged(s, args);

            this.logger = logger;
        }
Ejemplo n.º 8
0
        public JekyllSiteContext(
            IEventAggregator eventAggregator,
            IDialogService dialogService,
            IFileSystem fileSystem,
            IFileSystemWatcherFactory fileSystemWatcherFactory,
            string siteBasePath)
        {
            this.siteBasePath    = siteBasePath;
            this.fileSystem      = fileSystem;
            this.dialogService   = dialogService;
            this.eventAggregator = eventAggregator;
            fileSystemWatcher    = fileSystemWatcherFactory.Create(siteBasePath);
            fileSystemWatcher.IncludeSubdirectories = true;
            fileSystemWatcher.Created += FileSystemWatcherOnCreated;
            fileSystemWatcher.Changed += FileSystemWatcherOnChanged;
            fileSystemWatcher.Renamed += FileSystemWatcherOnRenamed;
            fileSystemWatcher.Deleted += FileSystemWatcherOnDeleted;

            fileSystemWatcher.EnableRaisingEvents = true;
        }