Пример #1
0
        private Dictionary <string, PointActionItemAttribute> GetPointActionItemAttributes <ItemT>(ItemT t) where ItemT : struct
        {
            Dictionary <string, PointActionItemAttribute> actionAttributes = new Dictionary <string, PointActionItemAttribute>(StringComparer.CurrentCultureIgnoreCase);

            if (t is NullEnum)
            {
            }
            else
            {
                System.Reflection.FieldInfo[] fields = t.GetType().GetFields(BindingFlags.Static | BindingFlags.Public);

                foreach (System.Reflection.FieldInfo field in fields)
                {
                    object[] objects = field.GetCustomAttributes(typeof(PointActionItemAttribute), true);
                    if (objects.Length > 0)
                    {
                        PointActionItemAttribute item = (PointActionItemAttribute)objects[0];
                        item.Action = field.Name;
                        actionAttributes.Add(field.Name, item);
                    }
                    else
                    {
                        PointActionItemAttribute item = new PointActionItemAttribute(field.Name, false, false);
                        item.Action = field.Name;
                        actionAttributes.Add(field.Name, item);
                    }
                }
            }

            return(actionAttributes);
        }
Пример #2
0
        private static PointActionItemAttribute GetPointActionItemAttribute <T>(string type, T actionType, bool isNeedValue) where T : struct
        {
            PointActionType pointActionType = GetPointActionType(type);

            if (pointActionType == null)
            {
                return(null);
            }

            PointActionItemAttribute attribute = null;

            if (isNeedValue)
            {
                if (pointActionType.NeedValueActionAttributes.ContainsKey(actionType.ToString()))
                {
                    attribute = pointActionType.NeedValueActionAttributes[actionType.ToString()];
                }
            }
            else
            {
                if (pointActionType.ActionAttributes.ContainsKey(actionType.ToString()))
                {
                    attribute = pointActionType.ActionAttributes[actionType.ToString()];
                }
            }
            return(attribute);
        }
Пример #3
0
        /*
         * public static bool UpdateUsersPointWithNoTrans<T>(Dictionary<int, T> userActions, string type, int count, int nodeID, TryUpdateUserPointCallback beforeUpdate) where T : struct
         * {
         *
         *  List<int> userIDs = new List<int>();
         *  foreach (KeyValuePair<int, T> pair in userActions)
         *  {
         *      userIDs.Add(pair.Key);
         *  }
         *  //先缓存一下用户
         *  UserBO.Instance.GetUsers(userIDs);
         *
         *  bool success = true;
         *  foreach (KeyValuePair<int, T> pair in userActions)
         *  {
         *      if (pair.Key == 0)//游客
         *          continue;
         *
         *      success = CheckPoints(pair.Key, type, pair.Value, 1, true, nodeID);
         *      if (success == false)
         *          break;
         *  }
         *
         *  if (success == false)
         *  {
         *      beforeUpdate(TryUpdateUserPointState.CheckFailed);
         *      return false;
         *  }
         *
         *  success = beforeUpdate(TryUpdateUserPointState.CheckSucceed);
         *
         *  //TODO:更新积分
         *  return success;
         *  //if (success)
         *  //{
         *  //    foreach (KeyValuePair<int, T> pair in userActions)
         *  //    {
         *  //        UserBO.Instance.UpdateUserPoints(
         *  //    }
         *  //}
         * }
         */
        private static bool CheckPoints <T>(int userID, string type, T actionType, int count, bool isNormal, int nodeID) where T : struct
        {
            int[]       points      = null;
            PointAction pointAction = AllSettings.Current.PointActionSettings.PointActions.GetPointAction(type, nodeID);

            points = pointAction.GetPoints(actionType.ToString(), userID);
            if (points == null)
            {
                return(true);
            }
            if (isNormal == false)//取相反的值
            {
                for (int i = 0; i < points.Length; i++)
                {
                    points[i] = -points[i];
                }
            }

            User user = UserBO.Instance.GetUser(userID);

            if (user == null)//可能该主题用户已被删除  但是不影响回复的人更新积分
            {
                return(true);
            }

            PointActionItemAttribute attribute = GetPointActionItemAttribute(type, actionType, false);

            if (attribute == null)
            {
                return(false);
            }

            lock (user.UpdateUserPointLocker)
            {
                //int[] userPoints;
                //bool success = PointActionManager.CheckPoints(attribute.ThrowOverMaxValue, attribute.ThrowOverMinValue, userID, points, out userPoints);
                bool success = UserBO.Instance.CheckUserPoint(userID, attribute.ThrowOverMinValue, attribute.ThrowOverMaxValue, points);
                return(success);
            }
        }
