/// <summary> /// Rolls back the last operation in this session. The operation will be removed from /// the session's operation list. /// </summary> /// <returns>True if an edit was undone.</returns> internal bool Rollback() { // Return if there is nothing to rollback. if (m_Operations.Count == 0) { return(false); } // Get the tail operation int index = m_Operations.Count - 1; Operation op = m_Operations[index]; // Move the data file to the project undo folder uint fileNum = op.FileNumber; if (fileNum == 0) { throw new ApplicationException("Edit does not appear to belong to the current editing session"); } string name = ProjectDatabase.GetDataFileName(fileNum); string sourceFileName = Path.Combine(m_Project.ProjectFolder, name); string destFileName = Path.Combine(m_Project.GetUndoFolder(), name); File.Move(sourceFileName, destFileName); // Remember the sequence number of the edit we're rolling back uint editSequence = op.EditSequence; // Remove the edit and undo it m_Operations.RemoveAt(index); this.MapModel.RemoveEdit(op); m_Project.SetLastItem(op.EditSequence - 1); op.Undo(); return(true); }
/// <summary> /// Opens an editing project that was previously created. /// </summary> /// <param name="projectName">The user-perceived name of the project</param> /// <returns>Information describing the state of the project (null if it could not be found).</returns> internal Project OpenProject(string projectName) { if (String.IsNullOrWhiteSpace(projectName)) { throw new ArgumentNullException(); } // Obtain the project ID string projectGuid = FindProjectId(projectName); if (projectGuid == null) { throw new ApplicationException(); } // Load the project creation event Guid projectId = Guid.Parse(projectGuid); string dataFolder = CreateDataFolder(projectId); string creationFileName = Path.Combine(dataFolder, NewProjectEvent.FileName); // Read current project settings dataFolder = CreateDataFolder(projectId); string settingsFileName = Path.Combine(dataFolder, "settings.txt"); ProjectSettings ps = ProjectSettings.CreateInstance(settingsFileName); Settings.Default.LastProjectName = projectName; Settings.Default.Save(); // Now load the data Project result = new Project(this, projectId, ps); // Get rid of any undo folder that may be left over from a crashed editing session result.DeleteUndoFolder(); // Bit jumbled up here (historical reasons), should tidy up... EditingController.Current.SetProject(result); result.LoadEdits(dataFolder); //EditingController.Current.SetProject(result); EditingController.Current.SetMapModel(result.Model, null); result.Model.Load(); // Get rid of any empty sessions //result.Model.RemoveEmptySessions(); // Debug CedExporter string ptsFileName = Path.Combine(dataFolder, projectName + ".pts"); CheckPts(ptsFileName, result.Model); // Need to set it again (need to find out why)... if you don't you get a null // ref on opening last project at startup EditingController.Current.SetMapModel(result.Model, null); // Create a new editing session uint sessionId = result.AllocateId(); NewSessionEvent s = new NewSessionEvent(sessionId) { UserName = System.Environment.UserName, MachineName = System.Environment.MachineName, }; string sessionFile = Path.Combine(dataFolder, GetDataFileName(sessionId)); string sessionText = EditSerializer.GetSerializedString <Change>(DataField.Edit, s); File.WriteAllText(sessionFile, sessionText); Session session = new Session(result, s, sessionFile); result.Model.AddSession(session); result.Model.SetWorkingSession(session); result.SetLastItem(session.Id); return(result); }