//============================================================================== /// <summary> /// /// </summary> /// <param name="sVariableName"></param> /// <param name="aValue"></param> /// <param name="iParentID"></param> /// <param name="iIndex"></param> /// <param name="Specifier"></param> /// <returns></returns> //============================================================================== protected virtual int defineVariable(string sVariableName, TDDMLValue aValue, int iParentID, int iIndex, TMainOutputSpecifier Specifier) { int result; if (FColumns.Count < 1) { result = -1; } else { result = FColumns.Count; } return(result); }
//============================================================================== /// <summary> /// /// </summary> /// <param name="sVariableName"></param> /// <param name="aValue"></param> /// <param name="iParentID"></param> /// <param name="iIndex"></param> /// <param name="Aggreg"></param> /// <param name="iDecPlaces"></param> /// <returns></returns> //============================================================================== protected virtual int defineVariable(string sVariableName, TDDMLValue aValue, int iParentID, int iIndex, AggregType Aggreg, int iDecPlaces) { int result; if (FColumns.Count < 1) { result = -1; } else { result = FColumns.Count; } return(result); }
// ----------------------------------------------------------------------- /// <summary> /// Set the value of a variable in another component. /// </summary> /// <param name="name"></param> /// <param name="units"></param> /// <param name="data"></param> // ----------------------------------------------------------------------- public void set(String name, String units, ref TDDMLValue data) { clearMessages(); int id = nameToRegistrationID(name, RegistrationKind.setReg); bool alreadyRegistered = (id != 0); if (!alreadyRegistered) { id = RegisterWithPM(name, units, "", RegistrationKind.setReg, data.asDDML()); } TMsgHeader msg = buildRequestSetMsg(id, data); if (msg.msgID != 0) { sendMessage(msg); } }
//============================================================================== /// <summary> /// Stores the current value of a requested variable. /// </summary> /// <param name="aValue"></param> //============================================================================== public void storeVariable(TTypedValue aValue) { int iReqIdx; TDDMLValue reqValue; iReqIdx = FRequestNames.IndexOf(aValue.Name); if (iReqIdx < 0) { throw (new ApplicationException("storeVariable() - Attempt to store invalid variable: " + aValue.Name)); } reqValue = FRequests[iReqIdx]; if (reqValue == null) { reqValue = new TDDMLValue(aValue); // First time: make a copy of the TTypedValue FRequests[iReqIdx] = reqValue; } reqValue.setValue(aValue); }
// ----------------------------------------------------------------------- /// <summary> /// Get the value of a variable from another component. /// </summary> /// <param name="name"></param> /// <param name="units"></param> /// <param name="optional"></param> /// <param name="data"></param> /// <returns></returns> // ----------------------------------------------------------------------- public Boolean get(String name, String units, Boolean optional, ref TDDMLValue data) { clearMessages(); // see if we have an array specifier. //// TODO: fix the ability to use array specifiers //// ArraySpecifier* arraySpecifier = ArraySpecifier::create(name); String nameWithoutArraySpec = name; //// if (arraySpecifier != NULL) //// nameWithoutArraySpec = arraySpecifier->variableName(); int id = nameToRegistrationID(nameWithoutArraySpec, RegistrationKind.getReg); Boolean alreadyRegistered = (id != 0); if (!alreadyRegistered) { id = RegisterWithPM(nameWithoutArraySpec, units, "", RegistrationKind.getReg, data.asDDML()); } interpreter.setField(Msgs.MSG_GETVALUE_ID, id); //the driver ID code TMsgHeader msg = interpreter.createMessage(Msgs.MSG_GETVALUE, parentID); msg.toAck = 1; //always sendMessage(msg); String errorMsg = ""; if (messages.Count == 0) { errorMsg = "No component responded to a 'get' for variable: " + name; } else if (messages.Count == 1) { interpreter.loadMessage(messages[0]); //take ownership of this msg int iCompID = interpreter.getIntField(Msgs.MSG_RETURNVALUE_COMPID); int iPropertyID = interpreter.getIntField(Msgs.MSG_RETURNVALUE_ID); string DDML = interpreter.getTextField(Msgs.MSG_RETURNVALUE_TYPE); byte[] dataPtr = new byte[1]; uint dataSize = interpreter.getValueField(Msgs.MSG_RETURNVALUE_VALUE, ref dataPtr); data.setData(dataPtr, dataSize, 0); ////if (arraySpecifier != NULL) ////arraySpecifier->summariseData(returnMessageData, returnValue.ddml); } else if (messages.Count > 1) { errorMsg = "Too many components responded to a 'get' for variable: " + name; } if (errorMsg != "") { if (!optional) { throw (new ApplicationException(errorMsg)); } return(false); } else { return(true); } }
// -------------------------------------------------------------------- /// <summary> /// Constructor /// </summary> /// <param name="Property"></param> /// <param name="Parent"></param> // -------------------------------------------------------------------- public FactoryProperty(ReflectedType Property, XmlNode Parent) { IsParam = false; IsInput = false; IsOutput = false; IsWritable = false; HaveSet = false; ReadOnly = Property.ReadOnly; WriteOnly = Property.WriteOnly; TypeName = Property.Typ.Name; Units = ""; Description = ""; this.Property = Property; this.Name = Property.Name; FQN = CalcParentName(Parent) + this.Name; this.OutputName = FQN; Data = GetFieldWrapper(Property.Typ); if (Data != null) { sDDML = Data.DDML(); } else { sDDML = "<type/>"; } regIndex = -1; foreach (Object Attr in Property.MetaData) { Param P = null; Input I = null; Output O = null; Writable W = null; Units U = null; Description D = null; if (Attr.GetType() == typeof(Param)) { P = (Param)(Attr); } else if (Attr.GetType() == typeof(Input)) { I = (Input)(Attr); } else if (Attr.GetType() == typeof(Output)) { O = (Output)(Attr); } else if (Attr.GetType() == typeof(Writable)) { W = (Writable)(Attr); } else if (Attr.GetType() == typeof(Units)) { U = (Units)(Attr); } else if (Attr.GetType() == typeof(Description)) { D = (Description)(Attr); } if (P != null) { IsParam = true; OptionalParam = P.IsOptional; ParamMinVal = P.MinVal; ParamMaxVal = P.MaxVal; if (P.Name != "") { Name = P.Name; FQN = CalcParentName(Parent) + this.Name; } } else if (I != null) { IsInput = true; OptionalInput = I.IsOptional; } else if (O != null) { IsOutput = true; if (O.Name != "") { OutputName = O.Name; } } else if (W != null) { IsWritable = true; ReadOnly = false; } else if (U != null) { Units = U.ToString(); } else if (D != null) { Description = D.ToString(); } } if (Units != "") { TDDMLValue DDMLValue = new TDDMLValue(sDDML, ""); DDMLValue.setUnits(Units); sDDML = DDMLValue.asDDML(); } }
//===================================================================== /// <summary> /// Scan through the cultivar list in mvCotton.xml and find any that have /// parameters and form them into an XML document based on TSDMLValue. /// </summary> /// <returns>The cultivar list as XML.</returns> //===================================================================== private String WriteCultivars() { //create new TSDMLValue for the cultivar details TDDMLValue CultivarValues = new TDDMLValue(CULTIVARTYPE, ""); CultivarValues.setElementCount(0); uint cultivarCount = 0; XmlDocument ModelDoc = new XmlDocument(); String ComponentType = Controller.ApsimData.Find(NodePath).Type; ModelDoc.LoadXml("<Model>" + Types.Instance.ModelContents(ComponentType) + "</Model>"); foreach (XmlNode Child in ModelDoc.DocumentElement.ChildNodes) { if (XmlHelper.Attribute(Child, "cultivar").ToLower() == "yes") { if (Child.ChildNodes.Count > 0) { XmlDocument CultivarDoc = new XmlDocument(); CultivarDoc.LoadXml(Child.OuterXml); CultivarValues.setElementCount(++cultivarCount); TTypedValue arrayitem = CultivarValues.item(cultivarCount); arrayitem.member("cultivar").setValue(CultivarDoc.DocumentElement.Name); //read root tag name foreach (XmlNode param in CultivarDoc.DocumentElement.ChildNodes) //for each child of cultivardoc { if (param.NodeType == XmlNodeType.Element) { TTypedValue field = arrayitem.member(param.Name); if (field != null) { if (param.Name == "FRUDD" || param.Name == "BLTME" | param.Name == "WT") { //add array node values String arrayField = param.InnerText; if (arrayField.Contains(" ")) { string[] VariableNameBits = arrayField.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); double[] values = MathUtility.StringsToDoubles(VariableNameBits); uint count = 0; foreach (double val in values) { field.setElementCount(++count); field.item(count).setValue(val); } } } else { double val = Convert.ToDouble(param.InnerText); //these are all doubles field.setValue(val); //copy child to new doc } } else { throw new Exception("Cannot set init value for " + param.Name + " in WriteCultivars()"); } } } } } } TSDMLValue writer = new TSDMLValue("<type/>", ""); return(writer.getText(CultivarValues, 0, 2)); }
public void SetDDML(String value) { //create a new ddmlvalue based on updated ddml (should try a better approach - NH) DDMLValue = new TDDMLValue(value, ""); TypeDDML = value; }
//============================================================================ /// <summary> /// Constructor /// </summary> /// <param name="sDBName">Full path to the database.</param> //============================================================================ public TAFDataModule(string sDBName) { DBName = sDBName; resultArray = new TDDMLValue(typeOutput, ""); }