public void ContainsTest1() { TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates()); var template = new TestObject(); synchronizer.NewGroup(template); var newItem = synchronizer.NewItem(template); synchronizer.RemoveItem(template, newItem); Assert.IsFalse(synchronizer.Contains(newItem)); }
public TECTemplates(Guid guid) : base(guid) { Catalogs.ScopeChildRemoved += scopeChildRemoved; SubScopeSynchronizer = new TemplateSynchronizer <TECSubScope>((item => { return(new TECSubScope(item)); }), (item => { }), syncSubScope, this.Templates); SubScopeSynchronizer.TECChanged += synchronizerChanged; EquipmentSynchronizer = new TemplateSynchronizer <TECEquipment>( //Copy (item => { TECEquipment newItem = new TECEquipment(); newItem.CopyPropertiesFromScope(item); foreach (TECSubScope subScope in item.SubScope) { newItem.SubScope.Add(SubScopeSynchronizer.NewItem(subScope)); } return(newItem); }), //Remove (item => { foreach (TECSubScope subScope in item.SubScope) { if (SubScopeSynchronizer.GetTemplate(subScope) != null) { SubScopeSynchronizer.RemoveItem(subScope); } } }), //Sync syncEquipment, this.Templates); EquipmentSynchronizer.TECChanged += synchronizerChanged; }
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); } } }