private void AddEntryRelationElement(StructureEntity structureEntity,
                                             string skuCode,
                                             LinkType linkType)
        {
            var parentProduct = _entityService.GetParentProduct(structureEntity);

            if (parentProduct == null)
            {
                return;
            }

            var parentCode = _catalogCodeGenerator.GetEpiserverCode(parentProduct);

            if (skuCode == parentCode)
            {
                return;
            }

            var addedRelationsName = "EntryRelation_" + _catalogCodeGenerator.GetRelationName(skuCode, parentCode);

            if (_epiElementContainer.HasRelation(addedRelationsName))
            {
                return;
            }

            var entryRelationElement = _catalogElementFactory.CreateEntryRelationElement(parentCode, linkType.SourceEntityTypeId, skuCode, structureEntity.SortOrder);

            _epiElementContainer.AddRelation(entryRelationElement, addedRelationsName);

            IntegrationLogger.Write(LogLevel.Debug, $"Added EntryRelation for {skuCode} to product {parentCode}. Relation name: {addedRelationsName}.");
        }
Ejemplo n.º 2
0
        private void AddNormalAssociations(StructureEntity structureEntity)
        {
            IntegrationLogger.Write(LogLevel.Debug, "AddNormalAssociations");

            string entityCode = _catalogCodeGenerator.GetEpiserverCode(structureEntity.EntityId);
            string parentCode = _catalogCodeGenerator.GetEpiserverCode(structureEntity.ParentId);

            string associationName = _epiMappingHelper.GetAssociationName(structureEntity);

            string associationKey = _catalogCodeGenerator.GetAssociationKey(entityCode, parentCode, associationName);

            if (_epiElementContainer.HasAssociation(associationKey))
            {
                return;
            }

            XElement existingAssociation = GetExistingAssociation(associationName, parentCode);

            if (existingAssociation != null)
            {
                XElement newElement = _catalogElementFactory.CreateAssociationElement(structureEntity);

                if (!existingAssociation.Descendants().Any(e => e.Name.LocalName == "EntryCode" && e.Value == entityCode))
                {
                    existingAssociation.Add(newElement);
                    _epiElementContainer.AddAssociationKey(associationKey);
                }
            }
            else
            {
                XElement associationElement = _catalogElementFactory.CreateCatalogAssociationElement(structureEntity);
                _epiElementContainer.AddAssociation(associationElement, associationKey);
            }
        }
Ejemplo n.º 3
0
        public async Task <ConnectorEvent> CVLValueUpdatedAsync(Entity channel, string cvlId, string cvlValueKey)
        {
            ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config,
                                                                               ConnectorEventType.CVLValueUpdated,
                                                                               $"CVL value updated, updating values in channel: {channel.DisplayName.Data}", 0);

            IEnumerable <FieldType> cvlFieldTypes = RemoteManager.ModelService.GetAllFieldTypes().Where(x => x.CVLId == cvlId);

            List <Criteria> criteria = cvlFieldTypes.Select(cvlFieldType => new Criteria
            {
                FieldTypeId = cvlFieldType.Id,
                Value       = cvlValueKey,
                Operator    = Operator.Equal
            }).ToList();

            var query = new Query {
                Criteria = criteria, Join = Join.Or
            };
            List <Entity> entities = RemoteManager.DataService.Search(query, LoadLevel.DataOnly);

            IntegrationLogger.Write(LogLevel.Debug, $"Found {entities.Count} entities with the CVL {cvlId} to update. Value-key to update: {cvlValueKey}.");

            XDocument updateDocument = _catalogDocumentFactory.CreateUpdateDocument(channel, entities);
            string    folderDateTime = DateTime.Now.ToString(Constants.PublicationFolderNameTimeComponent);

            string savedCatalogDocument = _documentFileHelper.SaveCatalogDocument(channel, updateDocument, folderDateTime);

            await _epiApi.ImportCatalogAsync(savedCatalogDocument);

            ConnectorEventHelper.UpdateEvent(connectorEvent, "Done sending Catalog.xml to EPiServer", 75);

            await _epiApi.NotifyEpiserverPostImportAsync(Path.Combine(_config.PublicationsRootPath, folderDateTime, savedCatalogDocument));

            return(connectorEvent);
        }
