Exemplo n.º 1
0
        /// <summary>
        /// Concludes this editing session by combining all data files, finishing off with an
        /// instance of <see cref="EndSessionEvent"/>.
        /// </summary>
        internal void EndSession()
        {
            // Pick up the files that relate to the session
            string endFolder = Path.GetDirectoryName(m_FileName);

            uint[] fileNumbers = GetFileNumbers(endFolder, m_Data.EditSequence);

            // Create an end session event
            EndSessionEvent endEvent = new EndSessionEvent(m_Project.AllocateId());
            string          endFile  = Path.Combine(endFolder, ProjectDatabase.GetDataFileName(endEvent.EditSequence));

            using (StreamWriter sw = File.CreateText(endFile))
            {
                foreach (uint fileNum in fileNumbers)
                {
                    string fileName = Path.Combine(endFolder, ProjectDatabase.GetDataFileName(fileNum));
                    string s        = File.ReadAllText(fileName);
                    sw.Write(s);
                }

                // And finish off with the end event
                string endText = EditSerializer.GetSerializedString <Change>(DataField.Edit, endEvent);
                sw.Write(endText);
            }

            // Get rid of the files that we've just combined
            foreach (uint fileNum in fileNumbers)
            {
                string fileName = Path.Combine(endFolder, ProjectDatabase.GetDataFileName(fileNum));
                File.Delete(fileName);
            }
        }
Exemplo n.º 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);
        }