public async Task <ActionResult> SearchConfig() { using (SearchConfigDataProvider dataProvider = new SearchConfigDataProvider()) { Model model = new Model { }; SearchConfigData data = await dataProvider.GetItemAsync(); if (data == null) { throw new Error(this.__ResStr("notFound", "The search configuration was not found.")); } model.SetData(data); return(View(model)); } }
public async Task <ActionResult> SearchConfig_Partial(Model model) { using (SearchConfigDataProvider dataProvider = new SearchConfigDataProvider()) { SearchConfigData data = await dataProvider.GetItemAsync();// get the original item if (!ModelState.IsValid) { return(PartialView(model)); } data = model.GetData(data); // merge new data into original model.SetData(data); // and all the data back into model for final display await dataProvider.UpdateConfigAsync(data); return(FormProcessed(model, this.__ResStr("okSaved", "Search configuration saved"))); } }
public async Task SearchSiteAsync(bool slow) { SearchConfigData searchConfig = await SearchConfigDataProvider.GetConfigAsync(); DateTime searchStarted = DateTime.UtcNow; // once we have all new keywords, delete all keywords that were added before this date/time using (SearchDataProvider searchDP = new SearchDataProvider()) { // Search all generated pages (unique modules or classes, like data providers) DynamicUrlsImpl dynamicUrls = new DynamicUrlsImpl(); List <Type> types = dynamicUrls.GetDynamicUrlTypes(); // search types that generate dynamic urls foreach (Type type in types) { #if DEBUG // if (type.Name != "FileDocumentDisplayModule") continue;//used for debugging #endif ISearchDynamicUrls iSearch = Activator.CreateInstance(type) as ISearchDynamicUrls; if (iSearch != null) { try { SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted); await iSearch.KeywordsForDynamicUrlsAsync(searchWords); if (slow) { Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items) } } catch (Exception exc) { Logging.AddErrorLog("KeywordsForDynamicUrls failed for {0}", type.FullName, exc); } } } // search all designed modules that have dynamic urls foreach (DesignedModule desMod in await DesignedModules.LoadDesignedModulesAsync()) { try { ModuleDefinition mod = await ModuleDefinition.LoadAsync(desMod.ModuleGuid, AllowNone : true); if (mod != null && types.Contains(mod.GetType()) && mod.WantSearch) { ISearchDynamicUrls iSearch = mod as ISearchDynamicUrls; if (iSearch != null) { SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted); await iSearch.KeywordsForDynamicUrlsAsync(searchWords); if (slow) { Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items) } } } } catch (Exception exc) { Logging.AddErrorLog("KeywordsForDynamicUrls failed for module {0}", desMod.ModuleGuid, exc); } } // Search all designed pages and extract keywords List <Guid> pages = await PageDefinition.GetDesignedGuidsAsync(); foreach (Guid pageGuid in pages) { PageDefinition page = await PageDefinition.LoadAsync(pageGuid); if (page != null) { SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted); await SearchPageAsync(searchWords, page); if (slow) { Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items) } } } // Remove old keywords await searchDP.RemoveOldItemsAsync(searchStarted); } }