Пример #4
0
        protected bool IsShow(PointActionItemAttribute action)
        {
            if (IsDisableAction(action)==false)
            {
                int[] points = GetPoints(action.Action);
                foreach (int point in points)
                {
                    if (point != 0)
                        return true;
                }
            }

            return false;
        }
Пример #5
0
 protected bool IsDisableAction(PointActionItemAttribute action)
 {
     if (PointActionType.DisableActions.Contains(action.Action))
         return true;
     else
         return false;
 }
Пример #6
0
        private static bool UpdateUserPoints(int userID, int[] points, int count, TryUpdateUserPointCallback beforeUpdate, PointActionItemAttribute attribute, string operateName, string remarks)
        {
            bool throwOverMaxValue = false, throwOverMinValue = false;

            if (attribute == null)
            {
                if (beforeUpdate != null)
                {
                    beforeUpdate(TryUpdateUserPointState.CheckFailed);
                }
                return(false);
            }

            throwOverMaxValue = attribute.ThrowOverMaxValue;
            throwOverMinValue = attribute.ThrowOverMinValue;


            return(UserBO.Instance.UpdateUserPoints(userID, throwOverMaxValue, throwOverMinValue, points, count, beforeUpdate, operateName, remarks));
        }
Пример #7
0
        private static bool UpdateUserPoints <T>(string type, T actionType, bool isNeedValue, int userID, int[] points, int count, TryUpdateUserPointCallback beforeUpdate) where T : struct
        {
            PointActionItemAttribute attribute = GetPointActionItemAttribute(type, actionType, isNeedValue);

            return(UpdateUserPoints(userID, points, count, beforeUpdate, attribute, attribute.ActionName, attribute.ActionName));
        }
