public static async Task <IActionResult> IndexItem( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("GetIndexItem: Starting"); string responseMessage = ""; try { string name = req.Query["name"]; if (string.IsNullOrEmpty(name)) { log.LogError("GetIndexItem: error, source name is missing"); return(new BadRequestObjectResult("Error missing source name")); } int id = Common.Helpers.Common.GetIntFromWebQuery(req, "id"); string storageAccount = Common.Helpers.Common.GetStorageKey(req); IndexManagement im = new IndexManagement(storageAccount); responseMessage = await im.GetIndexItem(name, id); } catch (Exception ex) { log.LogError($"GetIndexItem: {ex}"); return(new BadRequestObjectResult($"Error getting index item: {ex}")); } log.LogInformation("GetIndexItem: Complete"); return(new OkObjectResult(responseMessage)); }
public InitManagement(string monitorFolder, CodeIndexConfiguration codeIndexConfiguration, bool initFiles = false, int maxContentHighlightLength = Constants.DefaultMaxContentHighlightLength) { indexConfig = new IndexConfig { IndexName = "ABC", MonitorFolder = monitorFolder, MaxContentHighlightLength = maxContentHighlightLength }; if (initFiles) { var fileName1 = Path.Combine(monitorFolder, "A.txt"); var fileName2 = Path.Combine(monitorFolder, "B.txt"); var fileName3 = Path.Combine(monitorFolder, "C.txt"); File.AppendAllText(fileName1, "ABCD"); File.AppendAllText(fileName2, "ABCD EFGH"); File.AppendAllText(fileName3, "ABCD EFGH IJKL" + Environment.NewLine + "ABCD ABCE"); } management = new IndexManagement(codeIndexConfiguration, log1); management.AddIndex(indexConfig); var maintainer = management.GetIndexMaintainerWrapperAndInitializeIfNeeded(indexConfig.Pk); // Wait initialized finished while (maintainer.Result.Status == IndexStatus.Initializing_ComponentInitializeFinished || maintainer.Result.Status == IndexStatus.Initialized) { Thread.Sleep(100); } }
public static async Task <IActionResult> MakeIndex( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("CreateIndex: Starting"); try { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); CreateIndexParameters indexParm = JsonConvert.DeserializeObject <CreateIndexParameters>(requestBody); if (indexParm == null) { log.LogError("CreateIndex: error missing index parameters"); return(new BadRequestObjectResult("Error missing index parameters")); } string storageAccount = Common.Helpers.Common.GetStorageKey(req); IndexManagement im = new IndexManagement(storageAccount); await im.CreateIndex(indexParm); } catch (Exception ex) { log.LogError($"CreateIndex: {ex}"); return(new BadRequestObjectResult($"Error creating index: {ex}")); } log.LogInformation("CreateIndex: Complete"); return(new OkObjectResult("OK")); }
public void TestAddIndex() { var indexConfig = new IndexConfig { IndexName = "ABC", MonitorFolder = MonitorFolder }; using var management = new IndexManagement(Config, Log); CollectionAssert.IsEmpty(management.GetIndexList().Result); Assert.IsTrue(management.AddIndex(indexConfig).Status.Success); CollectionAssert.AreEquivalent(new[] { indexConfig.ToString() }, management.GetIndexList().Result.Select(u => u.IndexConfig.ToString())); Assert.IsFalse(management.AddIndex(indexConfig).Status.Success); Assert.IsFalse(management.AddIndex(indexConfig with { IndexName = null }).Status.Success); Assert.IsFalse(management.AddIndex(indexConfig with { IndexName = "BBB" }).Status.Success); Assert.IsFalse(management.AddIndex(indexConfig with { IndexName = "A".PadLeft(101, 'C') }).Status.Success); Assert.IsFalse(management.AddIndex(indexConfig with { Pk = Guid.NewGuid(), IndexName = "BBB", MonitorFolder = string.Empty }).Status.Success); Assert.IsFalse(management.AddIndex(indexConfig with { Pk = Guid.NewGuid(), IndexName = "BBB" }).Status.Success); Assert.IsFalse(management.AddIndex(indexConfig with { Pk = Guid.NewGuid(), IndexName = "BBB", MonitorFolder = "Dummy" }).Status.Success); CollectionAssert.AreEquivalent(new[] { indexConfig.ToString() }, management.GetIndexList().Result.Select(u => u.IndexConfig.ToString())); }
public async Task <ActionResult <string> > GetChildren(string source, int id) { string storageAccount = Common.Helpers.Common.GetStorageKey(Request); IndexManagement im = new IndexManagement(storageAccount); string result = await im.GetIndexItem(source, id); return(result); }
public void CreateWithOneIndexThrowsException() { //assert Assert.ThrowsAsync <ArgumentException>(() => IndexManagement.CreateIndex <City>( ConfigValues.project, new IndexField { fieldPath = nameof(City.Name), mode = nameof(ModeValues.ASCENDING) })); }
public async Task <ActionResult> Create(CreateIndexParameters iParameters) { logger.LogInformation("CreateIndexController: Starting index create"); try { string storageAccount = Common.Helpers.Common.GetStorageKey(Request); IndexManagement im = new IndexManagement(storageAccount); await im.CreateIndex(iParameters); } catch (Exception ex) { logger.LogInformation($"CreateIndexController: Error message = {ex}"); return(BadRequest(ex.ToString())); } return(NoContent()); }
public async Task <ActionResult <List <DmsIndex> > > Get(string source) { try { string storageAccount = Common.Helpers.Common.GetStorageKey(Request); IndexManagement im = new IndexManagement(storageAccount); string responseMessage = await im.GetIndexData(source); List <DmsIndex> index = JsonConvert.DeserializeObject <List <DmsIndex> >(responseMessage); return(index); } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public void TestConstructor_InitializeMaintainerPool() { var indexConfig = new IndexConfig { IndexName = "ABC", MonitorFolder = MonitorFolder }; using var management1 = new IndexManagement(Config, Log); CollectionAssert.IsEmpty(management1.GetIndexList().Result); management1.AddIndex(indexConfig); management1.Dispose(); using var management2 = new IndexManagement(Config, Log); CollectionAssert.AreEquivalent(new[] { indexConfig.ToString() }, management2.GetIndexList().Result.Select(u => u.IndexConfig.ToString())); }
public async Task <ActionResult <List <IndexFileList> > > GetTaxonomies() { try { string storageAccount = Common.Helpers.Common.GetStorageKey(Request); IndexManagement im = new IndexManagement(storageAccount); string responseMessage = await im.GetTaxonomies(); List <IndexFileList> indexParms = JsonConvert.DeserializeObject <List <IndexFileList> >(responseMessage); //List<string> files = indexParms.Select(item => item.Name).ToList(); return(indexParms); } catch (Exception) { return(BadRequest()); } }
public async Task CreateIndex() { //act var response = await IndexManagement.CreateIndex <City>(ConfigValues.project, new IndexField { fieldPath = nameof(City.Name), mode = nameof(ModeValues.ASCENDING) }, new IndexField { fieldPath = nameof(City.PopSize), mode = nameof(ModeValues.DESCENDING) }); //assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public static async Task <IActionResult> Taxonomies( [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("GetTaxonomies: Starting"); string responseMessage = ""; try { string storageAccount = Common.Helpers.Common.GetStorageKey(req); IndexManagement im = new IndexManagement(storageAccount); responseMessage = await im.GetTaxonomies(); } catch (Exception ex) { log.LogError($"GetTaxonomies: {ex}"); return(new BadRequestObjectResult($"Error getting taxonomies: {ex}")); } log.LogInformation("GetTaxonomies: Complete"); return(new OkObjectResult(responseMessage)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifeTime, IndexManagement indexManagement) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); // Register the Swagger generator and the Swagger UI middlewares app.UseOpenApi(); app.UseSwaggerUi3(); app.UseAuthentication(); app.UseAuthorization(); app.UseSession(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapBlazorHub(); endpoints.MapFallbackToPage("/_Host"); }); lifeTime.ApplicationStopping.Register(OnShutdown); IndexManagement = indexManagement; }
public async Task <FetchResult <bool> > DeleteIndex(Guid indexPk, [FromServices] IndexManagement indexManagement) { return(await Task.FromResult(indexManagement.DeleteIndex(indexPk))); }
public async Task <FetchResult <bool> > EditIndex(IndexConfig indexConfig, [FromServices] IndexManagement indexManagement) { return(await Task.FromResult(indexManagement.EditIndex(indexConfig))); }
public async Task <FetchResult <IndexStatusInfo[]> > GetIndexLists([FromServices] IndexManagement indexManagement) { return(await Task.FromResult(indexManagement.GetIndexList())); }
public CodeIndexSearcher(IndexManagement indexManagement, ILogger <CodeIndexSearcher> log) { IndexManagement = indexManagement; Log = log; }
public async Task <FetchResult <IndexConfigForView[]> > GetIndexViewList([FromServices] IndexManagement indexManagement) { return(await Task.FromResult(indexManagement.GetIndexViewList())); }