Ejemplo n.º 4
0
        public XDocument GetResourcesNodeForChannelEntities(List <StructureEntity> channelEntities, string resourcesBasePath)
        {
            var resourceDocument = new XDocument();

            try
            {
                if (!Directory.Exists(_config.ResourcesRootPath))
                {
                    Directory.CreateDirectory(_config.ResourcesRootPath);
                }

                var resourceIds = new List <int>();
                foreach (StructureEntity structureEntity in channelEntities)
                {
                    if (structureEntity.Type == "Resource" && !resourceIds.Contains(structureEntity.EntityId))
                    {
                        resourceIds.Add(structureEntity.EntityId);
                    }
                }

                List <Entity> resources = RemoteManager.DataService.GetEntities(resourceIds, LoadLevel.DataAndLinks);
                foreach (Entity res in resources)
                {
                    SaveFileToDisk(res, resourcesBasePath);
                }

                resourceDocument = CreateResourceDocument(resources, ImporterActions.Added, true);
            }
            catch (Exception ex)
            {
                IntegrationLogger.Write(LogLevel.Error, "Could not add resources", ex);
            }

            return(resourceDocument);
        }
        private XElement GetSpecificationMetaField(Entity entity)
        {
            var specificationLink = entity.OutboundLinks.FirstOrDefault(IsSpecificationLink);

            if (specificationLink == null)
            {
                return(null);
            }

            IntegrationLogger.Write(LogLevel.Debug, $"Found specification for entity {entity}. Creating MetaField element.");

            XElement specificationMetaField = new XElement("MetaField",
                                                           new XElement("Name", "SpecificationField"),
                                                           new XElement("Type", "LongHtmlString"));

            foreach (var culturePair in _config.LanguageMapping)
            {
                var htmlData = RemoteManager.DataService.GetSpecificationAsHtml(specificationLink.Target.Id, entity.Id, culturePair.Value);
                specificationMetaField.Add(
                    new XElement("Data",
                                 new XAttribute("language", culturePair.Key.Name.ToLower()),
                                 new XAttribute("value", htmlData)));
            }

            return(specificationMetaField);
        }
        public string SaveCatalogDocument(Entity channel, XDocument doc, string folderNameTimestampComponent)
        {
            var dirPath = Path.Combine(_config.PublicationsRootPath, folderNameTimestampComponent);

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            try
            {
                XDocument verified = VerifyAndCorrectDocument(doc);
                doc = verified;
            }
            catch (Exception exception)
            {
                IntegrationLogger.Write(LogLevel.Error, "Fail to verify the document: ", exception);
            }

            var filePath = Path.Combine(dirPath, Constants.CatalogExportFilename);

            var channelIdentifier = _channelHelper.GetChannelIdentifier(channel);

            IntegrationLogger.Write(LogLevel.Information, $"Saving verified document to path {filePath} for channel: {channelIdentifier}");

            doc.Save(filePath);
            return(filePath);
        }
        public string PostWithAsyncStatusCheck <T>(string url, T message)
        {
            IntegrationLogger.Write(LogLevel.Debug, $"Posting to {url}");

            var response = HttpClient.PostAsJsonAsync(url, message).Result;

            if (response.IsSuccessStatusCode)
            {
                var parsedResponse = response.Content.ReadAsAsync <string>().Result;

                while (parsedResponse == ImportStatus.IsImporting)
                {
                    Thread.Sleep(15000);
                    parsedResponse = Get(_isImportingAction);
                }

                if (parsedResponse.StartsWith("ERROR"))
                {
                    IntegrationLogger.Write(LogLevel.Error, parsedResponse);
                }

                return(parsedResponse);
            }

            string errorMsg = $"Import failed: {(int) response.StatusCode} ({response.ReasonPhrase})";

            IntegrationLogger.Write(LogLevel.Error, errorMsg);
            throw new HttpRequestException(errorMsg);
        }
