internal override CommandBase.OperationResult UndoOperation() { IHasCardinality owner = Project.TranslateComponent <Component>(componentGuid) as IHasCardinality; owner.Lower = oldLower; owner.Upper = oldUpper; return(OperationResult.OK); }
public static string GetCardinalityString(this IHasCardinality cardinalityElement) { if (cardinalityElement.Lower != cardinalityElement.Upper) { return(String.Format("{0}..{1}", cardinalityElement.Lower, cardinalityElement.Upper)); } else { return(cardinalityElement.Lower.ToString()); } }
internal override void CommandOperation() { IHasCardinality owner = Project.TranslateComponent <Component>(ComponentGuid) as IHasCardinality; string oldCardinality = owner.CardinalityString; oldLower = owner.Lower; oldUpper = owner.Upper; owner.Lower = newLower; owner.Upper = newUpper; Report = new CommandReport(CommandReports.CARDINALITY_CHANGED, owner, oldCardinality, owner.CardinalityString); }
static public Classifier GetTypeByCardinality(TypesTable.TypesTable tt, IHasCardinality card, Classifier baseType) { if (card.Upper > 1) { return(tt.Library.CreateCollection(CollectionKind.Set, baseType)); } else { return(baseType); } }
public static void SerializeCardinality(this IHasCardinality component, XElement parentNode, SerializationContext context) { if (component.Lower != 1) { XAttribute lowerAttribute = new XAttribute("Lower", SerializationContext.EncodeValue(component.Lower)); parentNode.Add(lowerAttribute); } if (component.Upper != 1) { XAttribute upperAttribute = new XAttribute("Upper", SerializationContext.EncodeValue(component.Upper)); parentNode.Add(upperAttribute); } }
public static void DeserializeCardinality(this IHasCardinality component, XElement parentNode, SerializationContext context) { if (parentNode.Attribute("Lower") != null) { component.Lower = SerializationContext.DecodeUInt(parentNode.Attribute("Lower").Value); } else { component.Lower = 1; } if (parentNode.Attribute("Upper") != null) { component.Upper = SerializationContext.DecodeUnlimitedInt(parentNode.Attribute("Upper").Value); } else { component.Upper = 1; } }
//protected override void TranslateAssociationChild(PSMAssociationChild associationChild, DataGeneratorContext context) //{ // int count = 1; // if (associationChild.ParentAssociation != null) // { // count = ChooseMultiplicity(associationChild.ParentAssociation); // } // for (int i = 0; i < count; i++) // { // if (associationChild is PSMClass) // { // PSMClass psmClass = (PSMClass)associationChild; // if (!psmClass.HasElementLabel) // { // if (GenerateComments) // { // XmlComment xmlComment = context.Document.CreateComment(string.Format("Content group {0} {1}", psmClass.Name, i)); // context.CurrentElement.AppendChild(xmlComment); // } // } // TranslateClass(psmClass, context); // } // else // { // TranslateClassUnion((PSMClassUnion)associationChild, context); // } // } //} //private void TranslateClassUnion(PSMClassUnion classUnion, DataGeneratorContext context) //{ // PSMAssociationChild selectedPath = classUnion.Components.ChooseOneRandomly(); // TranslateComments(classUnion, context); // TranslateAssociationChild(selectedPath, context); //} //protected override void TranslateAttributeContainer(PSMAttributeContainer attributeContainer, DataGeneratorContext context) //{ // foreach (PSMAttribute attribute in attributeContainer.PSMAttributes) // { // TranslateComments(attributeContainer, context); // TranslateAttributeAsElement(attribute, context); // } //} private uint ChooseCardinality(IHasCardinality cardinalityComponent) { uint lower = cardinalityComponent.Lower; uint upper = !cardinalityComponent.Upper.IsInfinity ? cardinalityComponent.Upper.Value : InfinityBound; if (upper > 2 && PathElements.Sum(e => e == cardinalityComponent ? 1 : 0) > 2) { upper = 2; } if (cardinalityComponent is PSMAssociation) { PSMAssociation association = (PSMAssociation)cardinalityComponent; uint occurrences = GetComponentOccurrences(association); if (occurrences > 10 && association.Lower > 0) { Log.AddError(string.Format("Association {0} is recursive and causes infinite nesting.", association)); throw new ExolutioException(string.Format("Association {0} is recursive and causes infinite nesting.", association)); } if (MinimalTree) { return(lower); } else { int result = RandomGenerator.Next((int)lower, (int)upper + 1, (int)(occurrences - 1)); return((uint)result); } } else { if (MinimalTree) { return(1); } else { return((uint)RandomGenerator.Next(Math.Max((int)lower, 1), (int)(upper + 1))); } } }
public static bool HasNondefaultCardinality(this IHasCardinality cardinalityElement) { return(cardinalityElement.Lower != 1 || cardinalityElement.Upper != 1); }
/// <summary> /// Writes minOccurs and maxOccurs attributes (if cardinalities are not equal to 1) /// </summary> public static void CardinalityAttributes(this XElement parentElement, IHasCardinality component) { CardinalityAttributes(parentElement, component.Lower, component.Upper); }
public void HandleCardinality(XElement parentElement, IHasCardinality cardinalityElement) { HandleCardinality(parentElement, cardinalityElement.Lower, cardinalityElement.Upper); }