Esempio n. 1
0
        public OperationLogEntry Create <TEntity>(TEntity entity, string operationType, TEntity historyData) where TEntity : class
        {
            IOperatorInfoGetter operatorInfoGetter = DIContainer.Resolve <IOperatorInfoGetter>();

            if (operatorInfoGetter == null)
            {
                throw new System.ApplicationException("IOperatorInfoGetter not registered to DIContainer");
            }
            OperatorInfo      operatorInfo      = operatorInfoGetter.GetOperatorInfo();
            OperationLogEntry operationLogEntry = new OperationLogEntry(operatorInfo);
            IOperationLogSpecificPartProcesser <TEntity> operationLogSpecificPartProcesser = DIContainer.Resolve <IOperationLogSpecificPartProcesser <TEntity> >();

            if (operationLogSpecificPartProcesser == null)
            {
                throw new System.ApplicationException(string.Format("IOperationLogSpecificPartProcesser<{0}> not registered to DIContainer", typeof(TEntity).Name));
            }
            if (historyData == null)
            {
                operationLogSpecificPartProcesser.Process(entity, operationType, operationLogEntry);
            }
            else
            {
                operationLogSpecificPartProcesser.Process(entity, operationType, historyData, operationLogEntry);
            }
            this.repository.Insert(operationLogEntry);
            return(operationLogEntry);
        }
Esempio n. 2
0
        public CommonEventArgs(string eventOperationType, int applicationId)
        {
            this._eventOperationType = eventOperationType;
            this._applicationId      = applicationId;
            IOperatorInfoGetter operatorInfoGetter = null;           //= DIContainer.Resolve<IOperatorInfoGetter>();

            if (operatorInfoGetter == null)
            {
                throw new System.ApplicationException("IOperatorInfoGetter not registered to DIContainer");
            }
            this.operatorInfo = operatorInfoGetter.GetOperatorInfo();
        }
Esempio n. 3
0
        /// <summary>
        /// 创建操作日志
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entity"></param>
        /// <param name="operationType"></param>
        /// <param name="historyData"></param>
        /// <returns></returns>
        public async Task <OperationLog> CreateAsync <TEntity>(TEntity entity, string operationType, TEntity historyData) where TEntity : class
        {
            IOperatorInfoGetter getter = ServiceLocator.GetService <IOperatorInfoGetter>();

            if (getter == null)
            {
                throw new ApplicationException("IOperatorInfoGetter not registered to DIContainer");
            }
            OperationLog operationLog = new OperationLog(getter.GetOperatorInfo());
            await repository.InsertAsync(operationLog);

            return(operationLog);
        }
Esempio n. 4
0
        /// <summary>
        /// 奖惩用户
        /// </summary>
        /// <param name="userId">被奖惩用户</param>
        /// <param name="experiencePoints">经验</param>
        /// <param name="reputationPoints">威望</param>
        /// <param name="tradePoints">金币</param>
        /// <param name="description">奖惩理由</param>
        public void Reward(long userId, int experiencePoints, int reputationPoints, int tradePoints, string description)
        {
            if (experiencePoints == 0 && reputationPoints == 0 && tradePoints == 0)
            {
                return;
            }
            IUserService userService = DIContainer.Resolve <IUserService>();
            IUser        user        = userService.GetUser(userId);

            if (user == null)
            {
                throw new ExceptionFacade(string.Format("用户“{0}”不存在或已被删除", userId));
            }
            //1、增减用户积分额并生成用户积分记录;
            bool        isIncome    = experiencePoints > 0 || reputationPoints > 0 || tradePoints > 0;
            PointRecord pointRecord = new PointRecord(userId, isIncome ? ResourceAccessor.GetString("Common_AdminReward") : ResourceAccessor.GetString("Common_AdminPunish"), description, experiencePoints, reputationPoints, tradePoints);

            pointRecordRepository.Insert(pointRecord);
            userService.ChangePoints(userId, experiencePoints, reputationPoints, tradePoints);

            //2、增减系统积分额并生成系统积分记录;
            PointRecord systemPointRecord = new PointRecord(0, isIncome ? ResourceAccessor.GetString("Common_RewardUser") : ResourceAccessor.GetString("Common_PunishUser"), description, -experiencePoints, -reputationPoints, -tradePoints);

            pointRecordRepository.Insert(systemPointRecord);

            ChangeSystemTradePoints(-tradePoints);

            //3、生成操作文章
            OperationLogService logService         = Tunynet.DIContainer.Resolve <OperationLogService>();
            IOperatorInfoGetter operatorInfoGetter = DIContainer.Resolve <IOperatorInfoGetter>();

            if (operatorInfoGetter == null)
            {
                return;
            }

            OperationLogEntry logEntry = new OperationLogEntry(operatorInfoGetter.GetOperatorInfo());

            logEntry.ApplicationId       = 0;
            logEntry.Source              = string.Empty;
            logEntry.OperationType       = EventOperationType.Instance().Update();
            logEntry.OperationObjectName = user.UserName;
            logEntry.OperationObjectId   = userId;

            PointCategory experiencePointCategory = GetPointCategory(PointCategoryKeys.Instance().ExperiencePoints());

            if (experiencePointCategory == null)
            {
                return;
            }
            PointCategory reputationPointCategory = GetPointCategory(PointCategoryKeys.Instance().ReputationPoints());

            if (reputationPointCategory == null)
            {
                return;
            }
            PointCategory tradePointCategory = GetPointCategory(PointCategoryKeys.Instance().TradePoints());

            if (tradePointCategory == null)
            {
                return;
            }

            logEntry.Description = string.Format("{0}“{1}”:{2}{3}{4},{5}{6}{7},{8}{9}{10}",
                                                 isIncome ? ResourceAccessor.GetString("Common_RewardUser") : ResourceAccessor.GetString("Common_PunishUser"), user.UserName,
                                                 experiencePoints, experiencePointCategory.Unit, experiencePointCategory.CategoryName,
                                                 reputationPoints, reputationPointCategory.Unit, reputationPointCategory.CategoryName,
                                                 tradePoints, tradePointCategory.Unit, tradePointCategory.CategoryName);
            logService.Create(logEntry);
        }