Exemple #1
0
        /// <summary>
        /// Associates an ID allocation with this group
        /// </summary>
        /// <param name="a">The allocation associated with this group</param>
        /// <returns>The ID packet corresponding to the supplied allocation</returns>
        internal IdPacket AddIdPacket(IdAllocation a)
        {
            IdPacket result = new IdPacket(this, a);

            m_Packets.Add(result);
            m_MaxAllocatedId = Math.Max(m_MaxAllocatedId, a.HighestId);
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Gets a new allocation for this ID group.
        /// </summary>
        /// <param name="announce">Should the allocation be announced to the user?</param>
        /// <returns>Information about the allocated range.</returns>
        internal IdPacket GetAllocation(bool announce)
        {
            IdPacket result = null;

            IDataServer ds = EditingController.Current.DataServer;

            if (ds == null)
            {
                throw new ApplicationException("Database not available");
            }

            ds.RunTransaction(delegate
            {
                // May be best to remove this from IIdGroup! -- DO want to be able to retrieve the value
                // currently stored in the database.
                int oldMaxUsedId = m_MaxAllocatedId;
                int newMaxUsedId = (oldMaxUsedId == 0 ? LowestId + PacketSize - 1 : oldMaxUsedId + PacketSize);

                /*
                 * // The following should be covered by the implementation of the ID server (for a personal ID server,
                 * // there should be nothing to do).
                 * string sql = String.Format("UPDATE [ced].[IdGroups] SET [MaxUsedId]={0} WHERE [GroupId]={1} AND [MaxUsedId]={2}",
                 *                              newMaxUsedId, Id, oldMaxUsedId);
                 * int nRows = ds.ExecuteNonQuery(sql);
                 *
                 * if (nRows != 1)
                 *  throw new ApplicationException("Allocation failed");
                 */

                // Remember the allocation as as part of this group
                IdAllocation alloc = new IdAllocation()
                {
                    GroupId   = this.Id,
                    LowestId  = newMaxUsedId - PacketSize + 1,
                    HighestId = newMaxUsedId,
                };

                result           = AddIdPacket(alloc);
                m_MaxAllocatedId = newMaxUsedId;

                // Write event data for the allocation
                CadastralMapModel.Current.WorkingSession.AddAllocation(alloc);
                EditingController.Current.Project.WriteChange(alloc);
            });

            // If the user should be informed, list out any ranges we created.
            if (announce && result != null)
            {
                string announcement = String.Format("Allocating extra IDs: {0}-{1}", result.Min, result.Max);
                MessageBox.Show(announcement);
            }

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Creates a new <c>IdPacket</c>
        /// </summary>
        /// <param name="group">The group that will contain this packet (not null)</param>
        /// <param name="alloc">The allocation associated with the group (not null)</param>
        /// <exception cref="ArgumentNullException">If either parameter is null</exception>
        /// <exception cref="ArgumentException">If the allocation does not refer to the supplied group</exception>
        internal IdPacket(IdGroup group, IdAllocation alloc)
        {
            if (group==null || alloc==null)
                throw new ArgumentNullException();

            if (group.Id != alloc.GroupId)
                throw new ArgumentException();

            m_Group = group;
            m_Allocation = alloc;
            m_Ids = new NativeId[m_Allocation.Size];
            m_ReservedIds = new List<uint>();
        }
Exemple #4
0
        /// <summary>
        /// Creates a new <c>IdPacket</c>
        /// </summary>
        /// <param name="group">The group that will contain this packet (not null)</param>
        /// <param name="alloc">The allocation associated with the group (not null)</param>
        /// <exception cref="ArgumentNullException">If either parameter is null</exception>
        /// <exception cref="ArgumentException">If the allocation does not refer to the supplied group</exception>
        internal IdPacket(IdGroup group, IdAllocation alloc)
        {
            if (group == null || alloc == null)
            {
                throw new ArgumentNullException();
            }

            if (group.Id != alloc.GroupId)
            {
                throw new ArgumentException();
            }

            m_Group       = group;
            m_Allocation  = alloc;
            m_Ids         = new NativeId[m_Allocation.Size];
            m_ReservedIds = new List <uint>();
        }
Exemple #5
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]);
        }
Exemple #6
0
 /// <summary>
 /// Remembers that an allocation has been made during this session.
 /// </summary>
 /// <param name="alloc">The allocation that was made</param>
 internal void AddAllocation(IdAllocation alloc)
 {
     AllocationCount++;
     m_LastSavedItem = Math.Max(m_LastSavedItem, alloc.EditSequence);
 }
Exemple #7
0
 /// <summary>
 /// Remembers that an allocation has been made during this session.
 /// </summary>
 /// <param name="alloc">The allocation that was made</param>
 internal void AddAllocation(IdAllocation alloc)
 {
     AllocationCount++;
     m_LastSavedItem = Math.Max(m_LastSavedItem, alloc.EditSequence);
 }
Exemple #8
0
 /// <summary>
 /// Associates an ID allocation with this group
 /// </summary>
 /// <param name="a">The allocation associated with this group</param>
 /// <returns>The ID packet corresponding to the supplied allocation</returns>
 internal IdPacket AddIdPacket(IdAllocation a)
 {
     IdPacket result = new IdPacket(this, a);
     m_Packets.Add(result);
     m_MaxAllocatedId = Math.Max(m_MaxAllocatedId, a.HighestId);
     return result;
 }
Exemple #9
0
        /// <summary>
        /// Gets a new allocation for this ID group.
        /// </summary>
        /// <param name="announce">Should the allocation be announced to the user?</param>
        /// <returns>Information about the allocated range.</returns>
        internal IdPacket GetAllocation(bool announce)
        {
            IdPacket result = null;

            IDataServer ds = EditingController.Current.DataServer;
            if (ds == null)
                throw new ApplicationException("Database not available");

            ds.RunTransaction(delegate
            {
                // May be best to remove this from IIdGroup! -- DO want to be able to retrieve the value
                // currently stored in the database.
                int oldMaxUsedId = m_MaxAllocatedId;
                int newMaxUsedId = (oldMaxUsedId == 0 ? LowestId + PacketSize - 1 : oldMaxUsedId + PacketSize);

                /*
                // The following should be covered by the implementation of the ID server (for a personal ID server,
                // there should be nothing to do).
                string sql = String.Format("UPDATE [ced].[IdGroups] SET [MaxUsedId]={0} WHERE [GroupId]={1} AND [MaxUsedId]={2}",
                                                newMaxUsedId, Id, oldMaxUsedId);
                int nRows = ds.ExecuteNonQuery(sql);

                if (nRows != 1)
                    throw new ApplicationException("Allocation failed");
                */

                // Remember the allocation as as part of this group
                IdAllocation alloc = new IdAllocation()
                {
                    GroupId = this.Id,
                    LowestId = newMaxUsedId - PacketSize + 1,
                    HighestId = newMaxUsedId,
                };

                result = AddIdPacket(alloc);
                m_MaxAllocatedId = newMaxUsedId;

                // Write event data for the allocation
                CadastralMapModel.Current.WorkingSession.AddAllocation(alloc);
                EditingController.Current.Project.WriteChange(alloc);
            });

            // If the user should be informed, list out any ranges we created.
            if (announce && result != null)
            {
                string announcement = String.Format("Allocating extra IDs: {0}-{1}", result.Min, result.Max);
                MessageBox.Show(announcement);
            }

            return result;
        }