Exemplo n.º 1
0
        /// <summary>
        /// Tries to get the first available recycled ID.
        /// </summary>
        /// <param name="entityIdType">the type of the entity id</param>
        /// <returns>a non-zero ID if one was available; 0 otheriwse</returns>
        /// <remarks>If an available ID is found, it'll be removed from the database.</remarks>
        public static uint TryGetLowerEntityId(EntityIdType entityIdType)
        {
            // Lock so someone else doesn't grab the same row
            m_idLock.Enter();

            try
            {
                RecycledEntityId eid = GetFirstRecycledId(entityIdType);

                if (eid == null)
                {
                    return(0);
                }
                else
                {
                    RemoveRecycledId(eid);

                    return((uint)eid.EntityId);
                }
            }
            finally
            {
                m_idLock.Exit();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a new recycled ID to the database.
 /// </summary>
 /// <param name="id">the ID to add</param>
 public static void AddRecycledId(RecycledEntityId id)
 {
     using (var db = RealmServerDataContext.GetContext())
     {
         db.RecycledEntityIds.InsertOnSubmit(id);
         db.SubmitChanges();
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Removes a recycled ID from the database.
 /// </summary>
 /// <param name="id">the ID to remove</param>
 public static void RemoveRecycledId(RecycledEntityId id)
 {
     using (var db = RealmServerDataContext.GetContext())
     {
         db.RecycledEntityIds.Attach(id);
         db.RecycledEntityIds.DeleteOnSubmit(id);
         db.SubmitChanges();
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Recycles an entity ID of the given type.
        /// </summary>
        /// <param name="lowerEntityId">the lower entity id</param>
        /// <param name="entityIdType">the type of the entity id</param>
        public static bool RecycleLowerEntityId(uint lowerEntityId, EntityIdType idType)
        {
            if (DoesIdExist(lowerEntityId, idType))
            {
                // TODO: What should we do if it already exists? This is are a serious bug.
                s_log.Debug(Resources.AlreadyRecycledEntityId, lowerEntityId, idType.ToString());

                return(false);
            }

            RecycledEntityId eid = new RecycledEntityId();

            eid.RecycledEntityIdGuid = Guid.NewGuid();
            eid.EntityId             = (long)lowerEntityId;
            eid.EntityType           = (int)idType;

            AddRecycledId(eid);

            return(true);
        }
Exemplo n.º 5
0
		/// <summary>
		/// Recycles an entity ID of the given type.
		/// </summary>
		/// <param name="lowerEntityId">the lower entity id</param>
		/// <param name="entityIdType">the type of the entity id</param>
		public static bool RecycleLowerEntityId(uint lowerEntityId, EntityIdType idType)
		{
			if (DoesIdExist(lowerEntityId, idType))
			{
				// TODO: What should we do if it already exists? This is are a serious bug.
				s_log.Debug(Resources.AlreadyRecycledEntityId, lowerEntityId, idType.ToString());

                return false;
			}

			RecycledEntityId eid = new RecycledEntityId();
            eid.RecycledEntityIdGuid = Guid.NewGuid();
			eid.EntityId = (long)lowerEntityId;
			eid.EntityType = (int)idType;

            AddRecycledId(eid);

            return true;
		}
Exemplo n.º 6
0
		/// <summary>
		/// Removes a recycled ID from the database.
		/// </summary>
		/// <param name="id">the ID to remove</param>
        public static void RemoveRecycledId(RecycledEntityId id)
        {
            using (var db = RealmServerDataContext.GetContext())
            {
                db.RecycledEntityIds.Attach(id);
                db.RecycledEntityIds.DeleteOnSubmit(id);
                db.SubmitChanges();
            }
        }
Exemplo n.º 7
0
		/// <summary>
		/// Adds a new recycled ID to the database.
		/// </summary>
		/// <param name="id">the ID to add</param>
        public static void AddRecycledId(RecycledEntityId id)
        {
            using (var db = RealmServerDataContext.GetContext())
            {
                db.RecycledEntityIds.InsertOnSubmit(id);
                db.SubmitChanges();
            }
        }