Exemplo n.º 1
0
        public void ShouldSetBestNewAge()
        {
            var service     = new MergeService(_dataAccess.Object, _repository.Object);
            var newCustomer = new MappedCustomerMessage
            {
                CustomerId = 1,
                SourceId   = 2,
                Data       = new Dictionary <string, Dictionary <string, object> > {
                    { "edad", new Dictionary <string, object> {
                          { "2", 36 }
                      } }
                }
            };
            var customerDocument = new CustomerDocument("1")
            {
                Data = new Dictionary <string, object> {
                    { "nombre", "cliente prueba" },
                    { "edad", 35 }
                },
                Full = JObject.Parse(elasticCustomer)
            };

            _dataAccess.Setup(x => x.Get <CustomerDocument>(It.IsAny <string>())).Returns(customerDocument);
            _dataAccess.Setup(x => x.Put(It.IsAny <CustomerDocument>()));
            service.Save("1", newCustomer);
            _dataAccess.Verify(x => x.Put(It.Is <CustomerDocument>(y => y.Data.Any(z => z.Key == "edad" && ((int)z.Value) == 36))));
        }
Exemplo n.º 2
0
        public void MergeJson2Docx_TranslatedStringsMatchJsonStringCountTest()
        {
            var resultStrings = new List <string>();

            resultStrings.Add("Result string 1");
            resultStrings.Add("Result string 2");
            resultStrings.Add("Result string 3");
            resultStrings.Add("Result string 4");
            resultStrings.Add("Result string 5");

            var mockTextMerger = new Mock <IDocxTextMerger>();

            mockTextMerger.Setup(tb => tb.Merge(It.IsAny <JsonConversionData>(), It.IsAny <DocxConversionData>(), It.IsAny <bool>()))
            .Returns(resultStrings);

            var sut = new MergeService(mockTextMerger.Object);

            var jsonFileData = new JsonConversionData(fullJsonTestFilePath)
            {
                TotalStrings2Translate = 5
            };

            var docxFileData = new DocxConversionData(fullDocxTestFilePath)
            {
                TotalStrings2Translate = 5
            };

            var result = sut.MergeJson2Docx(jsonFileData, docxFileData);

            Assert.AreEqual(result, "Success");
        }
