Exemple #1
0
 /// <summary>
 /// Sets the parameter of the simulator.
 /// </summary>
 /// <param name="simParam">the set parameter ID</param>
 internal void SetSimulationParameter(SimulationParameter simParam)
 {
     try
     {
         string simParamID = simParam.ID;
         m_currentProject.LoggerPolicyDic[simParamID] = simParam.LoggerPolicy;
         m_currentProject.InitialCondition[simParamID] = simParam.InitialConditions;
         m_env.Console.WriteLine(string.Format(MessageResources.InfoLoadSim, simParamID));
         m_env.Console.Flush();
     }
     catch (Exception)
     {
     }
 }
        /// <summary>
        /// Creates the parameter file.
        /// </summary>
        /// <param name="fileName">The parameter file name</param>
        /// <param name="sp">The simulation parameter</param>
        public static void Create(string fileName, SimulationParameter sp)
        {
            //
            // Checks the old model file.
            //
            if (File.Exists(fileName))
            {
                string date
                    = File.GetLastAccessTime(fileName).ToString().Replace(
                        Constants.delimiterColon, Constants.delimiterUnderbar);
                date = date.Replace(Constants.delimiterPath, Constants.delimiterUnderbar);
                date = date.Replace(Constants.delimiterSpace, Constants.delimiterUnderbar);
                string destFileName
                    = Path.GetDirectoryName(fileName) + Constants.delimiterPath
                    + Constants.delimiterUnderbar + date + Constants.delimiterUnderbar + Path.GetFileName(fileName);
                if (File.Exists(destFileName))
                    File.Delete(destFileName);
                File.Move(fileName, destFileName);
            }
            //
            // Saves the model
            //
            XmlTextWriter writer = new XmlTextWriter(fileName, System.Text.Encoding.UTF8);
            try
            {
                writer.Formatting = Formatting.Indented;
                writer.Indentation = 0;
                SimulationParameterWriter pw = new SimulationParameterWriter(writer);
                pw.WriteStartDocument();
                //
                // Divide stepper list into per-model lists;
                //
                Dictionary<string, List<EcellObject>> dic = new Dictionary<string, List<EcellObject>>();
                foreach (EcellObject stepper in sp.Steppers)
                {
                    if (stepper.Type.Equals(Constants.xpathStepper))
                    {
                        if (!dic.ContainsKey(stepper.ModelID))
                        {
                            dic[stepper.ModelID] = new List<EcellObject>();
                        }
                        dic[stepper.ModelID].Add(stepper);
                    }
                }

                foreach (string modelID in dic.Keys)
                {
                    pw.WriteSteppers(modelID, dic[modelID], sp.InitialConditions[modelID]);
                }
                pw.WriteLoggerPolicyElement(sp.LoggerPolicy);
                pw.WriteEndDocument();
            }
            finally
            {
                writer.Close();
            }
        }