Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }