/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="indexerName">Name of the indexer for which this DocumentWriting event is being executed on</param> private static void DocumentWriting(object sender, DocumentWritingEventArgs e, string indexerName) { IPublishedContent publishedContent = null; if (LookService.Instance._umbracoHelper == null) { throw new Exception("Unexpected null value for UmbracoHelper - Look not initialized"); } publishedContent = LookService.Instance._umbracoHelper.TypedContent(e.NodeId); if (publishedContent == null) { // attempt to get as media publishedContent = LookService.Instance._umbracoHelper.TypedMedia(e.NodeId); if (publishedContent == null) { // attempt to get as member publishedContent = LookService.Instance._umbracoHelper.SafeTypedMember(e.NodeId); } } if (publishedContent != null) { var indexingContext = new IndexingContext( hostNode: null, node: publishedContent, indexerName: indexerName); LookService.EnsureContext(); LookService.Index(indexingContext, e.Document); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="indexerName">Name of the indexer for which this DocumentWriting event is being executed on</param> private static void DocumentWriting(object sender, DocumentWritingEventArgs e, string indexerName) { IPublishedContent publishedContent = null; var indexerConfiguration = LookService.GetIndexerConfiguration(indexerName); if (indexerConfiguration.ShouldIndexContent) // attempt to get content { publishedContent = LookService.Instance._umbracoHelper.TypedContent(e.NodeId); } if (publishedContent == null && indexerConfiguration.ShouldIndexMedia) // attempt to get as media { publishedContent = LookService.Instance._umbracoHelper.TypedMedia(e.NodeId); } if (publishedContent == null && indexerConfiguration.ShouldIndexMembers) // attempt to get as member { publishedContent = LookService.Instance._umbracoHelper.SafeTypedMember(e.NodeId); } if (publishedContent != null) { var indexingContext = new IndexingContext(null, publishedContent, indexerName); LookService.EnsureContext(); LookService.Index(indexingContext, e.Document); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="indexerName">Name of the indexer for which this DocumentWriting event is being executed on</param> private static void DocumentWriting(object sender, DocumentWritingEventArgs e, string indexerName) { IPublishedContent publishedContent = null; if (LookService.Instance._umbracoHelper == null) { throw new Exception("Unexpected null value for UmbracoHelper - Look not initialized"); } publishedContent = LookService.Instance._umbracoHelper.TypedContent(e.NodeId); if (publishedContent == null) { // attempt to get as media publishedContent = LookService.Instance._umbracoHelper.TypedMedia(e.NodeId); if (publishedContent == null) { // attempt to get as member publishedContent = LookService.Instance._umbracoHelper.SafeTypedMember(e.NodeId); } } if (publishedContent != null) { var dummyHttpContext = new HttpContextWrapper(new HttpContext(new SimpleWorkerRequest("", "", new StringWriter()))); UmbracoContext.EnsureContext( dummyHttpContext, ApplicationContext.Current, new WebSecurity(dummyHttpContext, ApplicationContext.Current), UmbracoConfig.For.UmbracoSettings(), UrlProviderResolver.Current.Providers, true, false); var indexingContext = new IndexingContext( hostNode: null, node: publishedContent, indexerName: indexerName); LookService.Index(indexingContext, e.Document); } }