/// <summary> /// Create a new editing session to edit a project's model system /// </summary> /// <param name="ProjectEditingSession">The editing session to read from</param> /// <param name="modelSystemIndex">The model system's index inside of the project</param> public ModelSystemEditingSession(XTMFRuntime runtime, ProjectEditingSession ProjectEditingSession, int modelSystemIndex) { Runtime = runtime; this.ProjectEditingSession = ProjectEditingSession; ModelSystemIndex = modelSystemIndex; Reload(); }
internal bool SaveAsModelSystem(string name, ref string error) { lock (SessionLock) { List <ILinkedParameter> lp; var ms = Runtime.ModelSystemController.LoadOrCreate(name); ms.Name = name; ms.Description = ModelSystemModel.Description; if (EditingProject) { ms.ModelSystemStructure = ProjectEditingSession.CloneModelSystemStructure(out lp, ModelSystemIndex); ms.LinkedParameters = lp; return(ms.Save(ref error)); } else { ms.ModelSystemStructure = ModelSystemModel.Root.RealModelSystemStructure; ms.LinkedParameters = ModelSystemModel.LinkedParameters.LinkedParameters.Select(lpm => (ILinkedParameter)lpm.RealLinkedParameter).ToList(); using (var otherSession = Runtime.ModelSystemController.EditModelSystem(ms)) { return(otherSession.Save(ref error)); } } } }
/// <summary> /// Create a new editing session to edit a project's model system /// </summary> /// <param name="ProjectEditingSession">The editing session to read from</param> /// <param name="modelSystemIndex">The model system's index inside of the project</param> public ModelSystemEditingSession(XTMFRuntime runtime, ProjectEditingSession ProjectEditingSession, int modelSystemIndex) { Runtime = runtime; this.ProjectEditingSession = ProjectEditingSession; ModelSystemIndex = modelSystemIndex; ModelSystemModel = new ModelSystemModel(this, this.ProjectEditingSession.Project, modelSystemIndex); }
/// <summary> /// Run the model if it is contained inside of a project. /// </summary> /// <param name="runName"></param> /// <param name="error">A message in case of error</param> /// <param name="executeNow">Should the run start executing now or wait for all other runs to finish first?</param> /// <param name="forceLocal">Execute in the local process, overriding default behaviour.</param> /// <returns>A reference to the run.</returns> public XTMFRun Run(string runName, ref string error, bool overwrite = false, bool executeNow = true, bool forceLocal = false) { // this needs to block as if a command is running lock (_SessionLock) { if (!CanRun) { error = "You can not run this model system."; return(null); } lock (_RunningLock) { XTMFRun run; if (_ModelSystemIndex >= 0) { var cloneProject = ProjectEditingSession.CreateCloneProject(ProjectEditingSession.Project); cloneProject.ModelSystemStructure[_ModelSystemIndex] = ModelSystemModel.Root.RealModelSystemStructure; cloneProject.ModelSystemDescriptions[_ModelSystemIndex] = ModelSystemModel.Description; cloneProject.LinkedParameters[_ModelSystemIndex] = ModelSystemModel.LinkedParameters.GetRealLinkedParameters(); if (((Configuration)Configuration).RemoteHost) { run = XTMFRun.CreateRemoteHost(cloneProject, _ModelSystemIndex, ModelSystemModel, _Runtime.Configuration, runName, overwrite); } else { run = Debugger.IsAttached || forceLocal || !((Configuration)Configuration).RunInSeperateProcess ? XTMFRun.CreateLocalRun(cloneProject, _ModelSystemIndex, ModelSystemModel, _Runtime.Configuration, runName, overwrite) : XTMFRun.CreateRemoteHost(cloneProject, _ModelSystemIndex, ModelSystemModel, _Runtime.Configuration, runName, overwrite); } run.ProjectSavedByRun += (theRun, newMSS) => { string e = null; ProjectEditingSession.Project.ModelSystemStructure[_ModelSystemIndex] = newMSS; ProjectEditingSession.Project.Save(ref e); Reload(); ProjectWasExternallySaved?.Invoke(this, new EventArgs()); }; } else { run = XTMFRun.CreateLocalRun(ProjectEditingSession.Project, ModelSystemModel.Root, _Runtime.Configuration, runName, overwrite); } return(run); } } }
/// <summary> /// Create a model editing session for a previous run. This will be read-only! /// </summary> /// <param name="runtime">A link to the XTMFRuntime</param> /// <param name="projectSession">The project this is for.</param> /// <param name="runFile">The location of the previous run.</param> public ModelSystemEditingSession(XTMFRuntime runtime, ProjectEditingSession projectSession, string runFile) { _Runtime = runtime; ProjectEditingSession = projectSession; _ModelSystemIndex = -1; ModelSystemModel = new ModelSystemModel(_Runtime, this, projectSession.Project, runFile); }
/// <summary> /// Checks to see if the run directory already exists with the given name /// </summary> /// <param name="runName">The run name to check</param> /// <returns>True if the directory already exists, false otherwise</returns> public bool RunNameExists(string runName) { if (!EditingProject) { throw new InvalidOperationException("You can only call RunNameExists when it is editing a project's model system."); } return(ProjectEditingSession.RunNameExists(runName)); }
public bool SaveAs(string modelSystemName, ref string error) { lock (SessionLock) { return(ProjectEditingSession.CloneModelSystemAs(Runtime, ModelSystemModel.Root.RealModelSystemStructure, ModelSystemModel.LinkedParameters.GetRealLinkedParameters(), ModelSystemModel.Description, modelSystemName, ref error)); } }
/// <summary> /// Create a new editing session to edit a project's model system /// </summary> /// <param name="ProjectEditingSession">The editing session to read from</param> /// <param name="modelSystemIndex">The model system's index inside of the project</param> public ModelSystemEditingSession(XTMFRuntime runtime, ProjectEditingSession ProjectEditingSession, int modelSystemIndex) { _Runtime = runtime; this.ProjectEditingSession = ProjectEditingSession; _ModelSystemIndex = modelSystemIndex; Reload(); _saveSemaphor = new Semaphore(1, 1); }
/// <summary> /// Forces the session to terminate, even if we will lose data. /// </summary> private void ForceClose() { lock (_SessionLock) { if (EditingModelSystem) { _Runtime.ModelSystemController.ReleaseEditingSession(this); } else { ProjectEditingSession.ModelSystemEditingSessionClosed(this, _ModelSystemIndex); } } }
/// <summary> /// Run the model if it is contained inside of a project. /// </summary> /// <param name="runName"></param> /// <param name="error">A message in case of error</param> /// <returns></returns> public XTMFRun Run(string runName, ref string error) { // this needs to block as if a command is running lock (SessionLock) { if (!CanRun) { error = "You can not run this model system."; return(null); } lock (RunningLock) { if (AnyRunning) { error = "Only one run can be executing at the same time!"; return(null); } XTMFRun run; if (ModelSystemIndex >= 0) { Project cloneProject = ProjectEditingSession.CreateCloneProject(ProjectEditingSession.Project); cloneProject.ModelSystemStructure[ModelSystemIndex] = ModelSystemModel.Root.RealModelSystemStructure; cloneProject.ModelSystemDescriptions[ModelSystemIndex] = ModelSystemModel.Description; cloneProject.LinkedParameters[ModelSystemIndex] = ModelSystemModel.LinkedParameters.GetRealLinkedParameters(); run = new XTMFRun(cloneProject, ModelSystemIndex, ModelSystemModel, Runtime.Configuration, runName); } else { run = new XTMFRun(ProjectEditingSession.Project, ModelSystemModel.Root, Runtime.Configuration, runName); } this._Run.Add(run); AnyRunning = true; _IsRunning = true; run.RunComplete += () => TerminateRun(run); run.ValidationError += (e) => TerminateRun(run); run.RuntimeValidationError += (e) => TerminateRun(run); return(run); } } }
/// <summary> /// Gets an editing session for the project /// </summary> /// <param name="project">The project to create the editing session for</param> /// <param name="error">An error message in case of failure</param> /// <returns>The session to edit the project.</returns> public ProjectEditingSession EditProject(Project project, ref string error) { if (project == null) { throw new ArgumentNullException(nameof(project)); } lock (EditingSessionLock) { // check to see if it already exists int index; if ((index = IndexOf(EditingSessions, (session) => session.Project == project)) >= 0) { ReferenceCount[index]++; return(EditingSessions[index]); } // if it doesn't exist already we need to make a new session var newSession = new ProjectEditingSession(project, Runtime); EditingSessions.Add(newSession); ReferenceCount.Add(1); return(newSession); } }
/// <summary> /// Remove a reference that a session is being edited /// </summary> /// <param name="session">The session to remove a reference to.</param> internal void RemoveEditingReference(ProjectEditingSession session) { if (session == null) { throw new ArgumentNullException(nameof(session)); } lock (EditingSessionLock) { var index = EditingSessions.IndexOf(session); if (index >= 0) { ReferenceCount[index]--; if (ReferenceCount[index] <= 0) { // Make sure to remove this binding since it will hold memory EditingSessions[index].Project.ExternallySaved -= EditingSessions[index].Project_ExternallySaved; // now remove the references from our session EditingSessions.RemoveAt(index); ReferenceCount.RemoveAt(index); } } } }
/// <summary> /// Get a session to edit a project. /// </summary> /// <param name="project">The project to edit</param> public ProjectEditingSession EditProject(Project project) { if (project == null) { throw new ArgumentNullException(nameof(project)); } lock (EditingSessionLock) { // First check to see if a session is already open for (int i = 0; i < EditingSessions.Count; i++) { if (EditingSessions[i].Project == project) { ReferenceCount[i]++; return(EditingSessions[i]); } } // If we didn't find one create a new reference var session = new ProjectEditingSession(project, Runtime); EditingSessions.Add(session); ReferenceCount.Add(1); return(session); } }
public ProjectModel(IProject project, ProjectEditingSession session) { Project = project; RefreshModelSystems(); RefreshPastRuns(session); }
internal bool SetName(ProjectEditingSession session, string newName, ref string error) { var ret = session.RenameModelSystem(Root, newName, ref error); ModelHelper.PropertyChanged(PropertyChanged, this, "Name"); return ret; }
internal bool CloneModelSystemToProject(ProjectEditingSession session, string name, ref string error) { return session.CloneModelSystemToProjectAs(Root, name, ref error); }
public void RefreshPastRuns(ProjectEditingSession session) { if (PreviousRuns == null) { PreviousRuns = new List<PreviousRun>(); } else { PreviousRuns.Clear(); } Task.Factory.StartNew(() => { var list = new List<PreviousRun>(); PreviousRuns.Clear(); foreach (var pastRun in session.GetPreviousRuns()) { DirectoryInfo info = new DirectoryInfo(pastRun); list.Add(new PreviousRun() { Name = info.Name, Path = pastRun, TimeStamp = info.CreationTime.ToString() }); } lock (PreviousRuns) { PreviousRuns.AddRange(list); } ModelHelper.PropertyChanged(PropertyChanged, this, "PreviousRuns"); }); }
public ProjectModel(IProject project, ProjectEditingSession session) { Session = session; Project = project; session.ProjectWasExternallySaved += Session_ProjectWasExternallySaved; RefreshModelSystems(); RefreshPastRuns(session); }
/// <summary> /// Create a model editing session for a previous run. This will be read-only! /// </summary> /// <param name="runtime">A link to the XTMFRuntime</param> /// <param name="projectSession">The project this is for.</param> /// <param name="runFile">The location of the previous run.</param> public ModelSystemEditingSession(XTMFRuntime runtime, ProjectEditingSession projectSession, string runFile) { this.Runtime = runtime; ProjectEditingSession = projectSession; ModelSystemIndex = -1; ModelSystemModel = new ModelSystemModel(Runtime, this, projectSession.Project, runFile); }
/// <summary> /// Checks for validitiy of the passed run name /// </summary> /// <param name="runName"></param> /// <returns></returns> public bool IsValidRunName(string runName) { return(ProjectEditingSession.IsValidRunName(runName)); }