示例#1
0
        public void TestBulkDeleteRecordIds(ResourceId resource, RecordTypes recordType)
        {
            var handler = new DefaultManager();
            var ids     = new List <string>();

            if (recordType == RecordTypes.Single)
            {
                ids = new List <string> {
                    RecordsCreator.Data[$"{resource}{index}"].Id.ToString()
                };
                index++;
            }
            else
            {
                ids = new List <string> {
                    RecordsCreator.Data[$"{resource}{index + 1}"].Id.ToString(), RecordsCreator.Data[$"{resource}{index + 2}"].Id.ToString()
                };
                index = index + 2;
            }

            var request  = DefaultBulkDeleteParametersWithRecordIds(resource, ids);
            var response = handler.Send <BulkUpdateResponse>(BulkDeleteEndpoint, request.ToJson(), HttpMethod.POST);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssert.That(SearchHelpers.GetBulkUpdateQueueStatus(response.Result.Id.ToString(), WaitingTimeSecond, false), "Bulk delete is unsuccessful.");
        }
示例#2
0
        public async Task <IndexSearchServiceModel> Index(string searchTerm)
        {
            var searchItems = SearchHelpers.GetSearchItems(searchTerm);

            var articles = this.articleRepository.All();
            var videos   = this.videoRepository.All();

            foreach (var item in searchItems)
            {
                var tempItem = item;

                articles = articles.Where(p =>
                                          p.Content.ToLower().Contains(tempItem) ||
                                          p.Title.ToLower().Contains(tempItem));

                videos = videos.Where(p =>
                                      p.AssociatedTerms.ToLower().Contains(tempItem) ||
                                      p.Title.ToLower().Contains(tempItem));
            }

            var serviceModel = new IndexSearchServiceModel
            {
                Articles      = await articles.Distinct().Take(DefaultArticlesPerPage).To <ArticleServiceModel>().ToListAsync(),
                Videos        = await videos.Distinct().Take(DefaultVideosPerPage).To <VideoServiceModel>().ToListAsync(),
                ArticlesCount = await articles.CountAsync(),
                VideosCount   = await videos.CountAsync(),
            };

            this.SortOutCommentHierarchy(serviceModel.Videos);

            return(serviceModel);
        }
示例#3
0
        public async Task <VideosSearchServiceModel> GetVideos(string searchTerm, int take = DefaultVideosPerPage, int skip = 0)
        {
            var searchItems = SearchHelpers.GetSearchItems(searchTerm);

            var videosQuery = this.videoRepository.All();

            foreach (var item in searchItems)
            {
                var tempItem = item;

                videosQuery = videosQuery.Where(p =>
                                                p.AssociatedTerms.ToLower().Contains(tempItem) ||
                                                p.Title.ToLower().Contains(tempItem));
            }

            var videosCount = await videosQuery.Distinct().CountAsync();

            // TODO: Why does distinct create error in below query?? now working fine but distinct blows up
            var videos = await videosQuery
                         .Include(a => a.User)
                         .Include(a => a.VideoComments)
                         .Skip(skip)
                         .Take(take)
                         .To <VideoServiceModel>()
                         .ToListAsync();

            this.SortOutCommentHierarchy(videos);

            return(new VideosSearchServiceModel
            {
                Videos = videos,
                VideosCount = videosCount,
            });
        }