Ejemplo n.º 8
0
 internal static void CleanupOngoingEvents(IConfiguration configuration)
 {
     try
     {
         List <ConnectorEventSession> sessions = RemoteManager.ChannelService.GetOngoingConnectorEventSessions(configuration.ChannelId, configuration.Id);
         foreach (ConnectorEventSession connectorEventSession in sessions)
         {
             ConnectorEvent latestConnectorEvent = connectorEventSession.ConnectorEvents.First();
             var            connectorEvent       = new ConnectorEvent
             {
                 SessionId          = latestConnectorEvent.SessionId,
                 ChannelId          = latestConnectorEvent.ChannelId,
                 ConnectorId        = latestConnectorEvent.ConnectorId,
                 ConnectorEventType = latestConnectorEvent.ConnectorEventType,
                 Percentage         = latestConnectorEvent.Percentage,
                 IsError            = true,
                 Message            = "Event stopped due to closedown of connector",
                 EventTime          = DateTime.Now
             };
             ReportManager.Instance.WriteEvent(connectorEvent);
         }
     }
     catch (Exception e)
     {
         IntegrationLogger.Write(LogLevel.Error, e.Message);
     }
 }
        private void AddNodeEntryRelationElement(LinkType linkType, StructureEntity structureEntity, string skuCode)
        {
            IntegrationLogger.Write(LogLevel.Debug, $"For SKU {skuCode}: Found relation between {linkType.SourceEntityTypeId} and {linkType.TargetEntityTypeId} called {linkType.Id}");

            var parentNode = _channelHelper.GetParentChannelNode(structureEntity);

            if (parentNode == null)
            {
                return;
            }

            var parentCode   = _catalogCodeGenerator.GetEpiserverCode(parentNode);
            var relationName = "NodeEntryRelation_" + _catalogCodeGenerator.GetRelationName(skuCode, parentCode);

            if (_epiElementContainer.HasRelation(relationName))
            {
                return;
            }

            var relationElement = _catalogElementFactory.CreateNodeEntryRelation(parentCode, skuCode, structureEntity.SortOrder);

            _epiElementContainer.AddRelation(relationElement, relationName);

            IntegrationLogger.Write(LogLevel.Debug, $"Added NodeEntryRelation for EntryCode {skuCode}. Relation name: {relationName}.");
        }
        private void DoWithInitCheck(int channelId, ConnectorEventType eventType, Func <Entity, ConnectorEvent> thingsToDo)
        {
            if (channelId != _config.ChannelId)
            {
                return;
            }

            var channelEntity = _channelHelper.InitiateChannelConfiguration(channelId);

            if (channelEntity == null)
            {
                ConnectorEventHelper.InitiateEvent(_config, eventType, $"Failed perform {eventType}. Could not find the channel.", -1, true);
                return;
            }

            try
            {
                var connectorEvent = thingsToDo(channelEntity);

                _entityService.FlushCache();
                _resourceElementFactory.FlushCache();

                var message = $"{eventType} done for channel {channelEntity.Id} ({channelEntity.DisplayName.Data})";

                ConnectorEventHelper.UpdateEvent(connectorEvent, message, 100);
            }
            catch (Exception ex)
            {
                IntegrationLogger.Write(LogLevel.Error, "Exception in ChannelEntityAdded", ex);
                ConnectorEventHelper.InitiateEvent(_config, eventType, ex.Message, -1, true);

                _entityService.FlushCache();
                _resourceElementFactory.FlushCache();
            }
        }
 private static void LogCatalogProperties(CatalogElementContainer epiElements)
 {
     IntegrationLogger.Write(LogLevel.Information, $"Catalog saved with the following: " +
                             $"Nodes: {epiElements.Nodes.Count}. " +
                             $"Entries: {epiElements.Entries.Count}. " +
                             $"Relations: {epiElements.Relations.Count}. " +
                             $"Associations: {epiElements.Associations.Count}. ");
 }
        private void AddNodeElements(List <StructureEntity> batch)
        {
            var nodeStructureEntities = batch.Where(x => x.IsChannelNode() && x.EntityId != _config.ChannelId);

            foreach (var structureEntity in nodeStructureEntities)
            {
                var entity = _entityService.GetEntity(structureEntity.EntityId, LoadLevel.DataOnly);

                if (_config.ChannelId == structureEntity.ParentId)
                {
                    _epiApi.MoveNodeToRootIfNeeded(entity.Id);
                }

                IntegrationLogger.Write(LogLevel.Debug, $"Trying to add channelNode {entity.Id} to Nodes");
                var currentNodeCode = _catalogCodeGenerator.GetEpiserverCode(entity);

                XElement nodeElement = _epiElementContainer.Nodes.FirstOrDefault(e => e.Element("Code")?.Value == currentNodeCode);

                int linkIndex = structureEntity.SortOrder;

                if (nodeElement == null)
                {
                    nodeElement = _catalogElementFactory.CreateNodeElement(entity, structureEntity.ParentId, linkIndex);
                    _epiElementContainer.AddNode(nodeElement, currentNodeCode);
                    IntegrationLogger.Write(LogLevel.Debug, $"Added channelNode {entity.Id} to Nodes");
                }
                else
                {
                    var parentNode = nodeElement.Element("ParentNode");
                    if (parentNode != null &&
                        parentNode.Value != _config.ChannelId.ToString(CultureInfo.InvariantCulture) &&
                        structureEntity.ParentId == _config.ChannelId)
                    {
                        parentNode.Value = _config.ChannelId.ToString(CultureInfo.InvariantCulture);
                        var sortOrderElement = nodeElement.Element("SortOrder");
                        if (sortOrderElement != null)
                        {
                            string oldSortOrder = sortOrderElement.Value;
                            sortOrderElement.Value = linkIndex.ToString(CultureInfo.InvariantCulture);
                            linkIndex = int.Parse(oldSortOrder);
                        }
                    }

                    var relationName = _catalogCodeGenerator.GetRelationName(entity.Id, structureEntity.ParentId);

                    if (_epiElementContainer.HasRelation(relationName))
                    {
                        continue;
                    }

                    var nodeRelationElement = _catalogElementFactory.CreateNodeRelation(structureEntity.ParentId, entity.Id, linkIndex);

                    _epiElementContainer.AddRelation(nodeRelationElement, relationName);

                    IntegrationLogger.Write(LogLevel.Debug, $"Adding relation to channelNode {entity.Id}");
                }
            }
        }
        public new void Start()
        {
            ConnectorEvent startEvent = null;

            try
            {
                _config = new Configuration(Id);
                ConnectorEventHelper.CleanupOngoingEvents(_config);
                startEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.Start, "Connector is starting", 0);

                Entity channel = RemoteManager.DataService.GetEntity(_config.ChannelId, LoadLevel.Shallow);
                if (channel == null || channel.EntityType.Id != "Channel")
                {
                    _started = false;
                    ConnectorEventHelper.UpdateEvent(startEvent, "Channel id is not valid: Entity with given ID is not a channel, or doesn't exist. Unable to start", -1, true);
                    return;
                }

                _pimFieldAdapter      = new PimFieldAdapter(_config);
                _epiMappingHelper     = new EpiMappingHelper(_config, _pimFieldAdapter);
                _entityService        = new EntityService(_config, _epiMappingHelper);
                _catalogCodeGenerator = new CatalogCodeGenerator(_config, _entityService);
                _epiApi = new EpiApi(_config, _catalogCodeGenerator, _pimFieldAdapter);
                _catalogElementFactory  = new CatalogElementFactory(_config, _epiMappingHelper, _catalogCodeGenerator, _pimFieldAdapter);
                _channelHelper          = new ChannelHelper(_config, _entityService);
                _catalogDocumentFactory = new CatalogDocumentFactory(_config, _epiApi, _catalogElementFactory, _epiMappingHelper, _channelHelper, _catalogCodeGenerator, _entityService);
                _resourceElementFactory = new ResourceElementFactory(_catalogElementFactory, _epiMappingHelper, _catalogCodeGenerator, _config, _entityService);

                _documentFileHelper = new DocumentFileHelper(_config, _channelHelper);
                _cvlUpdater         = new CvlUpdater(_config, _catalogDocumentFactory, _epiApi, _documentFileHelper);

                _publisher = new ChannelPublisher(_config,
                                                  _catalogDocumentFactory,
                                                  _catalogElementFactory,
                                                  _resourceElementFactory,
                                                  _epiApi,
                                                  _epiMappingHelper,
                                                  _documentFileHelper,
                                                  _pimFieldAdapter,
                                                  _entityService,
                                                  _catalogCodeGenerator);

                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;

                InitConnector();

                base.Start();
                _started = true;
                ConnectorEventHelper.UpdateEvent(startEvent, "Connector has started", 100);
            }
            catch (Exception ex)
            {
                IntegrationLogger.Write(LogLevel.Error, "Error while starting connector", ex);
                ConnectorEventHelper.UpdateEvent(startEvent, "Issue while starting connector, see log.", 100, true);
                throw;
            }
        }
        public void UnPublish(int channelId)
        {
            if (channelId != _config.ChannelId)
            {
                return;
            }

            IntegrationLogger.Write(LogLevel.Information, $"Unpublish on channel: {channelId} called. No action taken.");
        }
        private void AddEntryElements(IEnumerable <StructureEntity> batch)
        {
            foreach (StructureEntity structureEntity in batch
                     .Where(x => x.EntityId != _config.ChannelId && !x.IsChannelNode()))
            {
                Entity entity = _entityService.GetEntity(structureEntity.EntityId, LoadLevel.DataAndLinks);

                if (ShouldCreateSkus(structureEntity))
                {
                    List <XElement> skus = _catalogElementFactory.GenerateSkuItemElemetsFromItem(entity);
                    foreach (XElement sku in skus)
                    {
                        XElement codeElement = sku.Element("Code");

                        if (codeElement == null || _epiElementContainer.HasEntry(codeElement.Value))
                        {
                            continue;
                        }

                        _epiElementContainer.AddEntry(sku, codeElement.Value);
                        IntegrationLogger.Write(LogLevel.Debug, $"Added Item/SKU {sku.Name.LocalName} to Entries");
                    }
                }

                if ((!structureEntity.IsItem() || !_config.ItemsToSkus || !_config.UseThreeLevelsInCommerce) && ShouldCreateSkus(structureEntity))
                {
                    continue;
                }
                {
                    if (structureEntity.IsItem() && !_channelHelper.ItemHasParentInChannel(structureEntity))
                    {
                        continue;
                    }

                    XElement element = _catalogElementFactory.InRiverEntityToEpiEntry(entity);

                    XElement codeElement = element.Element("Code");
                    if (codeElement == null || _epiElementContainer.HasEntry(codeElement.Value))
                    {
                        continue;
                    }

                    XElement specificationField = GetSpecificationMetaField(entity);

                    if (specificationField != null)
                    {
                        XElement metaFieldsElement = element.Descendants().FirstOrDefault(f => f.Name == "MetaFields");
                        metaFieldsElement?.Add(specificationField);
                    }

                    _epiElementContainer.AddEntry(element, codeElement.Value);

                    IntegrationLogger.Write(LogLevel.Debug, $"Added Entity {entity.Id} to Entries");
                }
            }
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
        private IEnumerable <string> GetDisplayConfigurations(Entity resource)
        {
            if (IsImage(resource))
            {
                return(_config.ResourceConfigurations);
            }

            IntegrationLogger.Write(LogLevel.Debug, $"No image configuration found for Resource {resource.Id}. Original will be used");
            return(new[] { Configuration.OriginalDisplayConfiguration });
        }
        public void Post <T>(string url, T message)
        {
            IntegrationLogger.Write(LogLevel.Debug, $"Posting to {url}");
            var timer = Stopwatch.StartNew();

            var response = HttpClient.PostAsJsonAsync(url, message).Result;

            response.EnsureSuccessStatusCode();

            IntegrationLogger.Write(LogLevel.Debug, $"Posted to {url}, took {timer.ElapsedMilliseconds}.");
        }
Ejemplo n.º 19
0
        public async Task PostAsync <T>(string url, T message)
        {
            IntegrationLogger.Write(LogLevel.Debug, $"Posting to {url}");
            Stopwatch timer = Stopwatch.StartNew();

            HttpResponseMessage response = await HttpClient.PostAsJsonAsync(url, message);

            response.EnsureSuccessStatusCode();

            IntegrationLogger.Write(LogLevel.Debug, $"Posted to {url}, took {timer.ElapsedMilliseconds}.");
        }
Ejemplo n.º 20
0
        public async Task <ConnectorEvent> ChannelEntityUpdatedAsync(Entity channel, int entityId, string data)
        {
            ConnectorEvent connectorEvent = ConnectorEventHelper.InitiateEvent(_config, ConnectorEventType.ChannelEntityUpdated,
                                                                               $"Received entity update for entity {entityId} in channel {channel.DisplayName}", 0);


            Entity updatedEntity = _entityService.GetEntity(entityId, LoadLevel.DataAndLinks);

            if (updatedEntity.EntityType.IsLinkEntityType)
            {
                return(connectorEvent);
            }

            string folderDateTime   = DateTime.Now.ToString(Constants.PublicationFolderNameTimeComponent);
            bool   resourceIncluded = false;
            List <StructureEntity> structureEntities = _entityService.GetStructureEntitiesForEntityInChannel(_config.ChannelId, entityId);

            if (updatedEntity.EntityType.Id.Equals("Resource"))
            {
                resourceIncluded = await HandleResourceUpdateAsync(updatedEntity, folderDateTime);
            }
            else
            {
                IntegrationLogger.Write(LogLevel.Debug, $"Updated entity found. Type: {updatedEntity.EntityType.Id}, id: {updatedEntity.Id}");

                if (updatedEntity.EntityType.Id.Equals("Item") && data != null && data.Split(',').Contains("SKUs"))
                {
                    resourceIncluded = await HandleSkuUpdateAsync(entityId, channel, connectorEvent, structureEntities);
                }
                else if (updatedEntity.EntityType.Id.Equals("ChannelNode"))
                {
                    await HandleChannelNodeUpdateAsync(channel, structureEntities, connectorEvent);

                    return(connectorEvent);
                }

                XDocument doc = _catalogDocumentFactory.CreateUpdateDocument(channel, updatedEntity);

                string catalogDocumentName = _documentFileHelper.SaveCatalogDocument(channel, doc, folderDateTime);

                IntegrationLogger.Write(LogLevel.Debug, "Starting automatic import!");

                await _epiApi.ImportCatalogAsync(catalogDocumentName);

                await _epiApi.NotifyEpiserverPostImportAsync(catalogDocumentName);
            }

            string channelName = _mappingHelper.GetNameForEntity(channel, 100);
            await _epiApi.ImportUpdateCompletedAsync(channelName, ImportUpdateCompletedEventType.EntityUpdated, resourceIncluded);

            return(connectorEvent);
        }
        public XDocument SkuFieldToDocument(Entity item)
        {
            Field skuField = item.GetField(FieldNames.SKUFieldName);

            if (skuField == null || skuField.Data == null)
            {
                XElement itemElement = InRiverEntityToEpiEntry(item);
                IntegrationLogger.Write(LogLevel.Information, $"Could not find SKU data for item: {item.Id}");
                return(new XDocument(itemElement));
            }

            return(XDocument.Parse(skuField.Data.ToString()));
        }
        public string SaveDocument(XDocument doc, string path)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var filePath = Path.Combine(path, Constants.ResourceExportFilename);

            IntegrationLogger.Write(LogLevel.Information, $"Saving document to path {filePath}.");
            doc.Save(filePath);
            return(filePath);
        }
        public Entity InitiateChannelConfiguration(int channelId)
        {
            Entity channel = _entityService.GetEntity(channelId, LoadLevel.DataOnly);

            if (channel == null)
            {
                IntegrationLogger.Write(LogLevel.Error, "Could not find channel");
                return(null);
            }

            UpdateChannelSettings(channel);
            return(channel);
        }
