Esempio n. 1
0
        internal void Init()
        {
            this.UpdateBuilder.TableName = EntityInfo.EntityName;
            if (IsMappingTable)
            {
                var mappingInfo = this.Context.MappingTables.SingleOrDefault(it => it.EntityName == EntityInfo.EntityName);
                if (mappingInfo != null)
                {
                    this.UpdateBuilder.TableName = mappingInfo.DbTableName;
                }
            }
            Check.Exception(UpdateObjs == null || UpdateObjs.Count() == 0, "UpdateObjs is null");
            int i = 0;

            foreach (var item in UpdateObjs)
            {
                List <DbColumnInfo> updateItem = new List <DbColumnInfo>();
                var isDic = item is Dictionary <string, object>;
                if (isDic)
                {
                    SetUpdateItemByDic(i, item, updateItem);
                }
                else
                {
                    SetUpdateItemByEntity(i, item, updateItem);
                }
                ++i;
            }
        }
Esempio n. 2
0
        public static void AddEncounter(WorldObject wo)
        {
            Encounters.Add(wo);

            var objDesc = new ObjDesc(wo.SetupTableId, wo.ClothingBase ?? 0, (PaletteTemplate)(wo.PaletteTemplate ?? 0), (float)(wo.Shade ?? 0.0));

            if (wo is Creature creature)
            {
                foreach (var equippedObject in creature.EquippedObjects.Values.OrderBy(i => (int)(i.ClothingPriority ?? 0)))
                {
                    if ((equippedObject.CurrentWieldedLocation & EquipMask.Selectable) != 0)
                    {
                        continue;
                    }

                    objDesc.Add(equippedObject.ClothingBase ?? 0, (PaletteTemplate)(equippedObject.PaletteTemplate ?? 0), (float)(equippedObject.Shade ?? 0.0));
                }
            }

            wo.PhysicsObj.UpdateObjDesc(objDesc);

            var r_PhysicsObj = new R_PhysicsObj(wo.PhysicsObj);

            Buffer.AddEncounter(r_PhysicsObj, objDesc);

            if (UpdateObjs == null)
            {
                UpdateObjs = new List <WorldObject>();
            }

            UpdateObjs.Add(wo);
        }
Esempio n. 3
0
        public static void Update()
        {
            if (UpdateObjs == null || Initting)
            {
                return;
            }

            for (var i = UpdateObjs.Count - 1; i >= 0; i--)
            {
                var updateObj = UpdateObjs[i];

                updateObj.PhysicsObj.update_object();

                if (updateObj.PhysicsObj.InitialUpdates > 1 || !updateObj.PhysicsObj.TransientState.HasFlag(TransientStateFlags.Active) || updateObj.PhysicsObj.IsDestroyed)
                {
                    UpdateObjs.RemoveAt(i);
                }
            }
        }
Esempio n. 4
0
        internal void Init()
        {
            this.UpdateBuilder.TableName = EntityInfo.EntityName;
            if (IsMappingTable)
            {
                var mappingInfo = this.Context.MappingTables.SingleOrDefault(it => it.EntityName == EntityInfo.EntityName);
                if (mappingInfo != null)
                {
                    this.UpdateBuilder.TableName = mappingInfo.DbTableName;
                }
            }
            Check.Exception(UpdateObjs == null || UpdateObjs.Count() == 0, "UpdateObjs is null");
            int i = 0;

            foreach (var item in UpdateObjs)
            {
                List <DbColumnInfo> updateItem = new List <DbColumnInfo>();
                foreach (var column in EntityInfo.Columns)
                {
                    var columnInfo = new DbColumnInfo()
                    {
                        Value        = column.PropertyInfo.GetValue(item, null),
                        DbColumnName = GetDbColumnName(column.PropertyName),
                        PropertyName = column.PropertyName,
                        PropertyType = UtilMethods.GetUnderType(column.PropertyInfo),
                        TableId      = i
                    };
                    if (columnInfo.PropertyType.IsEnum())
                    {
                        columnInfo.Value = Convert.ToInt64(columnInfo.Value);
                    }
                    updateItem.Add(columnInfo);
                }
                this.UpdateBuilder.DbColumnInfoList.AddRange(updateItem);
                ++i;
            }
        }
Esempio n. 5
0
        private void ValidateVersion()
        {
            var versionColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsEnableUpdateVersionValidation);
            var pks           = this.UpdateBuilder.DbColumnInfoList.Where(it => it.IsPrimarykey).ToList();

            if (versionColumn != null && this.IsVersionValidation)
            {
                Check.Exception(pks.IsNullOrEmpty(), "UpdateVersionValidation the primary key is required.");
                List <IConditionalModel> conModels = new List <IConditionalModel>();
                foreach (var item in pks)
                {
                    conModels.Add(new ConditionalModel()
                    {
                        FieldName = item.DbColumnName, ConditionalType = ConditionalType.Equal, FieldValue = item.Value.ObjToString()
                    });
                }
                var dbInfo = this.Context.Queryable <T>().Where(conModels).First();
                if (dbInfo != null)
                {
                    var currentVersion = this.EntityInfo.Type.GetProperty(versionColumn.PropertyName).GetValue(UpdateObjs.Last(), null);
                    var dbVersion      = this.EntityInfo.Type.GetProperty(versionColumn.PropertyName).GetValue(dbInfo, null);
                    Check.Exception(currentVersion == null, "UpdateVersionValidation entity property {0} is not null", versionColumn.PropertyName);
                    Check.Exception(dbVersion == null, "UpdateVersionValidation database column {0} is not null", versionColumn.DbColumnName);
                    if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.IntType, UtilConstants.LongType))
                    {
                        if (Convert.ToInt64(dbVersion) != Convert.ToInt64(currentVersion))
                        {
                            throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName));
                        }
                    }
                    else if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.DateType))
                    {
                        if (dbVersion.ObjToDate() != currentVersion.ObjToDate())
                        {
                            throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName));
                        }
                    }
                    else if (versionColumn.PropertyInfo.PropertyType.IsIn(UtilConstants.ByteArrayType))
                    {
                        if (UtilMethods.GetLong((byte[])dbVersion) != UtilMethods.GetLong((byte[])currentVersion))
                        {
                            throw new VersionExceptions(string.Format("UpdateVersionValidation {0} Not the latest version ", versionColumn.PropertyName));
                        }
                    }
                    else
                    {
                        Check.ThrowNotSupportedException(string.Format("UpdateVersionValidation Not Supported Type [ {0} ] , {1}", versionColumn.PropertyInfo.PropertyType, versionColumn.PropertyName));
                    }
                }
            }
        }
Esempio n. 6
0
 public UpdateObjsInfoEventArgs(BinaryExpression exp, EntityStruct obj)
 {
     UpdateObjs.Add(exp, obj);
 }