Exemplo n.º 1
0
        private void PublishingStrategyOnUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> publishEventArgs)
        {
            if (!publishEventArgs.PublishedEntities.Any <IContent>())
            {
                return;
            }
            IndexingRepository indexingRepository = new IndexingRepository((ICmsIndexer) new UmbracoIndexer(), (ILogFacade) new LogFacade(typeof(IndexingRepository)));

            using (IEnumerator <IContent> enumerator1 = publishEventArgs.PublishedEntities.GetEnumerator())
            {
                while (((IEnumerator)enumerator1).MoveNext())
                {
                    IContent current1 = enumerator1.Current;
                    try
                    {
                        using (IEnumerator <PropertyType> enumerator2 = ((IContentBase)current1).PropertyTypes.GetEnumerator())
                        {
                            while (((IEnumerator)enumerator2).MoveNext())
                            {
                                PropertyType current2 = enumerator2.Current;
                                try
                                {
                                    if (current2.DataTypeDefinitionId == -90)
                                    {
                                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("{0} was detected as upload property, will remove file from index", (object)current2.Alias), (Exception)null);
                                        Property property = ((KeyedCollection <string, Property>)((IContentBase)current1).Properties)[current2.Alias];
                                        if (property.Value != null && property.Value.ToString() != string.Empty)
                                        {
                                            string standaloneMediaId = MediaResolver.GetStandaloneMediaId(property.Value.ToString());
                                            if (!string.IsNullOrWhiteSpace(standaloneMediaId))
                                            {
                                                indexingRepository.DeleteMediaFromIndex("media" + standaloneMediaId);
                                                MediaResolver.RemoveStandAloneMedia(standaloneMediaId);
                                            }
                                        }
                                        else
                                        {
                                            this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Property value is empty, nothing to remove", (Exception)null);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error removing upload property media item from index.", ex);
                                }
                            }
                        }
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Unpublishing document \"" + ((IUmbracoEntity)current1).Name + "\", removing from Solr index.", (Exception)null);
                        indexingRepository.DeleteFromPublishedIndex((object)((IEntity)current1).Id);
                    }
                    catch (Exception ex)
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error removing node " + (object)((IEntity)current1).Id + " from index, are you sure Solr is running?", ex);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void RemoveStandAloneMedia(string mediaId)
        {
            XmlDocument xmlRegister = MediaResolver.EnsureStandaloneMediaRegister();
            XmlNode     oldChild    = xmlRegister.SelectSingleNode("//files/file[@id='" + mediaId + "']");

            if (oldChild == null)
            {
                return;
            }
            oldChild.ParentNode.RemoveChild(oldChild);
            MediaResolver.SaveStandaloneFile(xmlRegister);
        }
Exemplo n.º 3
0
        public static string GetStandaloneMediaId(string url)
        {
            XmlDocument xmlRegister = MediaResolver.EnsureStandaloneMediaRegister();
            XmlNode     xmlNode     = xmlRegister.SelectSingleNode("//files/file[@url='" + url + "']");

            if (xmlNode != null)
            {
                return(xmlNode.Attributes["id"].Value);
            }
            XmlNode      node       = xmlRegister.CreateNode(XmlNodeType.Element, "file", string.Empty);
            XmlAttribute attribute1 = xmlRegister.CreateAttribute("url");

            attribute1.Value = url;
            XmlAttribute attribute2 = xmlRegister.CreateAttribute("id");

            attribute2.Value = Guid.NewGuid().ToString();
            node.Attributes.Append(attribute1);
            node.Attributes.Append(attribute2);
            xmlRegister.SelectSingleNode("//files").AppendChild(node);
            MediaResolver.SaveStandaloneFile(xmlRegister);
            return(attribute2.Value);
        }