Example #1
0
        /// <summary>
        /// Update the search index with the contents of the section.
        /// </summary>
        /// <param name="section"></param>
        public static void UpdateIndexFromSection(Section section)
        {
            CuyahogaContainer container = ContainerAccessorUtil.GetContainer();
            // Get ModuleLoader from the container. This needs to happen explicit here because
            // this is a static method
            ModuleLoader   moduleLoader  = container.Resolve <ModuleLoader>();
            ISearchService searchService = container.Resolve <ISearchService>();
            IContentItemService <ContentItem> contentItemService = container.Resolve <IContentItemService <ContentItem> >();

            if (moduleLoader == null)
            {
                throw new NullReferenceException("Unable to find the ModuleLoader instance");
            }
            string indexDir = HttpContext.Current.Server.MapPath(Config.GetConfiguration()["SearchIndexDir"]);

            ModuleBase module = moduleLoader.GetModuleFromSection(section);

            if (module is ISearchable)
            {
                ISearchable searchableModule = module as ISearchable;
                if (searchableModule != null)
                {
                    SearchContent[] searchContentList = searchableModule.GetAllSearchableContent();
                    foreach (SearchContent searchContent in searchContentList)
                    {
                        searchService.UpdateContent(searchContent);
                    }
                }
            }
            //check for IContentItems
            else
            {
                IList <ContentItem> contents = contentItemService.FindContentItemsBySection(section);
                foreach (ContentItem content in contents)
                {
                    if (content is ISearchableContent)
                    {
                        searchService.UpdateContent(content);
                    }
                }
            }
        }        //end method
Example #2
0
        /// <summary>
        /// Obtain the Cuyahoga container.
        /// </summary>
        /// <returns></returns>
        public static CuyahogaContainer GetContainer()
        {
            IContainerAccessor containerAccessor = HttpContext.Current.ApplicationInstance as IContainerAccessor;

            if (containerAccessor == null)
            {
                throw new Exception("You must extend the HttpApplication in your web project " +
                                    "and implement the IContainerAccessor to properly expose your container instance");
            }

            CuyahogaContainer container = containerAccessor.Container as CuyahogaContainer;

            if (container == null)
            {
                throw new Exception("The container seems to be unavailable in " +
                                    "your HttpApplication subclass");
            }

            return(container);
        }