Ejemplo n.º 1
0
        /// <summary>
        /// 用於實體的指定字段的更新
        /// </summary>
        /// <typeparam name="T">實體類型</typeparam>
        /// <param name="express">表達式: p => p.XXX</param>
        /// <param name="val">要更新的值</param>
        public virtual void SetUpdate <T>(Expression <Func <T> > express, object val)
        {
            if (express == null || express.Body.NodeType != ExpressionType.MemberAccess)
            {
                throw new ArgumentException("'" + express + "': 不是有效的表達式!");
            }
            MemberExpression body = (MemberExpression)express.Body;
            var propStr           = GetUpdateKey(express);

            this.ObjectState = ObjectStateType.PartialModified;
            updateList.Add(propStr, val);
            //用於EF的局部更新,此方法不影響MongoDB的局部更新
            SetPropertyValue(this, propStr, val);
        }
Ejemplo n.º 2
0
        private static EntityState ConvertState(ObjectStateType state)
        {
            switch (state)
            {
            case ObjectStateType.Added:
                return(EntityState.Added);

            case ObjectStateType.Modified:
                return(EntityState.Modified);

            case ObjectStateType.Deleted:
                return(EntityState.Deleted);

            default:
                return(EntityState.Unchanged);
            }
        }
Ejemplo n.º 3
0
        public static void AddState(GUnit unit, int stateId, Vector3 param, ObjectStateType stateType)
        {
            if (!CanAddState(unit, stateId, param, stateType))
            {
                return;
            }

            var syncStateInfo = new ServerSyncStateInfo()
            {
                serverKeyFrame = _syncData.currentKeyFrame,
                unitId         = unit.UnitId,
                stateId        = stateId,
                stateParam     = param,
                stateType      = stateType
            };

            _syncData.cachedSyncInfoList.Add(syncStateInfo);
            _syncData.preparedSyncInfoList.Add(syncStateInfo);
        }
Ejemplo n.º 4
0
        public static bool CanAddState(GUnit unit, int stateId, Vector3 param, ObjectStateType stateType)
        {
            var cachedSyncInfoList = _syncData.cachedSyncInfoList;
            var currentKeyFrame    = _syncData.currentKeyFrame;

            for (var i = 0; i < cachedSyncInfoList.Count;)
            {
                var syncStateInfo = cachedSyncInfoList[i];
                if (syncStateInfo.serverKeyFrame < currentKeyFrame &&
                    currentKeyFrame - syncStateInfo.serverKeyFrame > 2)
                {
                    cachedSyncInfoList.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }

            var hasSame       = false;
            var sameStateList = cachedSyncInfoList.Where(_ => _.stateId == stateId).ToList();

            for (var i = 0; i < sameStateList.Count; i++)
            {
                var state = sameStateList[i];
                if (!hasSame && state.stateType == stateType && state.stateParam == param)
                {
                    hasSame = true;
                }
                else if (hasSame && (state.stateType != stateType || state.stateParam != param))
                {
                    hasSame = false;
                }
            }

            return(!hasSame);
        }