/// <summary> /// Colllects measurements from the given host every 50 milliseconds until the given time has expired <para/> /// If <c>mode</c> is <c>Performance</c>, each line in the result will have a single value representing the performance as percent of the total (e.g. "0" to "100") <para/> /// If <c>mode</c> is <c>Delays</c>, each line in the result will have one or more values, separated by ", ", representing the millisecond delays encountered (e.g. "2, 4, 3") <para/> /// If <c>mode</c> is <c>HitRate</c>, each line in the result will have number of hits and total attempts, separated by "/" (e.g. "86/99") /// </summary> /// <param name="mode">Collector mode to use</param> /// <param name="duration">Duration during which measurements will be collected</param> /// <returns></returns> public virtual List <String> Collect(CollectorMode mode, TimeSpan duration) { var result = new List <String>(); DateTime end = DateTime.Now.Add(duration); while (DateTime.Now < end) { switch (mode) { case CollectorMode.Performance: result.Add(CollectPerformance()); break; case CollectorMode.Delays: result.Add(CollectDelays()); break; case CollectorMode.HitRate: result.Add(CollectHitRate()); break; default: throw new ArgumentException("Unknown collector mode: " + mode.ToString()); } System.Threading.Thread.Sleep(50); } return(result); }
public void ShowWindowEx(CollectorDialogInitData initData) { Filename = initData.Filename; Username = initData.Username; switch (initData.Mode) { case CollectorDialogDisplayType.ENCRYPT: Mode = CollectorMode.ENCRYPT; break; case CollectorDialogDisplayType.DECRYPT_OVERWRITE_NO: Mode = CollectorMode.DECRYPT; DeleteAfterCB.Visibility = System.Windows.Visibility.Collapsed; break; case CollectorDialogDisplayType.DECRYPT_OVERWRITE_YES: Mode = CollectorMode.DECRYPT; break; default: log.Error("Unacceptable work mode"); break; } ShowState(); try { log.Info("Show Window called"); this.Topmost = true; this.Show(); // Check if association is ok? AssociationCheck(); } catch (Exception ex) { log.Info(ex); } }
private async Task <IEnumerable <string> > CollectGroupAsync(string groupName, CollectorMode collectorMode, IEnumerable <DataCollectionConfig> dataCollectionsConfig, CancellationToken cancellationToken) { var result = new List <string>(); foreach (var dataCollectionConfig in dataCollectionsConfig) { try { var(newFileNames, collectionFileInfos) = await _dataCollector.CollectDataAsync(collectorMode, dataCollectionConfig, cancellationToken); if (collectorMode == CollectorMode.Collect) { await _dataCollector.GarbageCollectDataAsync(dataCollectionConfig, newFileNames, collectionFileInfos, cancellationToken); } } catch { result.Add(dataCollectionConfig.DataCollectionName); // Give other DataCollections a chance } } return(result); }
public async Task <(IEnumerable <string> NewFileNames, IEnumerable <IFileInfo> CollectionFileInfos)> CollectDataAsync(CollectorMode collectorMode, DataCollectionConfig dataCollectionConfig, CancellationToken cancellationToken) { try { (IEnumerable <string> NewFileNames, IEnumerable <IFileInfo> CollectionFileInfos)result; _logger.LogInformation("Started processing data '{dataCollectionName}'", dataCollectionConfig.DataCollectionName); var watch = System.Diagnostics.Stopwatch.StartNew(); try { result = await _dataCollector.CollectDataAsync(collectorMode, dataCollectionConfig, cancellationToken); result = (result.NewFileNames.ToList(), result.CollectionFileInfos.ToList()); } finally { watch.Stop(); } _logger.LogInformation("Finished processing data '{dataCollectionName}'. Elapsed time: {elapsed}", dataCollectionConfig.DataCollectionName, watch.Elapsed); return(result); } catch (Exception e) { _logger.LogCritical("Error processing data '{dataCollectionName}': {errorMessage}", dataCollectionConfig.DataCollectionName, e.GetAggregateMessages()); throw; } }
public async Task <(IEnumerable <string> NewFileNames, IEnumerable <IFileInfo> CollectionFileInfos)> CollectDataAsync(CollectorMode collectorMode, DataCollectionConfig dataCollectionConfig, CancellationToken cancellationToken) { // assert at least one destination before preparing var destinations = await GetDestinationsAsync(dataCollectionConfig.DestinationIds, cancellationToken); if (!destinations.Any()) { throw new Exception("No destinations found"); } if ((dataCollectionConfig.InitialDelay ?? default).TotalSeconds > 0) { await _delay.DelayAsync(dataCollectionConfig.InitialDelay ?? default, $"initial delay for Data '{dataCollectionConfig.DataCollectionName}'", cancellationToken); } var collectMoment = DateTimeOffset.Now; var prepared = (collectorMode != CollectorMode.Collect) ? false : await _dataPreparer.PrepareDataAsync(dataCollectionConfig, cancellationToken); var collectItems = _collectItemsProvider.GetCollectItems(dataCollectionConfig.DataCollectionName, dataCollectionConfig.CollectFileIdentifiersUrl, dataCollectionConfig.CollectFileIdentifiersHeaders, dataCollectionConfig.CollectUrl, dataCollectionConfig.CollectHeaders, dataCollectionConfig.IdentityServiceClientInfo, cancellationToken).ToList(); var collectionFileInfos = collectItems.Select(x => x.CollectFileInfo); var acceptedCollectItems = await GetAcceptedCollectItemsAsync(collectItems, dataCollectionConfig.DataCollectionName, destinations, dataCollectionConfig.CollectParallelFileCount ?? 1, cancellationToken); if (collectorMode == CollectorMode.Collect) { if (prepared && (!acceptedCollectItems.Any())) { throw new Exception("No data prepared for collecting"); } if (dataCollectionConfig.MaxFileCount.HasValue) { acceptedCollectItems = acceptedCollectItems.Take(dataCollectionConfig.MaxFileCount.Value); } var redirectedCollectItems = await _collectItemsProvider.GetRedirectedCollectItemsAsync(acceptedCollectItems, dataCollectionConfig.DataCollectionName, dataCollectionConfig.CollectHeaders, dataCollectionConfig.CollectParallelFileCount ?? 1, dataCollectionConfig.IdentityServiceClientInfo, cancellationToken); var newFileNames = await _collectItemsCollector.CollectItemsAsync(redirectedCollectItems, dataCollectionConfig.DataCollectionName, destinations, dataCollectionConfig, collectMoment, cancellationToken); return(newFileNames, collectionFileInfos); } if ((collectorMode == CollectorMode.Check) && acceptedCollectItems.Any()) { throw new Exception("Found missing data"); } return(Enumerable.Empty <string>(), collectionFileInfos); }