示例#4
0
        public List <IPublishedContent> GetIPublishedContentNodes(string nodeTypeAlias)
        {
            var contentCriteria = SearchHelpers.CreateContentCriteria().NodeTypeAlias(nodeTypeAlias).Compile();
            var cachedContent   = UHelper.TypedSearch(contentCriteria).ToList();

            return(cachedContent);
        }
        private void QueryBuilder()
        {
            //Title
            Tuple <string, string> actorName    = ActorBox.Text.ToString().GetTupleFromName();
            Tuple <string, string> directorName = DirectorsBox.Text.ToString().GetTupleFromName();
            Tuple <string, string> writerName   = WritersBox.Text.ToString().GetTupleFromName();

            //string genre = (GenreDropDown.SelectedIndex == -1) ? string.Empty : GenreDropDown.SelectedValue.ToString();
            //List<CheckedListItem> selected = cmb.ItemsSource.Cast<CheckedListItem>().ToList();
            List <string> selectedGenreList   = (selectedGenres == string.Empty) ? new List <string>() : selectedGenres.Split(new[] { ',' }).ToList();
            List <string> selectedRatingsList = (selectedRatings == string.Empty) ? new List <string>() : selectedRatings.Split(new[] { ',' }).ToList();

            Tuple <int, int> length = (LengthDropDown.SelectedIndex == -1)
                                                ? new Tuple <int, int>(0, MovieAppHelpers.GetMaxMovieLength())
                                                : (Tuple <int, int>)LengthDropDown.SelectedValue;

            List <Film> results = (List <Film>)SearchHelpers.RunSearch(paramActorFirst: actorName.Item1, paramActorLast: actorName.Item2,
                                                                       paramRatings: selectedRatingsList, paramGenres: selectedGenreList,
                                                                       paramMin: length.Item1, paramMax: length.Item2,
                                                                       paramDirectorFirst: directorName.Item1, paramDirectorLast: directorName.Item2,
                                                                       paramWriterFirst: writerName.Item1, paramWriterLast: writerName.Item2
                                                                       );

            if (results.Any())
            {
                new Results(results).Switch();
            }
            else
            {
                MessageBox.Show("Your search yielded no results", "No results", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#6
0
        public IPublishedContent GetIPublishedNodeByAlias(string nodeTypeAlias)
        {
            var contentCriteria = SearchHelpers.CreateContentCriteria().NodeTypeAlias(nodeTypeAlias).Compile();
            var cachedContent   = UHelper.TypedSearch(contentCriteria).FirstOrDefault();

            return(cachedContent);
        }
示例#7
0
        public static void Generate(IServiceScopeFactory serviceScopeFactory, GeneratorConfig config, string basePath, bool generateSearchDocuments, string searchIndex, List <SitemapEntry> sitemapEntries)
        {
            using (StreamReader fileReader = new StreamReader(FileHelper.GetActualFilePath(basePath, "output/json/habitats.json")))
            {
                List <InterestFeature> habitats = JsonConvert.DeserializeObject <List <InterestFeature> >(fileReader.ReadToEnd());

                foreach (var habitat in habitats)
                {
                    var habitatPageContent = HabitatPageBuilder.RenderPage(serviceScopeFactory, config, habitat).Result;
                    FileHelper.WriteToFile(FileHelper.GetActualFilePath(basePath, String.Format("output/html/habitat/{0}/index.html", habitat.Code)), habitatPageContent);
                    sitemapEntries.Add(new SitemapEntry
                    {
                        URL = String.Format("/habitat/{0}/", habitat.Code)
                    });

                    if (generateSearchDocuments)
                    {
                        FileHelper.WriteJSONToFile(
                            String.Format("output/search/habitat/{0}.json", habitat.Code),
                            SearchHelpers.GetHabitatPageSearchDocument(searchIndex, habitat.Code, habitat.Name, habitatPageContent)
                            );
                    }

                    var habitatMapCompareContent = InterestFeatureComparisonPageBuilder.RenderPage(serviceScopeFactory, config, habitat).Result;
                    FileHelper.WriteToFile(FileHelper.GetActualFilePath(basePath, String.Format("output/html/habitat/{0}/comparison.html", habitat.Code)), habitatMapCompareContent);
                    sitemapEntries.Add(new SitemapEntry
                    {
                        URL = String.Format("/habitat/{0}/comparison", habitat.Code)
                    });

                    var habitatMapContent = InterestFeatureMapPageBuilder.RenderPage(serviceScopeFactory, config, habitat).Result;
                    FileHelper.WriteToFile(FileHelper.GetActualFilePath(basePath, String.Format("output/html/habitat/{0}/map.html", habitat.Code)), habitatMapContent);
                    sitemapEntries.Add(new SitemapEntry
                    {
                        URL = String.Format("/habitat/{0}/map", habitat.Code)
                    });

                    var habitatDistributionContent = InterestFeatureDistributionPageBuilder.RenderPage(serviceScopeFactory, config, habitat).Result;
                    FileHelper.WriteToFile(FileHelper.GetActualFilePath(basePath, String.Format("output/html/habitat/{0}/distribution.html", habitat.Code)), habitatDistributionContent);
                    sitemapEntries.Add(new SitemapEntry
                    {
                        URL = String.Format("/habitat/{0}/distribution", habitat.Code)
                    });
                }

                var habitatListContent = InterestFeatureListPageBuilder.RenderPage(serviceScopeFactory, config, true, habitats).Result;
                FileHelper.WriteToFile(FileHelper.GetActualFilePath(basePath, "output/html/habitat/index.html"), habitatListContent);
                sitemapEntries.Add(new SitemapEntry
                {
                    URL = "/habitat/"
                });

                Console.WriteLine("Generated pages for {0} habitats", habitats.Count);

                if (generateSearchDocuments)
                {
                    Console.WriteLine("Generated search elements for {0} habitats", habitats.Count);
                }
            }
        }
示例#8
0
        public void FindPath()
        {
            Stopwatch watch = Stopwatch.StartNew();

            bool[,] boolMap = SearchHelpers.GetSearchBoolMap(theGameStatus.TheMap);
            Point            startLocation        = new Point(100, 100);
            Point            endLocation          = new Point(300, 300);
            SearchParameters tempSearchParameters = new SearchParameters(startLocation, endLocation,
                                                                         boolMap);

            AStarPathFinder tempAStarPathFinder = new AStarPathFinder(tempSearchParameters);
            List <Point>    tempPath            = tempAStarPathFinder.FindPath();

            if (tempPath.Count == 0)
            {
                TheGameCore.RaiseMessage("No path found: " + startLocation + "-" + endLocation);
            }
            else
            {
                tempPath.Insert(0, startLocation);
                Vector3[] tempVect3 = SearchHelpers.PathToVector3Array(theGameStatus.TheMap, tempPath, 0.1f);
                RenderLayerBase.TheSceneManager.TheRenderLayerGame.AddPath(tempVect3);
            }
            watch.Stop();
            TheGameCore.RaiseMessage("FindPath() took " + watch.ElapsedMilliseconds + "ms,: " + startLocation + "-" + endLocation);
        }
示例#9
0
        public SearchViewModel BuildViewModels(SearchRequestModel request, int?topAncestorId)
        {
            var model = new SearchViewModel
            {
                SearchTerm = request.Query != null?_helper.CleanseSearchTerm(request.Query.ToLower(CultureInfo.InvariantCulture)) : string.Empty,
                                 CurrentPage         = request.Page,
                                 PageSize            = request.PageSize != 0 ? request.PageSize : _config.PageSize,
                                 RootContentNodeId   = request.RootContentNodeId,
                                 RootMediaNodeId     = request.RootMediaNodeId,
                                 IndexType           = !string.IsNullOrEmpty(request.IndexType) ? request.IndexType.ToLower(CultureInfo.InvariantCulture) : string.Empty,
                                 SearchFields        = request.SearchFields?.Any() ?? false ? request.SearchFields : _config.SearchFields.SplitToList(),
                                 HideFromSearchField = request.HideFromSearchField,
                                 SearchFormLocation  = SearchHelpers.GetFormLocation(request.FormLocation)
            };

            if (model.IndexType != UmbracoExamine.IndexTypes.Content && model.IndexType != UmbracoExamine.IndexTypes.Media)
            {
                model.IndexType = string.Empty;
            }

            if (model.RootContentNodeId <= 0 && topAncestorId.HasValue)
            {
                model.RootContentNodeId = topAncestorId.Value;
            }

            if (model.SearchFields.Contains(StaticValues.Properties.UmbracoFile) && !model.SearchFields.Contains(StaticValues.Properties.UmbracoFileName))
            {
                model.SearchFields.Add(StaticValues.Properties.UmbracoFileName);
            }

            model.SearchTerms = SearchHelpers.Tokenize(model.SearchTerm);

            return(model);
        }
示例#10
0
        private string Serve(string resource, string contentType)
        {
            if (resource == "/")
            {
                resource    = "/default.html";
                contentType = "text/html";
            }

            string header  = "";
            string content = "";
            string footer  = "";

            content = GetResourceContents(resource);

            if (contentType == "text/html")
            {
                header = GetResourceContents("/include/header.html");

                Dictionary <string, string> pageData = SearchHelpers.GetPageAttributes(content, out content);

                foreach (KeyValuePair <string, string> each in pageData)
                {
                    header  = header.Replace(SearchHelpers.VariableDelimiter + each.Key, each.Value);
                    content = content.Replace(SearchHelpers.VariableDelimiter + each.Key, each.Value);
                }

                footer = GetResourceContents("/include/footer.html");
            }

            return(header + content + footer);
        }
示例#11
0
        private static void BulkUpdateByReplaceFilter()
        {
            var handler  = new BulkUpdateManager();
            var response = handler.BulkUpdate <BulkUpdateResponse>(GetBulkUpdateContent(Filters.Replace), HttpMethod.Post);

            PrAssume.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssume.That(SearchHelpers.GetBulkUpdateQueueStatus(response.Result.Id.ToString(), 30, false));
        }
 async Task SearchVideos(string tag)
 {
     _searchResultsVideos = SearchHelpers.SearchVideos(tag, _searchResultsVideos);
     await DispatchHelper.InvokeAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
     {
         OnPropertyChanged(nameof(SearchResultsVideos));
         OnPropertyChanged(nameof(ResultsCount));
     });
 }
示例#13
0
 async Task SearchAlbums(string tag)
 {
     _searchResultsAlbums = SearchHelpers.SearchAlbums(tag, _searchResultsAlbums);
     await DispatchHelper.InvokeInUIThread(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
     {
         OnPropertyChanged(nameof(SearchResultsAlbums));
         OnPropertyChanged(nameof(ResultsCount));
     });
 }
示例#14
0
        public void LowerBoundLinear8_ArrayLengthIs8_WithoutDuplicates()
        {
            var keys = new long[] { 1, 3, 5, 7, 9, 11, 13, 15 };

            int index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 1);
            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 2);
            Assert.AreEqual(1, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 3);
            Assert.AreEqual(1, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 4);
            Assert.AreEqual(2, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 5);
            Assert.AreEqual(2, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 6);
            Assert.AreEqual(3, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 7);
            Assert.AreEqual(3, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 8);
            Assert.AreEqual(4, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 9);
            Assert.AreEqual(4, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 10);
            Assert.AreEqual(5, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 11);
            Assert.AreEqual(5, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 12);
            Assert.AreEqual(6, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 13);
            Assert.AreEqual(6, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 14);
            Assert.AreEqual(7, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 15);
            Assert.AreEqual(7, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 16);
            Assert.AreEqual(-1, index);
        }
        public void TestBulkCreateWithPhaseMissing(string fieldName, InputType inputType)
        {
            var    handler    = new BulkCreateManager();
            string fieldValue = fieldValue = DefaultValueFieldTypes[inputType](RecordsCreator, ResourceId.Client, fieldName, null);
            var    request    = DefaultBulkCreateParameters(ResourceId.Client, fieldName, fieldValue);
            var    response   = handler.BulkCreate <BulkUpdateResponse>(request, System.Net.Http.HttpMethod.Post);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssert.That(SearchHelpers.GetBulkUpdateQueueStatus(response.Result.Id.ToString(), WaitingTimeSecond, fieldName == Phase ? false : true), "Bulk create is unsuccessful.");
        }
