/// <summary> /// GetValueFromDMM /// </summary> /// <param name="dmm">DMDescriptorKeeper</param> /// <param name="type">DM type.</param> /// <param name="className">the class name,</param> /// <param name="name">the property name.</param> /// <returns></returns> private static EcellValue GetValueFromDMM(DMDescriptorKeeper dmm, string type, string className, string name) { EcellValue value = null; try { if (dmm.ContainsDescriptor(type, className)) { DMDescriptor desc = dmm.GetDMDescriptor(type, className); if (desc.ContainsProperty(name)) { PropertyDescriptor prop = desc[name]; value = new EcellValue(prop.DefaultValue); } else { value = new EcellValue(0.0); } } else { value = new EcellValue(""); } } catch(Exception e) { Trace.WriteLine(e.StackTrace); } return value; }
/// <summary> /// Stores the "EcellObject" 4 the "Process". /// </summary> /// <param name="simulator">The simulator</param> /// <param name="dmm">The "DMDescriptorKeeper"</param> /// <param name="ecellObject">The stored "Process"</param> /// <param name="initialCondition">The initial condition.</param> internal static void DataStored4Process( WrappedSimulator simulator, DMDescriptorKeeper dmm, EcellObject ecellObject, Dictionary<string, double> initialCondition) { string key = ecellObject.FullID; IList<string> wrappedPolymorph = null; try { wrappedPolymorph = simulator.GetEntityPropertyList(key); } catch (Exception ex) { Trace.WriteLine(ex); return; } // // Checks the stored "EcellData" // List<EcellData> processEcellDataList = new List<EcellData>(); Dictionary<string, EcellData> storedEcellDataDic = new Dictionary<string, EcellData>(); if (ecellObject.Value != null && ecellObject.Value.Count > 0) { foreach (EcellData storedEcellData in ecellObject.Value) { storedEcellDataDic[storedEcellData.Name] = storedEcellData; processEcellDataList.Add(storedEcellData); } } // // Stores the "EcellData" // foreach (string name in wrappedPolymorph) { string entityPath = Util.BuildFullPN(key, name); PropertyAttributes flag = simulator.GetEntityPropertyAttributes(entityPath); if (!flag.Gettable) { continue; } EcellValue value = null; if (name == Constants.xpathVRL) { // Won't restore the variable reference list from the simulator's corresponding // object. if (storedEcellDataDic.ContainsKey(name)) value = storedEcellDataDic[name].Value; else value = new EcellValue(new List<object>()); } else if (name == Constants.xpathActivity || name == Constants.xpathMolarActivity) { value = new EcellValue(0.0); } else { try { value = new EcellValue(simulator.GetEntityProperty(entityPath)); if (dmm.ContainsDescriptor(ecellObject.Type, ecellObject.Classname)) { DMDescriptor desc = dmm.GetDMDescriptor(ecellObject.Type, ecellObject.Classname); if (desc.ContainsProperty(name)) { PropertyDescriptor prop = desc[name]; if (prop.DefaultValue.Type == EcellValueType.List && !value.IsList) value = new EcellValue(new List<EcellValue>()); } } } catch (Exception ex) { Trace.WriteLine(ex); value = GetValueFromDMM(dmm, ecellObject.Type, ecellObject.Classname, name); } } EcellData ecellData = CreateEcellData(name, value, entityPath, flag); if (ecellData.Value != null) { ecellData.Logable = ecellData.Value.IsDouble && (ecellData.Settable == false || ecellData.Saveable == false); } if (storedEcellDataDic.ContainsKey(name)) { ecellData.Logged = storedEcellDataDic[name].Logged; processEcellDataList.Remove(storedEcellDataDic[name]); } processEcellDataList.Add(ecellData); } ecellObject.SetEcellDatas(processEcellDataList); }