/// <summary> /// 创建操作日志 /// </summary> /// <typeparam name="TEntity">操作对象类型</typeparam> /// <param name="entity">操作对象实体</param> /// <param name="operationType">操作类型</param> /// <param name="historyData">历史数据</param> /// <returns>返回创建的操作日志对象</returns> public OperationLogEntry Create <TEntity>(TEntity entity, string operationType, TEntity historyData) where TEntity : class { IOperatorInfoGetter operatorInfoGetter = DIContainer.Resolve <IOperatorInfoGetter>(); if (operatorInfoGetter == null) { throw new ApplicationException("IOperatorInfoGetter not registered to DIContainer"); } var operatorInfo = operatorInfoGetter.GetOperatorInfo(); OperationLogEntry entry = new OperationLogEntry(operatorInfo); IOperationLogSpecificPartProcesser <TEntity> operationLogSpecificPartProcesser = DIContainer.Resolve <IOperationLogSpecificPartProcesser <TEntity> >(); if (operationLogSpecificPartProcesser == null) { throw new ApplicationException(string.Format("IOperationLogSpecificPartProcesser<{0}> not registered to DIContainer", typeof(TEntity).Name)); } if (historyData == null) { operationLogSpecificPartProcesser.Process(entity, operationType, entry); } else { operationLogSpecificPartProcesser.Process(entity, operationType, historyData, entry); } repository.Insert(entry); return(entry); }
void PermissionOperationLogEventMoudle_BatchAfter(IEnumerable<PermissionItemInUserRole> senders, CommonEventArgs eventArgs) { //只记录批量更新操作 if (eventArgs.EventOperationType != EventOperationType.Instance().Update()) return; OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); PermissionService permissionService = new PermissionService(); OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = 0; entry.Source = string.Empty; entry.OperationType = eventArgs.EventOperationType; IEnumerable<string> roleNames = senders.Select(n => n.RoleName).Distinct(); entry.OperationObjectName = string.Join(",", roleNames); entry.OperationObjectId = 0; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType), "权限", entry.OperationObjectName); logService.Create(entry); }
/// <summary> /// 资讯操作日志事件处理 /// </summary> private void ContentFolderOperationLogEventModule_After(ContentFolder sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create() || eventArgs.EventOperationType == EventOperationType.Instance().Update() || eventArgs.EventOperationType == EventOperationType.Instance().Delete() ) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = CmsConfig.Instance().ApplicationId; entry.Source = CmsConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = sender.FolderName; entry.OperationObjectId = sender.ContentFolderId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "资讯栏目", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 文章操作文章事件处理 /// </summary> private void BlogOperationLogEventModule_After(BlogThread senders, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved() || eventArgs.EventOperationType == EventOperationType.Instance().SetEssential() || eventArgs.EventOperationType == EventOperationType.Instance().CancelEssential()) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = entry.ApplicationId; entry.Source = BlogConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = senders.Subject; entry.OperationObjectId = senders.ThreadId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "文章", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 微博操作文章事件处理 /// </summary> private void MicroblogOperationLogEventModule_After(MicroblogEntity senders, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Delete() || eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved() || eventArgs.EventOperationType == EventOperationType.Instance().SetEssential() || eventArgs.EventOperationType == EventOperationType.Instance().SetSticky() || eventArgs.EventOperationType == EventOperationType.Instance().CancelEssential() || eventArgs.EventOperationType == EventOperationType.Instance().CancelSticky()) { OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = entry.ApplicationId; entry.Source = MicroblogConfig.Instance().ApplicationName; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = StringUtility.Trim(senders.Body, 20); entry.OperationObjectId = senders.MicroblogId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType, entry.ApplicationId), "微博", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 资讯操作日志事件处理 /// </summary> private void RecommendOperationLogEventModule_After(RecommendItem sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create() || eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { TenantTypeService tenantTypeService = new TenantTypeService(); TenantType tenantType = tenantTypeService.Get(sender.TenantTypeId); if (tenantType == null) return; OperationLogEntry entry = new OperationLogEntry(eventArgs.OperatorInfo); entry.ApplicationId = tenantType.ApplicationId; entry.Source = tenantType.Name; entry.OperationType = eventArgs.EventOperationType; entry.OperationObjectName = sender.ItemName; entry.OperationObjectId = sender.ItemId; entry.Description = string.Format(ResourceAccessor.GetString("OperationLog_Pattern_" + eventArgs.EventOperationType), tenantType.Name + "推荐", entry.OperationObjectName); OperationLogService logService = Tunynet.DIContainer.Resolve<OperationLogService>(); logService.Create(entry); } }
/// <summary> /// 重建索引 /// </summary> /// <param name="code">CODE</param> /// <returns></returns> public ActionResult RebuildIndex(string code) { ISearcher searcher = SearcherFactory.GetSearcher(code); string name = searcher.Name; string manageIndexUrl = SiteUrls.Instance().ManageIndex(); string rebuildIndexUrl = SiteUrls.Instance().RebuildIndex(code); #region 操作日志 OperationLogEntry log = new OperationLogEntry(); log.DateCreated = DateTime.UtcNow; log.OperatorUserId = currentUser.UserId; log.Operator = currentUser.DisplayName; log.OperatorIP = Tunynet.Utilities.WebUtility.GetIP(); log.OperationType = EntityOperationType.Update.ToString(); log.OperationObjectName = "重建" + name + "索引"; log.Source = "索引管理"; log.AccessUrl = rebuildIndexUrl; #endregion string url = SiteUrls.Instance().ControlPanelOperating("正在执行[重建\"" + name + "\"索引]操作,请耐心等待", manageIndexUrl, rebuildIndexUrl); searcher.RebuildIndex(); log.Description = "重建" + name + "索引成功"; logService.Create(log); return Redirect(SiteUrls.Instance().ControlPanelSuccess("执行成功", SiteUrls.Instance().ManageIndex())); }
/// <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); }
/// <summary> /// 创建操作日志 /// </summary> /// <param name="entry">操作日志实体</param> /// <returns>返回创建的操作日志对象的Id</returns> public long Create(OperationLogEntry entry) { repository.Insert(entry); return(entry.Id); }