Пример #1
0
        /// <summary>
        /// Creates a new <c>Session</c> and defines it as the "current" session
        /// </summary>
        /// <param name="project">The project the session is part of</param>
        /// <param name="sessionData">Information about the session</param>
        /// <param name="sessionFile">The name of the file holding the session data</param>
        internal Session(Project project, NewSessionEvent sessionData, string sessionFile)
        {
            if (sessionData == null || project == null)
                throw new ArgumentNullException();

            m_Data = sessionData;
            m_FileName = sessionFile;
            m_Project = project;
            m_Operations = new List<Operation>();
            m_LastSavedItem = sessionData.EditSequence;
        }
Пример #2
0
        /// <summary>
        /// Creates a new <c>Session</c> and defines it as the "current" session
        /// </summary>
        /// <param name="project">The project the session is part of</param>
        /// <param name="sessionData">Information about the session</param>
        /// <param name="sessionFile">The name of the file holding the session data</param>
        internal Session(Project project, NewSessionEvent sessionData, string sessionFile)
        {
            if (sessionData == null || project == null)
            {
                throw new ArgumentNullException();
            }

            m_Data          = sessionData;
            m_FileName      = sessionFile;
            m_Project       = project;
            m_Operations    = new List <Operation>();
            m_LastSavedItem = sessionData.EditSequence;
        }
Пример #3
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);
        }