public UmbracoContentIndexer(IIndexCriteria indexerData, Lucene.Net.Store.Directory luceneDirectory, IDataService dataService, Analyzer analyzer, bool async)
     : base(indexerData, luceneDirectory, dataService, analyzer, async)
 {
     _contentService  = ApplicationContext.Current.Services.ContentService;
     _mediaService    = ApplicationContext.Current.Services.MediaService;
     _dataTypeService = ApplicationContext.Current.Services.DataTypeService;
     _userService     = ApplicationContext.Current.Services.UserService;
 }
 public UmbracoContentIndexer(IIndexCriteria indexerData, DirectoryInfo indexPath, IDataService dataService, Analyzer analyzer, bool async)
     : base(indexerData, indexPath, dataService, analyzer, async)
 {
     _contentService  = ApplicationContext.Current.Services.ContentService;
     _mediaService    = ApplicationContext.Current.Services.MediaService;
     _dataTypeService = ApplicationContext.Current.Services.DataTypeService;
     _userService     = ApplicationContext.Current.Services.UserService;
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 public UmbracoContentIndexer()
     : base()
 {
     _contentService  = ApplicationContext.Current.Services.ContentService;
     _mediaService    = ApplicationContext.Current.Services.MediaService;
     _dataTypeService = ApplicationContext.Current.Services.DataTypeService;
     _userService     = ApplicationContext.Current.Services.UserService;
 }
예제 #4
0
        // REMOVE!
        private void ContentService_Trashed(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.MoveEventArgs <Umbraco.Core.Models.IContent> e)
        {
            var fileSystemService = new FileSystemService(new DirectoryInfo(HttpRuntime.AppDomainAppPath));
            var configProvider    = new DexterConfigProvider(fileSystemService);
            var indexService      = new IndexService(configProvider);

            foreach (var moveInfo in e.MoveInfoCollection)
            {
                indexService.Remove(moveInfo.Entity);
            }
        }
 /// <summary>
 /// Constructor to allow for creating an indexer at runtime
 /// </summary>
 /// <param name="indexerData"></param>
 /// <param name="luceneDirectory"></param>
 /// <param name="dataService"></param>
 /// <param name="contentService"></param>
 /// <param name="mediaService"></param>
 /// <param name="dataTypeService"></param>
 /// <param name="userService"></param>
 /// <param name="analyzer"></param>
 /// <param name="async"></param>
 public UmbracoContentIndexer(IIndexCriteria indexerData, Lucene.Net.Store.Directory luceneDirectory, IDataService dataService,
                              IContentService contentService,
                              IMediaService mediaService,
                              IDataTypeService dataTypeService,
                              IUserService userService,
                              Analyzer analyzer, bool async)
     : base(indexerData, luceneDirectory, dataService, analyzer, async)
 {
     _contentService  = contentService;
     _mediaService    = mediaService;
     _dataTypeService = dataTypeService;
     _userService     = userService;
 }
 /// <summary>
 /// Creates an NRT indexer
 /// </summary>
 /// <param name="indexerData"></param>
 /// <param name="writer"></param>
 /// <param name="dataService"></param>
 /// <param name="contentTypeService"></param>
 /// <param name="async"></param>
 /// <param name="contentService"></param>
 /// <param name="mediaService"></param>
 /// <param name="dataTypeService"></param>
 /// <param name="userService"></param>
 public UmbracoContentIndexer(IIndexCriteria indexerData, IndexWriter writer, IDataService dataService,
                              IContentService contentService,
                              IMediaService mediaService,
                              IDataTypeService dataTypeService,
                              IUserService userService,
                              IContentTypeService contentTypeService,
                              bool async)
     : base(indexerData, writer, dataService, async)
 {
     _contentService     = contentService;
     _mediaService       = mediaService;
     _dataTypeService    = dataTypeService;
     _userService        = userService;
     _contentTypeService = contentTypeService;
 }
예제 #7
0
        public static UmbracoContentIndexer GetUmbracoIndexer(
            Directory luceneDir,
            Analyzer analyzer                = null,
            IDataService dataService         = null,
            IContentService contentService   = null,
            IMediaService mediaService       = null,
            IDataTypeService dataTypeService = null,
            IMemberService memberService     = null,
            IUserService userService         = null)
        {
            if (dataService == null)
            {
                dataService = new TestDataService();
            }
            if (contentService == null)
            {
                contentService = Mock.Of <IContentService>();
            }
            if (userService == null)
            {
                userService = Mock.Of <IUserService>(x => x.GetProfileById(It.IsAny <int>()) == Mock.Of <IProfile>(p => p.Id == (object)0 && p.Name == "admin"));
            }
            if (mediaService == null)
            {
                long totalRecs;

                var allRecs = dataService.MediaService.GetLatestMediaByXpath("//node")
                              .Root
                              .Elements()
                              .Select(x => Mock.Of <IMedia>(
                                          m =>
                                          m.Id == (int)x.Attribute("id") &&
                                          m.ParentId == (int)x.Attribute("parentID") &&
                                          m.Level == (int)x.Attribute("level") &&
                                          m.CreatorId == 0 &&
                                          m.SortOrder == (int)x.Attribute("sortOrder") &&
                                          m.CreateDate == (DateTime)x.Attribute("createDate") &&
                                          m.UpdateDate == (DateTime)x.Attribute("updateDate") &&
                                          m.Name == (string)x.Attribute("nodeName") &&
                                          m.Path == (string)x.Attribute("path") &&
                                          m.Properties == new PropertyCollection() &&
                                          m.ContentType == Mock.Of <IMediaType>(mt =>
                                                                                mt.Alias == (string)x.Attribute("nodeTypeAlias") &&
                                                                                mt.Id == (int)x.Attribute("nodeType"))))
                              .ToArray();


                mediaService = Mock.Of <IMediaService>(
                    x => x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out totalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                    ==
                    allRecs);
            }
            if (dataTypeService == null)
            {
                dataTypeService = Mock.Of <IDataTypeService>();
            }

            if (memberService == null)
            {
                memberService = Mock.Of <IMemberService>();
            }

            if (analyzer == null)
            {
                analyzer = new StandardAnalyzer(Version.LUCENE_29);
            }

            var indexSet      = new IndexSet();
            var indexCriteria = indexSet.ToIndexCriteria(dataService, UmbracoContentIndexer.IndexFieldPolicies);

            var i = new UmbracoContentIndexer(indexCriteria,
                                              luceneDir,         //custom lucene directory
                                              dataService,
                                              contentService,
                                              mediaService,
                                              dataTypeService,
                                              userService,
                                              analyzer,
                                              false);

            //i.IndexSecondsInterval = 1;

            i.IndexingError += IndexingError;

            return(i);
        }
예제 #8
0
        public static UmbracoContentIndexer GetUmbracoIndexer(
            IndexWriter writer,
            Analyzer analyzer                      = null,
            IDataService dataService               = null,
            IContentService contentService         = null,
            IMediaService mediaService             = null,
            IDataTypeService dataTypeService       = null,
            IMemberService memberService           = null,
            IUserService userService               = null,
            IContentTypeService contentTypeService = null,
            bool supportUnpublishedContent         = false)
        {
            if (dataService == null)
            {
                dataService = new TestDataService();
            }
            if (contentService == null)
            {
                long longTotalRecs;
                int  intTotalRecs;

                var allRecs = dataService.ContentService.GetLatestContentByXPath("//*[@isDoc]")
                              .Root
                              .Elements()
                              .Select(x => Mock.Of <IContent>(
                                          m =>
                                          m.Id == (int)x.Attribute("id") &&
                                          m.ParentId == (int)x.Attribute("parentID") &&
                                          m.Level == (int)x.Attribute("level") &&
                                          m.CreatorId == 0 &&
                                          m.SortOrder == (int)x.Attribute("sortOrder") &&
                                          m.CreateDate == (DateTime)x.Attribute("createDate") &&
                                          m.UpdateDate == (DateTime)x.Attribute("updateDate") &&
                                          m.Name == (string)x.Attribute("nodeName") &&
                                          m.Path == (string)x.Attribute("path") &&
                                          m.Properties == new PropertyCollection() &&
                                          m.ContentType == Mock.Of <IContentType>(mt =>
                                                                                  mt.Alias == x.Name.LocalName &&
                                                                                  mt.Id == (int)x.Attribute("nodeType") &&
                                                                                  mt.Icon == "test")))
                              .ToArray();


                contentService = Mock.Of <IContentService>(
                    x => x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <bool>(), It.IsAny <string>())
                    ==
                    allRecs &&
                    x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                    ==
                    allRecs &&
                    x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), out intTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                    ==
                    allRecs &&
                    x.GetPagedDescendants(
                        It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <bool>(), It.IsAny <IQuery <IContent> >())
                    ==
                    allRecs);
            }
            if (userService == null)
            {
                userService = Mock.Of <IUserService>(x => x.GetProfileById(It.IsAny <int>()) == Mock.Of <IProfile>(p => p.Id == 0 && p.Name == "admin"));
            }
            if (mediaService == null)
            {
                long longTotalRecs;
                int  intTotalRecs;

                var mediaXml = dataService.MediaService.GetLatestMediaByXpath("//node");
                var allRecs  = mediaXml
                               .Root
                               .Elements()
                               .Select(x => Mock.Of <IMedia>(
                                           m =>
                                           m.Id == (int)x.Attribute("id") &&
                                           m.ParentId == (int)x.Attribute("parentID") &&
                                           m.Level == (int)x.Attribute("level") &&
                                           m.CreatorId == 0 &&
                                           m.SortOrder == (int)x.Attribute("sortOrder") &&
                                           m.CreateDate == (DateTime)x.Attribute("createDate") &&
                                           m.UpdateDate == (DateTime)x.Attribute("updateDate") &&
                                           m.Name == (string)x.Attribute("nodeName") &&
                                           m.Path == (string)x.Attribute("path") &&
                                           m.Properties == new PropertyCollection() &&
                                           m.ContentType == Mock.Of <IMediaType>(mt =>
                                                                                 mt.Alias == (string)x.Attribute("nodeTypeAlias") &&
                                                                                 mt.Id == (int)x.Attribute("nodeType"))))
                               .ToArray();

                // MOCK!
                var mediaServiceMock = new Mock <IMediaService>();

                mediaServiceMock
                .Setup(x => x.GetPagedDescendants(
                           It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <bool>(), It.IsAny <string>())
                       ).Returns(() => allRecs);

                mediaServiceMock
                .Setup(x => x.GetPagedDescendants(
                           It.IsAny <int>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                       ).Returns(() => allRecs);

                mediaServiceMock
                .Setup(x => x.GetPagedDescendants(
                           It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), out intTotalRecs, It.IsAny <string>(), It.IsAny <Direction>(), It.IsAny <string>())
                       ).Returns(() => allRecs);

                mediaServiceMock.Setup(service => service.GetPagedXmlEntries(It.IsAny <string>(), It.IsAny <long>(), It.IsAny <int>(), out longTotalRecs))
                .Returns(() => allRecs.Select(x => x.ToXml()));

                mediaService = mediaServiceMock.Object;
            }
            if (dataTypeService == null)
            {
                dataTypeService = Mock.Of <IDataTypeService>();
            }

            if (memberService == null)
            {
                memberService = Mock.Of <IMemberService>();
            }

            if (contentTypeService == null)
            {
                var contentTypeServiceMock = new Mock <IContentTypeService>();
                contentTypeServiceMock.Setup(x => x.GetAllMediaTypes())
                .Returns(new List <IMediaType>()
                {
                    new MediaType(-1)
                    {
                        Alias = "Folder", Name = "Folder", Id = 1031, Icon = "icon-folder"
                    },
                    new MediaType(-1)
                    {
                        Alias = "Image", Name = "Image", Id = 1032, Icon = "icon-picture"
                    }
                });
                contentTypeService = contentTypeServiceMock.Object;
            }

            if (analyzer == null)
            {
                analyzer = new StandardAnalyzer(Version.LUCENE_29);
            }

            var indexSet      = new IndexSet();
            var indexCriteria = indexSet.ToIndexCriteria(dataService, UmbracoContentIndexer.IndexFieldPolicies);

            var i = new UmbracoContentIndexer(indexCriteria,
                                              writer,
                                              dataService,
                                              contentService,
                                              mediaService,
                                              dataTypeService,
                                              userService,
                                              contentTypeService,
                                              false)
            {
                SupportUnpublishedContent = supportUnpublishedContent
            };

            //i.IndexSecondsInterval = 1;

            i.IndexingError += IndexingError;

            return(i);
        }
        public static ContentIndexPopulator GetContentIndexRebuilder(PropertyEditorCollection propertyEditors, IContentService contentService, ISqlContext sqlContext, bool publishedValuesOnly)
        {
            var contentValueSetBuilder = GetContentValueSetBuilder(propertyEditors, publishedValuesOnly);
            var contentIndexDataSource = new ContentIndexPopulator(true, null, contentService, sqlContext, contentValueSetBuilder);

            return(contentIndexDataSource);
        }