コード例 #1
0
        /// <summary>
        /// Creates a brand new project. If this completes without any exception, you can
        /// call <see cref="OpenProject"/> to activate the project.
        /// </summary>
        /// <param name="projectName">The user-perceived name for the project.</param>
        /// <param name="layer">The map layer the project is for (not null)</param>
        internal void CreateProject(string projectName, ILayer layer)
        {
            if (String.IsNullOrWhiteSpace(projectName) || layer == null)
            {
                throw new ArgumentNullException();
            }

            // Confirm that the project name is unique
            if (FindProjectId(projectName) != null)
            {
                throw new ArgumentException("Specified project already exists");
            }

            // Define the event data
            NewProjectEvent e = new NewProjectEvent()
            {
                ProjectId     = Guid.NewGuid(),
                ProjectName   = projectName,
                LayerId       = layer.Id,
                DefaultSystem = String.Empty,
                UserName      = System.Environment.UserName,
                MachineName   = System.Environment.MachineName
            };

            // Create the index entry
            CreateIndexEntry(projectName, e.ProjectId);

            // Create the data folder
            string dataFolder = CreateDataFolder(e.ProjectId);

            // Serialize the event data to the data folder. Specify <Change> so that
            // the class name will be included in the output file.
            string s        = EditSerializer.GetSerializedString <Change>(DataField.Edit, e);
            string fileName = Path.Combine(dataFolder, GetDataFileName(e.EditSequence));

            File.WriteAllText(fileName, s);

            // Write initial project settings to the data folder
            ProjectSettings ps = new ProjectSettings();
            IDataServer     ds = EditingController.Current.DataServer;

            if (ds != null)
            {
                ps.ConnectionString = ds.ConnectionString;
            }

            // Turn off auto-number if there's no database connection string
            if (String.IsNullOrEmpty(ps.ConnectionString))
            {
                ps.IsAutoNumber = false;
            }

            // Remember default entity types for points, lines, text, polygons
            ps.SetEntityTypeDefaults(layer);

            // Save the settings
            string settingsFileName = Path.Combine(dataFolder, "settings.txt");

            ps.WriteXML(settingsFileName);
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        /// <summary>
        /// Writes the data for some sort of change to this project's data folder.
        /// </summary>
        /// <param name="c">The change to write</param>
        internal void WriteChange(Change c)
        {
            string dataFolder = Path.Combine(m_Container.FolderName, m_Id.ToString().ToUpper());
            string dataFile   = Path.Combine(dataFolder, ProjectDatabase.GetDataFileName(c.EditSequence));
            string changeText = EditSerializer.GetSerializedString <Change>(DataField.Edit, c);

            File.WriteAllText(dataFile, changeText);
        }
コード例 #4
0
        /// <summary>
        /// Checks whether two observations are the same. By rights, this should be
        /// included as part of <c>Observation</c> classes. It's here only because
        /// the method for making the comparison is a bit dumb, and I don't want to
        /// make use of it more generally.
        /// </summary>
        /// <param name="a">The first observation</param>
        /// <param name="b">The observation to compare with</param>
        /// <returns></returns>
        bool IsEqual(Observation a, Observation b)
        {
            if (a == null || b == null)
            {
                return(a == null && b == null);
            }
            else
            {
                if (Object.ReferenceEquals(a, b))
                {
                    return(true);
                }

                // The following is kind of heavy-handed
                string sa = EditSerializer.GetSerializedString <Observation>(DataField.Test, a);
                string sb = EditSerializer.GetSerializedString <Observation>(DataField.Test, b);
                return(sa.Equals(sb));
            }
        }
コード例 #5
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);
        }