示例#16
0
        public void UpperBoundLinear_ArrayLengthIsOne()
        {
            var keys  = new long[] { 1 };
            int index = SearchHelpers.UpperBoundLinear(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.UpperBoundLinear(keys, keys.Length, 1);
            Assert.AreEqual(-1, index);
        }
示例#17
0
 public void LowerBoundBinary_Seq()
 {
     for (int i = 1; i < 1000; i++)
     {
         var keys = GenerateKeys(i);
         for (int k = 0; k < keys.Length; k++)
         {
             Assert.AreEqual(SearchHelpers.LowerBoundLinear(keys, keys.Length, keys[k]), SearchHelpers.LowerBoundBinary(keys, keys.Length, keys[k]));
         }
     }
 }
        public ActionResult Search(string q, int page = 1)
        {
            var games = new List <DisplayGame>();

            if (!string.IsNullOrEmpty(q))
            {
                var searchResult = SearchHelpers.SearchGamesInDb(q);

                if (searchResult.Count > (page - 1) * PageLimit)
                {
                    var searchResultRanked = new List <DisplayGame>();

                    // Move all the unrated results to the bottom of the list
                    searchResultRanked.AddRange(searchResult.Where(x => x.IsRated));
                    searchResultRanked.AddRange(searchResult.Where(x => !x.IsRated));

                    games.AddRange(searchResultRanked.Skip((page - 1) * PageLimit).Take(PageLimit));

                    // Dispatch a Task on a different thread to ask GB for games
                    // related to the query, and add any results we don't yet have
                    // to our own DB.
                    Task.Run(() => GameHelpers.SearchGbAndCacheResults(q, page));
                }


                if (!games.Any()) // Ask GB for games instead
                {
                    var rawResults = GbGateway.Search(q, page);

                    if (rawResults.Any())
                    {
                        var filteredResults = GameHelpers.FilterOutUnsupportedPlatforms(rawResults);

                        GameHelpers.SaveGamesToDb(filteredResults);

                        // Not using RefreshDisplayGame here, since having to wait for
                        // potentially up to 10 games to be pulled from GB
                        // is a super duper bad idea
                        games.AddRange(filteredResults.Select(x => GameHelpers.CreateDisplayGameObject(x.Id)));
                    }
                }
            }

            var retval = new SearchResult
            {
                Page    = page,
                Results = games,
                Query   = q,
                Type    = SearchType.Standard
            };

            return(View(retval));
        }
示例#19
0
 public void LowerBoundBinary_Random()
 {
     for (int i = 1; i < 1000; i++)
     {
         var keys = GetSortedRandomKeys(i);
         for (int k = 0; k < keys.Length; k++)
         {
             Assert.AreEqual(SearchHelpers.LowerBoundLinear(keys, keys.Length, keys[k]), SearchHelpers.LowerBoundBinary(keys, keys.Length, keys[k]));
             Assert.AreEqual(SearchHelpers.LowerBoundLinear(keys, keys.Length, keys[k] + 1), SearchHelpers.LowerBoundBinary(keys, keys.Length, keys[k] + 1));
             Assert.AreEqual(SearchHelpers.LowerBoundLinear(keys, keys.Length, keys[k] - 1), SearchHelpers.LowerBoundBinary(keys, keys.Length, keys[k] - 1));
         }
     }
 }
        public ActionResult Advanced(
            string q,
            List <int> requireFlags,
            List <int> blockFlags,
            List <int> allowFlags,
            List <int> platforms,
            List <int> genres,
            int page = 1
            )
        {
            requireFlags = requireFlags?.Where(x => x >= 0).ToList() ?? new List <int>();
            blockFlags   = blockFlags?.Where(x => x >= 0).ToList() ?? new List <int>();
            allowFlags   = allowFlags?.Where(x => x >= 0).ToList() ?? new List <int>();
            platforms    = platforms?.Where(x => x >= 0).ToList() ?? new List <int>();
            genres       = genres?.Where(x => x >= 0).ToList() ?? new List <int>();

            // Determine if we're showing results or displaying the form
            if (string.IsNullOrEmpty(q) &&
                !requireFlags.Any() &&
                !blockFlags.Any() &&
                !allowFlags.Any() &&
                !platforms.Any() &&
                !genres.Any())
            {
                var viewModelGenres    = GameHelpers.GetGenres();
                var viewModelPlatforms = GameHelpers.GetPlatforms();

                return(View(new AdvancedSearchViewModel {
                    Genres = viewModelGenres, Platforms = viewModelPlatforms
                }));
            }

            var results = SearchHelpers.AdvancedSearch(q, requireFlags, blockFlags, allowFlags, platforms, genres);

            var games = results.Skip((page - 1) * PageLimit).Take(PageLimit).ToList();

            var retval = new SearchResult
            {
                Page         = page,
                Results      = games,
                Query        = q,
                AllowFlags   = allowFlags,
                BlockFlags   = blockFlags,
                RequireFlags = requireFlags,
                Genres       = genres,
                Platforms    = platforms,
                Type         = SearchType.Advanced
            };

            return(View("Search", retval));
        }
示例#21
0
        public void LowerBoundBinary_ArrayLengthIsOne()
        {
            var keys = new long[] { 1 };

            int index = SearchHelpers.LowerBoundBinary(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundBinary(keys, keys.Length, 1);
            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundBinary(keys, keys.Length, 2);
            Assert.AreEqual(-1, index);
        }
示例#22
0
        private static void CompareLinearAndBinarySearch()
        {
            for (int arraySize = 1; arraySize < 25; arraySize++)
            {
                Console.WriteLine("CompareLinearAndBinarySearch. ArraySize: {0}", arraySize);
                Console.WriteLine("*******************************************************************");
                int[] keys = new int[arraySize];
                for (int i = 0; i < arraySize; i++)
                {
                    keys[i] = i + 1;
                }
                Stopwatch sw = Stopwatch.StartNew();
                long      k  = 0;
                for (int i = 0; i < 1000000; i++)
                {
                    k += SearchHelpers.UpperBoundLinear(keys, arraySize, arraySize);
                }
                sw.Stop();
                Console.WriteLine("K: {0}. UpperBoundLinear: {1} ms", k, sw.ElapsedMilliseconds);

                sw.Restart();
                k = 0;
                for (int i = 0; i < 1000000; i++)
                {
                    k += SearchHelpers.UpperBoundLinear4(keys, arraySize, arraySize);
                }
                sw.Stop();
                Console.WriteLine("K: {0}. UpperBoundLinear4: {1} ms", k, sw.ElapsedMilliseconds);

                sw.Restart();
                k = 0;
                for (int i = 0; i < 1000000; i++)
                {
                    k += SearchHelpers.UpperBoundLinear8(keys, arraySize, arraySize);
                }
                sw.Stop();
                Console.WriteLine("K: {0}. UpperBoundLinear8: {1} ms", k, sw.ElapsedMilliseconds);

                sw.Restart();
                k = 0;
                for (int i = 0; i < 1000000; i++)
                {
                    k += SearchHelpers.UpperBoundBinary(keys, arraySize, arraySize);
                }
                sw.Stop();
                Console.WriteLine("K: {0}. UpperBoundBinary: {1} ms", k, sw.ElapsedMilliseconds);

                Console.WriteLine("*******************************************************************\r\n");
            }
        }
示例#23
0
        public void TestBulkUpdateSpecials(Specials inputType)
        {
            var handler  = new BulkUpdateManager();
            var request  = DefaultBulkUpdateParameters(RecordTypes.Single, Filters.Replace, ResourceId.Client, "P_Name", "Test Name", RecordsCreator);
            var response = handler.BulkUpdate <BulkUpdateResponse>(GetRequestForBulkUpdate(request, inputType), System.Net.Http.HttpMethod.Post);

            if (inputType == Specials.WrongSystemField || inputType == Specials.WrongUserField)
            {
                PrAssert.That(response, PrIs.ErrorResponse().And.HttpCode(System.Net.HttpStatusCode.BadRequest));
            }
            else
            {
                PrAssert.That(SearchHelpers.GetBulkUpdateQueueStatus(response.Result.Id.ToString()), PrIs.EqualTo(inputType == Specials.MissingPhaseDate ? true : false), "Bulk update could not update");
            }
        }
        public void TestBulkDeleteTwice()
        {
            var expectedId = RecordsCreator.Data[$"{ResourceId.Client}1"].Id.ToString();
            var handler    = new DefaultManager();
            var request    = DefaultBulkDeleteParametersWithRecordIds(ResourceId.Client, new List <string> {
                expectedId
            });
            var response = handler.Send <BulkUpdateResponse>(BulkDeleteEndpoint, request.ToJson(), HttpMethod.POST);

            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssert.That(SearchHelpers.GetBulkUpdateQueueStatus(response.Result.Id.ToString(), WaitingTimeSecond, false), "Bulk delete is unsuccessful.");

            //Delete twice
            response = handler.Send <BulkUpdateResponse>(BulkDeleteEndpoint, request.ToJson(), HttpMethod.POST);
            PrAssert.That(response, PrIs.SuccessfulResponse().And.HttpCode(System.Net.HttpStatusCode.OK));
            PrAssert.That(!SearchHelpers.GetBulkUpdateQueueStatus(response.Result.Id.ToString(), WaitingTimeSecond, false), "Bulk delete is not removed database out.");
        }
示例#25
0
        public void LowerBoundLinear8_ArrayLengthIsTwo()
        {
            var keys = new long[] { 1, 2 };

            int index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 1);
            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 2);
            Assert.AreEqual(1, index);

            index = SearchHelpers.LowerBoundLinear8(keys, keys.Length, 3);
            Assert.AreEqual(-1, index);
        }
        public static void Generate(IServiceScopeFactory serviceScopeFactory, GeneratorConfig config, string basePath, bool generateSearchDocuments, string searchIndex, List <SitemapEntry> sitemapEntries)
        {
            var gibraltarPageContent = MiscPageBuilder.RenderGibraltarPage(serviceScopeFactory, config).Result;

            FileHelper.WriteToFile(FileHelper.GetActualFilePath(basePath, "output/html/site/gibraltar.html"), gibraltarPageContent);
            sitemapEntries.Add(new SitemapEntry
            {
                URL = "/site/gibraltar"
            });

            if (generateSearchDocuments)
            {
                FileHelper.WriteJSONToFile(
                    FileHelper.GetActualFilePath(basePath, "output/search/site/gibraltar.json"),
                    SearchHelpers.GetMiscPageSearchDocument(searchIndex, "MISC-GIBRALTAR", "Natura 2000 in Gibraltar", gibraltarPageContent, "https://sac.jncc.gov.uk/site/gibraltar")
                    );
            }
        }