Ejemplo n.º 24
0
 internal void DeleteSkus(List <string> skuIds)
 {
     lock (EpiLockObject.Instance)
     {
         try
         {
             _httpClient.Post(_config.Endpoints.DeleteCatalogEntry, new DeleteRequest(skuIds));
         }
         catch (Exception exception)
         {
             IntegrationLogger.Write(LogLevel.Error, $"Failed to delete skus: {string.Join(",", skuIds)}", exception);
         }
     }
 }
Ejemplo n.º 25
0
 internal void DeleteSku(string skuId)
 {
     lock (EpiLockObject.Instance)
     {
         try
         {
             _httpClient.PostWithAsyncStatusCheck(_config.Endpoints.DeleteCatalogEntry, skuId);
         }
         catch (Exception exception)
         {
             IntegrationLogger.Write(LogLevel.Error, $"Failed to delete catalog entry based on SKU ID: {skuId}", exception);
         }
     }
 }
Ejemplo n.º 26
0
 internal void DeleteCatalog(int catalogId)
 {
     lock (EpiLockObject.Instance)
     {
         try
         {
             _httpClient.PostWithAsyncStatusCheck(_config.Endpoints.DeleteCatalog, catalogId);
         }
         catch (Exception exception)
         {
             IntegrationLogger.Write(LogLevel.Error, $"Failed to delete catalog with id: {catalogId}", exception);
         }
     }
 }
