Пример #1
0
        public void LinkExistingTest()
        {
            //Arrange
            TECScopeTemplates templates = new TECScopeTemplates();

            TemplateSynchronizer <TECSubScope> synchronizer =
                new TemplateSynchronizer <TECSubScope>(copySubScope, item => { }, syncSubScope, templates);

            TECSubScope templateSS = new TECSubScope();

            templateSS.Name = "Template SubScope";

            List <TECSubScope> newReferenceSS = new List <TECSubScope>();

            newReferenceSS.Add(new TECSubScope());
            newReferenceSS.Add(new TECSubScope());

            //Act
            synchronizer.LinkExisting(templateSS, newReferenceSS);
            templateSS.Description = "Test Description";

            //Assert
            foreach (TECSubScope refSS in newReferenceSS)
            {
                Assert.AreEqual(templateSS.Description, refSS.Description);
            }
        }
Пример #2
0
        public void ContainsTest()
        {
            TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates());
            var template = new TestObject();

            synchronizer.NewGroup(template);

            var existing = new TestObject();

            synchronizer.LinkExisting(template, existing);

            Assert.IsTrue(synchronizer.Contains(existing));
        }
Пример #3
0
        public void LinkExistingTest2()
        {
            TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates());
            var template = new TestObject();

            synchronizer.NewGroup(template);

            var existing1 = new TestObject();
            var existing2 = new TestObject();
            var existing  = new List <TestObject> {
                existing1, existing2
            };

            synchronizer.LinkExisting(template, existing);

            Assert.IsTrue(synchronizer.GetFullDictionary()[template].Contains(existing1));
            Assert.IsTrue(synchronizer.GetFullDictionary()[template].Contains(existing2));
        }
Пример #4
0
        private void syncEquipment(TemplateSynchronizer <TECEquipment> synchronizer, TECEquipment template, TECEquipment changed, TECChangedEventArgs args)
        {
            if (!(args.Sender is TECEquipment))
            {
                return;
            }
            TECEquipment        item       = args.Sender as TECEquipment;
            TECSubScope         value      = args.Value as TECSubScope;
            List <TECEquipment> references = synchronizer.GetFullDictionary()[template];

            if (value != null && args.Change == Change.Add)
            {
                TECSubScope newTemplate = value;
                if (item == template)
                {
                    SubScopeSynchronizer.NewGroup(newTemplate);
                }
                else
                {
                    TECSubScope parentTemplate = SubScopeSynchronizer.GetTemplate(newTemplate);
                    if (parentTemplate != null)
                    {
                        SubScopeSynchronizer.RemoveItem(newTemplate);
                        newTemplate = SubScopeSynchronizer.NewItem(parentTemplate);
                    }
                    else
                    {
                        newTemplate = new TECSubScope(value);
                    }
                    template.SubScope.Add(newTemplate);
                    SubScopeSynchronizer.NewGroup(newTemplate);
                    SubScopeSynchronizer.LinkExisting(newTemplate, value);
                }
                foreach (TECEquipment reference in references.Where(obj => obj != item))
                {
                    reference.SubScope.Add(SubScopeSynchronizer.NewItem(newTemplate));
                }
            }
            else if (value != null && args.Change == Change.Remove)
            {
                TECSubScope subScopeTemplate = value;
                if (item != template)
                {
                    subScopeTemplate = SubScopeSynchronizer.GetTemplate(value);
                }
                template.SubScope.Remove(subScopeTemplate);
                List <TECSubScope> subScopeReferences = SubScopeSynchronizer.GetFullDictionary()[subScopeTemplate];
                foreach (TECEquipment reference in references)
                {
                    List <TECSubScope> toRemove = new List <TECSubScope>();
                    foreach (TECSubScope referenceSubScope in reference.SubScope)
                    {
                        if (subScopeReferences.Contains(referenceSubScope))
                        {
                            toRemove.Add(referenceSubScope);
                        }
                    }
                    foreach (TECSubScope thing in toRemove)
                    {
                        reference.SubScope.Remove(thing);
                    }
                }
                SubScopeSynchronizer.RemoveGroup(subScopeTemplate);
                if (SubScopeSynchronizer.GetTemplate(subScopeTemplate) != null)
                {
                    SubScopeSynchronizer.RemoveItem(subScopeTemplate);
                }
            }
            else
            {
                if (item != template)
                {
                    template.CopyChildrenFromScope(item);
                }
                foreach (TECEquipment reference in references.Where(obj => obj != item))
                {
                    reference.CopyChildrenFromScope(item);
                }
            }
        }