示例#1
0
        private DocumentChange[] determineChanges(UpdateBatch batch)
        {
            var types = _operations.Value.Enumerate().Select(x => x.Key).TopologicalSort(GetTypeDependencies);

            foreach (var type in types)
            {
                if (!_operations.Value.TryFind(type, out var value))
                {
                    continue;
                }

                foreach (var operation in value)
                {
                    // No Virginia, I do not approve of this but I'm pulling all my hair
                    // out as is trying to make this work
                    if (operation is DocumentStorageOperation)
                    {
                        operation.As <DocumentStorageOperation>().Persist(batch, _tenant);
                    }
                    else
                    {
                        batch.Add(operation);
                    }
                }
            }

            writeEvents(batch);

            batch.Add(_ancillaryOperations);

            var changes = detectTrackerChanges();

            changes.GroupBy(x => x.DocumentType).Each(group =>
            {
                var upsert = _tenant.StorageFor(group.Key);

                group.Each(c => { upsert.RegisterUpdate(null, UpdateStyle.Upsert, batch, c.Document, c.Json); });
            });

            return(changes);
        }
示例#2
0
        private DocumentChange[] determineChanges(UpdateBatch batch)
        {
            var types = _operations.Select(x => x.Key).TopologicalSort(GetTypeDependencies);

            foreach (var type in types)
            {
                if (!_operations.ContainsKey(type))
                {
                    continue;
                }

                foreach (var operation in _operations[type])
                {
                    // No Virginia, I do not approve of this but I'm pulling all my hair
                    // out as is trying to make this work
                    if (operation is Upsert)
                    {
                        operation.As <Upsert>().Persist(batch, _schema);
                    }
                    else
                    {
                        batch.Add(operation);
                    }
                }
            }

            writeEvents(batch);

            batch.Add(_ancillaryOperations);

            var changes = detectTrackerChanges();

            changes.GroupBy(x => x.DocumentType).Each(group =>
            {
                var upsert = _schema.UpsertFor(group.Key);

                group.Each(c => { upsert.RegisterUpdate(batch, c.Document, c.Json); });
            });

            return(changes);
        }
示例#3
0
        private DocumentChange[] determineChanges(UpdateBatch batch)
        {
            var allOperations = _operations.Value.Enumerate().SelectMany(x => x.Value).ToList();

            if (shouldSort(allOperations, out var comparer))
            {
                allOperations.Sort(comparer);
            }

            foreach (var operation in allOperations)
            {
                // No Virginia, I do not approve of this but I'm pulling all my hair
                // out as is trying to make this work
                if (operation is DocumentStorageOperation)
                {
                    operation.As <DocumentStorageOperation>().Persist(batch, _tenant);
                }
                else
                {
                    batch.Add(operation);
                }
            }

            writeEvents(batch);

            batch.Add(_ancillaryOperations);

            var changes = detectTrackerChanges();

            changes.GroupBy(x => x.DocumentType).Each(group =>
            {
                var upsert = _tenant.StorageFor(group.Key);

                group.Each(c => { upsert.RegisterUpdate(null, UpdateStyle.Upsert, batch, c.Document, c.Json); });
            });

            return(changes);
        }
示例#4
0
        private DocumentChange[] determineChanges(UpdateBatch batch)
        {
            int index = 0;
            var order = _inserts.Keys.Union(_updates.Keys)
                        .TopologicalSort(GetTypeDependencies)
                        .ToDictionary(x => x, x => index++);

            _inserts.Keys.OrderBy(type => order[type]).Each(type =>
            {
                var upsert = _schema.UpsertFor(type);

                _inserts[type].Each(o => upsert.RegisterUpdate(batch, o));
            });

            _updates.Keys.OrderBy(type => order[type]).Each(type =>
            {
                var upsert = _schema.UpsertFor(type);

                _updates[type].Each(o => upsert.RegisterUpdate(batch, o));
            });

            writeEvents(batch);


            batch.Add(_operations);

            var changes = detectTrackerChanges();

            changes.GroupBy(x => x.DocumentType).Each(group =>
            {
                var upsert = _schema.UpsertFor(group.Key);

                group.Each(c =>
                {
                    upsert.RegisterUpdate(batch, c.Document, c.Json);
                });
            });

            return(changes);
        }