public async Task <IActionResult> GetPaginatedResultAsync( [FromQuery] NodeSearch nodeSearch, int currentPage) { var pageSize = 10; var pageSizeSetting = _contentAppSettings.PageSizeSettings.FirstOrDefault( pss => pss.Key == $"{nodeSearch.Module}:{nodeSearch.Type}" ); if (pageSizeSetting != null) { pageSize = int.Parse(pageSizeSetting.Value); } if (nodeSearch.PageSize > 0 && nodeSearch.PageSize < pageSize) { pageSize = nodeSearch.PageSize; } var results = await _nodeService.GetPaginatedResultAsync(nodeSearch, currentPage, pageSize); if (nodeSearch.TruncateContent > 0) { foreach (var result in results) { result.Content = Helper.Truncate(result.Content, nodeSearch.TruncateContent); } } if (!string.IsNullOrEmpty(nodeSearch.Slug) && results.Count == 0) { return(NotFound()); } return(Ok(results)); }
// https://www.mikesdotnetting.com/article/328/simple-paging-in-asp-net-core-razor-pages public async Task <List <Node> > GetPaginatedResultAsync(NodeSearch nodeSearch, int currentPage, int pageSize = 10) { var data = _nodeRepository.Get(nodeSearch); var output = await data.Skip((currentPage - 1) *pageSize).Take(pageSize).ToListAsync(); return(output); }
public async Task <Node> GetBySlugAsync( string module, string type, string slug, bool noStore = false) { var nodeSearch = new NodeSearch() { Module = module, Type = type, Slug = slug }; var requestUri = $"{API_URL}/GetPaginatedResult?{nodeSearch.ToQueryString()}"; using var request = new HttpRequestMessage(HttpMethod.Get, requestUri); if (noStore) { request.SetBrowserRequestCache(BrowserRequestCache.NoStore); } var response = await PublicHttpClient.SendAsync(request); if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { return(null); } var jsonString = await response.Content.ReadAsStringAsync(); var items = System.Text.Json.JsonSerializer.Deserialize <Node[]>(jsonString, _jsonSerializerOptions); return(items.FirstOrDefault()); }
public async Task <int> GetCountAsync(NodeSearch nodeSearch) { var request = $"{API_URL}/GetCount?{nodeSearch.ToQueryString()}"; var response = await PublicHttpClient.GetAsync(request); var count = await response.Content.ReadAsStringAsync(); return(int.Parse(count)); }
public async Task <int> GetCountAsync(NodeSearch nodeSearch) { var request = $"{API_URL}/GetCount"; var response = await PublicHttpClient.PostAsJsonAsync <NodeSearch>(request, nodeSearch); var count = await response.Content.ReadAsStringAsync(); return(int.Parse(count)); }
public async Async.Task Search_SpecificNode_NotFound_ReturnsNotFound() { var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var req = new NodeSearch(MachineId: _machineId); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson("GET", req)); Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode); }
public async Task <Node[]> SecureGetAsync( NodeSearch nodeSearch, int currentPage) { var request = $"{API_URL}/GetPaginatedResult?currentPage={currentPage}"; var response = await AuthorizedHttpClient.PostAsJsonAsync <NodeSearch>(request, nodeSearch); var jsonString = await response.Content.ReadAsStringAsync(); return(System.Text.Json.JsonSerializer.Deserialize <Node[]>(jsonString, _jsonSerializerOptions)); }
public NodeSearchContext(IGraphNode <T> start, GraphNodeVisitationControl <T> visitTracker, NodeSearch <T> predicate) { Settings = visitTracker; StartingPoint = start; MoveTo(start); _watch = new DisposableStopwatch(); SearchBehavior = predicate; }
public async Async.Task Search_MultipleNodes_CanFindNone() { var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var req = new NodeSearch(); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson("GET", req)); Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal("[]", BodyAsString(result)); }
public async Task <int> GetPageSizeAsync(NodeSearch nodeSearch) { var request = $"{API_URL}/GetPageSize?{nodeSearch.ToQueryString()}"; var response = await PublicHttpClient.GetAsync(request); var pageSize = await response.Content.ReadAsStringAsync(); int result; int.TryParse(pageSize, out result); return(result); }
public async Task <int> GetPageSizeAsync(NodeSearch nodeSearch) { var request = $"{API_URL}/GetPageSize"; var response = await PublicHttpClient.PostAsJsonAsync <NodeSearch>(request, nodeSearch); var pageSize = await response.Content.ReadAsStringAsync(); int result; int.TryParse(pageSize, out result); return(result); }
public async Task <Node[]> GetAsync( NodeSearch nodeSearch, int currentPage) { var request = $"{API_URL}/GetPaginatedResult?currentPage={currentPage}&{nodeSearch.ToQueryString()}"; var response = await PublicHttpClient.GetAsync(request); var jsonString = await response.Content.ReadAsStringAsync(); var result = System.Text.Json.JsonSerializer.Deserialize <Node[]>(jsonString, _jsonSerializerOptions); return(result); }
public async Task <int> GetPageSizeAsync(NodeSearch nodeSearch) { var pageSize = 10; var pageSizeSetting = (await _settingService.PageSizeSettingsAsync()).FirstOrDefault( pss => pss.Key == $"{nodeSearch.Module}:{nodeSearch.Type}" ); if (pageSizeSetting != null) { pageSize = int.Parse(pageSizeSetting.Value); } return(pageSize); }
protected override async Task OnParametersSetAsync() { var configSearch = new NodeSearch() { Module = Constants.ArticlesModule, Type = Constants.ConfigType }; var configNodes = (await NodeService.GetAsync(configSearch, 0)); if (configNodes.Length > 0) { Config = configNodes[0]; } }
public IActionResult GetPageSize( [FromQuery] NodeSearch nodeSearch) { var pageSize = 10; var pageSizeSetting = _contentAppSettings.PageSizeSettings.FirstOrDefault( pss => pss.Key == $"{nodeSearch.Module}:{nodeSearch.Type}" ); if (pageSizeSetting != null) { pageSize = int.Parse(pageSizeSetting.Value); } return(Ok(pageSize)); }
private void BHInsertNode(NodeSearch ns) { //We use index 0 as the root! if (sortedOpenList.Count == 0) { //UnityEngine.Debug.Log("here?"); sortedOpenList.Add(ns); openList[ns.ID].sortedIndex = 0; return; } sortedOpenList.Add(ns); bool canMoveFurther = true; int index = sortedOpenList.Count - 1; openList[ns.ID].sortedIndex = index; while (canMoveFurther) { int parent = Mathf.FloorToInt((index - 1) / 2); if (index == 0) //We are the root { canMoveFurther = false; openList[sortedOpenList[index].ID].sortedIndex = 0; } else { if (sortedOpenList[index].F < sortedOpenList[parent].F) { NodeSearch s = sortedOpenList[parent]; sortedOpenList[parent] = sortedOpenList[index]; sortedOpenList[index] = s; //Save sortedlist index's for faster look up openList[sortedOpenList[index].ID].sortedIndex = index; openList[sortedOpenList[parent].ID].sortedIndex = parent; //Reset index to parent ID index = parent; } else { canMoveFurther = false; } } } }
private void SaveSelected(ISelectedNode args) { if (args.SelectedNode.IsNull()) { return; } if (args.SelectedNode.MyBranch.NotEqualTo(this)) { return; } LastSelected = NodeSearch.Find(args.SelectedNode) .DefaultReturn(LastSelected) .RunOn(ThisGroupsUiNodes); }
public IActionResult GetPageSize( [FromBody] NodeSearch nodeSearch) { var pageSize = 10; var pageSizeSetting = _contentAppSettings.PageSizeSettings.FirstOrDefault( pss => pss.Module == nodeSearch.Module && pss.Type == nodeSearch.Type ); if (pageSizeSetting != null) { pageSize = pageSizeSetting.PageSize; } return(Ok(pageSize)); }
public async Task <Node> SecureGetAsync( string module, string type, string slug) { var nodeSearch = new NodeSearch() { Module = module, Type = type, Slug = slug }; var result = (await GetPaginatedResultAsync(nodeSearch, 0)).FirstOrDefault(); return(result != null ? result : new Node()); }
private void BHInsertNode(int p, NodeSearch ns) { //We use index 0 as the root! if (sortedOpenList.Count == 0) { sortedOpenList.Add(ns); paths[p].openList[ns.ID].sortedIndex = 0; return; } sortedOpenList.Add(ns); bool canMoveFurther = true; int index = sortedOpenList.Count - 1; paths[p].openList[ns.ID].sortedIndex = index; while (canMoveFurther) { int parent = Mathf.FloorToInt((index - 1) / 2); if (index == 0) //We are the root { paths[p].openList[sortedOpenList[index].ID].sortedIndex = 0; canMoveFurther = false; } else { if (sortedOpenList[index].Fv < sortedOpenList[parent].Fv) { NodeSearch s = sortedOpenList[parent]; sortedOpenList[parent] = sortedOpenList[index]; sortedOpenList[index] = s; //Save sortedlist index's for faster look up paths[p].openList[sortedOpenList[index].ID].sortedIndex = index; paths[p].openList[sortedOpenList[parent].ID].sortedIndex = parent; //Reset index to parent ID index = parent; } else { canMoveFurther = false; } } } }
private void SaveHighlighted(IHighlightedNode args) { if (args.Highlighted.MyBranch.NotEqualTo(this)) { return; } if (LastHighlighted == args.Highlighted) { return; } ClearNodeIfAlwaysHighlightedIsOn(); LastHighlighted = NodeSearch.Find(args.Highlighted) .DefaultReturn(LastSelected) .RunOn(ThisGroupsUiNodes); }
protected override async Task OnParametersSetAsync() { var nodeSearch = new NodeSearch() { Module = Constants.ArticlesModule, Type = Constants.CategoryType, OrderBy = $"{OrderBy.Title}" }; var nodes = await NodeService.GetAsync(nodeSearch, 0); Categories = nodes.ToArray().ConvertTo <Models.Category>(); var article = await NodeService.GetBySlugAsync( Constants.ArticlesModule, Constants.ArticleType, Slug); Article = Models.Article.Create(article); }
public async Async.Task Search_SpecificNode_Found_ReturnsOk() { await Context.InsertAll( new Node(_poolName, _machineId, null, _version)); var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var req = new NodeSearch(MachineId: _machineId); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson("GET", req)); Assert.Equal(HttpStatusCode.OK, result.StatusCode); // make sure we got the data from the table var deserialized = BodyAs <NodeSearchResult>(result); Assert.Equal(_version, deserialized.Version); }
private async Task <List <Node> > GetPaginatedResultAsync(NodeSearch nodeSearch, int currentPage) { var pageSize = 10; var pageSizeSetting = (await _settingService.PageSizeSettingsAsync()).FirstOrDefault( pss => pss.Key == $"{nodeSearch.Module}:{nodeSearch.Type}" ); if (pageSizeSetting != null) { pageSize = int.Parse(pageSizeSetting.Value); } if (nodeSearch.PageSize > 0 && nodeSearch.PageSize < pageSize) { pageSize = nodeSearch.PageSize; } return(await _nodeService.GetPaginatedResultAsync(nodeSearch, currentPage, pageSize)); }
protected override async Task OnParametersSetAsync() { var configSearch = new NodeSearch() { Module = Constants.ForumsModule, Type = Constants.ConfigType }; var configNodes = (await NodeService.GetAsync(configSearch, 0)); if (configNodes.Length > 0) { Config = configNodes[0]; } Forums = new ForumsModel(NodeService) { NodeSearch = new NodeSearch() { Module = Constants.ForumsModule, Type = Constants.ForumType, OrderBy = $"{OrderBy.Title}", RootOnly = true, TruncateContent = 140 } }; await Forums.InitAsync(); var loggedInUserId = (await AuthenticationStateTask).LoggedInUserId(); CanEditConfig = await SecurityService.AllowedAsync( loggedInUserId, null, Constants.ForumsModule, Constants.ConfigType, Actions.Edit ); CanAddForum = await SecurityService.AllowedAsync( loggedInUserId, null, Constants.ForumsModule, Constants.ForumType, Actions.Add ); }
protected override async Task OnParametersSetAsync() { var configSearch = new NodeSearch() { Module = Constants.VideosModule, Type = Constants.ConfigType }; var configNodes = (await NodeService.GetAsync(configSearch, 0)); if (configNodes.Length > 0) { Config = configNodes[0]; } Channels = new ChannelsModel(NodeService) { NodeSearch = new NodeSearch() { Module = Constants.VideosModule, Type = Constants.ChannelType, OrderBy = $"{OrderBy.Weight},{OrderBy.Latest},{OrderBy.Title}" } }; await Channels.InitAsync(); var loggedInUserId = (await AuthenticationStateTask).LoggedInUserId(); CanEditConfig = await SecurityService.AllowedAsync( loggedInUserId, null, Constants.VideosModule, Constants.ConfigType, Actions.Edit ); CanAddChannel = await SecurityService.AllowedAsync( loggedInUserId, null, Constants.VideosModule, Constants.ChannelType, Actions.Add ); }
public async Task <Node> SecureGetAsync( string module, string type, string slug) { var nodeSearch = new NodeSearch() { Module = module, Type = type, Slug = slug }; var request = $"{API_URL}/GetPaginatedResult"; var response = await AuthorizedHttpClient.PostAsJsonAsync <NodeSearch>(request, nodeSearch); var jsonString = await response.Content.ReadAsStringAsync(); var items = System.Text.Json.JsonSerializer.Deserialize <Node[]>(jsonString, _jsonSerializerOptions); return(items.FirstOrDefault()); }
public async Task <IActionResult> GetPaginatedResultAsync( [FromBody] NodeSearch nodeSearch, int currentPage) { var pageSize = 10; var pageSizeSetting = _contentAppSettings.PageSizeSettings.FirstOrDefault( pss => pss.Module == nodeSearch.Module && pss.Type == nodeSearch.Type ); if (pageSizeSetting != null) { pageSize = pageSizeSetting.PageSize; } if (nodeSearch.PageSize > 0 && nodeSearch.PageSize < pageSize) { pageSize = nodeSearch.PageSize; } return(Ok(await _nodeService.GetPaginatedResultAsync(nodeSearch, currentPage, pageSize))); }
public async Async.Task Search_MultipleNodes_ByPoolName() { await Context.InsertAll( new Node(PoolName.Parse("otherPool"), Guid.NewGuid(), null, _version), new Node(_poolName, Guid.NewGuid(), null, _version), new Node(_poolName, Guid.NewGuid(), null, _version)); var req = new NodeSearch(PoolName: _poolName); var auth = new TestEndpointAuthorization(RequestType.User, Logger, Context); var func = new NodeFunction(Logger, auth, Context); var result = await func.Run(TestHttpRequestData.FromJson("GET", req)); Assert.Equal(HttpStatusCode.OK, result.StatusCode); // make sure we got the data from the table var deserialized = BodyAs <NodeSearchResult[]>(result); Assert.Equal(2, deserialized.Length); }
private void BHSortNode(int id, int F) { bool canMoveFurther = true; int index = openList[id].sortedIndex; sortedOpenList[index].F = F; while (canMoveFurther) { int parent = Mathf.FloorToInt((index - 1) / 2); if (index == 0) //We are the root { canMoveFurther = false; openList[sortedOpenList[index].ID].sortedIndex = 0; } else { if (sortedOpenList[index].F < sortedOpenList[parent].F) { NodeSearch s = sortedOpenList[parent]; sortedOpenList[parent] = sortedOpenList[index]; sortedOpenList[index] = s; //Save sortedlist index's for faster look up openList[sortedOpenList[index].ID].sortedIndex = index; openList[sortedOpenList[parent].ID].sortedIndex = parent; //Reset index to parent ID index = parent; } else { canMoveFurther = false; } } } }
private void BHInsertNode(NodeSearch ns) { //We use index 0 as the root! if (sortedOpenList.Count == 0) { sortedOpenList.Add(ns); openList[ns.ID].sortedIndex = 0; return; } sortedOpenList.Add(ns); bool canMoveFurther = true; int index = sortedOpenList.Count - 1; openList[ns.ID].sortedIndex = index; while (canMoveFurther) { int parent = Mathf.FloorToInt((index - 1) / 2); if (index == 0) //We are the root { canMoveFurther = false; openList[sortedOpenList[index].ID].sortedIndex = 0; } else { if (sortedOpenList[index].F < sortedOpenList[parent].F) { NodeSearch s = sortedOpenList[parent]; sortedOpenList[parent] = sortedOpenList[index]; sortedOpenList[index] = s; //Save sortedlist index's for faster look up openList[sortedOpenList[index].ID].sortedIndex = index; openList[sortedOpenList[parent].ID].sortedIndex = parent; //Reset index to parent ID index = parent; } else { canMoveFurther = false; } } } }
private void BHInsertNode(NodeSearch ns){ int index; bool continueNodeInsertion = true; //Insert Node if there is nothing in the BinaryTree if (sortedOpenList.Count == 0) { sortedOpenList.Add(ns); openList[ns.ID].sortedIndex = 0; return; } sortedOpenList.Add(ns); index = sortedOpenList.Count - 1; openList[ns.ID].sortedIndex = index; while(continueNodeInsertion){ int parent = Mathf.FloorToInt((index - 1) / 2); //Root BinaryTree Node; Stop search if (index == 0){ continueNodeInsertion = false; openList[sortedOpenList[index].ID].sortedIndex = 0; }else{ if (sortedOpenList[index].F < sortedOpenList[parent].F) { NodeSearch s = sortedOpenList[parent]; sortedOpenList[parent] = sortedOpenList[index]; sortedOpenList[index] = s; //Save sortedlist index's for faster look up openList[sortedOpenList[index].ID].sortedIndex = index; openList[sortedOpenList[parent].ID].sortedIndex = parent; //Reset index to parent ID index = parent; }else{ continueNodeInsertion = false; } } } }
// Use this for initialization void Start() { audioSrc = GetComponent<AudioSource> (); rigbod = GetComponent<Rigidbody2D> (); nodeSearch = GetComponent<NodeSearch>(); target = GameObject.Find ("Player"); Physics2D.IgnoreCollision (GetComponent<Collider2D> (), target.GetComponent<Collider2D> ()); //stops collision with player //other ignore collisions set in charcontrol for things such as nodes and projectiles if (target.transform.position.x < transform.position.x) { towardTarget = -1; } else { towardTarget = 1; } StartCoroutine (updatePath()); }