protected void UpdateCoreInfos() { if (!TryCreateDirectory(_infoDirectory)) { return; } if (!TryCreateAbsoluteUrl(_baseUrl, _infoUrl, out Uri uri)) { ServiceRegistration.Get <ILogger>().Error("CoreHandler: Unable to create absolute core info url from settings, base url: '{0}', info url: '{1}'", _baseUrl, _infoUrl); return; } try { byte[] data = _downloader.DownloadDataAsync(uri.AbsoluteUri).Result; if (data == null || data.Length == 0) { ServiceRegistration.Get <ILogger>().Error("CoreInfoHandler: Failed to download core infos from '{0}', response was null or empty", uri.AbsoluteUri); return; } using (Stream stream = new MemoryStream(data)) using (IExtractor extractor = ExtractorFactory.Create(uri.AbsoluteUri, stream)) extractor.ExtractAll(_infoDirectory); } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("CoreInfoHandler: Exception updating core infos", ex); } }
private async Task BeginExtraction(CancellationToken cancellationToken) { try { using var scope = _serviceProvider.CreateScope(); var repository = scope.ServiceProvider.GetRequiredService <IItemRepository>(); var mediator = scope.ServiceProvider.GetRequiredService <IMediator>(); var commandList = new ConcurrentBag <UpdatePriceCommand>(); var items = await repository.ListAll(); var tasks = items.Select(async(x) => { try { if (!cancellationToken.IsCancellationRequested) { var extractor = ExtractorFactory.Create(x.Url); if (await extractor.ExtractValues(x, cancellationToken)) { _logger.LogInformation($"Price changed for {x.Name} to {extractor.InCashValue}"); commandList.Add(new UpdatePriceCommand(x.Id, extractor.InCashValue, extractor.NormalValue, extractor.FullValue, extractor.IsAvailable)); } } } catch (Exception e) { _logger.LogError($"Error calling url for product {x.Name}.", e); } }); await Task.WhenAll(tasks); foreach (var cmd in commandList) { await mediator.Send(cmd, cancellationToken); } } catch (OperationCanceledException e) { _logger.LogInformation("Cancelling " + e.Message); if (cancellationToken.IsCancellationRequested) { _logger.LogInformation("Cancelling per user request."); cancellationToken.ThrowIfCancellationRequested(); } } }
protected bool ExtractCore(string path) { bool extracted; using (IExtractor extractor = ExtractorFactory.Create(path)) { if (!extractor.IsArchive()) { return(true); } extracted = extractor.ExtractAll(Path.GetDirectoryName(path)); } if (extracted) { TryDeleteFile(path); } return(extracted); }
protected void DoExtract(ILocalFsResourceAccessor accessor, string selectedItem) { string resourcePath = accessor.CanonicalLocalResourcePath.LastPathSegment.Path; string extractionPath = GetExtractionPath(resourcePath, selectedItem); Logger.Debug("GoodMergeExtractor: Extracting '{0}' from '{1}' to '{2}'", selectedItem, resourcePath, extractionPath); bool result; using (IExtractor extractor = ExtractorFactory.Create(accessor.LocalFileSystemPath)) { extractor.ExtractionProgress += OnExtractionProgress; result = extractor.ExtractArchiveFile(selectedItem, extractionPath); } if (!result) { //Sometimes an empty file has been created when extraction fails DeleteExtractedFile(extractionPath); } _extractionThread = null; OnExtractionCompleted(new ExtractionCompletedEventArgs(selectedItem, extractionPath, result)); }
public static void Check(string text, string rules, IEnumerable <ExtractionDic> etalon, ExtractorSettings settings = null, IEnumerable <IExtension> extensions = null, IMorphAnalizer morph = null, params string[] rulesToExtract) { if (settings == null) { settings = new ExtractorSettings(); } var extractor = ExtractorFactory.Create(rules, settings, extensions: extensions, morph: morph); var result = extractor.Parse(text, rulesToExtract); _check(etalon.ToArray(), result.ToArray()); }
protected static bool ExtractGoodMergeData(string path, IDictionary <Guid, IList <MediaItemAspect> > extractedAspectData) { List <string> items; using (IExtractor extractor = ExtractorFactory.Create(path)) { if (!extractor.IsArchive()) { return(false); } items = extractor.GetArchiveFiles(); } if (items != null && items.Count > 0) { Logger.Debug("GoodMergeMetadataExtractor: Found {0} items in archive '{1}'", items.Count, path); MediaItemAspect.SetCollectionAttribute(extractedAspectData, GoodMergeAspect.ATTR_GOODMERGE_ITEMS, items); return(true); } else { Logger.Warn("GoodMergeMetadataExtractor: File '{0}' is empty or not a valid archive", path); } return(false); }