public PIMAttributeTextBox GetTextBoxOfAttribute(PIMAttribute pimAttribute) { if (RepresentantsCollection.ContainsKey(pimAttribute.PIMClass)) { PIMClassView cv = (PIMClassView)RepresentantsCollection[pimAttribute.PIMClass]; return(cv.AttributeTextBoxes.FirstOrDefault(tb => tb.PIMAttribute == pimAttribute)); } return(null); }
internal override void CommandOperation() { PIMAttribute a = Project.TranslateComponent <PIMAttribute>(attributeGuid); Report = new CommandReport(CommandReports.PIM_component_deleted, a); Project.TranslateComponent <PIMSchema>(schemaGuid).PIMAttributes.Remove(a); classGuid = a.PIMClass; index = Project.TranslateComponent <PIMClass>(classGuid).PIMAttributes.Remove(a); Project.mappingDictionary.Remove(attributeGuid); }
internal override CommandBase.OperationResult UndoOperation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass generalClass = Project.TranslateComponent <PIMClass>(generalClassGuid); PIMClass specialClass = Project.TranslateComponent <PIMClass>(specialClassGuid); specialClass.PIMAttributes.Remove(pimAttribute); pimAttribute.PIMClass = generalClass; generalClass.PIMAttributes.Insert(pimAttribute, index); return(OperationResult.OK); }
internal override void CommandOperation() { if (AttributeGuid == Guid.Empty) { AttributeGuid = Guid.NewGuid(); } PIMClass pimClass = Project.TranslateComponent <PIMClass>(classGuid); PIMAttribute pimAttribute = new PIMAttribute(Project, AttributeGuid, pimClass, Project.TranslateComponent <PIMSchema>(schemaGuid)); Report = new CommandReport(CommandReports.PIM_component_added, pimAttribute); }
internal override CommandBase.OperationResult UndoOperation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass oldClass = Project.TranslateComponent <PIMClass>(oldClassGuid); PIMClass newClass = Project.TranslateComponent <PIMClass>(newClassGuid); newClass.PIMAttributes.Remove(pimAttribute); pimAttribute.PIMClass = oldClass; oldClass.PIMAttributes.Insert(pimAttribute, index); return(OperationResult.OK); }
internal override PropagationMacroCommand PrePropagation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass specialPIMClass = Project.TranslateComponent <PIMClass>(specialClassGuid); PIMClass generalPIMClass = pimAttribute.PIMClass; List <PSMAttribute> psmAttributes = pimAttribute.GetInterpretedComponents().Cast <PSMAttribute>().ToList(); PropagationMacroCommand command = new PropagationMacroCommand(Controller) { CheckFirstOnlyInCanExecute = true }; command.Report = new CommandReport("Pre-propagation (specialize PIM attribute)"); foreach (PSMAttribute a in psmAttributes) { if (a.PSMClass.Interpretation == null) { //class without interpretation, maybe including impl.inheritance command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = a, ClassGuid = a.PSMClass.NearestInterpretedClass() }); } IEnumerable <Tuple <PSMClass, IEnumerable <PSMClass> > > paths = a.PSMClass.GetSpecialClassesWithPaths(); if (paths.Any(p => p.Item1.Interpretation == specialPIMClass)) //1) there is special PIMClass counterpart -> move there { IEnumerable <PSMClass> path = paths.First(p => p.Item1.Interpretation == specialPIMClass).Item2; foreach (PSMClass c in path) { command.Commands.Add(new acmdSpecializePSMAttribute(Controller, a, c)); } } else //2) There is none... create. TODO: FIX: multiple attributes in one class => multiple classes { Guid newClassGuid = Guid.NewGuid(); command.Commands.Add(new acmdNewPSMClass(Controller, a.PSMSchema) { ClassGuid = newClassGuid }); command.Commands.Add(new acmdRenameComponent(Controller, newClassGuid, specialPIMClass.Name)); command.Commands.Add(new acmdSetPSMClassInterpretation(Controller, newClassGuid, specialPIMClass)); command.Commands.Add(new acmdNewPSMGeneralization(Controller, a.PSMClass.NearestInterpretedClass(), newClassGuid, a.PSMSchema)); command.Commands.Add(new acmdSpecializePSMAttribute(Controller, a, newClassGuid)); } } return(command); }
private void ConvertPIMAttribute(EvoX.Model.PIM.PIMClass evoxPIMClass, Property attribute) { PIMAttribute pimAttribute = new PIMAttribute(evoxProject, evoxPIMClass, pimSchema); translatedElements[attribute] = pimAttribute; pimAttribute.Name = attribute.Name; pimAttribute.Lower = ConvertToUint(attribute.Lower); pimAttribute.Upper = ConvertToUnlimitedInt(attribute.Upper); if (attribute.Type != null) { pimAttribute.AttributeType = (EvoX.Model.AttributeType)ElementRef(attribute.Type); } }
public FakePSMAttribute(PIMAttribute p) : this() { Name = p.Name; Type = p.AttributeType; Multiplicity = p.GetCardinalityString(); DefaultValue = p.DefaultValue; SourceAttribute = null; RepresentedAttribute = p; ComesFrom = (PIMClass)p.PIMClass; Checked = false; XFormElement = false; }
internal override void CommandOperation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass generalClass = pimAttribute.PIMClass; generalClassGuid = generalClass; PIMClass specialClass = Project.TranslateComponent <PIMClass>(specialClassGuid); index = generalClass.PIMAttributes.IndexOf(pimAttribute); Report = new CommandReport("{0} specialized from {1} to {2}.", pimAttribute, generalClass, specialClass); generalClass.PIMAttributes.Remove(pimAttribute); pimAttribute.PIMClass = specialClass; specialClass.PIMAttributes.Add(pimAttribute); }
internal override void CommandOperation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass oldClass = pimAttribute.PIMClass; oldClassGuid = oldClass; PIMClass newClass = Project.TranslateComponent <PIMClass>(newClassGuid); index = oldClass.PIMAttributes.IndexOf(pimAttribute); Report = new CommandReport("{0} moved from {1} to {2}.", pimAttribute, oldClass, newClass); oldClass.PIMAttributes.Remove(pimAttribute); pimAttribute.PIMClass = newClass; newClass.PIMAttributes.Add(pimAttribute); }
private void AddAttributeIDPattern(PIMAttribute attribute) { if (attribute == null) { return; } if (attribute.ListOfValues != null && attribute.ListOfValues.UseValueID && !String.IsNullOrWhiteSpace(attribute.ListOfValues.IDPattern) && !AttributeIDPatterns.ContainsKey(attribute.ID)) { AttributeIDPatterns.Add(attribute.ID, attribute.ListOfValues.IDPattern); } }
public FakePSMAttribute(PIMAttribute p, TypeFinder typeFinder) : this() { Name = p.Name; Multiplicity = p.GetCardinalityString(); DefaultValue = p.DefaultValue; SourceAttribute = null; RepresentedAttribute = p; ComesFrom = (PIMClass)p.PIMClass; Checked = false; XFormElement = true; if (p.AttributeType != null) { Type = typeFinder(p.AttributeType); } }
internal override void CommandOperation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); AttributeType oldType = pimAttribute.AttributeType; oldTypeGuid = oldType; if (newTypeGuid != Guid.Empty) { pimAttribute.AttributeType = Project.TranslateComponent <AttributeType>(newTypeGuid); } else { pimAttribute.AttributeType = null; } Report = new CommandReport(CommandReports.TYPED_CHANGED, pimAttribute, oldType, pimAttribute.AttributeType); }
public override bool CanExecute() { if (attributeGuid == Guid.Empty) { ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH; return(false); } PIMAttribute attribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass oldclass = attribute.PIMClass; PIMClass newclass = oldclass.GeneralizationAsSpecific == null ? null : oldclass.GeneralizationAsSpecific.General; if (newclass == null) { ErrorDescription = CommandErrors.CMDERR_NO_GENERALIZATION; return(false); } return(true); }
public override bool CanExecute() { if (newClassGuid == Guid.Empty || attributeGuid == Guid.Empty) { ErrorDescription = CommandErrors.CMDERR_INPUT_TYPE_MISMATCH; return(false); } PIMClass newclass = Project.TranslateComponent <PIMClass>(newClassGuid); PIMAttribute attribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass oldclass = attribute.PIMClass; if (newclass.GetAssociationsWith(oldclass).Count <PIMAssociation>() == 0) { ErrorDescription = CommandErrors.CMDERR_NO_COMMON_ASSOCIATION; return(false); } return(true); }
public override bool CanExecute() { if (AttributeTypeGuid == Guid.Empty) { return(false); } if (ProjectVersionType) { ProjectVersion projectVersion = attributeType.ProjectVersion; PIMAttribute usingAttribute = projectVersion.PIMSchema.PIMAttributes.FirstOrDefault(a => a.AttributeType == attributeType); if (usingAttribute != null) { ErrorDescription = string.Format("'{0}' can not be deleted, because it is used by '{1}'.", attributeType, usingAttribute); return(false); } AttributeType usingAttributeType = projectVersion.PIMAttributeTypes.FirstOrDefault(a => a.BaseType == attributeType); if (usingAttributeType != null) { ErrorDescription = string.Format("'{0}' can not be deleted, because it is used by '{1}'.", attributeType, usingAttributeType); return(false); } } else { PSMSchema psmSchema = Controller.Project.TranslateComponent <PSMSchema>(OwnerPSMSchemaGuid); PSMAttribute usingAttribute = psmSchema.PSMAttributes.FirstOrDefault(a => a.AttributeType == attributeType); if (usingAttribute != null) { ErrorDescription = string.Format("'{0}' can not be deleted, because it is used by '{1}'.", attributeType, usingAttribute); return(false); } AttributeType usingAttributeType = psmSchema.PSMSchemaDefinedTypes.FirstOrDefault(a => a.BaseType == attributeType); if (usingAttributeType != null) { ErrorDescription = string.Format("'{0}' can not be deleted, because it is used by '{1}'.", attributeType, usingAttributeType); return(false); } } return(true); }
internal override CommandBase.OperationResult UndoOperation() { PIMAttribute a = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass pimClass = a.PIMClass; int index = pimClass.PIMAttributes.IndexOf(a); int count = pimClass.PIMAttributes.Count; if (up) { index = (index + 1) % count; } else { index = (index - 1) % count; } pimClass.PIMAttributes.Remove(a); pimClass.PIMAttributes.Insert(a, index); return(OperationResult.OK); }
internal override void CommandOperation() { PIMAttribute a = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass pimClass = a.PIMClass; int index = pimClass.PIMAttributes.IndexOf(a); int count = pimClass.PIMAttributes.Count; if (up) { index = (index + count - 1) % count; } else { index = (index + 1) % count; } pimClass.PIMAttributes.Remove(a); pimClass.PIMAttributes.Insert(a, index); Report = new CommandReport(CommandReports.PIM_ATTR_SHIFT, a, up ? "up" : "down"); }
internal override PropagationMacroCommand PrePropagation() { PIMAttribute pimAttribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass oldPIMClass = pimAttribute.PIMClass; PIMClass newPIMClass = oldPIMClass.GeneralizationAsSpecific.General; List <PSMAttribute> psmAttributes = pimAttribute.GetInterpretedComponents().Cast <PSMAttribute>().ToList(); PropagationMacroCommand command = new PropagationMacroCommand(Controller) { CheckFirstOnlyInCanExecute = true }; command.Report = new CommandReport("Pre-propagation (generalize PIM attribute)"); foreach (PSMAttribute a in psmAttributes) { IEnumerable <PSMClass> generals = a.PSMClass.NearestInterpretedClass().GetGeneralClasses(); if (generals.Any(c => c.Interpretation == newPIMClass)) { if (a.PSMClass.Interpretation == null) { //class without interpretation, maybe including impl.inheritance command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = a, ClassGuid = a.PSMClass.NearestInterpretedClass() }); } //whether the class uses implicit inheritance or not (a.PSMClass.Interpretation == oldPIMClass) we move it to the PSMClass, whose interpretation is newPIMClass command.Commands.Add(new cmdGeneralizePSMAttribute(Controller) { AttributeGuid = a, PSMClassGuid = generals.First(c => c.Interpretation == newPIMClass) }); } } return(command); }
/// <summary> /// <Attribute ID="CabinetFinish" MultiValued="false" ProductMode="Normal" FullTextIndexed="false" ExternallyMaintained="false" Derived="false" HierarchicalFiltering="false" ClassificationHierarchicalFiltering="false" Selected="true" Referenced="true"> /// <Name>Cabinet Finish</Name> /// <ListOfValueLink ListOfValueID = "CabinetFinish" /> /// <MetaData> /// <Value AttributeID= "AttributeHelpText"> Definition: The cabinet finish type.</Value> /// <Value AttributeID = "DisplaySequence"> 8 </Value> /// </MetaData> /// <AttributeGroupLink AttributeGroupID= "EngineeringGeneralSpecifications" /> /// <UserTypeLink UserTypeID= "MajorRevision" /> /// <UserTypeLink UserTypeID= "Item" /> /// </Attribute> /// </summary> /// <param name="attrEl"></param> /// <returns></returns> private PIMAttribute ParseAttribute(XElement attrEl, Dictionary <string, PIMListOfValue> lovs) { if (attrEl == null) { return(null); } var id = GetAttributeValue(attrEl, "ID"); if (String.IsNullOrWhiteSpace(id)) { return(null); } var attribute = new PIMAttribute() { ID = id }; attribute.Name = GetNodeText(attrEl.XPathSelectElement("Name")); // Match up the LOV var lovAttr = attrEl.XPathSelectElement("ListOfValueLink"); if (lovAttr != null) { var lovID = GetAttributeValue(lovAttr, "ListOfValueID"); if (lovID != null && lovs.ContainsKey(lovID)) { attribute.ListOfValues = lovs[lovID]; } } return(attribute); }
internal override PropagationMacroCommand PrePropagation() { PropagationMacroCommand command = new PropagationMacroCommand(Controller); command.Report = new CommandReport("Pre-propagation (move PIM attribute)"); PIMAttribute attribute = Project.TranslateComponent <PIMAttribute>(attributeGuid); PIMClass targetClass = Project.TranslateComponent <PIMClass>(newClassGuid); PIMClass sourceClass = attribute.PIMClass; IEnumerable <PIMAssociation> pimAssociations = targetClass.GetAssociationsWith(sourceClass); IEnumerable <PSMAttribute> interpretedAttributes = attribute.GetInterpretedComponents().Cast <PSMAttribute>().Where(a => a.ID != PropagateSource); foreach (PSMAttribute psmAttribute in interpretedAttributes) { PSMClass intclass = psmAttribute.PSMClass.NearestInterpretedClass(); Debug.Assert(intclass.Interpretation == sourceClass, "Intclass != sourceclass"); bool found = false; PSMAssociation parentAssociation = intclass.ParentAssociation; foreach (PIMAssociation association in pimAssociations) { if (parentAssociation != null && parentAssociation.Interpretation == association) { //moving the attribute up in PSM found = true; cmdCreateNewPSMAttribute c2 = new cmdCreateNewPSMAttribute(Controller); Guid attrGuid2 = Guid.NewGuid(); c2.AttributeGuid = attrGuid2; c2.Set(intclass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element); command.Commands.Add(c2); if (psmAttribute.PSMClass != intclass) { command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = psmAttribute, ClassGuid = intclass, Propagate = false }); } acmdSynchroPSMAttributes s2 = new acmdSynchroPSMAttributes(Controller) { Propagate = false }; s2.X1.Add(psmAttribute); s2.X2.Add(attrGuid2); command.Commands.Add(s2); if (psmAttribute.PSMClass != intclass) { command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = psmAttribute, ClassGuid = psmAttribute.PSMClass, Propagate = false }); } acmdSetInterpretation i2 = new acmdSetPSMAttributeInterpretation(Controller, attrGuid2, attribute); command.Commands.Add(i2); cmdMovePSMAttribute m2 = new cmdMovePSMAttribute(Controller) { Propagate = false }; m2.Set(attrGuid2, intclass.NearestInterpretedParentClass()); command.Commands.Add(m2); } //select nearest interpreted child PSM classes, whose parent association's interpretation is the PIM association through which we are moving the attribute IEnumerable <PSMClass> children = intclass.InterpretedSubClasses().Where <PSMClass>(pc => pc.Interpretation == targetClass && pc.ParentAssociation.Interpretation == association); foreach (PSMClass child in children) { found = true; cmdCreateNewPSMAttribute c = new cmdCreateNewPSMAttribute(Controller); Guid attrGuid = Guid.NewGuid(); c.AttributeGuid = attrGuid; c.Set(intclass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element); command.Commands.Add(c); if (psmAttribute.PSMClass != intclass) { command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = psmAttribute, ClassGuid = intclass, Propagate = false }); } acmdSynchroPSMAttributes s2 = new acmdSynchroPSMAttributes(Controller) { Propagate = false }; s2.X1.Add(psmAttribute); s2.X2.Add(attrGuid); command.Commands.Add(s2); if (psmAttribute.PSMClass != intclass) { command.Commands.Add(new cmdMovePSMAttribute(Controller) { AttributeGuid = psmAttribute, ClassGuid = psmAttribute.PSMClass, Propagate = false }); } acmdSetInterpretation i = new acmdSetPSMAttributeInterpretation(Controller, attrGuid, attribute); command.Commands.Add(i); cmdMovePSMAttribute m = new cmdMovePSMAttribute(Controller) { Propagate = false }; m.Set(attrGuid, child); command.Commands.Add(m); } if (!found) { cmdCreateNewPSMAttribute c = new cmdCreateNewPSMAttribute(Controller); Guid attrGuid = Guid.NewGuid(); c.AttributeGuid = attrGuid; c.Set(/*intclass*/ psmAttribute.PSMClass, psmAttribute.AttributeType, psmAttribute.Name, psmAttribute.Lower, psmAttribute.Upper, psmAttribute.Element); command.Commands.Add(c); /*if (psmAttribute.PSMClass != intclass) * { * cmdMovePSMAttribute m1 = new cmdMovePSMAttribute(Controller) { Propagate = false }; * m1.Set(psmAttribute, intclass); * command.Commands.Add(m1); * }*/ acmdSynchroPSMAttributes s = new acmdSynchroPSMAttributes(Controller) { Propagate = false }; s.X1.Add(psmAttribute); s.X2.Add(attrGuid); command.Commands.Add(s); /*if (psmAttribute.PSMClass != intclass) * { * cmdMovePSMAttribute m2 = new cmdMovePSMAttribute(Controller) { Propagate = false }; * m2.Set(psmAttribute, psmAttribute.PSMClass); * command.Commands.Add(m2); * }*/ acmdSetInterpretation i = new acmdSetPSMAttributeInterpretation(Controller, attrGuid, attribute); command.Commands.Add(i); //create psmassoc, class Guid ncGuid = Guid.NewGuid(); acmdNewPSMClass nc = new acmdNewPSMClass(Controller, psmAttribute.PSMSchema) { ClassGuid = ncGuid }; command.Commands.Add(nc); acmdRenameComponent rc = new acmdRenameComponent(Controller, ncGuid, targetClass.Name); command.Commands.Add(rc); acmdSetInterpretation ic = new acmdSetPSMClassInterpretation(Controller, ncGuid, targetClass); command.Commands.Add(ic); Guid naGuid = Guid.NewGuid(); acmdNewPSMAssociation na = new acmdNewPSMAssociation(Controller, /*intclass*/ psmAttribute.PSMClass, ncGuid, psmAttribute.PSMSchema) { AssociationGuid = naGuid }; command.Commands.Add(na); acmdRenameComponent ra = new acmdRenameComponent(Controller, naGuid, association.Name); command.Commands.Add(ra); PIMAssociationEnd e = targetClass.PIMAssociationEnds.Single <PIMAssociationEnd>(aend => aend.PIMAssociation == association); acmdUpdatePSMAssociationCardinality carda = new acmdUpdatePSMAssociationCardinality(Controller, naGuid, e.Lower, e.Upper) { Propagate = false }; command.Commands.Add(carda); acmdSetInterpretation ia = new acmdSetPSMAssociationInterpretation(Controller, naGuid, e, association); command.Commands.Add(ia); acmdMovePSMAttribute m = new acmdMovePSMAttribute(Controller, attrGuid, ncGuid) { Propagate = false }; command.Commands.Add(m); } } //delete attribute cmdDeletePSMAttribute d = new cmdDeletePSMAttribute(Controller) { Propagate = false }; d.Set(psmAttribute); command.Commands.Add(d); } command.CheckFirstOnlyInCanExecute = true; return(command); }
/// <summary> /// Tries find instance of PIMBridgeAttribute associated with <paramref name="att"/> from PIM. /// </summary> /// <exception cref="KeyNotFoundException"><paramref name="att"/> not exists in this class.</exception> public PIMBridgeAttribute FindAttribute(PIMAttribute att) { return(PIMAttribute[att]); }
internal void TranslateMembers() { //Attributy foreach (var pr in SourceClass.PIMAttributes) { Classifier baseType = pr.AttributeType != null ? TypeTable.Library.RootNamespace.NestedClassifier[pr.AttributeType.Name] : TypeTable.Library.Any; Classifier propType = BridgeHelpers.GetTypeByCardinality(TypeTable, pr, baseType); PIMBridgeAttribute newProp = new PIMBridgeAttribute(pr, PropertyType.One, propType); Properties.Add(newProp); //Hack newProp.Tag = pr; //Registration to find PIMAttribute.Add(pr, newProp); } //Associace foreach (var ass in SourceClass.PIMAssociationEnds) { var end = ass.PIMAssociation.PIMAssociationEnds.Where(a => a.ID != ass.ID).First(); Classifier assType = TypeTable.Library.RootNamespace.NestedClassifier[end.PIMClass.Name]; string name; if (string.IsNullOrEmpty(end.Name)) { name = assType.Name; } else { name = end.Name; } Classifier propType = BridgeHelpers.GetTypeByCardinality(TypeTable, end, assType); TypeTable.RegisterType(propType); PIMBridgeAssociation newass = new PIMBridgeAssociation(name, ass.PIMAssociation, end, PropertyType.One, propType); Properties.Add(newass); //hack newass.Tag = end; //Registration to find PIMAssociations.Add(end, newass); } //Operation foreach (var op in SourceClass.PIMOperations) { Operation newOp = new Operation(op.Name, true, op.ResultType != null ? TypeTable.Library.RootNamespace.NestedClassifier[op.ResultType.Name] : TypeTable.Library.Void, op.Parameters.Select(p => new Parameter(p.Name, TypeTable.Library.RootNamespace.NestedClassifier[p.Type.Name]))); Operations.Add(newOp); //hack newOp.Tag = op; // Registration to find PIMOperations.Add(op, newOp); } // allInstances { Operation allInstancesOp = new Operation(@"allInstances", true, this); Operations.Add(allInstancesOp); } }
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 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); }
public virtual void ProcessPIMAttribute(PIMAttribute pimAttribute, ref TContext context) { ProcessPIMComponent(pimAttribute, ref context); }
public virtual TResult ProcessPIMAttribute(PIMAttribute pimAttribute) { return(DefaultResult); }
public void Initialize(Exolutio.Controller.Controller controller, PIMClass PIMClass, PIMAttribute initialSelectedAttribute = null) { this.controller = controller; this.PIMClass = PIMClass; this.Title = string.Format(this.Title, PIMClass); tbName.Text = PIMClass.Name; //tbElementLabel.Text = PIMClass.ElementName; //cbAbstract.IsChecked = PIMClass.IsAbstract; //cbAnyAttribute.IsChecked = PIMClass.AllowAnyAttribute; typeColumn.ItemsSource = PIMClass.ProjectVersion.GetAvailablePIMTypes(); fakeAttributesList = new ObservableCollection <FakePIMAttribute>(); fakeAttributes = new FakeAttributeCollection(fakeAttributesList, PIMClass); fakeAttributesList.CollectionChanged += delegate { UpdateApplyEnabled(); }; gridAttributes.ItemsSource = fakeAttributesList; if (initialSelectedAttribute != null) { gridAttributes.SelectedItem = fakeAttributesList.SingleOrDefault(fa => fa.SourceAttribute == initialSelectedAttribute); } dialogReady = true; bApply.IsEnabled = false; }
private void bApply_Click(object sender, RoutedEventArgs e) { bApply.Focus(); applyButtonPressed = true; error = false; controller.BeginMacro(); //controller.CreatedMacro.Description = string.Format("PIM Classs '{0}' was updated. ", PIMClass); if (tbName.ValueChanged) { cmdRenameComponent renameCommand = new cmdRenameComponent(controller) { ComponentGuid = PIMClass, NewName = tbName.Text }; controller.CreatedMacro.Commands.Add(renameCommand); tbName.ForgetOldValue(); } //if (PIMClass.IsAbstract != cbAbstract.IsChecked) //{ // PIMClassController.ChangeAbstract(cbAbstract.IsChecked == true); //} //if (PIMClass.AllowAnyAttribute != cbAnyAttribute.IsChecked) //{ // PIMClassController.ChangeAllowAnyAttributeDefinition(cbAnyAttribute.IsChecked == true); //} #region check for deleted attributes List <PIMAttribute> removedAttributes = new List <PIMAttribute>(); List <FakePIMAttribute> addedAttributes = new List <FakePIMAttribute>(); foreach (PIMAttribute PIMAttribute in PIMClass.PIMAttributes) { bool found = false; foreach (FakePIMAttribute fakeAttribute in fakeAttributes) { if (fakeAttribute.SourceAttribute == PIMAttribute && fakeAttribute.Checked) { found = true; break; } else if (fakeAttribute.SourceAttribute == PIMAttribute && !fakeAttribute.Checked) { fakeAttribute.SourceAttribute = null; } } if (!found) { removedAttributes.Add(PIMAttribute); cmdDeletePIMAttribute deleteCommand = new cmdDeletePIMAttribute(controller); deleteCommand.Set(PIMAttribute); controller.CreatedMacro.Commands.Add(deleteCommand); } } #endregion #region remove dummy entries in fake collection List <FakePIMAttribute> toRemove = new List <FakePIMAttribute>(); foreach (FakePIMAttribute fakeAttribute in fakeAttributes) { if (String.IsNullOrEmpty(fakeAttribute.Name)) { if (fakeAttribute.SourceAttribute != null) { removedAttributes.Add(fakeAttribute.SourceAttribute); cmdDeletePIMAttribute deleteCommand = new cmdDeletePIMAttribute(controller); deleteCommand.Set(fakeAttribute.SourceAttribute); controller.CreatedMacro.Commands.Add(deleteCommand); } toRemove.Add(fakeAttribute); } } foreach (FakePIMAttribute attribute in toRemove) { fakeAttributes.Remove(attribute); } #endregion Dictionary <PIMAttribute, string> namesDict = new Dictionary <PIMAttribute, string>(); foreach (PIMAttribute a in PIMClass.PIMAttributes) { if (!removedAttributes.Contains(a)) { namesDict.Add(a, a.Name); } } // check for changes and new attributes var modified = from FakePIMAttribute a in fakeAttributes where a.SourceAttribute != null && !removedAttributes.Contains(a.SourceAttribute) && a.SomethingChanged() select a; var added = from FakePIMAttribute a in fakeAttributes where a.SourceAttribute == null select a; // editing exisiting attribute foreach (FakePIMAttribute modifiedAttribute in modified) { PIMAttribute sourceAttribute = modifiedAttribute.SourceAttribute; uint lower; UnlimitedInt upper; if ( !IHasCardinalityExt.ParseMultiplicityString(modifiedAttribute.Multiplicity, out lower, out upper)) { error = true; } cmdUpdatePIMAttribute updateCommand = new cmdUpdatePIMAttribute(controller); updateCommand.Set(sourceAttribute, modifiedAttribute.Type, modifiedAttribute.Name, lower, upper, modifiedAttribute.DefaultValue); controller.CreatedMacro.Commands.Add(updateCommand); namesDict[sourceAttribute] = modifiedAttribute.Name; } List <string> names = namesDict.Values.ToList(); // new attribute foreach (FakePIMAttribute addedAttribute in added) { if (!string.IsNullOrEmpty(addedAttribute.Name) && addedAttribute.Checked) { uint lower = 1; UnlimitedInt upper = 1; if (!String.IsNullOrEmpty(addedAttribute.Multiplicity)) { if (!IHasCardinalityExt.ParseMultiplicityString(addedAttribute.Multiplicity, out lower, out upper)) { error = true; } } cmdCreateNewPIMAttribute createNewPIMAttribute = new cmdCreateNewPIMAttribute(controller); createNewPIMAttribute.Set(PIMClass, addedAttribute.Type, addedAttribute.Name, lower, upper, addedAttribute.DefaultValue); controller.CreatedMacro.Commands.Add(createNewPIMAttribute); addedAttributes.Add(addedAttribute); names.Add(addedAttribute.Name); } } if (error) { controller.CancelMacro(); } else { CommandBase tmp = (CommandBase)controller.CreatedMacro; controller.CommitMacro(); if (string.IsNullOrEmpty(tmp.ErrorDescription)) { foreach (FakePIMAttribute attribute in addedAttributes) { attribute.SourceAttribute = PIMClass.PIMAttributes.Where (property => property.Name == attribute.Name).SingleOrDefault(); } addedAttributes.RemoveAll(attribute => attribute.SourceAttribute == null); bApply.IsEnabled = false; dialogReady = true; error = false; } else { error = true; } } Initialize(controller, PIMClass); applyButtonPressed = false; }
public PIMBridgeAttribute(PIMAttribute source, PropertyType propertyType, Classifier type) : base(source.Name, propertyType, type, BridgePropertyType.Attribute) { SourceAttribute = source; }