Example #1
0
        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;
            }
        }
Example #2
0
        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();
        }
Example #3
0
        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)));
        }