Beispiel #1
0
        public async Task Run_XXX()
        {
            // Arrange
            await _testDataCreationService.CreateRequests(10);

            // Act
            await _sut.Merge();

            // Assert
            Assert.AreEqual(1, 1);
        }
Beispiel #2
0
        public void When_merging()
        {
            var ms      = new MergeService();
            var mergeID = ms.Merge(_primary, _secondary);

            _primary.PushEvent(new MobilePhoneChangedEvent("0744 4444 444"));
            _store.Save("Users", _primary);

            _primary.ShouldSatisfyAllConditions(
                () => _primary.Name.ShouldBe("Andrew"),
                () => _primary.Phones[PhoneType.Mobile].ShouldBe("0744 4444 444"),
                () => _primary.Phones[PhoneType.Home].ShouldBe("01412 123 123")
                );
        }
Beispiel #3
0
        public void When_undoing_a_merge_with_modifications_after()
        {
            var ms      = new MergeService();
            var mergeID = ms.Merge(_primary, _secondary);

            _primary.PushEvent(new MobilePhoneChangedEvent("0744 4444 444"));
            _store.Save("Users", _primary);

            var user = ms.UndoMerge(_store, 1, mergeID);

            var undo = user.GetUncommittedEvents().ToList();

            undo.ShouldSatisfyAllConditions(
                () => undo.OfType <NameMergeRevertedEvent>().Single().Name.ShouldBe("Andy"),
                () => undo.Count.ShouldBe(1)
                );
        }
Beispiel #4
0
        public void When_undoing_a_merge()
        {
            var ms      = new MergeService();
            var mergeID = ms.Merge(_primary, _secondary);

            _store.Save("Users", _primary);

            var user = ms.UndoMerge(_store, 1, mergeID);

            var undo = user.GetUncommittedEvents().ToList();

            undo.ShouldSatisfyAllConditions(
                () => undo.OfType <NameMergeRevertedEvent>().Single().Name.ShouldBe("Andy"),
                () => undo.OfType <MobilePhoneMergeRevertedEvent>().Single().MobileNumber.ShouldBe("0798 1234 123"),
                () => undo.Count.ShouldBe(2)
                );
        }
Beispiel #5
0
        /// <summary>
        /// Sorts file by batches. Splits to batches, sorts it and writes in temp files.
        /// Then merge temp files and sorts during the splitting. Writes to output sorted file.
        /// </summary>
        private static void Sort(
            string fileName, long fileSize, string sortFilePath, ISorter sorter, Stopwatch timer)
        {
            char[] chars = Settings.Chars.ToArray();

            Console.WriteLine("File size too big - splitting and sorting batches of the file....");

            var batchService = new BatchService(
                fileName,
                fileSize,
                new BatchCreator(chars),
                new BatchWriter(),
                sorter);

            BatchInfo[] batches = batchService.Execute();

            Console.WriteLine($"The file was batched to '{batches.Length}' peaces: {timer.Elapsed:g}.");
            Console.WriteLine("Merging...");

            var mergeService = new MergeService(sortFilePath, chars, sorter, new Comparer());

            mergeService.Merge(batches);
        }
