예제 #1
0
        public async Task <ActionResult> SearchEdit_Partial(EditModel model)
        {
            using (SearchDataProvider dataProvider = new SearchDataProvider()) {
                SearchData data = await dataProvider.GetItemWithUrlAsync(model.SearchDataId);

                if (data == null)
                {
                    throw new Error(this.__ResStr("alreadyDeleted", "The search keyword with id {0} has been removed and can no longer be updated.", model.SearchDataId));
                }

                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

                switch (await dataProvider.UpdateItemAsync(data))
                {
                default:
                case UpdateStatusEnum.RecordDeleted:
                    throw new Error(this.__ResStr("alreadyDeleted", "The search keyword with id {0} has been removed and can no longer be updated.", model.SearchDataId));

                case UpdateStatusEnum.NewKeyExists:
                    throw new Error(this.__ResStr("alreadyExists", "A search keyword with id {0} already exists.", model.SearchDataId));

                case UpdateStatusEnum.OK:
                    break;
                }
                return(FormProcessed(model, this.__ResStr("okSaved", "Search keyword saved"), OnClose: OnCloseEnum.Return, OnPopupClose: OnPopupCloseEnum.ReloadModule));
            }
        }
예제 #2
0
            public SearchWords(SearchConfigData searchConfig, SearchDataProvider searchDP, DateTime searchStarted)
            {
                CurrentSearchDP      = searchDP;
                CurrentSearchStarted = searchStarted;

                SmallestMixedToken     = searchConfig.SmallestMixedToken;
                SmallestUpperCaseToken = searchConfig.SmallestUpperCaseToken;
            }
예제 #3
0
        public async Task <ActionResult> Remove(int searchDataId)
        {
            using (SearchDataProvider searchDP = new SearchDataProvider()) {
                await searchDP.RemoveItemAsync(searchDataId);

                return(Reload(null, Reload: ReloadEnum.ModuleParts));
            }
        }
예제 #4
0
        public async Task <ActionResult> RemoveAll()
        {
            using (SearchDataProvider searchDP = new SearchDataProvider()) {
                using (ILockObject lockObject = await YetaWF.Core.IO.Caching.LockProvider.LockResourceAsync($"{AreaRegistration.CurrentPackage.AreaName}_{nameof(SearchDataProvider)}")) {
                    await searchDP.RemoveItemsAsync(null);/* ALL */

                    await lockObject.UnlockAsync();
                }
                return(Reload(null, Reload: ReloadEnum.ModuleParts));
            }
        }
예제 #5
0
 private void Reset(SearchDataProvider currentSearchDP, DateTime currentSearchStarted)
 {
     CurrentSearchDP       = currentSearchDP;
     CurrentSearchStarted  = currentSearchStarted;
     CurrentUrl            = null;
     CurrentPageSecurity   = PageDefinition.PageSecurityType.Any;
     CurrentAllowAnonymous = false;
     CurrentAllowAnyUser   = false;
     CurrentDateCreated    = DateTime.MinValue;
     CurrentDateUpdated    = null;
     CurrentSearchData     = new List <SearchData>();
     CurrentCustomData     = null;
 }
예제 #6
0
        public async Task <ActionResult> SearchEdit(int searchDataId)
        {
            if (!SearchDataProvider.IsUsable)
            {
                return(View("SearchUnavailable_Edit"));
            }
            using (SearchDataProvider dataProvider = new SearchDataProvider()) {
                EditModel model = new EditModel {
                };
                SearchData data = await dataProvider.GetItemWithUrlAsync(searchDataId);

                if (data == null)
                {
                    throw new Error(this.__ResStr("notFound", "Search keyword with id {0} not found."), searchDataId);
                }
                model.SetData(data);
                return(View(model));
            }
        }
예제 #7
0
        private GridDefinition GetGridModel()
        {
            return(new GridDefinition {
                ModuleGuid = Module.ModuleGuid,
                SettingsModuleGuid = Module.PermanentGuid,
                InitialPageSize = 20,
                RecordType = typeof(BrowseItem),
                AjaxUrl = GetActionUrl(nameof(SearchBrowse_GridData)),
                DirectDataAsync = async(int skip, int take, List <DataProviderSortInfo> sort, List <DataProviderFilterInfo> filters) => {
                    using (SearchDataProvider searchDP = new SearchDataProvider()) {
                        DataProviderGetRecords <SearchData> browseItems = await searchDP.GetItemsWithUrlAsync(skip, take, sort, filters);

                        return new DataSourceResult {
                            Data = (from s in browseItems.Data select new BrowseItem(Module, s)).ToList <object>(),
                            Total = browseItems.Total
                        };
                    }
                },
            });
        }
예제 #8
0
        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);
            }
        }