コード例 #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);
                    }
                }
            }
        }
コード例 #2
0
        private void MediaServiceDeleted(IMediaService sender, DeleteEventArgs <IMedia> e)
        {
            IndexingRepository indexingRepository = new IndexingRepository((ICmsIndexer) new UmbracoIndexer(), (ILogFacade) new LogFacade(typeof(IndexingRepository)));

            using (IEnumerator <IMedia> enumerator = e.DeletedEntities.GetEnumerator())
            {
                while (((IEnumerator)enumerator).MoveNext())
                {
                    IMedia current = enumerator.Current;
                    try
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Deleted media item \"" + ((IUmbracoEntity)current).Name + "\", removing from Solr index.", (Exception)null);
                        indexingRepository.DeleteMediaFromIndex(((IEntity)current).Id.ToString((IFormatProvider)CultureInfo.InvariantCulture));
                    }
                    catch (Exception ex)
                    {
                        this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Error, "Error removing media item " + (object)((IEntity)current).Id + " from index, are you sure Solr is running?", ex);
                    }
                }
            }
        }