Example #1
0
        void LoadDataFiles(string folderName, uint[] fileNums)
        {
            Trace.Write("Reading data...");
            EditDeserializer ed          = new EditDeserializer(this);
            Session          lastSession = null;
            IdManager        idMan       = m_MapModel.IdManager;

            foreach (uint fileNum in fileNums)
            {
                string editFile = Path.Combine(folderName, ProjectDatabase.GetDataFileName(fileNum));

                using (TextReader tr = File.OpenText(editFile))
                {
                    TextEditReader er = new TextEditReader(tr);

                    // Ignore any empty files altogether
                    while (er.HasNext)
                    {
                        ed.SetReader(er);
                        Change edit = Change.Deserialize(ed);

                        if (edit is NewProjectEvent)
                        {
                            m_ProjectInfo = (NewProjectEvent)edit;

                            // If the project settings don't have default entity types, initialize them with
                            // the layer defaults. This covers a case where the settings file has been lost, and
                            // automatically re-created by ProjectSettings.CreateInstance.

                            var layer = EnvironmentContainer.FindLayerById(m_ProjectInfo.LayerId);
                            m_Settings.SetEntityTypeDefaults(layer);
                        }
                        else if (edit is NewSessionEvent)
                        {
                            lastSession = new Session(this, (NewSessionEvent)edit, editFile);
                            m_MapModel.AddSession(lastSession);
                        }
                        else if (edit is EndSessionEvent)
                        {
                            Debug.Assert(lastSession != null);
                            lastSession.EndTime = edit.When;
                        }
                        else if (edit is IdAllocation)
                        {
                            if (idMan != null)
                            {
                                IdAllocation alloc = (IdAllocation)edit;
                                IdGroup      g     = idMan.FindGroupById(alloc.GroupId);
                                g.AddIdPacket(alloc);

                                // Remember that allocations have been made in the session (bit of a hack
                                // to ensure the session isn't later removed if no edits are actually
                                // performed).
                                lastSession.AddAllocation(alloc);
                            }
                        }
                        else
                        {
                            Debug.Assert(edit is Operation);
                            Debug.Assert(lastSession != null);
                            lastSession.AddOperation((Operation)edit);
                        }
                    }
                }
            }

            if (m_ProjectInfo == null)
            {
                throw new ApplicationException("Could not locate the project creation event");
            }

            // Apply any forward references
            ed.ApplyForwardRefs();

            // Remember the highest internal ID used by the project
            SetLastItem(fileNums[fileNums.Length - 1]);
        }
Example #2
0
        void LoadDataFiles(string folderName, uint[] fileNums)
        {
            Trace.Write("Reading data...");
            EditDeserializer ed = new EditDeserializer(this);
            Session lastSession = null;
            IdManager idMan = m_MapModel.IdManager;

            foreach (uint fileNum in fileNums)
            {
                string editFile = Path.Combine(folderName, ProjectDatabase.GetDataFileName(fileNum));

                using (TextReader tr = File.OpenText(editFile))
                {
                    TextEditReader er = new TextEditReader(tr);

                    // Ignore any empty files altogether
                    while (er.HasNext)
                    {
                        ed.SetReader(er);
                        Change edit = Change.Deserialize(ed);

                        if (edit is NewProjectEvent)
                        {
                            m_ProjectInfo = (NewProjectEvent)edit;

                            // If the project settings don't have default entity types, initialize them with
                            // the layer defaults. This covers a case where the settings file has been lost, and
                            // automatically re-created by ProjectSettings.CreateInstance.

                            var layer = EnvironmentContainer.FindLayerById(m_ProjectInfo.LayerId);
                            m_Settings.SetEntityTypeDefaults(layer);
                        }
                        else if (edit is NewSessionEvent)
                        {
                            lastSession = new Session(this, (NewSessionEvent)edit, editFile);
                            m_MapModel.AddSession(lastSession);
                        }
                        else if (edit is EndSessionEvent)
                        {
                            Debug.Assert(lastSession != null);
                            lastSession.EndTime = edit.When;
                        }
                        else if (edit is IdAllocation)
                        {
                            if (idMan != null)
                            {
                                IdAllocation alloc = (IdAllocation)edit;
                                IdGroup g = idMan.FindGroupById(alloc.GroupId);
                                g.AddIdPacket(alloc);

                                // Remember that allocations have been made in the session (bit of a hack
                                // to ensure the session isn't later removed if no edits are actually
                                // performed).
                                lastSession.AddAllocation(alloc);
                            }

                        }
                        else
                        {
                            Debug.Assert(edit is Operation);
                            Debug.Assert(lastSession != null);
                            lastSession.AddOperation((Operation)edit);
                        }
                    }
                }
            }

            if (m_ProjectInfo == null)
                throw new ApplicationException("Could not locate the project creation event");

            // Apply any forward references
            ed.ApplyForwardRefs();

            // Remember the highest internal ID used by the project
            SetLastItem(fileNums[fileNums.Length - 1]);
        }