示例#27
0
        public void LowerBoundBinary_ContainsDuplicates()
        {
            var keys  = new long[] { 1, 2, 3, 3 };
            int index = SearchHelpers.LowerBoundBinary(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundBinary(keys, keys.Length, 1);
            Assert.AreEqual(0, index);

            index = SearchHelpers.LowerBoundBinary(keys, keys.Length, 2);
            Assert.AreEqual(1, index);

            index = SearchHelpers.LowerBoundBinary(keys, keys.Length, 3);
            Assert.AreEqual(2, index);

            index = SearchHelpers.LowerBoundBinary(keys, keys.Length, 4);
            Assert.AreEqual(-1, index);
        }
示例#28
0
        private void ServeIndex(HttpProcessor p, string url)
        {
            List <SearchResult> results = new List <SearchResult>();

            string[] index = SearchHelpers.SearchIndex;

            foreach (string each in index)
            {
                string contents = SearchHelpers.GetResourceContents(each);

                Dictionary <string, string> meta = SearchHelpers.GetPageAttributes(contents, out contents);
                SearchResult result = new SearchResult(each, meta[SearchHelpers.TitleAttribute]);
                results.Add(result);
            }

            HtmlGenerator html = new HtmlGenerator(results, "");

            p.WriteSuccessHeaders(200, "text/html", html.HTML);
        }
示例#29
0
        public void UpperBoundLinear_ArrayLengthIsThree()
        {
            var keys = new long[] { 1, 2, 3 };

            int index = SearchHelpers.UpperBoundLinear(keys, keys.Length, 0);

            Assert.AreEqual(0, index);

            index = SearchHelpers.UpperBoundLinear(keys, keys.Length, 1);
            Assert.AreEqual(1, index);

            index = SearchHelpers.UpperBoundLinear(keys, keys.Length, 2);
            Assert.AreEqual(2, index);

            index = SearchHelpers.UpperBoundLinear(keys, keys.Length, 3);
            Assert.AreEqual(-1, index);

            index = SearchHelpers.UpperBoundLinear(keys, keys.Length, 4);
            Assert.AreEqual(-1, index);
        }
示例#30
0
        private List <ProjectViewModel> GetProjectsInternal(string website, bool onlyFeatured = false)
        {
            var response = new List <ProjectViewModel>();
            var site     = GetIPublishedContentNodes(Website.ModelTypeAlias).FirstOrDefault(x => x.Name.ToLower().Contains(website.ToLower()));

            var projectListPage = site?.Children.FirstOrDefault(x => x.DocumentTypeAlias.Contains(nameof(ProjectList)));

            if (projectListPage != null)
            {
                var projectCriteria = SearchHelpers.CreateContentCriteria().NodeTypeAlias(Project.ModelTypeAlias).And().ParentId(projectListPage.Id).Compile();
                var cachedProjects  = onlyFeatured ? UHelper.TypedSearch(projectCriteria).Take(4).OrderBy(x => x.Name).ToList()
                    : UHelper.TypedSearch(projectCriteria).OrderBy(x => x.Name).ToList();

                if (cachedProjects.Any())
                {
                    response.AddRange(cachedProjects.Select(cachedProject => IPubishedContentToPvm(cachedProject)));
                }
            }

            return(response);
        }