internal override void GenerateSubCommands() { report.Append("Fixing association interpretations" + newline); foreach (PSMAssociation a in Project.LatestVersion.PSMSchemas.SelectMany(s => s.PSMAssociations).Where(assoc => assoc.Interpretation != null && assoc.InterpretedAssociationEnd == null)) { PIMAssociationEnd e; PIMAssociation pimassoc = a.Interpretation as PIMAssociation; PSMClass child = a.Child as PSMClass; if (child == null) { report.Append("child not class: " + a.ToString() + newline); continue; } PIMClass childInterpretation = child.Interpretation as PIMClass; if (pimassoc.PIMAssociationEnds.Where(ae => ae.PIMClass == childInterpretation).Count() > 1) { report.Append("cannot fix - self reference detected: " + a.ToString() + newline); continue; } else { e = pimassoc.PIMAssociationEnds.Single(ae => ae.PIMClass == childInterpretation); } report.Append("fixed OK: " + a.ToString() + newline); Commands.Add(new acmdSetPSMAssociationInterpretation(Controller, a, e, a.Interpretation) { Propagate = false }); } }
public override bool VerifyConsistency(object superordinateObject, object candidate) { PIMAssociation pimAssociation = (PIMAssociation)superordinateObject; PIMAssociationEnd pimAssociationEnd = (PIMAssociationEnd)candidate; return(pimAssociation.PIMAssociationEnds.Contains(pimAssociationEnd)); }
public FakePSMAssociation(PIMAssociation p) : this() { Name = p.Name; Multiplicity = "1"; SourceAssociation = null; RepresentedPIMAssociation = p; Checked = false; }
internal override void GenerateSubCommands() { if (NewGuids == null) { List <Tuple <Guid, Guid, Guid> > guids = new List <Tuple <Guid, Guid, Guid> >(); for (int i = 0; i < Count; i++) { guids.Add(new Tuple <Guid, Guid, Guid>(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid())); } NewGuids = guids; } PIMAssociation original = Project.TranslateComponent <PIMAssociation>(PIMAssociationGuid); PIMAssociationEnd originalEnd1 = original.PIMAssociationEnds.First(); PIMAssociationEnd originalEnd2 = original.PIMAssociationEnds.Last(); int counter = 0; foreach (Tuple <Guid, Guid, Guid> t in NewGuids) { counter++; Guid newAssociationGuid = t.Item1; Guid newAssociationEnd1Guid = t.Item2; Guid newAssociationEnd2Guid = t.Item3; Commands.Add(new acmdNewPIMAssociation(Controller, originalEnd1.PIMClass, newAssociationEnd1Guid, originalEnd2.PIMClass, newAssociationEnd2Guid, original.PIMSchema) { AssociationGuid = newAssociationGuid }); Commands.Add(new acmdRenameComponent(Controller, newAssociationGuid, original.Name + counter)); Commands.Add(new acmdRenameComponent(Controller, newAssociationEnd1Guid, originalEnd1.Name)); Commands.Add(new acmdRenameComponent(Controller, newAssociationEnd2Guid, originalEnd2.Name)); Commands.Add(new acmdUpdatePIMAssociationEndCardinality(Controller, newAssociationEnd1Guid, originalEnd1.Lower, originalEnd1.Upper)); Commands.Add(new acmdUpdatePIMAssociationEndCardinality(Controller, newAssociationEnd2Guid, originalEnd2.Lower, originalEnd2.Upper)); foreach (PIMDiagram d in Project.SingleVersion.PIMDiagrams) { if (d.PIMComponents.Contains(original)) { Commands.Add(new acmdAddComponentToDiagram(Controller, newAssociationGuid, d)); } } } Commands.Add(new acmdSynchroPIMAssociations(Controller) { X1 = Enumerable.Repeat(original.ID, 1).ToList(), X2 = NewGuids.Select(t => t.Item1).ToList() }); Commands.Add(new cmdDeletePIMAssociation(Controller) { AssociationGuid = original }); }
public override bool CanExecute() { if (ForceExecute) { return(true); } if (!(PSMComponentGuid != Guid.Empty && PIMComponentGuid == Guid.Empty || (Project.VerifyComponentType <PSMAssociation>(PSMComponentGuid) && Project.VerifyComponentType <PIMAssociation>(PIMComponentGuid)) )) { ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH; return(false); } if (PIMComponentGuid == Guid.Empty) { return(true); } PIMAssociation pimAssoc = Project.TranslateComponent <PIMAssociation>(PIMComponentGuid); PSMAssociation psmAssoc = Project.TranslateComponent <PSMAssociation>(PSMComponentGuid); PSMClass child = psmAssoc.Child as PSMClass; if (child == null) { ErrorDescription = CommandErrors.CMDERR_CANNOT_SET_INTERPRETATION_CHILD_NOT_CLASS; return(false); } if (child.Interpretation == null) { ErrorDescription = CommandErrors.CMDERR_CANNOT_SET_INTERPRETATION_CMDERR_CANNOT_SET_INTERPRETATION_CHILD_NOT_INTERPRETED; return(false); } PSMClass intclass = psmAssoc.NearestInterpretedClass(); if (intclass == null) { ErrorDescription = CommandErrors.CMDERR_CANNOT_SET_INTERPRETATION_NO_INTCLASS; return(false); } if (!(child.Interpretation as PIMClass).GetAssociationsWithIncludeInherited(intclass.Interpretation as PIMClass).Contains <PIMAssociation>(pimAssoc)) { ErrorDescription = CommandErrors.CMDERR_NO_COMMON_INTERPRETED_ASSOCIATION; return(false); } return(true); }
internal override void CommandOperation() { PSMAssociation psmAssociation = Project.TranslateComponent <PSMAssociation>(PSMComponentGuid); PIMAssociation oldInterpretation = psmAssociation.Interpretation as PIMAssociation; PIMAssociationEnd childAE = childAssociationEnd == Guid.Empty ? null : Project.TranslateComponent <PIMAssociationEnd>(childAssociationEnd); if (psmAssociation.UsedGeneralizations.Count > 0) { oldUsedGeneralizations.AddRange(psmAssociation.UsedGeneralizations.Select(g => g.ID)); } if (psmAssociation.Interpretation == null) { oldPimComponentGuid = Guid.Empty; oldChildAssociationEnd = Guid.Empty; } else { oldPimComponentGuid = psmAssociation.Interpretation; oldChildAssociationEnd = psmAssociation.InterpretedAssociationEnd; } if (PIMComponentGuid != Guid.Empty) { psmAssociation.Interpretation = Project.TranslateComponent <PIMAssociation>(PIMComponentGuid); psmAssociation.InterpretedAssociationEnd = childAE; //Get used generalizations on the child and the parent end psmAssociation.UsedGeneralizations.Clear(); List <PIMGeneralization> gens = new List <PIMGeneralization>(); PIMAssociation interpretation = psmAssociation.Interpretation as PIMAssociation; PIMClass nicint = psmAssociation.NearestInterpretedClass().Interpretation as PIMClass; PIMClass childint = (psmAssociation.Child as PSMClass).Interpretation as PIMClass; gens.AddRange(childint.GetGeneralizationPathTo(childAE.PIMClass)); gens.AddRange(nicint.GetGeneralizationPathTo(interpretation.PIMAssociationEnds.Single(ae => ae != childAE).PIMClass)); foreach (PIMGeneralization g in gens) { psmAssociation.UsedGeneralizations.Add(g); } } else { psmAssociation.Interpretation = null; psmAssociation.InterpretedAssociationEnd = null; psmAssociation.UsedGeneralizations.Clear(); } Report = new CommandReport(CommandReports.SET_INTERPRETATION, psmAssociation, oldInterpretation, psmAssociation.Interpretation); }
private static void CheckPIMAssociation(PIMAssociation pimAssociation) { CheckPIMComponent(pimAssociation); foreach (PIMAssociationEnd pimAssociationEnd in pimAssociation.PIMAssociationEnds) { CheckPIMAssociationEnd(pimAssociationEnd); } CollectionAssert.Contains(pimAssociation.PIMSchema.PIMAssociations, pimAssociation); foreach (PIMAssociationEnd pimAssociationEnd in pimAssociation.PIMAssociationEnds) { Assert.IsTrue(pimAssociationEnd.PIMClass.PIMAssociationEnds.Contains(pimAssociationEnd)); Assert.IsTrue(pimAssociationEnd.PIMAssociation.PIMAssociationEnds.Contains(pimAssociationEnd)); } }
internal override CommandBase.OperationResult UndoOperation() { PIMAssociation a = Project.TranslateComponent <PIMAssociation>(AssociationGuid); PIMSchema s = Project.TranslateComponent <PIMSchema>(schemaGuid); foreach (PIMAssociationEnd e in a.PIMAssociationEnds) { s.PIMAssociationEnds.Remove(e); if (e.PIMClass != null) { e.PIMClass.PIMAssociationEnds.Remove(e); } Project.mappingDictionary.Remove(e); } s.PIMAssociations.Remove(a); Project.mappingDictionary.Remove(a); return(OperationResult.OK); }
private void ConvertPIMAssociation(Association pimAssociation, AssociationViewHelper associationViewHelper) { PIMAssociation association; if (!TranslatedAlready(pimAssociation, out association)) { association = new PIMAssociation(evoxProject, pimSchema); translatedElements[pimAssociation] = association; } association.Name = pimAssociation.Name; foreach (AssociationEnd pimAssociationEnd in pimAssociation.Ends) { PIMAssociationEnd associationEnd = new PIMAssociationEnd(evoxProject, (EvoX.Model.PIM.PIMClass)ElementRef(pimAssociationEnd.Class), association, pimSchema); associationEnd.Lower = ConvertToUint(pimAssociationEnd.Lower); associationEnd.Upper = ConvertToUnlimitedInt(pimAssociationEnd.Upper); associationEnd.Name = pimAssociationEnd.Name; } }
internal override void GenerateSubCommands() { PIMAssociation a = Project.TranslateComponent <PIMAssociation>(AssociationGuid); foreach (PIMAssociationEnd e in a.PIMAssociationEnds) { Commands.Add(new acmdRenameComponent(Controller, e, "") { Propagate = false }); Commands.Add(new acmdUpdatePIMAssociationEndCardinality(Controller, e, 1, 1) { Propagate = false }); } Commands.Add(new acmdRenameComponent(Controller, a, "") { Propagate = false }); Commands.AddRange(acmdRemoveComponentFromDiagram.CreateCommandsToRemoveFromAllDiagrams(Controller, AssociationGuid)); Commands.Add(new acmdDeletePIMAssociation(Controller, a)); }
public static Project CreateSimpleSampleProject() { Project p = new Project(); p.InitNewEmptyProject(); PSMSchema Spsm1 = new PSMSchema(p); p.SingleVersion.PSMSchemas.Add(Spsm1); PIMSchema sPIM = new PIMSchema(p); p.SingleVersion.PIMSchema = sPIM; PIMClass pimcProduct = new PIMClass(p, sPIM) { Name = "Product" }; PIMClass pimcItem = new PIMClass(p, sPIM) { Name = "Item" }; PIMAssociation a = new PIMAssociation(p, sPIM, pimcItem, pimcProduct); a.PIMAssociationEnds[0].Upper = 2; a.PIMAssociationEnds[1].Upper = UnlimitedInt.Infinity; AttributeType stringType = new AttributeType(p) { Name = "string", IsSealed = true, XSDDefinition = "string" }; p.SingleVersion.PIMAttributeTypes.Add(stringType); #if SILVERLIGHT #else ModelConsistency.CheckProject(p); #endif return(p); }
internal override void CommandOperation() { PIMAssociation a = Project.TranslateComponent <PIMAssociation>(AssociationGuid); PIMSchema s = a.PIMSchema; endGuids = new Dictionary <Guid, Guid>(); classGuids = new List <Guid>(); Debug.Assert(a.PIMClasses.Count == 2, "PIMAssociation " + a.Name + " has " + a.PIMClasses.Count + " PIMClasses on delete."); Report = new CommandReport(CommandReports.PIM_component_deleted, a); foreach (PIMAssociationEnd e in a.PIMAssociationEnds) { s.PIMAssociationEnds.Remove(e); if (e.PIMClass != null) { e.PIMClass.PIMAssociationEnds.Remove(e); classGuids.Add(e.PIMClass); endGuids.Add(e.PIMClass, e); } Project.mappingDictionary.Remove(e); } s.PIMAssociations.Remove(a); Project.mappingDictionary.Remove(a); }
internal override PropagationMacroCommand PostPropagation() { PSMAssociation association = Project.TranslateComponent <PSMAssociation>(componentGuid); PIMAssociation interpretation = association.Interpretation as PIMAssociation; if (interpretation == null) { return(null); } PIMAssociationEnd e = ((association.Child as PSMClass).Interpretation as PIMClass).PIMAssociationEnds.First <PIMAssociationEnd>(end => end.PIMAssociation == interpretation); PropagationMacroCommand command = new PropagationMacroCommand(Controller); acmdUpdatePIMAssociationEndCardinality d = new acmdUpdatePIMAssociationEndCardinality(Controller, e, newLower, newUpper) { Propagate = true }; command.Commands.Add(d); return(command); }
/// <summary> /// Creates <see cref="PIMAssociationEndViewHelper"/> for each <paramref name="association"/>'s end. /// </summary> /// <param name="association">model association</param> public void CreateEndsViewHelpers(PIMAssociation association) { //associationEndsViewHelpers.Clear(); List <PIMAssociationEndViewHelper> used = new List <PIMAssociationEndViewHelper>(); // add new ends foreach (PIMAssociationEnd associationEnd in association.PIMAssociationEnds) { PIMAssociationEndViewHelper endViewHelper = associationEndsViewHelpers.Where(helper => helper.AssociationEnd == associationEnd).SingleOrDefault(); if (endViewHelper == null) { endViewHelper = new PIMAssociationEndViewHelper(Diagram, this); endViewHelper.AssociationEnd = associationEnd; associationEndsViewHelpers.Add(endViewHelper); } used.Add(endViewHelper); } if (used.Count == 2 && associationEndsViewHelpers.Count > 2 && UseDiamond) { associationEndsViewHelpers[0].Points.Clear(); } associationEndsViewHelpers.RemoveAll(helper => !used.Contains(helper)); if (association.PIMAssociationEnds.Count > 2 || ForceUseDiamond) { UseDiamond = true; } else { UseDiamond = false; } }
public FakeAssociationCollection(ObservableCollection <FakePSMAssociation> associationList, PSMClass psmClass) : base(associationList) { foreach (PSMAssociation psmAssociation in psmClass.ChildPSMAssociations) { associationList.Add(new FakePSMAssociation(psmAssociation)); } bool classEmpty = psmClass.ChildPSMAssociations.Count == 0; PSMClass nearestInterpretedClass = psmClass.NearestInterpretedClass(); if (nearestInterpretedClass != null) { foreach (PIMAssociationEnd associationEnd in ((PIMClass)nearestInterpretedClass.Interpretation).PIMAssociationEnds) { PIMAssociation pimAssociation = associationEnd.PIMAssociation; if (!associationList.Any(p => p.SourceAssociation != null && p.SourceAssociation.Interpretation == pimAssociation)) { foreach (PIMAssociationEnd otherEnd in pimAssociation.PIMAssociationEnds) { if (otherEnd.PIMClass == nearestInterpretedClass.Interpretation) { continue; } associationList.Add(new FakePSMAssociation(pimAssociation) { Checked = false, SourcePIMAssociationEnd = otherEnd }); } } } } }
private static void RelationsCorrespond(IVersionedItem versionedItem, IVersionedItem other) { #region PIMSchema { PIMSchema PIMSchema1 = versionedItem as PIMSchema; if (PIMSchema1 != null) { SubcollectionCheck(PIMSchema1, other, owner => owner.PIMAttributes); SubcollectionCheck(PIMSchema1, other, owner => owner.PIMAssociationEnds); SubcollectionCheck(PIMSchema1, other, owner => owner.PIMClasses); SubcollectionCheck(PIMSchema1, other, owner => owner.PIMAssociations); } } #endregion #region PIMClass { PIMClass pimClass1 = versionedItem as PIMClass; if (pimClass1 != null) { SubcollectionCheck(pimClass1, other, owner => owner.PIMAttributes); SubcollectionCheck(pimClass1, other, owner => owner.PIMAssociationEnds); } } #endregion #region PIMAttribute { PIMAttribute PIMAttribute1 = versionedItem as PIMAttribute; if (PIMAttribute1 != null) { ReferenceCheck(PIMAttribute1, other, owner => owner.PIMClass); ReferenceCheck(PIMAttribute1, other, owner => owner.AttributeType); } } #endregion #region PIMAssociation { PIMAssociation PIMAssociation1 = versionedItem as PIMAssociation; if (PIMAssociation1 != null) { SubcollectionCheck(PIMAssociation1, other, owner => owner.PIMClasses); SubcollectionCheck(PIMAssociation1, other, owner => owner.PIMAssociationEnds); } } #endregion #region PSMClass { PSMClass PSMClass1 = versionedItem as PSMClass; if (PSMClass1 != null) { SubcollectionCheck(PSMClass1, other, owner => owner.PSMAttributes); SubcollectionCheck(PSMClass1, other, owner => owner.ChildPSMAssociations); ReferenceCheck(PSMClass1, other, owner => owner.RepresentedClass); ReferenceCheck(PSMClass1, other, owner => owner.ParentAssociation); } } #endregion #region PSMAttribute { PSMAttribute PSMAttribute1 = versionedItem as PSMAttribute; if (PSMAttribute1 != null) { ReferenceCheck(PSMAttribute1, other, owner => owner.PSMClass); ReferenceCheck(PSMAttribute1, other, owner => owner.AttributeType); } } #endregion #region PSMAssociation { PSMAssociation PSMAssociation1 = versionedItem as PSMAssociation; if (PSMAssociation1 != null) { ReferenceCheck(PSMAssociation1, other, owner => owner.Parent); ReferenceCheck(PSMAssociation1, other, owner => owner.Child); } } #endregion #region PSMContentModel { PSMContentModel PSMContentModel1 = versionedItem as PSMContentModel; if (PSMContentModel1 != null) { SubcollectionCheck(PSMContentModel1, other, owner => owner.ChildPSMAssociations); ReferenceCheck(PSMContentModel1, other, owner => owner.ParentAssociation); } } #endregion #region PSMSchema { PSMSchema PSMSchema1 = versionedItem as PSMSchema; if (PSMSchema1 != null) { SubcollectionCheck(PSMSchema1, other, owner => owner.PSMAttributes); SubcollectionCheck(PSMSchema1, other, owner => owner.PSMContentModels); SubcollectionCheck(PSMSchema1, other, owner => owner.PSMClasses); SubcollectionCheck(PSMSchema1, other, owner => owner.PSMAssociations); SubcollectionCheck(PSMSchema1, other, owner => owner.PSMSchemaReferences); SubcollectionCheck(PSMSchema1, other, owner => owner.Roots); ReferenceCheck(PSMSchema1, other, owner => owner.PSMSchemaClass); } } #endregion }
public static void CommandTest() { Project p = new Project(); p.InitNewEmptyProject(); PIMSchema sPIM = new PIMSchema(p); AttributeType stringType = new AttributeType(p) { Name = "string", IsSealed = true, XSDDefinition = "string" }; p.SingleVersion.PIMAttributeTypes.Add(stringType); p.SingleVersion.PIMSchema = sPIM; PIMClass pimcProduct = new PIMClass(p, sPIM) { Name = "Product" }; PIMClass pimcCustomer = new PIMClass(p, sPIM) { Name = "Customer" }; PIMClass pimcPurchase = new PIMClass(p, sPIM) { Name = "Purchase" }; PIMClass pimcItem = new PIMClass(p, sPIM) { Name = "Item" }; PIMClass pimcAddress = new PIMClass(p, sPIM) { Name = "Address" }; PIMAttribute pimattProduct_title = new PIMAttribute(p, pimcProduct, sPIM) { Name = "title", AttributeType = stringType }; PIMAttribute pimattProduct_price = new PIMAttribute(p, pimcProduct, sPIM) { Name = "price" }; PIMAttribute pimattCustomer_name = new PIMAttribute(p, pimcCustomer, sPIM) { Name = "name" }; PIMAttribute pimattCustomer_email = new PIMAttribute(p, pimcCustomer, sPIM) { Name = "email", Lower = 1, Upper = UnlimitedInt.Infinity }; PIMAttribute pimattCustomer_phone = new PIMAttribute(p, pimcCustomer, sPIM) { Name = "phone", Lower = 0, Upper = UnlimitedInt.Infinity }; PIMAttribute pimattItem_tester = new PIMAttribute(p, pimcItem, sPIM) { Name = "tester" }; PIMAttribute pimattItem_itemprice = new PIMAttribute(p, pimcItem, sPIM) { Name = "itemprice" }; PIMAttribute pimattItem_amount = new PIMAttribute(p, pimcItem, sPIM) { Name = "amount" }; PIMAttribute pimattPurchase_code = new PIMAttribute(p, pimcPurchase, sPIM) { Name = "code" }; PIMAttribute pimattPurchase_create_date = new PIMAttribute(p, pimcPurchase, sPIM) { Name = "create-date" }; PIMAttribute pimattPurchase_status = new PIMAttribute(p, pimcPurchase, sPIM) { Name = "status" }; PIMAttribute pimattAddress_street = new PIMAttribute(p, pimcAddress, sPIM) { Name = "street" }; PIMAttribute pimattAddress_city = new PIMAttribute(p, pimcAddress, sPIM) { Name = "city" }; PIMAttribute pimattAddress_country = new PIMAttribute(p, pimcAddress, sPIM) { Name = "country" }; PIMAttribute pimattAddress_gps = new PIMAttribute(p, pimcAddress, sPIM) { Name = "gps" }; PIMAssociationEnd pimaeProduct1 = new PIMAssociationEnd(p, pimcProduct, sPIM); PIMAssociationEnd pimaeItem1 = new PIMAssociationEnd(p, pimcItem, sPIM) { Lower = 0, Upper = UnlimitedInt.Infinity }; PIMAssociation pimaProduct_Item = new PIMAssociation(p, sPIM, pimaeProduct1, pimaeItem1); PIMAssociationEnd pimaeItem2 = new PIMAssociationEnd(p, pimcItem, sPIM); PIMAssociationEnd pimaePurchase1 = new PIMAssociationEnd(p, pimcPurchase, sPIM) { Lower = 1, Upper = UnlimitedInt.Infinity }; PIMAssociation pimaItem_Purchase = new PIMAssociation(p, sPIM, pimaeItem2, pimaePurchase1); PIMAssociationEnd pimaePurchase2 = new PIMAssociationEnd(p, pimcPurchase, sPIM) { Lower = 1, Upper = UnlimitedInt.Infinity }; PIMAssociationEnd pimaeCustomer1 = new PIMAssociationEnd(p, pimcCustomer, sPIM); PIMAssociation pimaMakes = new PIMAssociation(p, sPIM, pimaePurchase2, pimaeCustomer1) { Name = "makes" }; PIMAssociationEnd pimaePurchase3 = new PIMAssociationEnd(p, pimcPurchase, sPIM) { Lower = 0, Upper = 1 }; PIMAssociationEnd pimaeAddress1 = new PIMAssociationEnd(p, pimcAddress, sPIM) { Lower = 0, Upper = 1 }; PIMAssociation pimaShipTo = new PIMAssociation(p, sPIM, pimaePurchase3, pimaeAddress1) { Name = "ship-to" }; PIMAssociationEnd pimaePurchase4 = new PIMAssociationEnd(p, pimcPurchase, sPIM) { Lower = 0, Upper = 1 }; PIMAssociationEnd pimaeAddress2 = new PIMAssociationEnd(p, pimcAddress, sPIM); PIMAssociation pimaBillTo = new PIMAssociation(p, sPIM, pimaePurchase4, pimaeAddress2) { Name = "bill-to" }; PSMSchema sPSM1 = new PSMSchema(p); p.SingleVersion.PSMSchemas.Add(sPSM1); PSMSchemaClass sPSM1C = new PSMSchemaClass(p, sPSM1) { Name = "PSMSchemaClass1" }; PSMClass psmcAddress = new PSMClass(p, sPSM1) { Name = "Address", Interpretation = pimcAddress }; sPSM1.Roots.Add(psmcAddress); PSMAttribute psmattStreet = new PSMAttribute(p, psmcAddress, sPSM1) { Name = "street", Element = true, Interpretation = pimattAddress_street }; PSMAttribute psmattCity = new PSMAttribute(p, psmcAddress, sPSM1) { Name = "city", Element = true, Interpretation = pimattAddress_city }; PSMClass psmcPurchase = new PSMClass(p, sPSM1) { Name = "Purchase", Interpretation = pimcPurchase }; PSMAssociation psmaPurchase = new PSMAssociation(p, sPSM1C, psmcPurchase, sPSM1) { Name = "purchase" }; PSMAttribute psmattPurchase_code = new PSMAttribute(p, psmcPurchase, sPSM1) { Name = "code", Element = false, Interpretation = pimattPurchase_code }; PSMAttribute psmattPurchase_create_date = new PSMAttribute(p, psmcPurchase, sPSM1) { Name = "create-date", Element = true, Interpretation = pimattPurchase_create_date }; PSMAttribute psmattPurchase_version = new PSMAttribute(p, psmcPurchase, sPSM1) { Name = "version", Element = false }; PSMClass psmcBillAddress = new PSMClass(p, sPSM1) { Name = "BillAddress", Interpretation = pimcAddress, RepresentedClass = psmcAddress }; PSMClass psmcShipAddress = new PSMClass(p, sPSM1) { Name = "ShipAddress", Interpretation = pimcAddress, RepresentedClass = psmcAddress }; PSMClass psmcCustomer = new PSMClass(p, sPSM1) { Name = "Customer", Interpretation = pimcCustomer }; PSMClass psmcItems = new PSMClass(p, sPSM1) { Name = "Items" }; PSMAttribute psmattCustomer_name = new PSMAttribute(p, psmcCustomer, sPSM1) { Name = "name", Element = true, Interpretation = pimattCustomer_name }; PSMAssociation psmaBillTo = new PSMAssociation(p, psmcPurchase, psmcBillAddress, sPSM1) { Name = "bill-to", Interpretation = pimaBillTo }; PSMAssociation psmaShipTo = new PSMAssociation(p, psmcPurchase, psmcShipAddress, sPSM1) { Name = "ship-to", Interpretation = pimaShipTo, Lower = 0 }; PSMAssociation psmacust = new PSMAssociation(p, psmcPurchase, psmcCustomer, sPSM1) { Name = "cust", Interpretation = pimaMakes }; PSMAssociation psmaItems = new PSMAssociation(p, psmcPurchase, psmcItems, sPSM1) { Name = "items" }; PSMClass psmcContact = new PSMClass(p, sPSM1) { Name = "Contact" }; PSMAttribute psmattContactEmail = new PSMAttribute(p, psmcContact, sPSM1) { Name = "email", Lower = 1, Upper = UnlimitedInt.Infinity, Interpretation = pimattCustomer_email, Element = true }; PSMAttribute psmattContactPhone = new PSMAttribute(p, psmcContact, sPSM1) { Name = "phone", Lower = 0, Upper = UnlimitedInt.Infinity, Interpretation = pimattCustomer_phone, Element = true }; PSMAssociation psmaCustomerContact = new PSMAssociation(p, psmcCustomer, psmcContact, sPSM1); PSMClass psmcItem = new PSMClass(p, sPSM1) { Name = "Item", Interpretation = pimcItem }; PSMAssociation psmaItemsItem = new PSMAssociation(p, psmcItems, psmcItem, sPSM1) { Name = "item", Lower = 1, Upper = UnlimitedInt.Infinity, Interpretation = pimaItem_Purchase }; PSMContentModel psmcm1 = new PSMContentModel(p, sPSM1) { Type = PSMContentModelType.Choice }; PSMAssociation psmaPSMC1 = new PSMAssociation(p, psmcItem, psmcm1, sPSM1); PSMClass psmcProduct = new PSMClass(p, sPSM1) { Name = "Product", Interpretation = pimcProduct }; PSMAttribute psmattProduct_code = new PSMAttribute(p, psmcProduct, sPSM1) { Name = "code", Element = true, Interpretation = pimattProduct_title }; PSMAssociation psmaPSMC1Product = new PSMAssociation(p, psmcm1, psmcProduct, sPSM1) { Interpretation = pimaProduct_Item }; PSMClass psmcItemTester = new PSMClass(p, sPSM1) { Name = "ItemTester" }; PSMAttribute psmattItemTester_tester = new PSMAttribute(p, psmcItemTester, sPSM1) { Name = "tester", Element = false, Interpretation = pimattItem_tester }; PSMAssociation psmaPSMC1ItemTester = new PSMAssociation(p, psmcm1, psmcItemTester, sPSM1); PSMClass psmcItemPricing = new PSMClass(p, sPSM1) { Name = "ItemPricing" }; PSMAttribute psmattItemPricing_price = new PSMAttribute(p, psmcItemPricing, sPSM1) { Name = "price", Element = true, Interpretation = pimattItem_itemprice }; PSMAttribute psmattItemPricing_amount = new PSMAttribute(p, psmcItemPricing, sPSM1) { Name = "amount", Element = true, Interpretation = pimattItem_amount }; PSMAssociation psmaPSMC1ItemPricing = new PSMAssociation(p, psmcm1, psmcItemPricing, sPSM1); PSMSchema sPSM2 = new PSMSchema(p); p.SingleVersion.PSMSchemas.Add(sPSM2); p.HasUnsavedChanges = true; Controller.Controller c = new Controller.Controller(p); Guid sPSM1Guid = sPSM1; ModelConsistency.CheckProject(p); //Exolutio.Controller.Commands.Atomic.PIM.MacroWrappers.cmdDeletePIMClass command = new Exolutio.Controller.Commands.Atomic.PIM.MacroWrappers.cmdDeletePIMClass(c); //command.Set(pimcItem); //command.Execute(); Exolutio.Controller.Commands.UndoCommand undo = new Exolutio.Controller.Commands.UndoCommand(c); undo.Execute(); Exolutio.Controller.Commands.RedoCommand redo = new Exolutio.Controller.Commands.RedoCommand(c); redo.Execute(); /*cmdDeletePSMSchema command = new cmdDeletePSMSchema(c); * * command.Set(sPSM1); * * command.Execute(); * ModelConsistency.CheckProject(p); * * try * { * p.TranslateComponent<PSMSchema>(sPSM1Guid); * } * catch { } * * command.UnExecute(); * * sPSM1 = p.TranslateComponent<PSMSchema>(sPSM1Guid); * ModelConsistency.CheckProject(p); * * command.ExecuteAsRedo();*/ }
public virtual TResult ProcessPIMAssociation(PIMAssociation pimAssociation) { return(DefaultResult); }
public static Project CreateSampleProject() { //return CreateSimpleSampleProject(); Project p = new Project(); p.InitNewEmptyProject(); PIMSchema sPIM = new PIMSchema(p); AttributeType stringType = new AttributeType(p) { Name = "string", IsSealed = true, XSDDefinition = "string" }; p.SingleVersion.PIMAttributeTypes.Add(stringType); p.SingleVersion.PIMSchema = sPIM; PIMClass pimcProduct = new PIMClass(p, sPIM) { Name = "Product" }; PIMClass pimcCustomer = new PIMClass(p, sPIM) { Name = "Customer" }; PIMClass pimcPurchase = new PIMClass(p, sPIM) { Name = "Purchase" }; PIMClass pimcItem = new PIMClass(p, sPIM) { Name = "Item" }; PIMClass pimcAddress = new PIMClass(p, sPIM) { Name = "Address" }; PIMAttribute pimattProduct_title = new PIMAttribute(p, pimcProduct, sPIM) { Name = "title", AttributeType = stringType }; PIMAttribute pimattProduct_price = new PIMAttribute(p, pimcProduct, sPIM) { Name = "price" }; PIMAttribute pimattCustomer_name = new PIMAttribute(p, pimcCustomer, sPIM) { Name = "name" }; PIMAttribute pimattCustomer_email = new PIMAttribute(p, pimcCustomer, sPIM) { Name = "email", Lower = 1, Upper = UnlimitedInt.Infinity }; PIMAttribute pimattCustomer_phone = new PIMAttribute(p, pimcCustomer, sPIM) { Name = "phone", Lower = 0, Upper = UnlimitedInt.Infinity }; PIMAttribute pimattItem_tester = new PIMAttribute(p, pimcItem, sPIM) { Name = "tester" }; PIMAttribute pimattItem_itemprice = new PIMAttribute(p, pimcItem, sPIM) { Name = "itemprice" }; PIMAttribute pimattItem_amount = new PIMAttribute(p, pimcItem, sPIM) { Name = "amount" }; PIMAttribute pimattPurchase_code = new PIMAttribute(p, pimcPurchase, sPIM) { Name = "code" }; PIMAttribute pimattPurchase_create_date = new PIMAttribute(p, pimcPurchase, sPIM) { Name = "create-date" }; PIMAttribute pimattPurchase_status = new PIMAttribute(p, pimcPurchase, sPIM) { Name = "status" }; PIMAttribute pimattAddress_street = new PIMAttribute(p, pimcAddress, sPIM) { Name = "street" }; PIMAttribute pimattAddress_city = new PIMAttribute(p, pimcAddress, sPIM) { Name = "city" }; PIMAttribute pimattAddress_country = new PIMAttribute(p, pimcAddress, sPIM) { Name = "country" }; PIMAttribute pimattAddress_gps = new PIMAttribute(p, pimcAddress, sPIM) { Name = "gps" }; PIMAssociationEnd pimaeProduct1 = new PIMAssociationEnd(p, pimcProduct, sPIM); PIMAssociationEnd pimaeItem1 = new PIMAssociationEnd(p, pimcItem, sPIM) { Lower = 0, Upper = UnlimitedInt.Infinity }; PIMAssociation pimaProduct_Item = new PIMAssociation(p, sPIM, pimaeProduct1, pimaeItem1); PIMAssociationEnd pimaeItem2 = new PIMAssociationEnd(p, pimcItem, sPIM); PIMAssociationEnd pimaePurchase1 = new PIMAssociationEnd(p, pimcPurchase, sPIM) { Lower = 1, Upper = UnlimitedInt.Infinity }; PIMAssociation pimaItem_Purchase = new PIMAssociation(p, sPIM, pimaeItem2, pimaePurchase1); PIMAssociationEnd pimaePurchase2 = new PIMAssociationEnd(p, pimcPurchase, sPIM) { Lower = 1, Upper = UnlimitedInt.Infinity }; PIMAssociationEnd pimaeCustomer1 = new PIMAssociationEnd(p, pimcCustomer, sPIM); PIMAssociation pimaMakes = new PIMAssociation(p, sPIM, pimaePurchase2, pimaeCustomer1) { Name = "makes" }; PIMAssociationEnd pimaePurchase3 = new PIMAssociationEnd(p, pimcPurchase, sPIM) { Lower = 0, Upper = 1 }; PIMAssociationEnd pimaeAddress1 = new PIMAssociationEnd(p, pimcAddress, sPIM) { Lower = 0, Upper = 1 }; PIMAssociation pimaShipTo = new PIMAssociation(p, sPIM, pimaePurchase3, pimaeAddress1) { Name = "ship-to" }; PIMAssociationEnd pimaePurchase4 = new PIMAssociationEnd(p, pimcPurchase, sPIM) { Lower = 0, Upper = 1 }; PIMAssociationEnd pimaeAddress2 = new PIMAssociationEnd(p, pimcAddress, sPIM); PIMAssociation pimaBillTo = new PIMAssociation(p, sPIM, pimaePurchase4, pimaeAddress2) { Name = "bill-to" }; PSMSchema sPSM1 = new PSMSchema(p); p.SingleVersion.PSMSchemas.Add(sPSM1); PSMSchemaClass sPSM1C = new PSMSchemaClass(p, sPSM1) { Name = "PSMSchemaClass1" }; PSMClass psmcAddress = new PSMClass(p, sPSM1) { Name = "Address", Interpretation = pimcAddress }; //sPSM1.Roots.Add(psmcAddress); PSMAttribute psmattStreet = new PSMAttribute(p, psmcAddress, sPSM1) { Name = "street", Element = true, Interpretation = pimattAddress_street }; PSMAttribute psmattCity = new PSMAttribute(p, psmcAddress, sPSM1) { Name = "city", Element = true, Interpretation = pimattAddress_city }; PSMClass psmcPurchase = new PSMClass(p, sPSM1) { Name = "Purchase", Interpretation = pimcPurchase }; PSMAssociation psmaPurchase = new PSMAssociation(p, sPSM1C, psmcPurchase, sPSM1) { Name = "purchase" }; PSMAttribute psmattPurchase_code = new PSMAttribute(p, psmcPurchase, sPSM1) { Name = "code", Element = false, Interpretation = pimattPurchase_code }; PSMAttribute psmattPurchase_create_date = new PSMAttribute(p, psmcPurchase, sPSM1) { Name = "create-date", Element = true, Interpretation = pimattPurchase_create_date }; PSMAttribute psmattPurchase_version = new PSMAttribute(p, psmcPurchase, sPSM1) { Name = "version", Element = false }; PSMClass psmcBillAddress = new PSMClass(p, sPSM1) { Name = "BillAddress", Interpretation = pimcAddress, RepresentedClass = psmcAddress }; PSMClass psmcShipAddress = new PSMClass(p, sPSM1) { Name = "ShipAddress", Interpretation = pimcAddress, RepresentedClass = psmcAddress }; PSMClass psmcCustomer = new PSMClass(p, sPSM1) { Name = "Customer", Interpretation = pimcCustomer }; PSMClass psmcItems = new PSMClass(p, sPSM1) { Name = "Items" }; PSMAttribute psmattCustomer_name = new PSMAttribute(p, psmcCustomer, sPSM1) { Name = "name", Element = true, Interpretation = pimattCustomer_name }; PSMAssociation psmaBillTo = new PSMAssociation(p, psmcPurchase, psmcBillAddress, sPSM1) { Name = "bill-to", Interpretation = pimaBillTo }; PSMAssociation psmaShipTo = new PSMAssociation(p, psmcPurchase, psmcShipAddress, sPSM1) { Name = "ship-to", Interpretation = pimaShipTo, Lower = 0 }; PSMAssociation psmacust = new PSMAssociation(p, psmcPurchase, psmcCustomer, sPSM1) { Name = "cust", Interpretation = pimaMakes }; PSMAssociation psmaItems = new PSMAssociation(p, psmcPurchase, psmcItems, sPSM1) { Name = "items" }; PSMClass psmcContact = new PSMClass(p, sPSM1) { Name = "Contact" }; PSMAttribute psmattContactEmail = new PSMAttribute(p, psmcContact, sPSM1) { Name = "email", Lower = 1, Upper = UnlimitedInt.Infinity, Interpretation = pimattCustomer_email, Element = true }; PSMAttribute psmattContactPhone = new PSMAttribute(p, psmcContact, sPSM1) { Name = "phone", Lower = 0, Upper = UnlimitedInt.Infinity, Interpretation = pimattCustomer_phone, Element = true }; PSMAssociation psmaCustomerContact = new PSMAssociation(p, psmcCustomer, psmcContact, sPSM1); PSMClass psmcItem = new PSMClass(p, sPSM1) { Name = "Item", Interpretation = pimcItem }; PSMAssociation psmaItemsItem = new PSMAssociation(p, psmcItems, psmcItem, sPSM1) { Name = "item", Lower = 1, Upper = UnlimitedInt.Infinity, Interpretation = pimaItem_Purchase }; PSMContentModel psmcm1 = new PSMContentModel(p, sPSM1) { Type = PSMContentModelType.Choice }; PSMAssociation psmaPSMC1 = new PSMAssociation(p, psmcItem, psmcm1, sPSM1); PSMClass psmcProduct = new PSMClass(p, sPSM1) { Name = "Product", Interpretation = pimcProduct }; PSMAttribute psmattProduct_code = new PSMAttribute(p, psmcProduct, sPSM1) { Name = "code", Element = true, Interpretation = pimattProduct_title }; PSMAssociation psmaPSMC1Product = new PSMAssociation(p, psmcm1, psmcProduct, sPSM1) { Interpretation = pimaProduct_Item }; PSMClass psmcItemTester = new PSMClass(p, sPSM1) { Name = "ItemTester" }; PSMAttribute psmattItemTester_tester = new PSMAttribute(p, psmcItemTester, sPSM1) { Name = "tester", Element = false, Interpretation = pimattItem_tester }; PSMAssociation psmaPSMC1ItemTester = new PSMAssociation(p, psmcm1, psmcItemTester, sPSM1); PSMClass psmcItemPricing = new PSMClass(p, sPSM1) { Name = "ItemPricing" }; PSMAttribute psmattItemPricing_price = new PSMAttribute(p, psmcItemPricing, sPSM1) { Name = "price", Element = true, Interpretation = pimattItem_itemprice }; PSMAttribute psmattItemPricing_amount = new PSMAttribute(p, psmcItemPricing, sPSM1) { Name = "amount", Element = true, Interpretation = pimattItem_amount }; PSMAssociation psmaPSMC1ItemPricing = new PSMAssociation(p, psmcm1, psmcItemPricing, sPSM1); p.HasUnsavedChanges = true; // classes were added to roots... foreach (PSMAssociationMember member in sPSM1.Roots.ToArray()) { if (member.ParentAssociation != null) { sPSM1.Roots.Remove(member); } } #if SILVERLIGHT #else ModelConsistency.CheckProject(p); #endif return(p); }
private bool FindNavigationsForPIMNavigationRecursive(PIMPath pimPath, int stepIndex, PSMAssociationMember currentMember, PSMPath builtPath, bool canGoToParent, ref List <PSMPath> result, PSMAssociation associationUsedAlready) { if (stepIndex == pimPath.Steps.Count) { result.Add(builtPath); return(true); } PIMPathStep currentStep = pimPath.Steps[stepIndex]; if (currentStep is PIMPathAssociationStep) { Debug.Assert(currentMember != null); PIMPathAssociationStep nextStep = (PIMPathAssociationStep)currentStep; List <PSMAssociationMember> candidates = currentMember.ChildPSMAssociations.Where(a => allowNonTree || !a.IsNonTreeAssociation).Select(a => a.Child).ToList(); /* * we forbid non-tree associations for now, * it certainly makes thinks easier and I am not sure * whether it is really a restriction */ List <PSMAssociation> candidatesAssociations = currentMember.ChildPSMAssociations.Where(a => allowNonTree || !a.IsNonTreeAssociation).ToList(); PSMAssociationMember parent = currentMember.ParentAssociation != null ? currentMember.ParentAssociation.Parent : null; if (parent != null && canGoToParent && !(parent is PSMSchemaClass)) { bool candidateParent = true; if (currentMember.ParentAssociation.Interpretation != null) { PIMAssociation interpretedAssociation = (PIMAssociation)currentMember.ParentAssociation.Interpretation; PIMAssociationEnd interpretedEnd = currentMember.ParentAssociation.InterpretedAssociationEnd; PIMAssociationEnd oppositeEnd = interpretedAssociation.PIMAssociationEnds.Single(e => e != interpretedEnd); // upwards navigation on ends with upper cardinality > 1 breaks semantics of the expression if (oppositeEnd.Upper > 1) { candidateParent = false; } } if (candidateParent) { candidates.Add(parent); candidatesAssociations.Add(currentMember.ParentAssociation); } } bool found = false; for (int index = 0; index < candidates.Count; index++) { PSMAssociationMember candidate = candidates[index]; PSMAssociation candidateAssociation = candidatesAssociations[index]; bool parentStep = candidate == parent && !candidateAssociation.IsNonTreeAssociation; // forbid traversing the same association several times if (associationUsedAlready == candidateAssociation) { continue; } int nextStepIndex = stepIndex; bool interpretedClassSatisfies = candidateAssociation.Interpretation != null && candidate.DownCastSatisfies <PSMClass>(c => c.Interpretation == nextStep.Class); if (candidate.Interpretation == null || interpretedClassSatisfies) { PSMPath nextBuiltPath = (PSMPath)builtPath.Clone(); nextBuiltPath.Steps.Add(new PSMPathAssociationStep(nextBuiltPath) { Association = candidateAssociation, To = candidate, From = currentMember, IsUp = candidateAssociation.Parent == candidate }); if (interpretedClassSatisfies) { nextStepIndex++; } found |= FindNavigationsForPIMNavigationRecursive(pimPath, nextStepIndex, candidate, nextBuiltPath, canGoToParent && !parentStep, ref result, parentStep ? candidateAssociation : null); } } return(found); } else if (currentStep is PIMPathVariableStep) { Debug.Assert(currentMember == null); PIMPathVariableStep pathVariableStep = (PIMPathVariableStep)currentStep; IEnumerable <PSMClass> candidates = TargetPSMSchema.PSMClasses.Where(c => c.Interpretation == pimPath.StartingClass); if (!VariableClassMappings.ContainsKey(pathVariableStep.Variable)) { return(false); } candidates = candidates.Intersect(VariableClassMappings[pathVariableStep.Variable]); bool found = false; List <PSMClass> eliminatedCandidates = new List <PSMClass>(); eliminatedCandidates.AddRange(VariableClassMappings[pathVariableStep.Variable].Except(candidates)); foreach (PSMClass candidate in candidates) { PSMBridgeClass startType = psmBridge.Find(candidate); builtPath = new PSMPath(); VariableDeclaration vd; if (!variableTranslations.ContainsKey(pathVariableStep.Variable)) { vd = new VariableDeclaration(pathVariableStep.Variable.Name, startType, null); variableTranslations[pathVariableStep.Variable] = vd; } else { vd = variableTranslations[pathVariableStep.Variable]; } builtPath.Steps.Add(new PSMPathVariableStep(builtPath) { VariableExp = new VariableExp(vd) }); bool candidateUsable = FindNavigationsForPIMNavigationRecursive(pimPath, stepIndex + 1, candidate, builtPath, true, ref result, null); if (!candidateUsable) { eliminatedCandidates.Add(candidate); } found |= candidateUsable; } VariableClassMappings[pathVariableStep.Variable].RemoveAll(eliminatedCandidates.Contains); if (PathMappings.ContainsKey(pimPath)) { PathMappings[pimPath].RemoveAll(p => eliminatedCandidates.Contains(p.StartingClass)); } return(found); } else if (currentStep is PIMPathAttributeStep) { PIMPathAttributeStep pathAttributeStep = (PIMPathAttributeStep)currentStep; Debug.Assert(currentMember is PSMClass); bool found = false; foreach (PSMAttribute psmAttribute in ((PSMClass)currentMember).PSMAttributes) { if (psmAttribute.Interpretation == pathAttributeStep.Attribute) { PSMPath nextBuiltPath = (PSMPath)builtPath.Clone(); nextBuiltPath.Steps.Add(new PSMPathAttributeStep(nextBuiltPath) { Attribute = psmAttribute }); result.Add(nextBuiltPath); found |= true; } } return(found); } else { throw new NotImplementedException(); } }
public virtual void ProcessPIMAssociation(PIMAssociation pimAssociation, ref TContext context) { ProcessPIMComponent(pimAssociation, ref context); }
public PIMBridgeAssociation(string name, PIMAssociation sourceAss, PIMAssociationEnd sourceAssEnd, PropertyType propertyType, Classifier type) : base(name, propertyType, type, BridgePropertyType.Association) { this.SourceAssociation = sourceAss; this.SourceAssociationEnd = sourceAssEnd; }