/// <summary> /// Initialize the model /// </summary> /// <param name="modelObject">the model object.</param> /// <param name="simulator">the loaded simulator.</param> public static void InitializeModel(EcellModel modelObject, WrappedSimulator simulator) { bool isWarn = false; string errMsg = MessageResources.WarnLoadDM + "\n"; Dictionary<string, object> processPropertyDic = new Dictionary<string, object>(); // Initialize object foreach (EcellObject obj in modelObject.Children) { // Initialize Stepper if (obj is EcellStepper) { try { simulator.CreateStepper(obj.Classname, obj.Key); } catch (Exception e) { errMsg += obj.FullID + ":" + e.Message + "\n"; Trace.WriteLine(e.ToString()); isWarn = true; } foreach (EcellData data in obj.Value) { simulator.LoadStepperProperty( obj.Key, data.Name, data.Value.Value); } } else if (obj is EcellSystem) { // Initialize System if (!obj.Key.Equals(Constants.delimiterPath)) { try { simulator.CreateEntity( obj.Classname, obj.FullID); } catch (Exception e) { throw new EmlParseException("Failed to create a System entity", e); } } foreach (EcellData data in obj.Value) { simulator.LoadEntityProperty( data.EntityPath, data.Value.Value); } // Initialize Entity foreach (EcellObject entity in obj.Children) { if (entity.Type.Equals(EcellObject.TEXT)) continue; bool isCreated = true; // 4 "EcellCoreLib" try { simulator.CreateEntity( entity.Classname, entity.FullID); } catch (Exception e) { errMsg += entity.FullID + ":" + e.Message + "\n"; Trace.WriteLine(e.ToString()); isCreated = false; isWarn = true; } foreach (EcellData data in entity.Value) { string entityPath = data.EntityPath; if (obj.Type.Equals(Constants.xpathVariable)) { if (isCreated == true) simulator.LoadEntityProperty(entityPath, data.Value.Value); } else { processPropertyDic[entityPath] = data.Value.Value; } } } } } // List<string> removeList = new List<string>(); foreach (KeyValuePair<string, object> pair in processPropertyDic) { try { simulator.LoadEntityProperty(pair.Key, pair.Value); } catch (WrappedException e) { isWarn = true; errMsg += pair.Key + ":" + e.Message + "\n"; } if (pair.Key.EndsWith(Constants.xpathVRL)) removeList.Add(pair.Key); } foreach (string entityPath in removeList) { processPropertyDic.Remove(entityPath); } if (isWarn) { modelObject.ErrMsg = errMsg; } }
/// <summary> /// Loads the "Stepper" 2 the "EcellCoreLib". /// </summary> /// <param name="simulator">The simulator</param> /// <param name="stepperList">The list of the "Stepper"</param> /// <param name="setStepperDic">The list of stepper.</param> private static void LoadStepper( WrappedSimulator simulator, List<EcellObject> stepperList, Dictionary<string, Dictionary<string, object>> setStepperDic) { Debug.Assert(stepperList != null && stepperList.Count > 0); foreach (EcellObject stepper in stepperList) { if (stepper == null) continue; simulator.CreateStepper(stepper.Classname, stepper.Key); // 4 property if (stepper.Value == null || stepper.Value.Count <= 0) continue; foreach (EcellData ecellData in stepper.Value) { if (ecellData.Name == null || ecellData.Name.Length <= 0 || ecellData.Value == null) continue; else if (!ecellData.Value.IsDouble && !ecellData.Value.IsInt) continue; // 4 MaxStepInterval == Double.MaxValue EcellValue value = ecellData.Value; try { if ((double)value == Double.PositiveInfinity || (double)value == Double.MaxValue) continue; XmlConvert.ToDouble(value); } catch (Exception ex) { Trace.WriteLine(ex); continue; } if (value.IsDouble && (Double.IsInfinity((double)value) || Double.IsNaN((double)value))) continue; if (ecellData.Saveable) { simulator.LoadStepperProperty( stepper.Key, ecellData.Name, value.Value); } else if (ecellData.Settable) { if (!setStepperDic.ContainsKey(stepper.Key)) { setStepperDic[stepper.Key] = new Dictionary<string, object>(); } setStepperDic[stepper.Key][ecellData.Name] = value.Value; } } } }