private void Crawler(string directoryName, Func <string, bool> ignorePaths, string dir) { var finder = new LogFileFinder(WriteFile, _fileSystem, _logger, ignorePaths); string localPath = _fileSystem.Path.Combine(_serviceVariables.OutputFolderPath, directoryName, _fileSystem.Path.GetFileName(dir) + ""); _fileSystem.EnsureDirectory(localPath); _folderNotificationHelper.SetCurrentFolderNames(null, dir); finder.FindFilesInDirectories(new DirectorySetting(dir), _serviceVariables.StartDateForLogs, _serviceVariables.StopDateForLogs, localPath); Debug.WriteLine("found=>" + dir); }
public void Execute(CommonCollectorServiceVariables serviceVariables) { _serviceVariables = serviceVariables; //_serviceVariables.QvSettings.QvLogLocations = new List<QvLogLocation>(); //_serviceVariables.QvSettings.QvLogLocations.Add(new QvLogLocation //{ // Name = $"CommonFiles - QlikTech - su-pubdev2", // Type = QvLogLocationSource.QdsClusterInfoUrl, // Path = $"\\\\su-pubdev2\\c$\\ProgramData\\QlikTech", // LogCollectionType = QvLogCollectionType.SettingsOnly //}); var cts = new CancellationTokenSource(); var cancellationToken = cts.Token; _folderNotificationHelper = new FolderNotificationHelper(_logger, _notify, _notificationKey, _serviceVariables); Task.Run(async() => { while (true) { await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken); _folderNotificationHelper.Analyze(_localFileCounter, _localDirCounter); if (cancellationToken.IsCancellationRequested) { break; } } }, cancellationToken); _serviceVariables.QvSettings.QvLogLocations.ForEach(p => { _folderNotificationHelper.SetCurrentFolderNames(p.Name, null); CrawlAllLogBaseDirectories(new DirectorySetting(p.Path), p.Name, p.IgnorePaths); p.AddToFileCount(_localFileCounter); Interlocked.Exchange(ref _localFileCounter, 0); Interlocked.Exchange(ref _localDirCounter, 0); }); cts.Cancel(); _notify($"{FoundFileCount} logs found on {_serviceVariables.QvSettings.QvLogLocations.Count} locations.", MessageLevels.Ok, _notificationKey); }