public async Task <IList <BatchResult> > ExecuteAsync(params ICommandData[] commands)
        {
            if (commands == null)
            {
                throw new ArgumentNullException(nameof(commands));
            }

            var result = await _commands.BatchAsync(commands);

            return(result.ToList());
        }
Example #2
0
            private IEnumerable <Task> CreateSampleData()
            {
                // this code assumes a small enough dataset, and doesn't do any sort
                // of paging or batching whatsoever.

                HomeModel.ShowCreateSampleData.Value = false;
                model.IsGeneratingSampleData         = true;

                using (var sampleData = typeof(HomeModel).Assembly.GetManifestResourceStream("Raven.Studio.Assets.EmbeddedData.MvcMusicStore_Dump.json"))
                    using (var streamReader = new StreamReader(sampleData))
                    {
                        var musicStoreData = (RavenJObject)RavenJToken.ReadFrom(new JsonTextReader(streamReader));
                        foreach (var index in musicStoreData.Value <RavenJArray>("Indexes"))
                        {
                            var indexName    = index.Value <string>("name");
                            var ravenJObject = index.Value <RavenJObject>("definition");
                            var putDoc       = databaseCommands
                                               .PutIndexAsync(indexName,
                                                              ravenJObject.JsonDeserialization <IndexDefinition>(),
                                                              true);
                            yield return(putDoc);
                        }

                        var batch = databaseCommands.BatchAsync(
                            musicStoreData.Value <RavenJArray>("Docs").OfType <RavenJObject>().Select(
                                doc =>
                        {
                            var metadata = doc.Value <RavenJObject>("@metadata");
                            doc.Remove("@metadata");
                            return(new PutCommandData
                            {
                                Document = doc,
                                Metadata = metadata,
                                Key = metadata.Value <string>("@id"),
                            });
                        }).ToArray()
                            );

                        yield return(batch);

                        model.IsGeneratingSampleData = false;
                    }
            }
Example #3
0
            Task FlushBatch(List <RavenJObject> batch)
            {
                totalCount += batch.Count;
                var sw       = Stopwatch.StartNew();
                var commands = (from doc in batch
                                let metadata = doc.Value <RavenJObject>("@metadata")
                                               let removal = doc.Remove("@metadata")
                                                             select new PutCommandData
                {
                    Metadata = metadata,
                    Document = doc,
                    Key = metadata.Value <string>("@id"),
                }).ToArray();

                output(String.Format("Wrote {0} documents  in {1:#,#;;0} ms",
                                     batch.Count, sw.ElapsedMilliseconds));

                return(databaseCommands
                       .BatchAsync(commands));
            }
Example #4
0
        private Task FlushBatch()
        {
            if (batch.Count == 0)
            {
                return(new CompletedTask());
            }

            var putCommands = (from doc in batch
                               let metadata = doc.Value <RavenJObject>("@metadata")
                                              let removal = doc.Remove("@metadata")
                                                            select new PutCommandData
            {
                Metadata = metadata,
                Document = doc,
                Key = metadata.Value <string>("@id"),
            }).ToArray();

            return(commands
                   .BatchAsync(putCommands)
                   .ContinueOnSuccess(task => batch.Clear()));
        }