예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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;
            }
        }