Exemplo n.º 1
0
 private void FrmUSBPrep_OnContentRendered(object sender, EventArgs e)
 {
     try
     {
         watcher.Query =
             new WqlEventQuery("SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2 OR EventType = 3");
         watcher.EventArrived += watcher_EventArrived;
         watcher.Start();
     }
     catch (Exception Ex)
     {
         MessageBox.Show(Ex.Message);
         //LargeError LE = new LargeError("EventWatcher", "Unable to start EventWatcher.", lblStatus.Text, Ex);
         //LE.Upload();
     }
     Scan();
 }
 public void Subscribe()
 {
     if (EventWatcher != null)
     {
         return;
     }
     EventWatcher = CreateEventWatcher();
     EventWatcher.EventArrived += EventWatcher_EventArrived;
     EventWatcher.Start();
 }
Exemplo n.º 3
0
        public void WatchesForFileChanges()
        {
            _configuration.LocalDirectory = "dir";

            var watcher = new EventWatcher(_processor.Object, _configurationProvider.Object, _fileWatcher.Object);

            watcher.Start();

            _fileWatcher.Verify(x => x.WatchForChanges(_configuration.LocalDirectory));
        }
Exemplo n.º 4
0
        public void UploadsDirectoryWhenCreated()
        {
            _configuration.LocalDirectory = "dir";
            var filename = "file";

            _fileWatcher.Setup(x => x.IsDirectory(It.IsAny <string>())).Returns(true);

            var watcher = new EventWatcher(_processor.Object, _configurationProvider.Object, _fileWatcher.Object);

            watcher.Start();

            _fileWatcher.Raise(x => x.Created += null,
                               new FileSystemEventArgs(WatcherChangeTypes.Created, _configuration.LocalDirectory, filename));

            _processor.Verify(x => x.ProcessDirectory(It.IsAny <IDirectoryObject>()));
        }
Exemplo n.º 5
0
        public void RenamesFile()
        {
            _configuration.LocalDirectory = "c:\\dir";

            var watcher = new EventWatcher(_processor.Object, _configurationProvider.Object, _fileWatcher.Object);

            watcher.Start();

            _fileWatcher.Raise(x => x.Renamed += null,
                               new RenamedEventArgs(WatcherChangeTypes.Renamed, _configuration.LocalDirectory, "newName.txt", "oldName.txt"));

            var oldFullPath = Path.Combine(_configuration.LocalDirectory, "oldName.txt");

            _processor.Verify(x => x.RenameFile(
                                  It.Is <IFileObject>(f => f.FullName == oldFullPath),
                                  "newName.txt"));
        }
Exemplo n.º 6
0
        public void UploadsFileWhenCreated()
        {
            _configuration.LocalDirectory = "dir";
            var filename = "file";

            var wasUploaded = false;

            _processor.Setup(x => x.CopyFile(It.IsAny <IFileObject>())).Callback(() => wasUploaded = true);

            var watcher = new EventWatcher(_processor.Object, _configurationProvider.Object, _fileWatcher.Object);

            watcher.Start();

            _fileWatcher.Raise(x => x.Created += null,
                               new FileSystemEventArgs(WatcherChangeTypes.Created, _configuration.LocalDirectory, filename));

            Assert.IsTrue(wasUploaded);
        }
Exemplo n.º 7
0
        private void StartProcessing(ProcessorConfiguration configuration)
        {
            _asyncTaskQueue.TaskError += _asyncTaskQueue_TaskError;
            _asyncTaskQueue.StartProcessing();

            var processorFactory = new ProcessorFactory();

            _processor = processorFactory.Create(configuration, _asyncTaskQueue);

            _processor.ProcessSourceDirectory();

            _watcher = new EventWatcher(_processor,
                                        AppContainer.Container.Resolve <IConfigurationProvider>(),
                                        AppContainer.Container.Resolve <IFileWatcher>());
            StaticLogger.Log("Starting file watcher...");
            _watcher.Start();

            StaticLogger.Log("Ready.");
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            var usbWatcher = new EventWatcher();

            usbWatcher.DeviceInserted += (s, ea) =>
            {
                Console.WriteLine($"{ea.Disk.Name} was {ea.EventType}");
                Console.WriteLine($"{ea.Disk}");
            };
            usbWatcher.DeviceRemoved += (s, ea) =>
            {
                Console.WriteLine($"{ea.Disk.Name} was {ea.EventType}");
            };

            usbWatcher.Start();

            Console.WriteLine("Press enter to quit...");
            Console.ReadLine();
        }
Exemplo n.º 9
0
        public void RenamesDirectory()
        {
            var newName = "newName";
            var oldName = "oldName";

            _configuration.LocalDirectory = "c:\\dir";

            _fileWatcher.Setup(x => x.IsDirectory(It.IsAny <string>())).Returns(true);

            var watcher = new EventWatcher(_processor.Object, _configurationProvider.Object, _fileWatcher.Object);

            watcher.Start();

            _fileWatcher.Raise(x => x.Renamed += null,
                               new RenamedEventArgs(WatcherChangeTypes.Renamed, _configuration.LocalDirectory, newName, oldName));

            var oldFullPath = Path.Combine(_configuration.LocalDirectory, oldName);

            _processor.Verify(x => x.RenameDirectory(
                                  It.Is <IDirectoryObject>(f => f.FullName == oldFullPath),
                                  newName));
        }