public void UpdateSubScopeReferenceProperties(TECSubScope subScope) { var templateSS = SubScopeSynchronizer.GetTemplate(subScope); if (templateSS != subScope) { setProperties(subScope, templateSS); } SubScopeSynchronizer.ActOnReferences(templateSS, updateSubScope); void updateSubScope(TemplateSynchronizer <TECSubScope> synchronizer, TECSubScope template) { foreach (TECSubScope item in synchronizer.GetFullDictionary()[template]) { setProperties(template, item); } } void setProperties(TECSubScope tSS, TECSubScope rSS) { rSS.CopyPropertiesFromScope(tSS); rSS.ScopeBranches.ObservablyClear(); foreach (TECScopeBranch branch in tSS.ScopeBranches) { rSS.ScopeBranches.Add(new TECScopeBranch(branch)); } } }
public void GetTemplateTest() { 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); Assert.AreEqual(template, synchronizer.GetTemplate(newItem)); Assert.AreEqual(template, synchronizer.GetTemplate(template)); }
//Copy Constructor public TECEquipment(TECEquipment equipmentSource, Dictionary <Guid, Guid> guidDictionary = null, ObservableListDictionary <ITECObject> characteristicReference = null, TemplateSynchronizer <TECSubScope> ssSynchronizer = null) : this() { if (guidDictionary != null) { guidDictionary[_guid] = equipmentSource.Guid; } foreach (TECSubScope subScope in equipmentSource.SubScope) { var toAdd = new TECSubScope(subScope, guidDictionary, characteristicReference); if (ssSynchronizer != null && ssSynchronizer.Contains(subScope)) { ssSynchronizer.LinkNew(ssSynchronizer.GetTemplate(subScope), toAdd); } characteristicReference?.AddItem(subScope, toAdd); SubScope.Add(toAdd); } copyPropertiesFromScope(equipmentSource); }
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; }