public async Task UploadToCosmos(CrudManager <TraveltimeSegment> crudManager, List <TraveltimeSegment> segments) { { List <Task> tasks = new List <Task>(); foreach (var segment in segments) { concurrencySemaphore.Wait(); var t = Task.Factory.StartNew(() => { try { crudManager.Create(segment).Wait(); } finally { concurrencySemaphore.Release(); UpdateProgress(); } }); tasks.Add(t); } await Task.WhenAll(tasks.ToArray()); } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var BlobName = Request.Form["blobName"]; var BlobKey = Request.Form["blobKey"]; var BlobContainer = Request.Form["blobContainer"]; var CosmosUrl = Request.Form["cosmosUrl"]; var CosmosKey = Request.Form["cosmosKey"]; var DatabaseName = Request.Form["OutputDB"]; var CollectionName = Request.Form["OutputColl"]; var Path = Request.Form["folder"]; BlobManager blobManager = new BlobManager(BlobName, BlobKey); List <IListBlobItem> items = blobManager.ListAllBlobsAsync(BlobContainer, Path).Result; _logger.LogInformation($"{items.Count} items found to import"); List <TraveltimeSegmentStatic> segments = new List <TraveltimeSegmentStatic>(); foreach (IListBlobItem item in items) { segments.AddRange(CSVReader.GetStaticsFromCSVString(blobManager.DownloadBlob(item.Container.Name, BlobManager.getBlobIdFromURI(item.Uri)).Result)); } _logger.LogInformation($"{segments.Count} documents parsed"); CrudManager <TraveltimeSegmentStatic> crudManager = new CrudManager <TraveltimeSegmentStatic> { DatabaseUri = CosmosUrl, DatabaseKey = CosmosKey, DatabaseName = DatabaseName, CollectionName = CollectionName }; crudManager.Init(); foreach (TraveltimeSegmentStatic segment in segments) { await crudManager.Create(segment); } return(RedirectToPage("/BE-Mobile/BEM_import_static")); }