示例#1
0
        public void Archive_CreatedArchiveFolder()
        {
            // Arrange
            string testFile      = TestHelper.GetFullPath(TestFile);
            string importFile    = TestHelper.GetFullPath(ImportFile);
            string archiveFolder = TestHelper.GetFullPath(ArchiveFolder);

            File.WriteAllText(importFile, Properties.Resources.file);

            // Act
            _provider.Archive(importFile, archiveFolder);
            // Assert
            Assert.IsTrue(Directory.Exists(archiveFolder), "Expected archive folder to be created");
        }
示例#2
0
        public void ProcessFile(object sender, FileSystemEventArgs e)
        {
            if (e.ChangeType != WatcherChangeTypes.Changed &&
                e.ChangeType != WatcherChangeTypes.Created)
            {
                return;
            }
            _logger.Info(this, $"Checking if file/folder '{e.Name}' is ready to process");
            SendHeartBeat();
            if (IsFileReady(e.FullPath))
            {
                try {
                    // Disable further events whilst processing
                    _fileWatcher.EnableRaisingEvents = false;
                    switch (e.ChangeType)
                    {
                    case WatcherChangeTypes.Changed:
                    case WatcherChangeTypes.Created:
                        _fileProvider.Archive(
                            e.FullPath, _configurationProvider.ArchiveWatchPath);
                        _logger.Info(this, $"Beginning processing of file '{e.Name}'");
                        var importLog = new StringBuilder();
                        _userService.ImportUsers(e.FullPath, ((entry) => {
                            importLog.AppendLine(entry);
                        }));
                        _logger.Info(
                            this, $"File '{e.Name}' processed.\r\n{importLog.ToString()}");
                        break;

                    default:
                        break;
                    }
                } catch (Exception err) {
                    _logger.LogException(
                        new Exception($"Error processing file {e.FullPath}", err), true);
                } finally {
                    // Re-enable events after processing
                    _fileWatcher.EnableRaisingEvents = true;
                }
            }
            else
            {
                _logger.Info(this, String.Format("File/folder '{0}' NOT ready to process", e.Name));
            }
        }