/// <summary> /// Constructor /// </summary> /// <param name="structure"></param> public StructureValue(StructureValue other) : base(other.Structure, new Dictionary <string, Utils.INamable>()) { Enclosing = other.Structure; foreach (KeyValuePair <string, Utils.INamable> pair in other.Val) { Variables.Variable variable = pair.Value as Variables.Variable; if (variable != null) { Variables.Variable var2 = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable(); var2.Type = variable.Type; var2.Name = variable.Name; var2.Mode = variable.Mode; var2.Default = variable.Default; var2.Enclosing = this; if (variable.Value != null) { var2.Value = variable.Value.RightSide(var2, true); } else { var2.Value = null; } set(var2); } } }
/// <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> /// 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) { StructureElement element = structureType.FindStructureElement(pair.Key); if (element != null) { Variable variable = (Variable) acceptor.getFactory().createVariable(); variable.Name = element.Name; variable.Value = pair.Value.ConvertBack(element.Type); retVal.set(variable); } else { throw new FaultException<EFSServiceFault>( new EFSServiceFault("Cannot find element named " + element.Name + " in structure " + structureType.FullName)); } } } CheckReturnValue(retVal, type); return retVal; }
/// <summary> /// Creates a valid right side IValue, according to the target variable (left side) /// </summary> /// <param name="variable">The target variable</param> /// <param name="duplicate">Indicates that a duplication of the variable should be performed</param> /// <returns></returns> public override Values.IValue RightSide(Variables.IVariable variable, bool duplicate) { StructureValue retVal = this; if (duplicate) { retVal = new StructureValue(retVal); } retVal.Enclosing = variable; return(retVal); }
/// <summary> /// Constructor /// </summary> /// <param name="other"></param> public StructureValue(StructureValue other) : base(other.Structure, new Dictionary <string, INamable>()) { Enclosing = other.Structure; foreach (KeyValuePair <string, INamable> pair in other.Val) { Field field = pair.Value as Field; if (field != null) { Field field2 = CreateField(field.StructureElement, Structure); if (field.Value != null) { field2.Value = field.Value.RightSide(field2, true, true); } else { field2.Value = null; } } } }
/// <summary> /// Converts a DataDictionary.Values.IValue into an EFSIPCInterface.Value /// </summary> /// <param name="value"></param> /// <returns></returns> public Value ConvertOut(IValue value) { // Handles the boolean case { BoolValue v = value as BoolValue; if (v != null) { return(new Values.BoolValue(v.Val)); } } // Handles the integer case { IntValue v = value as IntValue; if (v != null) { return(new Values.IntValue(v.Val)); } } // Handles the double case { DoubleValue v = value as DoubleValue; if (v != null) { return(new Values.DoubleValue(v.Val)); } } // Handles the string case { StringValue v = value as StringValue; if (v != null) { return(new Values.StringValue(v.Val)); } } // Handles the state case { State v = value as State; if (v != null) { return(new StateValue(v.FullName)); } } // Handles the enumeration value case { EnumValue v = value as EnumValue; if (v != null) { return(new Values.EnumValue(v.FullName)); } } // Handles the list case { ListValue v = value as ListValue; if (v != null) { List <Value> list = new List <Value>(); foreach (IValue item in v.Val) { list.Add(ConvertOut(item)); } return(new Values.ListValue(list)); } } // Handles the structure case { StructureValue v = value as StructureValue; if (v != null) { Dictionary <string, Value> record = new Dictionary <string, Value>(); foreach (KeyValuePair <string, INamable> pair in v.Val) { IVariable variable = pair.Value as IVariable; if (variable != null) { record.Add(variable.Name, ConvertOut(variable.Value)); } } return(new Values.StructureValue(record)); } } // Handles the function case { DataDictionary.Functions.Function v = value as DataDictionary.Functions.Function; if (v != null) { List <Segment> segments = new List <Segment>(); if (v.FormalParameters.Count == 1) { Graph graph = v.CreateGraph(new InterpretationContext(), (Parameter)v.FormalParameters[0], null); if (graph != null) { foreach (Graph.Segment segment in graph.Segments) { double length = segment.End - segment.Start; segments.Add(new Segment { A = segment.Expression.A, V0 = segment.Expression.V0, D0 = segment.Start, Length = length }); } } } return(new FunctionValue(segments)); } } // Handles the 'empty' value { EmptyValue emptyValue = value as EmptyValue; if (emptyValue != null) { return(null); } } throw new FaultException <EFSServiceFault>(new EFSServiceFault("Cannot convert value " + value)); }