Exemplo n.º 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();
            }
        }
Exemplo n.º 2
0
        public string GetFile()
        {
            // If we are monitoring a network mapped drive, make sure that we can still connect to it.
            // If we lose connection to a networked drive, FileSystemWatcher does not fire any new events
            // even after the connection is re-established.
            _networkDrive.EnsureDrive(_fileWatcher.Path);

            if (_dataFiles.IsEmpty)
            {
                return(null);
            }

            string filePath;

            _dataFiles.TryDequeue(out filePath);
            return(filePath);
        }