Example #1
0
        /// <summary>
        /// Closes a open project. If no edits have been performed, this will delete the file that
        /// records the session. Otherwise the timestamp stored in the session file will be updated.
        /// Local project settings will also be saved for luck.
        /// </summary>
        /// <param name="p">The project to close</param>
        internal void CloseProject(Project p)
        {
            Session s = p.Model.WorkingSession;

            if (s != null)
            {
                if (s.ChangeCount == 0)
                {
                    string sessionFile = s.FileName;
                    File.Delete(sessionFile);
                }
                else
                {
                    // Rollup the edits in the session
                    s.EndSession();

                    // Get rid of any undo folder
                    p.DeleteUndoFolder();
                }
            }

            p.SaveSettings();
        }
Example #2
0
        /// <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);
        }