示例#1
0
        protected bool DoSaveBiota(ShardDbContext context, Biota biota)
        {
            SetBiotaPopulatedCollections(biota);

            Exception firstException = null;

retry:

            try
            {
                context.SaveChanges();

                if (firstException != null)
                {
                    log.Debug($"[DATABASE] DoSaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} retry succeeded after initial exception of: {firstException.GetFullMessage()}");
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (firstException == null)
                {
                    firstException = ex;
                    goto retry;
                }

                // Character name might be in use or some other fault
                log.Error($"[DATABASE] DoSaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed first attempt with exception: {firstException.GetFullMessage()}");
                log.Error($"[DATABASE] DoSaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed second attempt with exception: {ex.GetFullMessage()}");
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// Default is formed from: input.Id.ToString("X8") + " " + name
        /// </summary>
        public string GetDefaultFileName(Biota input)
        {
            var result = input.Id.ToString("X8");

            var name = input.GetProperty(PropertyString.Name);

            if (!String.IsNullOrWhiteSpace(name))
            {
                result += " " + name;
            }

            return(result + ".sql");
        }
示例#3
0
文件: Door.cs 项目: roidzilla/ACE
        private void SetEphemeralValues()
        {
            // TODO we shouldn't be auto setting properties that come from our weenie by default

            BaseDescriptionFlags |= ObjectDescriptionFlag.Door;

            if (!DefaultOpen)
            {
                CurrentMotionState = motionStateClosed;
                IsOpen             = false;
                //Ethereal = false;
            }
            else
            {
                CurrentMotionState = motionStateOpen;
                IsOpen             = true;
                //Ethereal = true;
            }

            IsLocked       = Biota.GetProperty(PropertyBool.Locked) ?? false;
            ResetInterval  = Biota.GetProperty(PropertyFloat.ResetInterval) ?? 30.0f;
            ResistLockpick = Biota.GetProperty(PropertyInt.ResistLockpick) ?? 0;
            LockCode       = Biota.GetProperty(PropertyString.LockCode) ?? "";

            // If we had the base weenies this would be the way to go
            ////if (DefaultLocked)
            ////    IsLocked = true;
            ////else
            ////    IsLocked = false;

            // But since we don't know what doors were DefaultLocked, let's assume for now that any door that starts Locked should default as such.
            if (IsLocked ?? false)
            {
                DefaultLocked = true;
            }

            movementOpen.ForwardCommand   = (uint)MotionCommand.On;
            movementClosed.ForwardCommand = (uint)MotionCommand.Off;

            if (UseRadius < 2)
            {
                UseRadius = 2;
            }
        }
示例#4
0
        public bool SaveBiota(Biota biota, ReaderWriterLockSlim rwLock)
        {
            if (BiotaContexts.TryGetValue(biota, out var cachedContext))
            {
                rwLock.EnterReadLock();
                try
                {
                    SetBiotaPopulatedCollections(biota);

                    Exception firstException = null;
retry:

                    try
                    {
                        cachedContext.SaveChanges();

                        if (firstException != null)
                        {
                            log.Debug($"SaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} retry succeeded after initial exception of: {firstException.GetFullMessage()}");
                        }

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        if (firstException == null)
                        {
                            firstException = ex;
                            goto retry;
                        }

                        // Character name might be in use or some other fault
                        log.Error($"SaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed first attempt with exception: {firstException}");
                        log.Error($"SaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed second attempt with exception: {ex}");
                        return(false);
                    }
                }
                finally
                {
                    rwLock.ExitReadLock();
                }
            }

            var context = new ShardDbContext();

            BiotaContexts.Add(biota, context);

            rwLock.EnterReadLock();
            try
            {
                SetBiotaPopulatedCollections(biota);

                context.Biota.Add(biota);

                Exception firstException = null;
retry:

                try
                {
                    context.SaveChanges();

                    if (firstException != null)
                    {
                        log.Debug($"SaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} retry succeeded after initial exception of: {firstException.GetFullMessage()}");
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    if (firstException == null)
                    {
                        firstException = ex;
                        goto retry;
                    }

                    // Character name might be in use or some other fault
                    log.Error($"SaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed first attempt with exception: {firstException}");
                    log.Error($"SaveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed second attempt with exception: {ex}");
                    return(false);
                }
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }
        public override bool RemoveBiota(Biota biota, ReaderWriterLockSlim rwLock)
        {
            if (BiotaContexts.TryGetValue(biota, out var cachedContext))
            {
                BiotaContexts.Remove(biota);

                rwLock.EnterReadLock();
                try
                {
                    cachedContext.Biota.Remove(biota);

                    Exception firstException = null;
retry:

                    try
                    {
                        cachedContext.SaveChanges();

                        if (firstException != null)
                        {
                            log.Debug($"[DATABASE] RemoveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} retry succeeded after initial exception of: {firstException.GetFullMessage()}");
                        }

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        if (firstException == null)
                        {
                            firstException = ex;
                            goto retry;
                        }

                        // Character name might be in use or some other fault
                        log.Error($"[DATABASE] RemoveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed first attempt with exception: {firstException}");
                        log.Error($"[DATABASE] RemoveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed second attempt with exception: {ex}");
                        return(false);
                    }
                }
                finally
                {
                    rwLock.ExitReadLock();

                    cachedContext.Dispose();
                }
            }

            if (!ObjectGuid.IsPlayer(biota.Id))
            {
                using (var context = new ShardDbContext())
                {
                    var existingBiota = context.Biota
                                        .AsNoTracking()
                                        .FirstOrDefault(r => r.Id == biota.Id);

                    if (existingBiota == null)
                    {
                        return(true);
                    }

                    rwLock.EnterWriteLock();
                    try
                    {
                        context.Biota.Remove(biota);

                        Exception firstException = null;
retry:

                        try
                        {
                            context.SaveChanges();

                            if (firstException != null)
                            {
                                log.Debug($"[DATABASE] RemoveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} retry succeeded after initial exception of: {firstException.GetFullMessage()}");
                            }

                            return(true);
                        }
                        catch (Exception ex)
                        {
                            if (firstException == null)
                            {
                                firstException = ex;
                                goto retry;
                            }

                            // Character name might be in use or some other fault
                            log.Error($"[DATABASE] RemoveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed first attempt with exception: {firstException}");
                            log.Error($"[DATABASE] RemoveBiota 0x{biota.Id:X8}:{biota.GetProperty(PropertyString.Name)} failed second attempt with exception: {ex}");
                            return(false);
                        }
                    }
                    finally
                    {
                        rwLock.ExitWriteLock();
                    }
                }
            }

            // If we got here, the biota didn't come from the database through this class.
            // Most likely, it doesn't exist in the database, so, no need to remove.
            return(true);
        }
示例#6
0
 public uint?GetProperty(PropertyInstanceId property)
 {
     return(Biota.GetProperty(property, BiotaDatabaseLock));
 }
示例#7
0
 public double?GetProperty(PropertyFloat property)
 {
     return(Biota.GetProperty(property, BiotaDatabaseLock));
 }
示例#8
0
 public bool?GetProperty(PropertyBool property)
 {
     return(Biota.GetProperty(property, BiotaDatabaseLock));
 }
示例#9
0
 public string GetProperty(PropertyString property)
 {
     return(Biota.GetProperty(property, BiotaDatabaseLock));
 }
示例#10
0
 public long?GetProperty(PropertyInt64 property)
 {
     return(Biota.GetProperty(property, BiotaDatabaseLock));
 }
示例#11
0
 public int?GetProperty(PropertyInt property)
 {
     return(Biota.GetProperty(property, BiotaDatabaseLock));
 }