public static PredictiveProcessData ParseProcessData(XElement pd, int links, decimal precision) { PredictiveProcessData res = new PredictiveProcessData(links, precision); res.Name = pd.Attribute("Name").Value; res.ProcessDataId = pd.Attribute("Id").Value; res.UtcFrom = DateTime.Parse(pd.Attribute("UtcFrom").Value); res.UtcTo = DateTime.Parse(pd.Attribute("UtcTo").Value); foreach (XElement parm in pd.Element("Params").Elements("Param")) { ProcessDataParam param = new ProcessDataParam(); String type = parm.Attribute("DataType").Value; param.Name = parm.Attribute("Name").Value; if (type == "date") param.DateValue = DateTime.Parse(parm.Attribute("Value").Value); else if (type == "decimal") { string val = parm.Attribute("Value").Value; if (val == "") val = "0.0"; param.NumValue = decimal.Parse(val.Replace(".", ",")); } else param.StrValue = parm.Attribute("Value").Value; res.Params.Add(param); } foreach (XElement parm in pd.Element("EnergyData").Elements("Val")) { res.AddEnergyPoint(DateTime.Parse(parm.Attribute("UtcFrom").Value), Decimal.Parse(parm.Attribute("Value").Value)); } return res; }
/// <summary> /// /// </summary> /// <param name="processDataParam"></param> /// <returns></returns> public static Tuple<object, string> getValueAndType(ProcessDataParam processDataParam) { if (processDataParam == null) return new Tuple<object, string>("null", "null"); ; object val = processDataParam.StrValue; string dataType = "string"; if (processDataParam.NumValue.HasValue) { val = processDataParam.NumValue.Value; dataType = "decimal"; } else if (processDataParam.DateValue.HasValue) { val = processDataParam.DateValue.Value; dataType = "date"; } return new Tuple<object, string>(val, dataType); }