Exemplo n.º 1
0
        private List <InRiverImportResource> DeserializeRequest(ImportResourcesRequest request)
        {
            _logger.Debug($"Deserializing and preparing {request.ResourceXmlPath} for import.");

            var       serializer = new XmlSerializer(typeof(Resources));
            Resources resources;

            using (XmlReader reader = XmlReader.Create(request.ResourceXmlPath))
            {
                resources = (Resources)serializer.Deserialize(reader);
            }

            var resourcesForImport = new List <InRiverImportResource>();

            foreach (Resource resource in resources.ResourceFiles.Resource)
            {
                var newRes = new InRiverImportResource
                {
                    Action = resource.action
                };

                if (resource.ParentEntries?.EntryCode != null)
                {
                    foreach (Interfaces.Poco.EntryCode entryCode in resource.ParentEntries.EntryCode)
                    {
                        if (String.IsNullOrEmpty(entryCode.Value))
                        {
                            continue;
                        }

                        newRes.Codes.Add(entryCode.Value);
                        newRes.EntryCodes.Add(new EntryCode
                        {
                            Code          = entryCode.Value,
                            IsMainPicture = entryCode.IsMainPicture
                        });
                    }
                }

                if (resource.action != ImporterActions.Deleted)
                {
                    newRes.MetaFields = GenerateMetaFields(resource);

                    // path is ".\some file.ext"
                    if (resource.Paths?.Path != null)
                    {
                        string filePath = resource.Paths.Path.Value.Remove(0, 1);
                        filePath    = filePath.Replace("/", "\\");
                        newRes.Path = request.BasePath + filePath;
                    }
                }

                newRes.ResourceId = resource.id;
                resourcesForImport.Add(newRes);
            }

            return(resourcesForImport);
        }
Exemplo n.º 2
0
        public void ImportResources(ImportResourcesRequest request)
        {
            List <InRiverImportResource> resources = DeserializeRequest(request);

            if (!resources.Any())
            {
                return;
            }

            _logger.Debug($"Starting import of {resources.Count} resources.");

            try
            {
                List <IResourceImporterHandler> importerHandlers =
                    ServiceLocator.Current.GetAllInstances <IResourceImporterHandler>().ToList();

                if (_config.RunResourceImporterHandlers)
                {
                    foreach (IResourceImporterHandler handler in importerHandlers)
                    {
                        handler.PreImport(resources);
                    }
                }

                var errors = 0;

                // TODO: Degree of parallelism should be configurable, default to 2.
                Parallel.ForEach(resources, new ParallelOptions {
                    MaxDegreeOfParallelism = _config.DegreesOfParallelism
                }, resource =>
                {
                    try
                    {
                        ImportResource(resource);
                    }
                    catch (Exception ex)
                    {
                        errors++;
                        _logger.Error("Importing resource failed:", ex);
                    }
                });

                _logger.Information($"Imported/deleted/updated {resources.Count} resources. {errors} errors.");

                if (_config.RunResourceImporterHandlers)
                {
                    foreach (IResourceImporterHandler handler in importerHandlers)
                    {
                        handler.PostImport(resources);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Resource Import Failed", ex);
            }
        }
Exemplo n.º 3
0
        public async Task ImportResources(string resourceXmlFilePath, string baseResourcePath)
        {
            IntegrationLogger.Write(LogLevel.Information, $"Starting Resource Import. Manifest: {resourceXmlFilePath} BaseResourcePath: {baseResourcePath}");

            var importResourcesRequest = new ImportResourcesRequest {
                BasePath = baseResourcePath, ResourceXmlPath = resourceXmlFilePath
            };

            await _httpClient.PostWithAsyncStatusCheck(_config.Endpoints.ImportResources, importResourcesRequest);
        }
        public string ImportResources(ImportResourcesRequest request)
        {
            DoWithErrorHandling(() =>
            {
                Task.Run(
                    () =>
                {
                    ImportStatusContainer.Instance.IsImporting = true;

                    _mediaImporter.ImportResources(request);

                    ImportStatusContainer.Instance.IsImporting = false;
                    ImportStatusContainer.Instance.Message     = "Import Successful";
                });
            });
            return(ImportStatusContainer.Instance.Message);
        }