public void GetFullDictionaryTest() { TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates()); var template = new TestObject(); synchronizer.NewGroup(template); synchronizer.NewItem(template); synchronizer.NewGroup(new TestObject()); Assert.IsTrue(synchronizer.GetFullDictionary()[template].Count == 1); Assert.IsTrue(synchronizer.GetFullDictionary().Keys.Count == 2); }
private void syncSubScope(TemplateSynchronizer <TECSubScope> synchronizer, TECSubScope template, TECSubScope changed, TECChangedEventArgs args) { if (changed != template) { syncItem(changed, template); } foreach (TECSubScope item in synchronizer.GetFullDictionary()[template].Where(item => item != changed)) { syncItem(changed, item); } void syncItem(TECSubScope changedItem, TECSubScope subject) { subject.CopyChildrenFromScope(changedItem); subject.Points.ObservablyClear(); subject.Devices.ObservablyClear(); subject.Interlocks.ObservablyClear(); foreach (TECPoint point in changedItem.Points) { subject.AddPoint(new TECPoint(point)); } foreach (IEndDevice device in changedItem.Devices) { subject.AddDevice(device); } foreach (TECInterlockConnection connection in changedItem.Interlocks) { subject.Interlocks.Add(connection); } } }
public void NewGroupTest() { TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates()); var template = new TestObject(); synchronizer.NewGroup(template); Assert.IsNotNull(synchronizer.GetFullDictionary()[template]); }
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)); }
private void syncSubScope(TemplateSynchronizer <TECSubScope> synchronizer, TECSubScope templateSS, TECSubScope toSync, TECChangedEventArgs args) { toSync.CopyPropertiesFromScope(templateSS); foreach (TECSubScope reference in synchronizer.GetFullDictionary()[templateSS].Where(item => item != toSync)) { reference.CopyPropertiesFromScope(toSync); } }
public void RemoveGroupTest() { TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates()); var template = new TestObject(); synchronizer.NewGroup(template); synchronizer.RemoveGroup(template); Assert.IsFalse(synchronizer.GetFullDictionary().ContainsKey(template)); }
public void RemoveItemTest1() { 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.GetFullDictionary()[template].Contains(newItem)); }
public void CopyTemplateWithReferences() { //Arrange TECTemplates templates = new TECTemplates(); TECEquipment tempEquip = new TECEquipment(); templates.Templates.EquipmentTemplates.Add(tempEquip); TECSubScope tempSS = new TECSubScope(); tempSS.Name = "Template SS"; templates.Templates.SubScopeTemplates.Add(tempSS); tempEquip.SubScope.Add(templates.SubScopeSynchronizer.NewItem(tempSS)); TECSubScope equipSS = new TECSubScope(); equipSS.Name = "Equipment SS"; tempEquip.SubScope.Add(equipSS); //Act TECEquipment equipCopy = new TECEquipment(tempEquip, ssSynchronizer: templates.SubScopeSynchronizer); //Assert TECSubScope newTempSS = null, newEquipSS = null; foreach (TECSubScope ss in equipCopy.SubScope) { if (ss.Name == "Template SS") { newTempSS = ss; } else if (ss.Name == "Equipment SS") { newEquipSS = ss; } else { Assert.Fail("Different subScope than expected in equipment copy."); } } Assert.IsNotNull(newTempSS, "Template SubScope didn't copy properly."); Assert.IsNotNull(newEquipSS, "Equipment SubScope didn't copy properly."); TemplateSynchronizer <TECSubScope> ssSync = templates.SubScopeSynchronizer; Assert.IsTrue(ssSync.Contains(newTempSS)); Assert.IsTrue(ssSync.GetFullDictionary()[tempSS].Contains(newTempSS)); }
public void LinkNewTest() { TemplateSynchronizer <TestObject> synchronizer = new TemplateSynchronizer <TestObject>(obj => new TestObject(), obj => { }, (sync, obj1, obj2, e) => { }, new TECScopeTemplates()); var template = new TestObject(); synchronizer.NewGroup(template); bool changed = false; synchronizer.TECChanged += arg => { changed = true; }; var existing = new TestObject(); synchronizer.LinkNew(template, existing); Assert.IsTrue(synchronizer.GetFullDictionary()[template].Contains(existing)); Assert.IsTrue(changed); }
public void Load_Templates_CombinedSynchronizer() { Guid parentSystemGuid = new Guid("d562049c-ea9e-449c-8c1f-eaa7fbcb70d3"); Guid equipmentTemplateGuid = new Guid("adced9c6-41c1-478b-b9db-3833f1618378"); Guid equipmentReferenceGuid = new Guid("53d8c07f-872c-41de-8dd1-8aa349978ef4"); Guid subScopeTemplateGuid = new Guid("59d6adb3-7f48-4448-82fa-f77cdfac47ad"); Guid subScopeChildTemplateGuid = new Guid("a26ab8aa-3b44-4321-a48e-872b250490a9"); Guid subScopeChildReferenceGuid = new Guid("c96120a1-b9e7-40e8-b015-e7383feca57d"); TECSystem actualSystem = null; foreach (TECSystem system in actualTemplates.Templates.SystemTemplates) { if (system.Guid == parentSystemGuid) { actualSystem = system; break; } } Assert.IsNotNull(actualSystem, "Parent system not found."); TECEquipment actualTemplateEquip = null; foreach (TECEquipment equip in actualTemplates.Templates.EquipmentTemplates) { if (equip.Guid == equipmentTemplateGuid) { actualTemplateEquip = equip; break; } } Assert.IsNotNull(actualTemplateEquip, "Equipment template not found."); TECEquipment actualRefEquip = null; foreach (TECEquipment equip in actualSystem.Equipment) { if (equip.Guid == equipmentReferenceGuid) { actualRefEquip = equip; break; } } Assert.IsNotNull(actualRefEquip, "Equipment reference not found."); TECSubScope actualTemplateSS = null; foreach (TECSubScope ss in actualTemplates.Templates.SubScopeTemplates) { if (ss.Guid == subScopeTemplateGuid) { actualTemplateSS = ss; break; } } Assert.IsNotNull(actualTemplateSS, "SubScope template not found."); TECSubScope actualChildTemplateSS = null; foreach (TECSubScope ss in actualTemplateEquip.SubScope) { if (ss.Guid == subScopeChildTemplateGuid) { actualChildTemplateSS = ss; break; } } Assert.IsNotNull(actualChildTemplateSS, "Child subScope in template equipment not found."); TECSubScope actualChildRefSS = null; foreach (TECSubScope ss in actualRefEquip.SubScope) { if (ss.Guid == subScopeChildReferenceGuid) { actualChildRefSS = ss; break; } } Assert.IsNotNull(actualChildRefSS, "Child subScope in reference equipment not found."); TemplateSynchronizer <TECSubScope> ssSync = actualTemplates.SubScopeSynchronizer; TemplateSynchronizer <TECEquipment> equipSync = actualTemplates.EquipmentSynchronizer; Assert.IsTrue(equipSync.Contains(actualTemplateEquip), "Equipment template not in synchronizer."); Assert.IsTrue(equipSync.Contains(actualRefEquip), "Equipment reference not in synchronizer."); Assert.IsTrue(equipSync.GetFullDictionary()[actualTemplateEquip].Contains(actualRefEquip), "Equipment template not synchronized with equipment reference."); Assert.IsTrue(ssSync.Contains(actualTemplateSS), "SubScope template not in synchroninzer."); Assert.IsTrue(ssSync.Contains(actualChildTemplateSS), "SubScope reference not in synchronizer."); Assert.IsTrue(ssSync.Contains(actualChildRefSS), "Child SubScope reference not in synchronizer."); Assert.IsTrue(ssSync.GetFullDictionary()[actualTemplateSS].Contains(actualChildTemplateSS), "SubScope template not synchronized with subScope reference."); Assert.IsTrue(ssSync.GetFullDictionary()[actualChildTemplateSS].Contains(actualChildRefSS), "Child subScope template not synchronized with child subScope reference."); }
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); } } }
public void SaveNew_Templates_Synchronizer() { //Arrange TECSystem expectedSys = null, actualSys = null; TECEquipment expectedTempEquip = null, actualTempEquip = null; TECEquipment expectedRefEquip = null, actualRefEquip = null; TECSubScope expectedTempSS = null, actualTempSS = null; TECSubScope expectedRefSSInTemp = null, actualRefSSInTemp = null; TECSubScope expectedRefSSInRef = null, actualRefSSInRef = null; #region Expected foreach (TECSystem sys in expectedTemplates.Templates.SystemTemplates) { if (sys.Name == "Sync System") { expectedSys = sys; break; } } Assert.IsNotNull(expectedSys); foreach (TECEquipment equip in expectedTemplates.Templates.EquipmentTemplates) { if (equip.Name == "Sync Equip") { expectedTempEquip = equip; break; } } Assert.IsNotNull(expectedTempEquip); foreach (TECEquipment equip in expectedSys.Equipment) { if (equip.Name == "Sync Equip") { expectedRefEquip = equip; break; } } Assert.IsNotNull(expectedRefEquip); foreach (TECSubScope ss in expectedTemplates.Templates.SubScopeTemplates) { if (ss.Name == "Sync SS") { expectedTempSS = ss; break; } } Assert.IsNotNull(expectedTempSS); foreach (TECSubScope ss in expectedTempEquip.SubScope) { if (ss.Name == "Sync SS") { expectedRefSSInTemp = ss; break; } } Assert.IsNotNull(expectedRefSSInTemp); foreach (TECSubScope ss in expectedRefEquip.SubScope) { if (ss.Name == "Sync SS") { expectedRefSSInRef = ss; break; } } Assert.IsNotNull(expectedRefSSInRef); #endregion #region Actual foreach (TECSystem sys in actualTemplates.Templates.SystemTemplates) { if (sys.Name == "Sync System" && sys.Guid == expectedSys.Guid) { actualSys = sys; break; } } Assert.IsNotNull(actualSys); foreach (TECEquipment equip in actualTemplates.Templates.EquipmentTemplates) { if (equip.Name == "Sync Equip" && equip.Guid == expectedTempEquip.Guid) { actualTempEquip = equip; break; } } Assert.IsNotNull(actualTempEquip); foreach (TECEquipment equip in actualSys.Equipment) { if (equip.Name == "Sync Equip" && equip.Guid == expectedRefEquip.Guid) { actualRefEquip = equip; break; } } Assert.IsNotNull(actualRefEquip); foreach (TECSubScope ss in actualTemplates.Templates.SubScopeTemplates) { if (ss.Name == "Sync SS" && ss.Guid == expectedTempSS.Guid) { actualTempSS = ss; break; } } Assert.IsNotNull(actualTempSS); foreach (TECSubScope ss in actualTempEquip.SubScope) { if (ss.Name == "Sync SS" && ss.Guid == expectedRefSSInTemp.Guid) { actualRefSSInTemp = ss; break; } } Assert.IsNotNull(actualRefSSInTemp); foreach (TECSubScope ss in actualRefEquip.SubScope) { if (ss.Name == "Sync SS" && ss.Guid == expectedRefSSInRef.Guid) { actualRefSSInRef = ss; break; } } Assert.IsNotNull(actualRefSSInRef); #endregion //Assert TemplateSynchronizer <TECEquipment> equipSync = actualTemplates.EquipmentSynchronizer; TemplateSynchronizer <TECSubScope> ssSync = actualTemplates.SubScopeSynchronizer; Assert.IsTrue(equipSync.Contains(actualTempEquip)); Assert.IsTrue(equipSync.Contains(actualRefEquip)); Assert.IsTrue(equipSync.GetFullDictionary()[actualTempEquip].Contains(actualRefEquip)); Assert.IsTrue(ssSync.Contains(actualTempSS)); Assert.IsTrue(ssSync.Contains(actualRefSSInTemp)); Assert.IsTrue(ssSync.Contains(actualRefSSInRef)); Assert.IsTrue(ssSync.GetFullDictionary()[actualTempSS].Contains(actualRefSSInTemp)); Assert.IsTrue(ssSync.GetFullDictionary()[actualRefSSInTemp].Contains(actualRefSSInRef)); }
public void CopyTemplateWithReferences() { //Arrange TECTemplates templates = new TECTemplates(); TemplateSynchronizer <TECEquipment> equipSync = templates.EquipmentSynchronizer; TemplateSynchronizer <TECSubScope> ssSync = templates.SubScopeSynchronizer; TECSystem templateSys = new TECSystem(); templates.Templates.SystemTemplates.Add(templateSys); TECEquipment templateEquip = new TECEquipment(); templateEquip.Name = "Template Equip"; templates.Templates.EquipmentTemplates.Add(templateEquip); templateSys.Equipment.Add(equipSync.NewItem(templateEquip)); TECSubScope templateSS = new TECSubScope(); templateSS.Name = "Template SS"; templates.Templates.SubScopeTemplates.Add(templateSS); templateEquip.SubScope.Add(ssSync.NewItem(templateSS)); TECSubScope equipSS = new TECSubScope(); equipSS.Name = "Equip SS"; templateEquip.SubScope.Add(equipSS); //Act TECSystem sysCopy = new TECSystem(templateSys, synchronizers: new Tuple <TemplateSynchronizer <TECEquipment>, TemplateSynchronizer <TECSubScope> >(equipSync, ssSync)); //Assert TECEquipment tempEquipCopy = sysCopy.Equipment[0]; TECSubScope tempSSCopy = null, equipSSCopy = null; foreach (TECSubScope ss in tempEquipCopy.SubScope) { if (ss.Name == "Template SS") { tempSSCopy = ss; } else if (ss.Name == "Equip SS") { equipSSCopy = ss; } else { Assert.Fail("Different subScope than expected in System copy."); } } Assert.IsNotNull(tempSSCopy, "Template SubScope didn't copy properly."); Assert.IsNotNull(equipSSCopy, "Equipment SubScope didn't copy properly."); Assert.IsTrue(equipSync.Contains(tempEquipCopy)); Assert.IsTrue(equipSync.GetFullDictionary()[templateEquip].Contains(tempEquipCopy)); Assert.IsTrue(ssSync.Contains(tempSSCopy)); Assert.IsTrue(ssSync.Contains(equipSSCopy)); Assert.IsTrue(ssSync.GetFullDictionary()[templateSS].Contains(ssSync.GetParent(tempSSCopy))); Assert.IsTrue(ssSync.GetFullDictionary()[equipSS].Contains(equipSSCopy)); }