Exemplo n.º 3
0
        public void should_merge_overlapping_resource_modules()
        {
            var spec2 = new FubuMVC.Swank.Specification.Specification {
                Modules = new List <Module> {
                    new Module {
                        Name      = "Some module",
                        Resources = new List <Resource> {
                            new Resource {
                                Name      = "Some module resource",
                                Endpoints = new List <Endpoint> {
                                    new Endpoint {
                                        Url    = "/overlappingmoduleresource",
                                        Method = "POST"
                                    },
                                    new Endpoint {
                                        Url    = "/overlappingmoduleresource",
                                        Method = "GET"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var spec = new MergeService().Merge(_spec1, spec2);

            spec.Modules.Count.ShouldEqual(1);
            var module = spec.Modules[0];

            module.Name.ShouldEqual("Some module");
            module.Comments.ShouldEqual("Some module comments");
            module.Resources.Count.ShouldEqual(1);

            var resource = module.Resources[0];

            resource.Name.ShouldEqual("Some module resource");
            resource.Comments.ShouldEqual("Some module resource comments");
            resource.Endpoints.Count.ShouldEqual(3);

            var endpoint = resource.Endpoints[0];

            endpoint.Name.ShouldBeNull();
            endpoint.Comments.ShouldBeNull();
            endpoint.Url.ShouldEqual("/overlappingmoduleresource");
            endpoint.Method.ShouldEqual("GET");

            endpoint = resource.Endpoints[1];
            endpoint.Name.ShouldBeNull();
            endpoint.Comments.ShouldBeNull();
            endpoint.Url.ShouldEqual("/overlappingmoduleresource");
            endpoint.Method.ShouldEqual("POST");

            endpoint = resource.Endpoints[2];
            endpoint.Name.ShouldEqual("Some endpoint");
            endpoint.Comments.ShouldEqual("Some endpoint comments");
            endpoint.Url.ShouldEqual("/some/url");
            endpoint.Method.ShouldEqual("METHOD");
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var source  = FileService.ReadFile(args[0]);
            var changeA = FileService.ReadFile(args[1]);
            var changeB = FileService.ReadFile(args[2]);
            var result  = MergeService.ThreeWayMerge(source, changeA, changeB);

            FileService.WriteFile(result);
        }
Exemplo n.º 5
0
        public void ThreeWayMerge_NoChange_ResultEqualsToSource()
        {
            var source  = FileService.ReadFile("TestFiles/NoChanges/source.txt");
            var changeA = FileService.ReadFile("TestFiles/NoChanges/changeA.txt");
            var changeB = FileService.ReadFile("TestFiles/NoChanges/changeB.txt");

            var result = MergeService.ThreeWayMerge(source, changeA, changeB);

            Assert.AreEqual(source, result);
        }
Exemplo n.º 6
0
        public void ThreeWayMerge_MergeConflict_ResultHaveConflictNotice()
        {
            var source         = FileService.ReadFile("TestFiles/MergeConflict/source.txt");
            var changeA        = FileService.ReadFile("TestFiles/MergeConflict/changeA.txt");
            var changeB        = FileService.ReadFile("TestFiles/MergeConflict/changeB.txt");
            var expectedResult = FileService.ReadFile("TestFiles/MergeConflict/result.txt");

            var result = MergeService.ThreeWayMerge(source, changeA, changeB);

            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 7
0
        public void ThreeWayMerge_AddedInBoth_ResultHaveBothChanges()
        {
            var source         = FileService.ReadFile("TestFiles/Added/source.txt");
            var changeA        = FileService.ReadFile("TestFiles/Added/changeA.txt");
            var changeB        = FileService.ReadFile("TestFiles/Added/changeB.txt");
            var expectedResult = FileService.ReadFile("TestFiles/Added/result.txt");

            var result = MergeService.ThreeWayMerge(source, changeA, changeB);

            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 8
0
        public void ThreeWayMerge_MultipleChanges_ResultAllChanges()
        {
            var source         = FileService.ReadFile("TestFiles/Multiple/source.txt");
            var changeA        = FileService.ReadFile("TestFiles/Multiple/changeA.txt");
            var changeB        = FileService.ReadFile("TestFiles/Multiple/changeB.txt");
            var expectedResult = FileService.ReadFile("TestFiles/Multiple/result.txt");

            var result = MergeService.ThreeWayMerge(source, changeA, changeB);

            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 9
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")
                );
        }
Exemplo n.º 10
0
        //when editing this function delete everything from this folder: 'C:\Users\YOUR_NAME\AppData\Local\Microsoft\VisualStudio\NUMBER_WITH_EXP_IN'
        //FYI: This will reset the whole VS experimental instance
        //or for only resetting the extension find it and delete the folder.
        protected override ITeamExplorerSection CreateViewModel(SectionInitializeEventArgs e)
        {
            var logger       = new Logger();
            var configHelper = new ConfigHelper();

            var solutionService = new SolutionService(ServiceProvider, configHelper);
            var tfvcService     = new TFVCService(ServiceProvider, solutionService);

            var teamService  = new TeamService(ServiceProvider, tfvcService);
            var mergeService = new MergeService(ServiceProvider, tfvcService);

            var mergeOperation = new MergeOperation(mergeService, configHelper);

            return(base.CreateViewModel(e) ?? new TeamMergeViewModel(teamService, mergeOperation, configHelper, logger, solutionService));
        }
Exemplo n.º 11
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)
                );
        }
Exemplo n.º 12
0
        public void MergeJson2Docx_TextBuilderExceptionHandledTest()
        {
            var exceptionMessage = "This is the exception message.";
            var mockTextMerger   = new Mock <IDocxTextMerger>();

            mockTextMerger.Setup(tm => tm.Merge(It.IsAny <JsonConversionData>(), It.IsAny <DocxConversionData>(), It.IsAny <bool>()))
            .Throws(new ArgumentNullException("docxFileData", exceptionMessage));

            var sut = new MergeService(mockTextMerger.Object);

            var jsonFileData = new JsonConversionData(fullJsonTestFilePath);
            var docxFileData = new DocxConversionData(fullDocxTestFilePath);

            var result = sut.MergeJson2Docx(jsonFileData, docxFileData);

            Assert.AreEqual(0, result.IndexOf(exceptionMessage));
        }
Exemplo n.º 13
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)
                );
        }
Exemplo n.º 14
0
        public void TestMergeJson2Docx()
        {
            //make sure test files exist
            TestingJsonFileTest();
            TestingTestDocxFile();

            JsonConversionData jsonFileData = docxJsonService.BuildJsonConversionData(FullJsonTestFilePath);
            DocxConversionData docxFileData = docxFileService.CreateCleanedCopy(FullDocxTestFilePath, false);

            var    mergeService    = new MergeService(new DocxTextMerger(new DocumentTextRunExtractionService()));
            string ResponseMessage = mergeService.MergeJson2Docx(jsonFileData, docxFileData);

            Assert.AreEqual(ResponseMessage, "Success");
            Assert.IsTrue(File.Exists(docxFileData.FullPath));

            //Clean Up file that was created
            File.Delete(docxFileData.FullPath);
        }
Exemplo n.º 15
0
        [Fact] public void MergePlayerValid()
        {
            var existing = new List <BaseballPlayer>
            {
                BuildPlayer(1, 1, PlayerType.B, true),
                BuildPlayer(1, 2, PlayerType.P, true),
                BuildPlayer(2, 3, PlayerType.B, true),
                BuildPlayer(3, 4, PlayerType.P, true),
                BuildPlayer(4, 5, PlayerType.B, true),
                BuildPlayer(5, 6, PlayerType.P, true),
                BuildPlayer(8, 13, PlayerType.B, true),
                BuildPlayer(9, 14, PlayerType.P, true),
            };
            var batters = new List <BaseballPlayer>
            {
                BuildPlayer(1, 7, PlayerType.B, false),
                BuildPlayer(2, 8, PlayerType.B, false),
                BuildPlayer(6, 9, PlayerType.B, false),
                BuildPlayer(9, 15, PlayerType.B, false),
            };
            var pitchers = new List <BaseballPlayer>
            {
                BuildPlayer(1, 10, PlayerType.P, false),
                BuildPlayer(3, 11, PlayerType.P, false),
                BuildPlayer(7, 12, PlayerType.P, false),
                BuildPlayer(8, 16, PlayerType.P, false),
            };
            var results = new MergeService().MergePlayers(existing, batters, pitchers);

            Assert.Equal(12, results.Count);
            ValidatePlayer(existing[0], batters[0], results[0]);
            ValidatePlayer(existing[2], batters[1], results[1]);
            ValidatePlayer(null, batters[2], results[2]);
            ValidatePlayer(null, batters[3], results[3]);
            ValidatePlayer(existing[1], pitchers[0], results[4]);
            ValidatePlayer(existing[3], pitchers[1], results[5]);
            ValidatePlayer(null, pitchers[2], results[6]);
            ValidatePlayer(null, pitchers[3], results[7]);
            ValidatePlayer(existing[4], null, results[8]);
            ValidatePlayer(existing[5], null, results[9]);
            ValidatePlayer(existing[6], null, results[10]);
            ValidatePlayer(existing[7], null, results[11]);
        }
Exemplo n.º 16
0
        public void MergeJson2Docx_EnsureStringCountsMatchTest()
        {
            var mockTextMerger = new Mock <IDocxTextMerger>();
            var sut            = new MergeService(mockTextMerger.Object);

            var jsonFileData = new JsonConversionData(fullJsonTestFilePath)
            {
                TotalStrings2Translate = 5
            };

            var docxFileData = new DocxConversionData(fullDocxTestFilePath)
            {
                TotalStrings2Translate = 3
            };

            var result = sut.MergeJson2Docx(jsonFileData, docxFileData);

            Assert.AreEqual(result.IndexOf("MERGE FAILED"), 0);
        }
Exemplo n.º 17
0
        private static MergeCommand GetSut()
        {
            var fileLocationOptions =
                new OptionsWrapper <FileLocationOptions>(new FileLocationOptions {
                WorkRoot = @"DefaultInput"
            });
            var excelRepository = new ExcelRepository(TestLogger.Create <ExcelRepository>(),
                                                      new IEntityAdapter[]
            {
                new CounselorEntityAdapter(), new EventEntityAdapter(), new LocationEntityAdapter(),
                new RequestEntityAdapter()
            }, fileLocationOptions
                                                      );
            var mergeService = new MergeService(TestLogger.Create <MergeService>(), excelRepository);

            return(new MergeCommand(TestLogger.Create <MergeCommand>(),
                                    fileLocationOptions,
                                    excelRepository,
                                    mergeService));
        }
Exemplo n.º 18
0
        public MergeServiceTests()
        {
            _fixture = new Fixture();
            var fileLocationOptions =
                new OptionsWrapper <FileLocationOptions>(new FileLocationOptions {
                WorkRoot = @"DefaultInput"
            });
            var excelRepository = new ExcelRepository(TestLogger.Create <ExcelRepository>(),
                                                      new IEntityAdapter[]
            {
                new CounselorEntityAdapter(),
                new EventEntityAdapter(),
                new LocationEntityAdapter(),
                new RequestEntityAdapter(),
                new ResultEntityAdapter(),
            }, fileLocationOptions
                                                      );

            _sut = new MergeService(TestLogger.Create <MergeService>(), excelRepository);
            _testDataCreationService = new TestDataCreationService(TestLogger.Create <TestDataCreationService>(), excelRepository);
        }
Exemplo n.º 19
0
        public void should_merge_overlapping_modules()
        {
            var spec2 = new FubuMVC.Swank.Specification.Specification {
                Modules = new List <Module> {
                    new Module {
                        Name      = "Some module",
                        Resources = new List <Resource> {
                            new Resource {
                                Name      = "/overlappingmodule",
                                Endpoints = new List <Endpoint> {
                                    new Endpoint {
                                        Url = ""
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var spec = new MergeService().Merge(_spec1, spec2);

            spec.Modules.Count.ShouldEqual(1);
            var module = spec.Modules[0];

            module.Name.ShouldEqual("Some module");
            module.Comments.ShouldEqual("Some module comments");
            module.Resources.Count.ShouldEqual(2);

            var resource = module.Resources[0];

            resource.Name.ShouldEqual("/overlappingmodule");
            resource.Comments.ShouldBeNull();
            resource.Endpoints.Count.ShouldEqual(1);

            resource = module.Resources[1];
            resource.Name.ShouldEqual("Some module resource");
            resource.Comments.ShouldEqual("Some module resource comments");
            resource.Endpoints.Count.ShouldEqual(1);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        public virtual IList <IEntityMetaData> GetMetaData(IList <Type> entityTypes)
        {
            IList <Type> realEntityTypes = new List <Type>(entityTypes.Count);

            foreach (Type entityType in entityTypes)
            {
                realEntityTypes.Add(ProxyHelper.GetRealType(entityType));
            }
            ICache    cache     = this.Cache.CurrentCache;
            Lock      readLock  = cache != null ? cache.ReadLock : null;
            LockState lockState = readLock != null?readLock.ReleaseAllLocks() : default(LockState);

            try
            {
                return(MergeService.GetMetaData(realEntityTypes));
            }
            finally
            {
                if (readLock != null)
                {
                    readLock.ReacquireLocks(lockState);
                }
            }
        }
Exemplo n.º 22
0
        public void ShouldCreateNewCustomer()
        {
            long sourceId    = 2;
            var  service     = new MergeService(_dataAccess.Object, _repository.Object);
            var  newCustomer = new MappedCustomerMessage
            {
                CustomerId = 1,
                SourceId   = sourceId,
                Data       = new Dictionary <string, Dictionary <string, object> > {
                    { "edad", new Dictionary <string, object> {
                          { sourceId.ToString(), 36 }
                      } },
                    { "nombre", new Dictionary <string, object> {
                          { sourceId.ToString(), "Nuevo cliente" }
                      } }
                }
            };

            _dataAccess.Setup(x => x.Get <CustomerDocument>(It.IsAny <string>()));
            _dataAccess.Setup(x => x.Put(It.IsAny <CustomerDocument>()));
            service.Save("1", newCustomer);
            _dataAccess.Verify(x => x.Put(It.Is <CustomerDocument>(y => y.Data.Any(z => z.Key == "nombre" && (z.Value.ToString()) == "Nuevo cliente"))));
            _dataAccess.Verify(x => x.Put(It.Is <CustomerDocument>(y => y.Data.Any(z => z.Key == "edad" && ((int)z.Value) == 36))));
        }
Exemplo n.º 23
0
        public DocumentResponse mergeDocument()
        {
            MergeService ms = new MergeService();

            return(ms.Merge(this.HttpContext));
        }
Exemplo n.º 24
0
        public void should_merge_all_the_things_from_a_file()
        {
            var spec = new MergeService().Merge(
                _spec1,
                _jsonPath);

            spec.Types.Count.ShouldEqual(1);
            var type = spec.Types[0];

            type.Id.ShouldEqual("Some type id");
            type.Name.ShouldEqual("SomeType");
            type.Comments.ShouldEqual("Some type comments");
            type.Members.Count.ShouldEqual(1);

            var member = type.Members[0];

            member.Name.ShouldEqual("SomeMember");
            member.Comments.ShouldEqual("Some member comments");
            member.Required.ShouldBeTrue();
            member.DefaultValue.ShouldEqual("some default value");
            member.Type.ShouldEqual("some type");
            member.IsArray.ShouldBeTrue();
            member.Options.Count.ShouldEqual(1);

            var option = member.Options[0];

            option.Name.ShouldEqual("SomeOption");
            option.Comments.ShouldEqual("Some option comments");
            option.Value.ShouldEqual("Some option value");

            spec.Modules.Count.ShouldEqual(1);
            var module = spec.Modules[0];

            module.Name.ShouldEqual("Some module");
            module.Comments.ShouldEqual("Some module comments");
            module.Resources.Count.ShouldEqual(1);

            var resource = module.Resources[0];

            resource.Name.ShouldEqual("Some module resource");
            resource.Comments.ShouldEqual("Some module resource comments");
            resource.Endpoints.Count.ShouldEqual(1);

            var endpoint = resource.Endpoints[0];

            endpoint.Name.ShouldEqual("Some endpoint");
            endpoint.Comments.ShouldEqual("Some endpoint comments");
            endpoint.Url.ShouldEqual("/some/url");
            endpoint.Method.ShouldEqual("METHOD");
            endpoint.UrlParameters.Count.ShouldEqual(1);

            var urlParameter = endpoint.UrlParameters[0];

            urlParameter.Name.ShouldEqual("Some url param");
            urlParameter.Comments.ShouldEqual("Some url param comments");
            urlParameter.Type.ShouldEqual("Some type");
            urlParameter.Options.Count.ShouldEqual(1);

            option = urlParameter.Options[0];
            option.Name.ShouldEqual("Some option");
            option.Value.ShouldEqual("Some option value");
            option.Comments.ShouldEqual("Some option comments");

            endpoint.QuerystringParameters.Count.ShouldEqual(1);
            var querystringParameter = endpoint.QuerystringParameters[0];

            querystringParameter.Name.ShouldEqual("Some querystring");
            querystringParameter.Comments.ShouldEqual("Some querystring comments");
            querystringParameter.DefaultValue.ShouldEqual("Some default value");
            querystringParameter.MultipleAllowed.ShouldBeTrue();
            querystringParameter.Required.ShouldBeTrue();
            querystringParameter.Type.ShouldEqual("Some type");
            querystringParameter.Options.Count.ShouldEqual(1);

            option = urlParameter.Options[0];
            option.Name.ShouldEqual("Some option");
            option.Value.ShouldEqual("Some option value");
            option.Comments.ShouldEqual("Some option comments");

            endpoint.StatusCodes.Count.ShouldEqual(1);
            var statusCode = endpoint.StatusCodes[0];

            statusCode.Name.ShouldEqual("Some error");
            statusCode.Comments.ShouldEqual("Some error comments");
            statusCode.Code.ShouldEqual(999);

            endpoint.Request.Name.ShouldEqual("Some request");
            endpoint.Request.Comments.ShouldEqual("Some request comments");
            endpoint.Request.Type.ShouldEqual("Some type");
            endpoint.Request.IsArray.ShouldBeTrue();

            endpoint.Response.Name.ShouldEqual("Some response");
            endpoint.Response.Comments.ShouldEqual("Some response comments");
            endpoint.Response.Type.ShouldEqual("Some type");
            endpoint.Response.IsArray.ShouldBeTrue();
        }
Exemplo n.º 25
0
 /// <summary>
 /// Merge the selected files.
 /// </summary>
 private void OnMerge()
 {
     MergeService.Mp3Merge(MP3Files.FileName1, MP3Files.FileName2, MP3Files.OutputDirectory);
 }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
 public IValueObjectConfig GetValueObjectConfig(Type valueType)
 {
     return(MergeService.GetValueObjectConfig(valueType));
 }