Example #1
0
        private void TryConnect(DateTime startTime)
        {
            if (startTime.AddHours(1) < DateTime.Now)
            {
                throw new FileWatcherException(string.Format("Unable to connect to network drive for 1 hour. Network Drive: {0}. Configuration \"{1}\".", _driveInfo, _configName));
            }

            bool reconnected;
            var  driveAvailable = NetworkDriveUtil.EnsureDrive(_driveInfo, _logger, out reconnected, _configName);

            if (driveAvailable && _configRunner.IsDisconnected())
            {
                _configRunner.ChangeStatus(ConfigRunner.RunnerStatus.Running);
            }

            if (!driveAvailable)
            {
                if (_configRunner.IsRunning())
                {
                    _configRunner.ChangeStatus(ConfigRunner.RunnerStatus.Disconnected);
                }
                // keep trying every 1 minute for a hour or until the drive is available again.
                Thread.Sleep(TimeSpan.FromMinutes(1));

                TryConnect(startTime);
            }

            if (reconnected)
            {
                Program.LogInfo(string.Format("Re-connected drive {0} for configuration \"{1}\".  Restarting file watcher.", _driveInfo,
                                              _configName));
                RestartFileWatcher();
            }
        }
        public AutoQCFileSystemWatcher(IAutoQCLogger logger)
        {
            _fileWatcher = InitFileSystemWatcher();

            _logger = logger;

            _networkDrive = new NetworkDriveUtil(this, logger);
        }
Example #3
0
        public void Init(AutoQcConfig config)
        {
            _configName = config.Name;

            var mainSettings = config.MainSettings;

            _dataFiles  = new ConcurrentQueue <string>();
            _retryFiles = new Queue <RawFile>();

            _fileStatusChecker = GetFileStatusChecker(mainSettings);

            _fileWatcher.EnableRaisingEvents = false;

            if (mainSettings.IncludeSubfolders)
            {
                _fileWatcher.IncludeSubdirectories = true;
                _includeSubfolders = true;
            }

            _fileWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.CreationTime;

            _instrument        = mainSettings.InstrumentType;
            _dataInDirectories = IsDataInDirectories(_instrument);

            _fileWatcher.Filter = GetFileFilter(mainSettings.InstrumentType);

            _fileWatcher.Path = mainSettings.FolderToWatch;

            _fileFilter = mainSettings.QcFileFilter;

            _acquisitionTimeSetting = mainSettings.AcquisitionTime;

            _driveInfo = new DriveInfo {
                DriveLetter = NetworkDriveUtil.GetDriveLetter(_fileWatcher.Path)
            };
            if (_driveInfo.DriveLetter == null)
            {
                throw new FileWatcherException(string.Format("Unable to get drive letter for path {0}", _fileWatcher.Path));
            }
            try
            {
                _driveInfo.NetworkDrivePath = NetworkDriveUtil.ReadNetworkDrivePath(_driveInfo.DriveLetter);
            }
            catch (FileWatcherException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new FileWatcherException(string.Format("Unable to read network drive properties for {0}", _driveInfo.DriveLetter), e);
            }
        }
Example #4
0
 public DriveInfo(string path)
 {
     Path        = path;
     DriveLetter = NetworkDriveUtil.GetDriveLetter(path);
     if (DriveLetter != null)
     {
         try
         {
             NetworkPath = NetworkDriveUtil.GetNetworkPath(DriveLetter);
         }
         catch (FileWatcherException)
         {
             throw;
         }
         catch (Exception e)
         {
             throw new FileWatcherException(string.Format("Unable to read network drive properties for {0}", DriveLetter), e);
         }
     }
     else if (path.StartsWith(@"\\"))
     {
         NetworkPath = path;
     }
 }