public void SetUp() { _env = new ApplicationEnvironment(); ProjectInfo info = ProjectInfoLoader.Load(TestConstant.Project_Drosophila); _unitUnderTest = new Project(info, _env); _unitUnderTest.UnLock(); _unitUnderTest.LoadModel(); }
/// <summary> /// Loads the simulation parameters. /// </summary> /// <param name="project">the project object.</param> private void LoadSimulationParameters(Project project) { // Check directory. string simulationDirName = null; if (project.Info.ProjectPath != null) simulationDirName = Path.Combine(project.Info.ProjectPath, Constants.xpathParameters); if (!Directory.Exists(simulationDirName)) return; // Get Parameter files. string[] parameters = Directory.GetFileSystemEntries( simulationDirName, Constants.delimiterWildcard + Constants.FileExtXML); if (parameters == null || parameters.Length <= 0) return; // Load parameters. foreach (string parameter in parameters) { // Check filename. string fileName = Path.GetFileName(parameter); if (fileName.IndexOf(Constants.delimiterUnderbar) == 0) continue; // Load parameter. SimulationParameter simParam = LoadSimulationParameter(parameter, project); // Set parameter. SetSimulationParameter(simParam); } }
/// <summary> /// Loads the simulation parameter. /// </summary> /// <param name="fileName">The simulation parameter file name</param> /// <param name="project">The project</param> /// <returns></returns> private SimulationParameter LoadSimulationParameter(string fileName, Project project) { string message = null; SimulationParameter simParam = null; string projectID = project.Info.Name; try { message = "[" + fileName + "]"; // Initializes Debug.Assert(!string.IsNullOrEmpty(fileName)); // Parses the simulation parameter. WrappedSimulator simulator = project.CreateSimulatorInstance(); simParam = SimulationParameterReader.Parse(fileName, simulator); simulator.Dispose(); } catch (Exception ex) { throw new EcellException(string.Format(MessageResources.ErrLoadSimParam, fileName), ex); } Trace.WriteLine("Load Simulation Parameter: " + message); return simParam; }
/// <summary> /// Load the analysis directory. /// </summary> /// <param name="project">the project object.</param> private void LoadAnalysisDirectory(Project project) { string path = project.GetAnalysisDirectory(); if (path == null || !Directory.Exists(path)) return; string[] dirs = Directory.GetDirectories(path); for (int i = 0; i < dirs.Length; i++) { DirectoryInfo d = new DirectoryInfo(dirs[i]); string groupName = d.Name; string[] ele = groupName.Split(new char[] { '_' }); if (ele.Length != 2) continue; string analysisName = ele[0]; string date = ele[1]; if (!m_env.JobManager.AnalysisDic.ContainsKey(analysisName)) continue; string modelDir = dirs[i] + "/" + Constants.ModelDirName; string logDir = dirs[i] + "/" + Constants.LogDirName; // load model string modelFile = modelDir + "/" + date + ".eml"; ProjectInfo info = ProjectInfoLoader.Load(modelFile); string projectID = info.Name; Project aproject = new Project(info, m_env); aproject.LoadModel(); List<EcellObject> systemObjList = aproject.SystemDic[aproject.Model.ModelID]; List<EcellObject> stepperObjList = aproject.StepperDic[aproject.Model.ModelID]; // create job group and analysis. JobGroup g = m_env.JobManager.CreateJobGroup(analysisName, date, systemObjList, stepperObjList); IAnalysisModule analysis = m_env.JobManager.AnalysisDic[analysisName].CreateNewInstance(g); // load analysis parameters. analysis.LoadAnalysisInfo(modelDir); g.LoadJobEntry(logDir); g.IsSaved = true; g.TopDir = dirs[i]; g.UpdateStatus(); m_env.JobManager.Update(); } }
/// <summary> /// Creates the new "Project" object. /// </summary> /// <param name="projectID">The "Project" ID</param> /// <param name="comment">The comment</param> private void CreateProject(string projectID, string comment) { Project prj = null; try { // // Closes the current project. // if (m_currentProject != null) { this.CloseProject(); } // // Initialize // ProjectInfo info = new ProjectInfo(projectID, comment, DateTime.Now.ToString(), Constants.defaultSimParam); prj = new Project(info, m_env); m_currentProject = prj; // // 4 PluginManager // List<EcellData> ecellDataList = new List<EcellData>(); ecellDataList.Add(new EcellData(Constants.textComment, new EcellValue(comment), null)); EcellObject ecellObject = EcellObject.CreateObject(projectID, "", Constants.xpathProject, "", ecellDataList); List<EcellObject> ecellObjectList = new List<EcellObject>(); ecellObjectList.Add(ecellObject); m_env.PluginManager.DataAdd(ecellObjectList); m_env.ActionManager.AddAction(new NewProjectAction(projectID, comment)); m_env.PluginManager.ChangeStatus(ProjectStatus.Loaded); m_env.Console.WriteLine(string.Format(MessageResources.InfoCrePrj, projectID)); m_env.Console.Flush(); Trace.WriteLine(string.Format(MessageResources.InfoCrePrj, projectID)); } catch (Exception ex) { if (m_currentProject != null) m_currentProject.Close(); m_currentProject = null; string message = string.Format( MessageResources.ErrCrePrj, projectID); Trace.WriteLine(message); throw new EcellException(message, ex); } }
/// <summary> /// Closes project without confirming save or no save. /// </summary> public void CloseProject() { try { if (this.m_currentProject != null) { string msg = string.Format(MessageResources.InfoClose, m_currentProject.Info.Name); Trace.WriteLine(msg); m_env.Console.WriteLine(msg); m_env.Console.Flush(); this.m_currentProject.Close(); this.m_currentProject = null; } this.m_env.PluginManager.AdvancedTime(0); this.m_env.PluginManager.Clear(); this.m_env.ActionManager.Clear(); this.m_env.ReportManager.Clear(); this.m_env.LoggerManager.Clear(); this.m_env.JobManager.Clear(); this.m_parameterList.Clear(); this.m_observedList.Clear(); this.m_loggerEntry.Clear(); this.ClearSteppingModel(); m_deleteParameterList.Clear(); m_editCount = 0; m_env.PluginManager.ChangeStatus(ProjectStatus.Uninitialized); } catch (Exception ex) { Trace.WriteLine(ex); string errmes = string.Format(MessageResources.ErrClosePrj, ""); throw new EcellException(errmes, ex); } }
/// <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); } }
/// <summary> /// LoadProject /// </summary> /// <param name="info">the load project information.</param> public void LoadProject(ProjectInfo info) { List<EcellObject> passList = new List<EcellObject>(); string message = ""; string projectID = ""; Project project = null; try { // Check Current. if (info == null) throw new EcellException(MessageResources.ErrLoadPrj); if (m_currentProject != null) CloseProject(); // Create project. projectID = info.Name; message = "[" + projectID + "]"; // Confirm Locked file. ConfirmLock(info); project = new Project(info, m_env); // Set current project. m_currentProject = project; m_env.PluginManager.ChangeStatus(ProjectStatus.Loading); // Load DMs. project.UnloadSimulator(); m_env.DMDescriptorKeeper.Load(project.GetDMDirs()); project.ReloadSimulator(); // Create EcellProject. List<EcellData> ecellDataList = new List<EcellData>(); ecellDataList.Add(new EcellData(Constants.textComment, new EcellValue(project.Info.Comment), null)); passList.Add(EcellObject.CreateObject(projectID, "", Constants.xpathProject, "", ecellDataList)); // Prepare datas. project.LoadModel(); foreach (EcellObject model in project.ModelList) { Trace.WriteLine(string.Format(MessageResources.InfoLoadModel, model.ModelID)); m_env.Console.WriteLine(string.Format(MessageResources.InfoLoadModel, model.ModelID)); m_env.Console.Flush(); passList.Add(model); } foreach (string storedModelID in project.SystemDic.Keys) { passList.AddRange(project.StepperDic[storedModelID]); passList.AddRange(project.SystemDic[storedModelID]); } // Set current project. m_currentProject = project; // Load analysis directory. LoadAnalysisDirectory(project); // Load SimulationParameters. LoadSimulationParameters(project); m_env.PluginManager.ParameterSet(projectID, project.Info.SimulationParam); m_editCount = 0; ClearSteppingModel(); } catch (Exception ex) { passList = null; CloseProject(); throw new EcellException(string.Format(MessageResources.ErrLoadPrj, projectID)+ "\n" + ex.Message, ex); } finally { if (m_currentProject != null) { if (passList != null && passList.Count > 0) { this.m_env.PluginManager.DataAdd(passList); } foreach (string paramID in this.GetSimulationParameterIDs()) { this.m_env.PluginManager.ParameterAdd(projectID, paramID); } m_env.ActionManager.AddAction(new LoadProjectAction(projectID, project.Info.Filename)); // Send Message. m_env.Console.WriteLine(string.Format(MessageResources.InfoLoadPrj, projectID)); m_env.Console.Flush(); m_env.PluginManager.ChangeStatus(ProjectStatus.Loaded); } } }
/// <summary> /// Return true if reset simulation /// </summary> /// <param name="project"></param> /// <returns></returns> private bool ConfirmReset(Project project) { if (project.SimulationStatus == SimulationStatus.Wait) return true; string msg = MessageResources.ConfirmReset; return Util.ShowOKCancelDialog(msg); }
/// <summary> /// Show the dialog to confirm to override the project. /// </summary> /// <param name="project">the override project.</param> /// <returns>if ok is true.</returns> private bool ConfirmOverwrite(Project project) { if(!Util.IsExistProject(project.Info.Name)) return true; string msg = MessageResources.ConfirmOverwrite; // In case new project. if(!Util.IsExistProject(project.Info.Name)) return true; // If Already exists. if (project.Info.Type != ProjectType.Project) { msg = string.Format(MessageResources.ErrExistProject, project.Info.Name) + "\n" + MessageResources.ConfirmOverwrite; return Util.ShowOKCancelDialog(msg); } else if(Path.GetFileName(project.Info.ProjectPath) != project.Info.Name) { return Util.ShowOKCancelDialog(msg); } return true; }
/// <summary> /// Constructor. /// </summary> /// <param name="project">Project object.</param> public ScriptWriter(Project project) { m_currentProject = project; }
public void TearDown() { _unitUnderTest.Close(); _unitUnderTest = null; }
public void TestConstructorProject() { _unitUnderTest.Close(); Project testProject = null; Ecell.ProjectInfo info = null; try { testProject = new Project(info, _env); testProject.UnLock(); Assert.Fail("Error param"); } catch (EcellException) { } try { info = ProjectInfoLoader.Load(TestConstant.Model_Oscillation); testProject = new Project(info, null); testProject.UnLock(); Assert.Fail("Error param"); } catch (EcellException) { } info = ProjectInfoLoader.Load(TestConstant.Model_Oscillation); testProject = new Project(info, _env); testProject.UnLock(); testProject.LoadModel(); Assert.IsNotNull(testProject, "Constructor of type, Project failed to create instance."); Assert.IsNotEmpty(testProject.DmDic, "DmDic is unexpected value."); Assert.IsNotEmpty(testProject.InitialCondition, "InitialCondition is unexpected value."); Assert.IsEmpty(testProject.LogableEntityPathDic, "LogableEntityPathDic is unexpected value."); testProject.LogableEntityPathDic = new Dictionary<string, string>(); Assert.IsNotNull(testProject.LogableEntityPathDic, "LogableEntityPathDic is unexpected value."); Assert.IsNotEmpty(testProject.LoggerPolicyDic, "LoggerPolicyDic is unexpected value."); Assert.IsNotNull(testProject.LoggerPolicy, "LoggerPolicy is unexpected value."); Assert.IsNotEmpty(testProject.ModelList, "ModelList is unexpected value."); Assert.IsNotNull(testProject.Model, "Model is unexpected value."); Assert.IsNotEmpty(testProject.StepperDic, "StepperDic is unexpected value."); Assert.IsNotEmpty(testProject.SystemDic, "SystemDic is unexpected value."); Assert.IsNotEmpty(testProject.SystemList, "SystemList is unexpected value."); Assert.IsNotEmpty(testProject.ProcessList, "ProcessList is unexpected value."); Assert.IsNotEmpty(testProject.VariableList, "VariableList is unexpected value."); Assert.IsNotEmpty(testProject.TextList, "TextList is unexpected value."); Assert.AreEqual(SimulationStatus.Wait, testProject.SimulationStatus, "SimulationStatus is unexpected value."); testProject.SimulationStatus = SimulationStatus.Suspended; Assert.AreEqual(SimulationStatus.Suspended, testProject.SimulationStatus, "SimulationStatus is unexpected value."); Assert.AreEqual(info, testProject.Info, "Info is unexpected value."); Assert.IsNotNull(testProject.Simulator, "Simulator is unexpected value."); testProject.Simulator = null; Assert.IsNull(testProject.Simulator, "Simulator is unexpected value."); info = ProjectInfoLoader.Load(TestConstant.Project_Drosophila); info.Type = ProjectType.Template; testProject = new Project(info, _env); testProject.UnLock(); Assert.AreEqual(info, testProject.Info, "Info is unexpected value."); }