コード例 #1
0
        public void DeleteLinkEntity(Entity channelEntity, int linkEntityId)
        {
            XDocument deleteXml = new XDocument(new XElement("xml", new XAttribute("action", "deleted")));

            var channelHelper = new ChannelHelper(_context);

            if (deleteXml.Root != null && deleteXml.Root.Elements().FirstOrDefault(e => e.Name.LocalName == "entry") != null)
            {
                string channelIdentifier = channelHelper.GetChannelIdentifier(channelEntity);
                string folderDateTime    = DateTime.Now.ToString("yyyyMMdd-HHmmss.fff");


                if (!DocumentFileHelper.ZipDocumentAndUploadToAzure(XmlDocumentType.Catalog, deleteXml, DeleteUtilConfig, folderDateTime))
                {
                    _context.Log(LogLevel.Information, "Failed to zip and upload the catalog file to azure from delete utility DeleteLinkEntity() method");
                }
                _context.Log(LogLevel.Debug, "catalog saved");
            }
        }
コード例 #2
0
        public void Delete(Entity channelEntity, int parentEntityId, Entity targetEntity, string linkTypeId, List <int> productParentIds = null)
        {
            var    channelHelper     = new ChannelHelper(_context);
            string channelIdentifier = channelHelper.GetChannelIdentifier(channelEntity);
            string folderDateTime    = DateTime.Now.ToString("yyyyMMdd-HHmmss.fff");

            channelHelper.BuildEntityIdAndTypeDict(DeleteUtilConfig);


            if (!DeleteUtilConfig.ChannelEntities.ContainsKey(targetEntity.Id))
            {
                DeleteUtilConfig.ChannelEntities.Add(targetEntity.Id, targetEntity);
            }

            string resourceZipFile = string.Format("resource_{0}.zip", folderDateTime);

            if (_context.ExtensionManager.ChannelService.EntityExistsInChannel(channelEntity.Id, targetEntity.Id))
            {
                var existingEntities = _context.ExtensionManager.ChannelService.GetAllStructureEntitiesForEntityInChannel(
                    channelEntity.Id,
                    targetEntity.Id);

                Entity parentEnt = _context.ExtensionManager.DataService.GetEntity(parentEntityId, LoadLevel.DataOnly);

                if (parentEnt != null)
                {
                    if (!DeleteUtilConfig.ChannelEntities.ContainsKey(parentEnt.Id))
                    {
                        DeleteUtilConfig.ChannelEntities.Add(parentEnt.Id, parentEnt);
                    }
                    if (targetEntity.EntityType.Id == "Resource")
                    {
                        DeleteResource(
                            targetEntity,
                            parentEnt,
                            channelIdentifier,
                            folderDateTime,
                            resourceZipFile);
                    }
                    else
                    {
                        DeleteEntityThatStillExistInChannel(
                            channelEntity,
                            targetEntity,
                            parentEnt,
                            linkTypeId,
                            existingEntities,
                            channelIdentifier,
                            folderDateTime,
                            resourceZipFile);
                    }
                }
                else
                {
                    _context.Log(LogLevel.Information, $"Unable to find entity {parentEntityId} (already deleted?)");
                }
            }
            else
            {
                //DeleteEntity
                DeleteEntity(
                    channelEntity,
                    parentEntityId,
                    targetEntity,
                    linkTypeId,
                    channelIdentifier,
                    folderDateTime,
                    productParentIds);
            }
        }
コード例 #3
0
        public void AddCvl(string cvlId, string folderDateTime)
        {
            List <XElement>  metafields         = new List <XElement>();
            List <FieldType> affectedFieldTypes = _businessHelper.GetFieldTypesWithCVL(cvlId, CvlUtilConfig);

            foreach (FieldType fieldType in affectedFieldTypes)
            {
                if (_epiMappingHelper.SkipField(fieldType, CvlUtilConfig))
                {
                    continue;
                }

                XElement metaField = _epiElement.InRiverFieldTypeToMetaField(fieldType, CvlUtilConfig);

                if (fieldType.DataType.Equals(DataType.CVL))
                {
                    metaField.Add(_epiMappingHelper.GetDictionaryValues(fieldType, CvlUtilConfig));
                }

                if (metafields.Any(
                        mf =>
                {
                    XElement nameElement = mf.Element("Name");
                    return(nameElement != null && nameElement.Value.Equals(_epiMappingHelper.GetEPiMetaFieldNameFromField(fieldType, CvlUtilConfig)));
                }))
                {
                    XElement existingMetaField =
                        metafields.FirstOrDefault(
                            mf =>
                    {
                        XElement nameElement = mf.Element("Name");
                        return(nameElement != null && nameElement.Value.Equals(_epiMappingHelper.GetEPiMetaFieldNameFromField(fieldType, CvlUtilConfig)));
                    });

                    if (existingMetaField == null)
                    {
                        continue;
                    }

                    var movefields = metaField.Elements("OwnerMetaClass");
                    existingMetaField.Add(movefields);
                }
                else
                {
                    metafields.Add(metaField);
                }
            }

            XElement  metaData = new XElement("MetaDataPlusBackup", new XAttribute("version", "1.0"), metafields.ToArray());
            XDocument doc      = _epiDocument.CreateDocument(null, metaData, null, CvlUtilConfig);

            Entity channelEntity = _context.ExtensionManager.DataService.GetEntity(CvlUtilConfig.ChannelId, LoadLevel.DataOnly);

            if (channelEntity == null)
            {
                _context.Log(LogLevel.Error, string.Format("Could not find channel {0} for cvl add", CvlUtilConfig.ChannelId));
                return;
            }

            string channelIdentifier = _channelHelper.GetChannelIdentifier(channelEntity);

            if (!DocumentFileHelper.ZipDocumentAndUploadToAzure(XmlDocumentType.Catalog, doc, CvlUtilConfig, folderDateTime))
            {
                _context.Log(LogLevel.Information, "Failed to zip and upload the catalog file to azure from cvl utility AddCvl() method");
            }

            _context.Log(LogLevel.Debug, string.Format("catalog {0} saved", channelIdentifier));

            if (CvlUtilConfig.ActivePublicationMode.Equals(PublicationMode.Automatic))
            {
                _context.Log(LogLevel.Debug, "Starting automatic import!");

                _epiApi.StartImportIntoEpiServerCommerce(
                    Path.Combine(CvlUtilConfig.PublicationsRootPath, folderDateTime, Configuration.ExportFileName),
                    _channelHelper.GetChannelGuid(channelEntity, CvlUtilConfig), CvlUtilConfig);
            }
        }