Пример #1
0
        public async Task <StacNode> ExtractMetadata(StacItemNode itemNode, IDestination destination, StacStoreService storeService)
        {
            StacNode newItemNode = itemNode;

            foreach (var processing in processingManager.GetProcessings(ProcessingType.MetadataExtractor))
            {
                if (!processing.CanProcess(newItemNode, destination))
                {
                    continue;
                }
                // Create a new destination for each processing
                IDestination procDestination   = destination.To(itemNode, processing.GetRelativePath(itemNode, destination));
                var          processedResource = await processing.Process(newItemNode, procDestination);

                StacItemNode stacItemNode = processedResource as StacItemNode;
                // Maybe the node is already a stac node
                if (stacItemNode == null)
                {
                    // No? Let's try to translate it to Stac
                    stacItemNode = await translatorManager.Translate <StacItemNode>(processedResource);

                    if (stacItemNode == null)
                    {
                        throw new InvalidDataException(string.Format("Impossible to translate node {0} into STAC.", processedResource.Uri));
                    }
                }
                newItemNode = await storeService.StoreItemNodeAtDestination(stacItemNode, destination);
            }
            return(newItemNode);
        }
Пример #2
0
        private async Task <IAsset> DeliverTarEntry(TarEntryAsset tarEntryAsset, IDestination destination, CarrierManager carrierManager)
        {
            var archiveAssetDestination = destination.To(tarEntryAsset);

            archiveAssetDestination.PrepareDestination();
            var assetDeliveries = carrierManager.GetSingleDeliveryQuotations(tarEntryAsset, archiveAssetDestination);

            logger.LogDebug(tarEntryAsset.Name);
            var assetExtracted = await assetDeliveries.First().Carrier.Deliver(assetDeliveries.First());

            return(new GenericAsset(assetExtracted, tarEntryAsset.Name, new string[] { "data" }));
        }
Пример #3
0
        public async Task <StacNode> ExtractArchive(StacItemNode stacItemNode, IDestination destination, StacStoreService storeService)
        {
            StacNode newItemNode = stacItemNode;

            foreach (var processing in processingManager.GetProcessings(ProcessingType.ArchiveExtractor))
            {
                if (!processing.CanProcess(newItemNode, destination))
                {
                    continue;
                }
                // Create a new destination for each processing
                IDestination procDestination = destination.To(stacItemNode, processing.GetRelativePath(stacItemNode, destination));
                StacItemNode newStacItemNode = null;
                try
                {
                    var processedResource = await processing.Process(newItemNode, procDestination);

                    if (processedResource == null)
                    {
                        continue;
                    }
                    newStacItemNode = processedResource as StacItemNode;

                    // Maybe the node is already a stac node
                    if (newStacItemNode == null)
                    {
                        // No? Let's try to translate it to Stac
                        newStacItemNode = await translatorManager.Translate <StacItemNode>(processedResource);

                        if (newStacItemNode == null)
                        {
                            throw new InvalidDataException(string.Format("Impossible to translate node {0} into STAC.", processedResource.Uri));
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.LogWarning("Exception extracting archive assets in {0} : {1}", newItemNode.Uri, e.Message);
                    continue;
                }
                newItemNode = await storeService.StoreItemNodeAtDestination(newStacItemNode, destination);

                break;
            }
            return(newItemNode);
        }
Пример #4
0
        internal async override Task <IAssetsContainer> ExtractToDestination(IDestination destination, CarrierManager carrierManager)
        {
            Dictionary <string, IAsset> assetsExtracted = new Dictionary <string, IAsset>();
            string subFolder = AutodetectSubfolder();

            foreach (var archiveAsset in Assets)
            {
                var archiveAssetDestination = destination.To(archiveAsset.Value, subFolder);
                archiveAssetDestination.PrepareDestination();
                var assetDeliveries = carrierManager.GetSingleDeliveryQuotations(archiveAsset.Value, archiveAssetDestination);
                logger.LogDebug(archiveAsset.Key);
                foreach (var delivery in assetDeliveries)
                {
                    var assetExtracted = await delivery.Carrier.Deliver(delivery);

                    if (assetExtracted != null)
                    {
                        assetsExtracted.Add(asset.ContentDisposition.FileName + "!" + archiveAsset.Key, new GenericAsset(assetExtracted, archiveAsset.Value.Title, archiveAsset.Value.Roles));
                        break;
                    }
                }
            }
            return(new GenericAssetContainer(this, assetsExtracted));
        }
Пример #5
0
        public IDeliveryQuotation GetAssetsDeliveryQuotations(IAssetsContainer assetsContainer, IDestination destination)
        {
            Dictionary <string, IOrderedEnumerable <IDelivery> > assetsQuotes = new Dictionary <string, IOrderedEnumerable <IDelivery> >();
            Dictionary <string, Exception> assetsExceptions = new Dictionary <string, Exception>();

            foreach (var asset in assetsContainer.Assets)
            {
                try
                {
                    string relPath = null;
                    if (assetsContainer.Uri != null && assetsContainer.Uri.IsAbsoluteUri)
                    {
                        var relUri = assetsContainer.Uri.MakeRelativeUri(asset.Value.Uri);
                        // Use the relative path only if a sub-directory
                        if (!relUri.IsAbsoluteUri && !relUri.ToString().StartsWith(".."))
                        {
                            relPath = Path.GetDirectoryName(relUri.ToString());
                        }
                    }
                    var assetsDeliveryQuotations = GetSingleDeliveryQuotations(asset.Value, destination.To(asset.Value, relPath));
                    assetsQuotes.Add(asset.Key, assetsDeliveryQuotations);
                }
                catch (Exception e)
                {
                    logger.LogDebug("Cannot quote delivery for {0}: {1}", asset.Value.Uri, e.Message);
                    assetsExceptions.Add(asset.Key, e);
                }
            }
            return(new DeliveryQuotation(assetsQuotes, assetsExceptions));
        }