Beispiel #6
0
        protected virtual void ProcessCUDResult(Object objectToMerge, ICUDResult cudResult, IList <Object> unpersistedObjectsToDelete,
                                                ProceedWithMergeHook proceedHook, bool addNewEntitiesToCache)
        {
            if (cudResult.AllChanges.Count > 0 || (unpersistedObjectsToDelete != null && unpersistedObjectsToDelete.Count > 0))
            {
                if (proceedHook != null)
                {
                    bool proceed = proceedHook.Invoke(cudResult, unpersistedObjectsToDelete);
                    if (!proceed)
                    {
                        return;
                    }
                }
            }
            if (cudResult.AllChanges.Count == 0)
            {
                if (Log.InfoEnabled)
                {
                    Log.Info("Service call skipped early because there is nothing to merge");
                }
            }
            else
            {
                IOriCollection oriColl;
                EventDispatcher.EnableEventQueue();
                try
                {
                    EventDispatcher.Pause(Cache);
                    try
                    {
                        bool?oldNewlyPersistedEntities = addNewlyPersistedEntitiesTL.Value;
                        addNewlyPersistedEntitiesTL.Value = addNewEntitiesToCache;
                        try
                        {
                            IResultingBackgroundWorkerDelegate <IOriCollection> runnable = new IResultingBackgroundWorkerDelegate <IOriCollection>(delegate()
                            {
                                IOriCollection oriColl2 = MergeService.Merge(cudResult, null);
                                MergeController.ApplyChangesToOriginals(cudResult, oriColl2, null);
                                return(oriColl2);
                            });
                            if (Transaction == null || Transaction.Active)
                            {
                                oriColl = runnable();
                            }
                            else
                            {
                                oriColl = Transaction.RunInLazyTransaction(runnable);
                            }
                        }
                        finally
                        {
                            addNewlyPersistedEntitiesTL.Value = oldNewlyPersistedEntities;
                        }
                    }
                    finally
                    {
                        EventDispatcher.Resume(Cache);
                    }
                }
                finally
                {
                    EventDispatcher.FlushEventQueue();
                }
                DataChangeEvent dataChange = DataChangeEvent.Create(-1, -1, -1);
                // This is intentionally a remote source
                dataChange.IsLocalSource = false;

                if (IsNetworkClientMode)
                {
                    IList <IChangeContainer> allChanges = cudResult.AllChanges;

                    IList <IObjRef> orisInReturn = oriColl.AllChangeORIs;
                    for (int a = allChanges.Count; a-- > 0;)
                    {
                        IChangeContainer changeContainer   = allChanges[a];
                        IObjRef          reference         = changeContainer.Reference;
                        IObjRef          referenceInReturn = orisInReturn[a];
                        if (changeContainer is CreateContainer)
                        {
                            if (referenceInReturn.IdNameIndex != ObjRef.PRIMARY_KEY_INDEX)
                            {
                                throw new ArgumentException("Implementation error: Only PK references are allowed in events");
                            }
                            dataChange.Inserts.Add(new DataChangeEntry(referenceInReturn.RealType, referenceInReturn.IdNameIndex, referenceInReturn.Id, referenceInReturn.Version));
                        }
                        else if (changeContainer is UpdateContainer)
                        {
                            if (referenceInReturn.IdNameIndex != ObjRef.PRIMARY_KEY_INDEX)
                            {
                                throw new ArgumentException("Implementation error: Only PK references are allowed in events");
                            }
                            dataChange.Updates.Add(new DataChangeEntry(referenceInReturn.RealType, referenceInReturn.IdNameIndex, referenceInReturn.Id, referenceInReturn.Version));
                        }
                        else if (changeContainer is DeleteContainer)
                        {
                            if (reference.IdNameIndex != ObjRef.PRIMARY_KEY_INDEX)
                            {
                                throw new ArgumentException("Implementation error: Only PK references are allowed in events");
                            }
                            dataChange.Deletes.Add(new DataChangeEntry(reference.RealType, reference.IdNameIndex, reference.Id, reference.Version));
                        }
                    }
                    //EventDispatcher.DispatchEvent(dataChange, DateTime.Now, -1);
                }
            }
            if (unpersistedObjectsToDelete != null && unpersistedObjectsToDelete.Count > 0)
            {
                // Create a DCE for all objects without an id but which should be deleted...
                // This is the case for newly created objects on client side, which should be
                // "cancelled". The DCE notifies all models which contain identity references to the related
                // objects to erase their existence in all controls. They are not relevant in the previous
                // server merge process
                DataChangeEvent dataChange = DataChangeEvent.Create(0, 0, unpersistedObjectsToDelete.Count);

                for (int a = unpersistedObjectsToDelete.Count; a-- > 0;)
                {
                    Object unpersistedObject = unpersistedObjectsToDelete[a];
                    dataChange.Deletes.Add(new DirectDataChangeEntry(unpersistedObject));
                }
                EventDispatcher.DispatchEvent(dataChange, DateTime.Now, -1);
            }
            RevertChangesHelper.RevertChanges(objectToMerge);
        }
        public DocumentResponse mergeDocument()
        {
            MergeService ms = new MergeService();

            return(ms.Merge(this.HttpContext));
        }