public void LoadAndRead(DirectorySetting[] directories, CommonCollectorServiceVariables settings) { _settings = settings; if (!settings.GetLogsScripting) { _ignoredFiles = SenseLogBaseTypes.Script; } var cts = new CancellationTokenSource(); var cancellationToken = cts.Token; _folderNotificationHelper = new FolderNotificationHelper(_logger, _notify, NotificationKey, _settings); Task.Run(async() => { while (true) { await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken); _folderNotificationHelper.Analyze(_localFileCounter, _localDirCounter); if (cancellationToken.IsCancellationRequested) { break; } } }, cancellationToken); foreach (DirectorySetting directory in directories) { CrawlAllLogBaseDirectories(directory); } cts.Cancel(); //_onLogDirectorFinishedReading?.Invoke(this); }
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); }