Exemple #1
0
        /// <summary>
        ///     Allows migration of a collection of documents one document at a time.
        ///     Also allows additional commands to be batched with the changes to each document.
        /// </summary>
        /// <param name="tag">The name of the collection.</param>
        /// <param name="migrate">The func to migrate a single document and metadata and return additional commands to run in the same batch.</param>
        /// <param name="pageSize">The page size for batching the documents.</param>
        public void CollectionWithAdditionalCommands(string tag, Func <RavenJObject, RavenJObject, IEnumerable <ICommandData> > migrate, int pageSize = 128)
        {
            QueryHeaderInformation headerInfo;
            var enumerator = DocumentStore.DatabaseCommands.StreamQuery("Raven/DocumentsByEntityName",
                                                                        new IndexQuery
            {
                Query = "Tag:" + tag,
            },
                                                                        out headerInfo);


            var actions = new RavenActions();

            using (enumerator)
                while (enumerator.MoveNext())
                {
                    var entity   = enumerator.Current;
                    var metadata = entity.Value <RavenJObject>("@metadata");

                    var actionCommands = migrate(entity, metadata) ?? new List <ICommandData>();

                    actions.AdditionalMigrationCommands.AddRange(actionCommands);

                    actions.MigrationCommands.Add(new PutCommandData
                    {
                        Document = entity,
                        Metadata = metadata,
                        Key      = metadata.Value <string>("@id"),
                    });

                    if (actions.MigrationCommands.Count == pageSize)
                    {
                        DocumentStore.DatabaseCommands.Batch(actions.AllCommands());
                        Logger.WriteInformation("Updated {0} documents", actions.MigrationCommands.Count);
                        actions.ClearMigrationCommands();
                    }
                }

            var commands = actions.AllCommands();

            if (commands.Count > 0)
            {
                DocumentStore.DatabaseCommands.Batch(commands);
            }
            Logger.WriteInformation("Updated {0} documents", actions.MigrationCommands.Count);
        }
Exemple #2
0
        /// <summary>
        ///     Allows migration of a collection of documents one document at a time.
        ///     Also allows additional commands to be batched with the changes to each document.
        /// </summary>
        /// <param name="tag">The name of the collection.</param>
        /// <param name="migrate">The func to migrate a single document and metadata and return additional commands to run in the same batch.</param>
        /// <param name="pageSize">The page size for batching the documents.</param>
        public void CollectionWithAdditionalCommands(string tag, Func<RavenJObject, RavenJObject, IEnumerable<ICommandData>> migrate, int pageSize = 128)
        {
            QueryHeaderInformation headerInfo;
            var enumerator = DocumentStore.DatabaseCommands.StreamQuery("Raven/DocumentsByEntityName",
                new IndexQuery
                {
                    Query = "Tag:" + tag,
                },
                out headerInfo);


            var actions = new RavenActions();
            using (enumerator)
            while (enumerator.MoveNext())
            {
                var entity = enumerator.Current;
                var metadata = entity.Value<RavenJObject>("@metadata");

                var actionCommands = migrate(entity, metadata) ?? new List<ICommandData>();

                actions.AdditionalMigrationCommands.AddRange(actionCommands);

                actions.MigrationCommands.Add(new PutCommandData
                {
                    Document = entity,
                    Metadata = metadata,
                    Key = metadata.Value<string>("@id"),
                });

                if (actions.MigrationCommands.Count == pageSize)
                {
                    DocumentStore.DatabaseCommands.Batch(actions.AllCommands());
                    actions.ClearMigrationCommands();
                }
            }

            if (actions.AllCommands().Count > 0)
                DocumentStore.DatabaseCommands.Batch(actions.AllCommands());
        }