Ejemplo n.º 27
0
 internal void DeleteCatalogNode(Entity catalogNode, int catalogId)
 {
     lock (EpiLockObject.Instance)
     {
         try
         {
             var code = _catalogCodeGenerator.GetEpiserverCode(catalogNode);
             _httpClient.Post(_config.Endpoints.DeleteCatalogNode, code);
         }
         catch (Exception ex)
         {
             IntegrationLogger.Write(LogLevel.Error, $"Failed to delete catalogNode with id: {catalogNode.Id} for channel: {catalogId}", ex);
         }
     }
 }
Ejemplo n.º 28
0
 internal void MoveNodeToRootIfNeeded(int entityId)
 {
     lock (EpiLockObject.Instance)
     {
         try
         {
             string entryNodeId = _catalogCodeGenerator.GetEpiserverCode(entityId);
             _httpClient.PostWithAsyncStatusCheck(_config.Endpoints.CheckAndMoveNodeIfNeeded, entryNodeId);
         }
         catch (Exception exception)
         {
             IntegrationLogger.Write(LogLevel.Warning, "Failed when calling the interface function: CheckAndMoveNodeIfNeeded", exception);
         }
     }
 }
Ejemplo n.º 29
0
        internal static ConnectorEvent UpdateEvent(ConnectorEvent connectorEvent, string message, int percentage, bool error = false)
        {
            IntegrationLogger.Write(LogLevel.Debug, message);

            if (percentage >= 0)
            {
                connectorEvent.Percentage = percentage;
            }

            connectorEvent.Message   = message;
            connectorEvent.IsError   = error;
            connectorEvent.EventTime = DateTime.Now;
            ReportManager.Instance.WriteEvent(connectorEvent);
            return(connectorEvent);
        }
