public static async Task FindDoc(HttpContext http) { try { var filter = await http.ReadAs <Dictionary <string, string> >(); if (!filter.TryGetValue("branch", out string branch)) { branch = "master"; } var baseinfos = await DocumentDBRepo <BaseInfo> .GetItemsAsync(b => b.basename == filter["basename"] && b.branch == branch); List <string> commits = new List <string>(); foreach (BaseInfo b in baseinfos) { commits.Add(b.commit); } var documents = await DocumentDBRepo <Document> .GetItemsAsync( d => d.Url == filter["url"] && d.Locale == filter["locale"] && d.Version == filter["version"] && commits.Contains(d.Commit) ); await http.Write(documents); } catch { throw; } }
static void Main(string[] args) { DocumentDBRepo <BaseInfo> .Initialize(CollectionBase); DocumentDBRepo <Document> .Initialize(CollectionDocument); BlobStorage.Initialize(); WebHost.CreateDefaultBuilder(args) .ConfigureServices(services => services.AddRouting()) .Configure(Configure) .Build() .Run(); }
public static async Task PutDoc(HttpContext http) { var docs = await http.ReadAs <List <Document> >(); using (var semaphoreSlim = new SemaphoreSlim(50)) { var tasks = docs.Select(async doc => { await semaphoreSlim.WaitAsync().ConfigureAwait(false); try { await DocumentDBRepo <Document> .UpsertItemsAsync(doc); } finally { semaphoreSlim.Release(); } }); await Task.WhenAll(tasks).ConfigureAwait(false); } //await Task.WhenAll(docs.Select(doc => DocumentDBRepo<Document>.UpsertItemsAsync(doc))); }