Пример #8
0
        //public static bool UpdateUsersPoint<T1, T2>(Dictionary<int,Dictionary<PointActionType,T1> actions)
        //{
        //}

        /*
         * public static bool UpdateUsersPointValue<T>(Dictionary<int, int> userPoints, string type, T actionType, TryUpdateUserPointCallback beforeUpdate, TryUpdateUserPointCallback2 beforeUpdate2) where T : struct
         * {
         *  using (BbsContext context = new BbsContext())
         *  {
         *      context.BeginTransaction();
         *      try
         *      {
         *
         *          bool updatePoint = true;
         *          if (beforeUpdate2 != null)
         *          {
         *              updatePoint = beforeUpdate2(TryUpdateUserPointState.CheckSucceed, out userPoints);
         *          }
         *          else if (beforeUpdate != null)
         *              updatePoint = beforeUpdate(TryUpdateUserPointState.CheckSucceed);
         *
         *          if (updatePoint)
         *          {
         *              bool success = true;
         *              foreach (KeyValuePair<int, int> pair in userPoints)
         *              {
         *                  success = UpdateUserPointValue<T>(pair.Key, type, actionType, pair.Value, null);
         *                  if (!success)
         *                      break;
         *              }
         *              if (success)
         *              {
         *                  context.CommitTransaction();
         *                  return true;
         *              }
         *          }
         *          context.RollbackTransaction();
         *          return false;
         *      }
         *      catch (Exception ex)
         *      {
         *          context.RollbackTransaction();
         *          throw ex;
         *      }
         *  }
         *  return true;
         * }
         *
         */
        public static bool UpdateUserPointValue <T>(int userId, string type, T actionType, int nodeID, int value, TryUpdateUserPointCallback beforeUpdate) where T : struct
        {
            PointAction pointAction;
            UserPoint   userPoint = GetUserPoint <T>(userId, type, actionType, nodeID, out pointAction);

            int?minRemaining, maxValue;
            int minValue;


            pointAction.GetActionPointValueSetting(actionType.ToString(), userId, out minRemaining, out minValue, out maxValue);


            int absValue = Math.Abs(value);

            if (absValue < minValue)//小于最低值
            {
                Context.ThrowError <UserPointTradeMinValueError>(new UserPointTradeMinValueError("UserPointTradeMinValueError", userPoint.Name, absValue, minValue));
                if (beforeUpdate != null)
                {
                    beforeUpdate(TryUpdateUserPointState.CheckFailed);
                }
                return(false);
            }
            if (maxValue != null && absValue > maxValue.Value)//大于最高值
            {
                Context.ThrowError <UserPointTradeMaxValueError>(new UserPointTradeMaxValueError("UserPointTradeMaxValueError", userPoint.Name, absValue, maxValue.Value));
                if (beforeUpdate != null)
                {
                    beforeUpdate(TryUpdateUserPointState.CheckFailed);
                }
                return(false);
            }

            PointActionItemAttribute attribute = GetPointActionItemAttribute(type, actionType, true);

            if (attribute == null)
            {
                if (beforeUpdate != null)
                {
                    beforeUpdate(TryUpdateUserPointState.CheckFailed);
                }
                return(false);
            }

            if (attribute.IgnoreTax == false)
            {
                value = GetPointValue(value);
            }

            User user = UserBO.Instance.GetUser(userId);


            int[] points = new int[Consts.PointCount];
            points[(int)userPoint.Type] = value;

            PointActionItemAttribute tempAttribute;

            if (minRemaining != null && minRemaining.Value > userPoint.MinValue)
            {
                int[] minValues = new int[8];
                minValues[(int)userPoint.Type] = minRemaining.Value;
                lock (user.UpdateUserPointLocker)
                {
                    int point;
                    int result = UserBO.Instance.CheckUserPoint(userId, true, false, points, minValues, null, out point);
                    if (result != 0)
                    {
                        int remaning = point + value;
                        Context.ThrowError <UserPointTradeRemainingError>(new UserPointTradeRemainingError("UserPointTradeRemainingError", userPoint.Name, remaning, minRemaining.Value));
                        if (beforeUpdate != null)
                        {
                            beforeUpdate(TryUpdateUserPointState.CheckFailed);
                        }
                        return(false);
                    }
                }

                if (beforeUpdate != null)
                {
                    bool success = beforeUpdate(TryUpdateUserPointState.CheckSucceed);
                    if (success == false)
                    {
                        return(false);
                    }
                }

                beforeUpdate = null;

                //由于上面已经检查过积分 所以下面不再检查
                tempAttribute = new PointActionItemAttribute(attribute.ActionName, false, false, attribute.IgnoreTax, attribute.IsShowInList);
            }
            else
            {
                tempAttribute = attribute;
            }

            /*
             * lock (user.UpdateUserPointLocker)
             * {
             *  if (minRemaining != null && minRemaining.Value > userPoint.MinValue)
             *  {
             *      int remaning = user.ExtendedPoints[(int)userPoint.Type] + value;
             *      if (remaning < minRemaining.Value)//交易后小于最低余额
             *      {
             *          Context.ThrowError<UserPointTradeRemainingError>(new UserPointTradeRemainingError("UserPointTradeRemainingError", userPoint.Name, remaning, minRemaining.Value));
             *          if (beforeUpdate != null)
             *          {
             *              beforeUpdate(TryUpdateUserPointState.CheckFailed);
             *          }
             *          return false;
             *      }
             *  }
             * }
             */

            return(UpdateUserPoints(userId, points, 1, beforeUpdate, tempAttribute, tempAttribute.ActionName, tempAttribute.ActionName));
        }