Esempio n. 1
0
        /// <summary>
        /// LoadSBML
        /// </summary>
        /// <param name="filename">the SBML file name.</param>
        public void LoadSBML(string filename)
        {
            WrappedSimulator sim = null;
            try
            {
                CloseProject();
                m_env.PluginManager.ChangeStatus(ProjectStatus.Loading);

                // Load model
                EcellModel model = SBML2EML.Convert(filename);

                // Initialize
                try
                {
                    sim = new WrappedSimulator(Util.GetDMDirs());
                    EmlReader.InitializeModel(model, sim);
                    sim.Initialize();
                }
                catch (Exception e)
                {
                    if (m_env.PluginManager.DockPanel != null)
                        Util.ShowWarningDialog(MessageResources.WarnInvalidData + "\n" + e.Message);
                    Trace.WriteLine(e.ToString());
                }

                // Create Project
                string projectID = model.ModelID;
                string comment = "Convert from SBML: " + Path.GetFileName(filename);
                ProjectInfo info = new ProjectInfo(projectID, comment, DateTime.Now.ToString(), Constants.defaultSimParam);
                info.Type = ProjectType.SBML;
                Project project = new Project(info, m_env);
                project.LoggerPolicyDic[Constants.defaultSimParam] = new LoggerPolicy();
                m_currentProject = project;
                project.Simulator = sim;
                project.InitializeModel(model, sim);

                // Load model
                List<EcellObject> passList = new List<EcellObject>();
                List<EcellData> ecellDataList = new List<EcellData>();
                ecellDataList.Add(new EcellData(Constants.textComment, new EcellValue(comment), null));
                passList.Add(EcellObject.CreateObject(projectID, "", Constants.xpathProject, "", ecellDataList));
                passList.Add(model);
                passList.AddRange(model.Children);
                m_env.PluginManager.DataAdd(passList);
                m_env.PluginManager.ParameterSet(projectID, Constants.defaultSimParam);
                m_env.PluginManager.ChangeStatus(ProjectStatus.Loaded);

            }
            catch (Exception e)
            {
                CloseProject();
                m_env.Console.WriteLine("Failed to convert SBML: " + filename);
                m_env.Console.WriteLine(e.ToString());
                throw new EcellException("Failed to convert SBML. " + filename, e);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the dummy simulator 4 property lists.
        /// </summary>
        /// <param name="simulator">The dummy simulator</param>
        /// <param name="defaultProcess">The dm name of "Process"</param>
        /// <param name="defaultStepper">The dm name of "Stepper"</param>
        private static void BuildDefaultSimulator(
            WrappedSimulator simulator, string defaultProcess, string defaultStepper)
        {
            try
            {
                // Set DefaultProcess if null
                if (defaultProcess == null)
                    defaultProcess = Constants.DefaultProcessName;
                // Set DefaultStepper if null
                if (defaultStepper == null)
                    defaultStepper = Constants.DefaultStepperName;

                //
                simulator.CreateStepper(defaultStepper, Constants.textKey);
                simulator.CreateEntity(
                    Constants.xpathVariable,
                    Constants.xpathVariable + Constants.delimiterColon +
                    Constants.delimiterPath + Constants.delimiterColon +
                    Constants.xpathSize.ToUpper()
                    );
                simulator.CreateEntity(
                    defaultProcess,
                    Constants.xpathProcess + Constants.delimiterColon +
                    Constants.delimiterPath + Constants.delimiterColon +
                    Constants.xpathSize.ToUpper()
                );
                simulator.LoadEntityProperty(
                    Constants.xpathSystem +  "::/:" + Constants.xpathStepperID,
                    new string[] { Constants.textKey }
                );
                simulator.LoadEntityProperty(
                    Util.BuildFullPN(
                        Constants.xpathVariable,
                        Constants.delimiterPath,
                        Constants.xpathSize.ToUpper(),
                        Constants.xpathValue
                    ),
                    new string[] { "0.1" }
                );
                simulator.Initialize();
            }
            catch (Exception ex)
            {
                throw new EcellException(
                    MessageResources.ErrCombiStepProc, ex);
            }
        }
Esempio n. 3
0
        public void TestWrappedSimulator()
        {
            _unitUnderTest.UnloadSimulator();

            // When you do not carry out Initialize, Dispose is available.
            WrappedSimulator sim1 = new WrappedSimulator(_unitUnderTest.GetDMDirs());
            EmlReader.Parse(TestConstant.Model_RBC, sim1);
            Console.WriteLine(sim1.GetEntityProperty("System::/:Name"));
            sim1.Dispose();

            // when I carry out Initialize, Dispose returns error.
            WrappedSimulator sim2 = new WrappedSimulator(_unitUnderTest.GetDMDirs());
            EmlReader.Parse(TestConstant.Model_RBC, sim2);
            Console.WriteLine(sim2.GetEntityProperty("System::/:Name"));
            try
            {
                sim2.Initialize();
                sim2.Dispose();
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                Assert.Fail(e.Message);
            }
        }