/// <summary> /// Constructor /// </summary> /// <param name="args"></param> /// <param name="value"></param> /// <param name="element"></param> public ToolStripAddStructureMember(CellRightClickEventArgs args, StructureValue value, StructureElement element) : base(args, "Add " + element.Name) { Value = value; Element = element; }
/// <summary> /// Accepts drop of a tree node, in a drag & drop operation /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { base.AcceptDrop(SourceNode); if (SourceNode is StructureElementTreeNode) { StructureElementTreeNode structureElementTreeNode = SourceNode as StructureElementTreeNode; DataDictionary.Types.StructureElement element = structureElementTreeNode.Item; structureElementTreeNode.Delete(); AddElement(element); } else if (SourceNode is SpecificationView.ParagraphTreeNode) { SpecificationView.ParagraphTreeNode node = SourceNode as SpecificationView.ParagraphTreeNode; DataDictionary.Specification.Paragraph paragaph = node.Item; DataDictionary.Types.StructureElement element = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); element.Name = paragaph.Name; DataDictionary.ReqRef reqRef = (DataDictionary.ReqRef)DataDictionary.Generated.acceptor.getFactory().createReqRef(); reqRef.Name = paragaph.FullId; element.appendRequirements(reqRef); AddElement(element); } }
/// <summary> /// Executes the action requested by this tool strip button /// </summary> protected override void OnClick(EventArgs e) { Collection collectionType = (Collection)Variable.Type; Structure structureType = (Structure)collectionType.Type; StructureValue element = new StructureValue(structureType, false); if (structureType.Elements.Count == 1) { StructureElement subElement = (StructureElement)structureType.Elements[0]; Structure subElementStructureType = subElement.Type as Structure; if (subElementStructureType != null) { element.CreateField(subElement, structureType); } } ListValue value = Variable.Value.RightSide(Variable, false, true) as ListValue; Variable.Value = value; if (value != null) { value.Val.Add(element); element.Enclosing = value; } base.OnClick(e); }
/// <summary> /// Converts the value provided as an EFS value /// </summary> /// <returns></returns> public override IValue ConvertBack(Type type) { DataDictionary.Values.StructureValue retVal = null; Structure structureType = type as Structure; if (structureType != null) { retVal = new DataDictionary.Values.StructureValue(structureType); foreach (KeyValuePair <string, Value> pair in Value) { if (pair.Value != null) { StructureElement element = structureType.FindStructureElement(pair.Key); if (element != null) { Field field = retVal.CreateField(element, structureType); field.Value = pair.Value.ConvertBack(element.Type); } else { throw new FaultException <EFSServiceFault>( new EFSServiceFault("Cannot find element named " + pair.Key + " in structure " + structureType.FullName)); } } } } CheckReturnValue(retVal, type); return(retVal); }
/// <summary> /// Creates a structure element in the structure provided /// </summary> /// <param name="enclosing"></param> /// <param name="name"></param> /// <param name="type"></param> /// <returns></returns> protected StructureElement CreateStructureElement(Structure enclosing, string name, string type) { StructureElement retVal = (StructureElement)Factory.createStructureElement(); enclosing.appendElements(retVal); retVal.Name = name; retVal.TypeName = type; return(retVal); }
/// <summary> /// Sets the value of a given association /// </summary> /// <param name="structureElement"></param> /// <param name="log">The element on which errors should be logged</param> /// <returns>the newly created field</returns> public Field CreateField(StructureElement structureElement, ModelElement log) { Field retVal = null; if (structureElement != null) { retVal = new Field(this, structureElement); Val[retVal.Name] = retVal; } else { log.AddError("Cannot find structure element"); } return(retVal); }
/// <summary> /// Sets the value of a given association /// </summary> /// <param name="enclosing"></param> /// <param name="name"></param> /// <param name="log">The element on which errors should be logged</param> /// <returns>the newly created field</returns> public Field CreateField(object enclosing, string name, ModelElement log) { Field retVal = null; StructureElement structureElement = Structure.FindStructureElement(name); if (structureElement != null) { retVal = CreateField(structureElement, log); } else { log.AddError("Cannot find structure element " + name); } return(retVal); }
/// <summary> /// Constructor /// </summary> /// <param name="structureExpression"></param> /// <param name="context"></param> /// <param name="explain"></param> public StructureValue(StructExpression structureExpression, InterpretationContext context, ExplanationPart explain) : base(structureExpression.GetExpressionType() as Structure, new Dictionary <string, INamable>()) { Enclosing = Structure; try { HashSet <string> members = new HashSet <string>(); foreach (KeyValuePair <Designator, Expression> pair in structureExpression.Associations) { StructureElement structureElement = Structure.FindStructureElement(pair.Key.Image); if (structureElement != null) { IValue val = pair.Value.GetExpressionValue(new InterpretationContext(context), explain); if (val != null) { Field field = CreateField(structureElement, structureExpression.RootLog); field.Value = val; members.Add(field.Name); } else { structureExpression.AddError("Cannot evaluate value for " + pair.Value, RuleChecksEnum.ExecutionFailed); } } else { structureExpression.AddError("Cannot find structure element " + pair.Key.Image, RuleChecksEnum.ExecutionFailed); } } foreach (StructureElement element in Structure.Elements) { if (!members.Contains(element.Name)) { Field field = CreateField(element, structureExpression.RootLog); field.Value = element.DefaultValue; } } } finally { _depth -= 1; } }
public void TestCollectionConcatenation() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace = CreateNameSpace(dictionary, "NameSpace"); Structure structure = CreateStructure(nameSpace, "ModelElement"); StructureElement structElem = CreateStructureElement(structure, "Value", "Boolean"); structElem.setDefault("True"); Collection collection = CreateCollection(nameSpace, "Coll", "ModelElement", 10); collection.Type = structure; collection.setMaxSize(3); collection.Default = "[]"; Variable variable = CreateVariable(nameSpace, "V", "Coll"); RuleCondition ruleCondition = CreateRuleAndCondition(nameSpace, "Test"); Action action = CreateAction(ruleCondition, "V <- V + [ModelElement{Value => True}] "); RuleCheckerVisitor visitor = new RuleCheckerVisitor(dictionary); visitor.visit(nameSpace); Util.IsThereAnyError isThereAnyError = new Util.IsThereAnyError(); Assert.AreEqual(0, isThereAnyError.ErrorsFound.Count); Assert.AreEqual("[]", variable.Value.LiteralName); Runner runner = new Runner(false); runner.Cycle(); Assert.AreEqual("[" + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName); runner.Cycle(); Assert.AreEqual("[" + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName); runner.Cycle(); Assert.AreEqual("[" + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName); // In this case, the new collection cannot be placed in the variable runner.Cycle(); Assert.AreEqual(1, action.Messages.Count); Assert.AreEqual(ElementLog.LevelEnum.Error, action.Messages[0].Level); }
private void AddDMIOutStructure(CustomProcedure.DMIProcedureConfig aConfig) { DataDictionary.Types.Structure aStructure = (DataDictionary.Types.Structure)DataDictionary.Generated.acceptor.getFactory().createStructure(); aStructure.Name = aConfig.ProcedureName; aStructure.NeedsRequirement = true; Item.appendStructures(aStructure); StructureTreeNode aStructureTreeNode = new StructureTreeNode(aStructure); Nodes.Add(aStructureTreeNode); DataDictionary.Types.StructureElement structElemIn = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); structElemIn.Name = "OutputInformation"; structElemIn.TypeName = "DMI.OutputInformation"; structElemIn.Mode = DataDictionary.Generated.acceptor.VariableModeEnumType.aIncoming; aStructureTreeNode.AddStructureElement(structElemIn); SortSubNodes(); }
public void TestVariableAndTypeWithSameName() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace = CreateNameSpace(dictionary, "NameSpace"); Structure structure = CreateStructure(nameSpace, "ModelElement"); StructureElement structElem = CreateStructureElement(structure, "Value", "Boolean"); structElem.setDefault("True"); Variable variable = CreateVariable(nameSpace, "ModelElement", "ModelElement"); variable.SubVariables["Value"].Value = System.BoolType.False; Expression expression = new Parser().Expression(dictionary, "NameSpace.ModelElement.Value"); IValue value = expression.GetExpressionValue(new InterpretationContext(), null); Assert.AreEqual(value, variable.SubVariables["Value"].Value); }
private void AddStructureElementHandler(object sender, EventArgs args) { DataDictionary.Types.StructureElement element = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); element.Name = "<Element" + (GetNodeCount(false) + 1) + ">"; AddElement(element); }
/// <summary> /// Adds a structure element to the model /// </summary> /// <param name="element"></param> public void AddElement(DataDictionary.Types.StructureElement element) { Item.appendElements(element); Nodes.Add(new StructureElementTreeNode(element)); SortSubNodes(); }
/// <summary> /// Appends the corresponding field in the structure, according to its type /// </summary> /// <param name="obj">The object which represents the field</param> /// <param name="structure">The structure which should contain the field</param> private void AppendField(object obj, DataDictionary.Types.Structure structure, string defaultValue) { if (obj is Field) { Field field = obj as Field; DataDictionary.Types.StructureElement element = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); element.Name = field.name; element.TypeName = EFSType(field.type_definition); if (element.TypeName == null) { element.TypeName = getTypeName(field.type); } element.setMode(DataDictionary.Generated.acceptor.VariableModeEnumType.aInOut); if (field.name.Equals("NID_PACKET")) { element.Default = defaultValue; } else { element.Default = DefaultValue(field.type_definition); } structure.appendElements(element); } else if (obj is LoopFieldSequence) { LoopFieldSequence loopFieldSequence = obj as LoopFieldSequence; // Create a structure for the elements enclosed in the loop field DataDictionary.Types.Structure subStructure = (DataDictionary.Types.Structure)DataDictionary.Generated.acceptor.getFactory().createStructure(); subStructure.Name = "SubStructure" + numberOfSubStructures; numberOfSubStructures += 1; structure.NameSpace.appendStructures(subStructure); RenameDuplicates(loopFieldSequence.Items); foreach (object obj2 in loopFieldSequence.Items) { AppendField(obj2, subStructure, ""); } // Create the collection type for the sequence DataDictionary.Types.Collection collection = (DataDictionary.Types.Collection)DataDictionary.Generated.acceptor.getFactory().createCollection(); collection.Name = "Collection" + numberOfCollections; collection.setTypeName(subStructure.Name); collection.setDefault("[]"); structure.NameSpace.appendCollections(collection); // Create the field in the strcuture which shall hold the collection DataDictionary.Types.StructureElement element = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); element.Name = "Sequence" + numberOfCollections; element.TypeName = collection.Name; element.setMode(DataDictionary.Generated.acceptor.VariableModeEnumType.aInOut); structure.appendElements(element); numberOfCollections += 1; } else if (obj is ConditionalFieldSequence) { ConditionalFieldSequence conditionalFieldSequence = obj as ConditionalFieldSequence; RenameDuplicates(conditionalFieldSequence.content); foreach (object obj2 in conditionalFieldSequence.content) { AppendField(obj2, structure, ""); } } else if (obj is FieldGroupReference) { FieldGroupReference fieldGroupReference = obj as FieldGroupReference; DataDictionary.Types.StructureElement element = (DataDictionary.Types.StructureElement)DataDictionary.Generated.acceptor.getFactory().createStructureElement(); element.Name = fieldGroupReference.name; if (Utils.Utils.isEmpty(element.Name)) { string[] names = [email protected]('/'); element.Name = names[names.Length - 1]; } element.setMode(DataDictionary.Generated.acceptor.VariableModeEnumType.aInOut); element.TypeName = getTypeName(fieldGroupReference.@ref) + ".Message"; element.Default = "EMPTY"; structure.appendElements(element); } else if (obj is Choice) { Choice choice = obj as Choice; RenameDuplicates(choice.field_group_reference); foreach (FieldGroupReference obj2 in choice.field_group_reference) { AppendField(obj2, structure, ""); } } }
/// <summary> /// Creates a variable according to the structure element provided /// </summary> /// <param name="element"></param> /// <returns></returns> private static Variable CreateVariable(StructureElement element) { Structure elementStructureType = (Structure) element.Type; StructureValue subValue = new StructureValue(elementStructureType, false); Variable retVal = (Variable) acceptor.getFactory().createVariable(); retVal.Name = element.Name; retVal.Type = element.Type; retVal.Value = subValue; return retVal; }
/// <summary> /// Creates a variable according to the structure element provided /// </summary> /// <param name="element"></param> /// <returns></returns> private static Field CreateField(StructureElement element) { Structure elementStructureType = (Structure) element.Type; StructureValue subValue = new StructureValue(elementStructureType, false); Field retVal = new Field(elementStructureType, element); retVal.Value = subValue; return retVal; }
public void AddStructureElement(DataDictionary.Types.StructureElement element) { elements.AddElement(element); }