Ejemplo n.º 30
0
        internal bool SaveFileToDisk(Entity resource, string resourcesBasePath)
        {
            try
            {
                int resourceFileId = GetResourceFileId(resource);
                if (resourceFileId < 0)
                {
                    IntegrationLogger.Write(LogLevel.Information, $"Resource with id:{resource.Id} has no value for ResourceFileId");
                    return(false);
                }

                foreach (string displayConfiguration in GetDisplayConfigurations(resource))
                {
                    byte[] resourceData = RemoteManager.UtilityService.GetFile(resourceFileId, displayConfiguration);
                    if (resourceData == null)
                    {
                        IntegrationLogger.Write(LogLevel.Error, $"Resource with id:{resource.Id} and ResourceFileId: {resourceFileId} could not get file");
                        return(false);
                    }

                    string fileName = GetResourceFileName(resource, resourceFileId, displayConfiguration);

                    string folder = GetFolderName(displayConfiguration, resource);
                    string dir    = Path.Combine(resourcesBasePath, folder);

                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    string fullFilePath = Path.Combine(dir, fileName);

                    File.WriteAllBytes(fullFilePath, resourceData);
                    IntegrationLogger.Write(LogLevel.Debug, $"Saving Resource {resource.Id} to {fullFilePath}.");
                }
            }
            catch (Exception ex)
            {
                if (resource != null)
                {
                    IntegrationLogger.Write(LogLevel.Error, $"Could not save resource! id:{resource.Id}, ResourceFileId:{resource.GetField("ResourceFileId")}", ex);
                }

                return(false);
            }

            return(true);
        }