private void MicroblogEntity_After(MicroblogEntity microblogEntity, CommonEventArgs commonEventArgs) { if (microblogEntity == null) { return; } if (microblogSearcher == null) { microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); } //添加索引 if (commonEventArgs.EventOperationType == EventOperationType.Instance().Create()) { microblogSearcher.Insert(microblogEntity); } //删除索引 if (commonEventArgs.EventOperationType == EventOperationType.Instance().Delete()) { microblogSearcher.Delete(microblogEntity.MicroblogId); } //更新索引 if (commonEventArgs.EventOperationType == EventOperationType.Instance().Update() || commonEventArgs.EventOperationType == EventOperationType.Instance().Approved() || commonEventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { microblogSearcher.Update(microblogEntity); } }
/// <summary> /// MicroblogEntity转换成<see cref="Lucene.Net.Documents.Document"/> /// </summary> /// <param name="microblog">微博实体</param> /// <returns>Lucene.Net.Documents.Document</returns> public static Document Convert(MicroblogEntity microblog) { Document doc = new Document(); //索引微博基本信息 doc.Add(new Field(MicroblogIndexDocument.MicroblogId, microblog.MicroblogId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); if (microblog.OriginalMicroblog != null) { doc.Add(new Field(MicroblogIndexDocument.Body, HtmlUtility.StripHtml(microblog.Body, true, false).ToLower() + HtmlUtility.StripHtml(microblog.OriginalMicroblog.Body, true, false).ToLower(), Field.Store.NO, Field.Index.ANALYZED)); } else { doc.Add(new Field(MicroblogIndexDocument.Body, HtmlUtility.StripHtml(microblog.Body, true, false).ToLower(), Field.Store.NO, Field.Index.ANALYZED)); } doc.Add(new Field(MicroblogIndexDocument.DateCreated, DateTools.DateToString(microblog.DateCreated, DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(MicroblogIndexDocument.HasMusic, microblog.HasMusic ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(MicroblogIndexDocument.HasPhoto, microblog.HasPhoto ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(MicroblogIndexDocument.HasVideo, microblog.HasVideo ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(MicroblogIndexDocument.IsOriginality, microblog.ForwardedMicroblogId == 0 ? "1" : "0", Field.Store.YES, Field.Index.NOT_ANALYZED)); doc.Add(new Field(MicroblogIndexDocument.TenantTypeId, microblog.TenantTypeId, Field.Store.YES, Field.Index.NOT_ANALYZED)); TagService tagService = new TagService(TenantTypeIds.Instance().Microblog()); IEnumerable<ItemInTag> itemInTags = tagService.GetItemInTagsOfItem(microblog.MicroblogId); foreach (ItemInTag itemInTag in itemInTags) { doc.Add(new Field(MicroblogIndexDocument.Topic, itemInTag.TagName.ToLower(), Field.Store.YES, Field.Index.ANALYZED)); } return doc; }
/// <summary> /// 审核状态发生变化时处理积分 /// </summary> /// <param name="sender">微博实体</param> /// <param name="eventArgs">时间参数</param> private void MicroblogPointModule_After(MicroblogEntity sender, AuditEventArgs eventArgs) { string pointItemKey = string.Empty, eventOperationType = string.Empty; ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool?auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Microblog_CreateMicroblog(); if (eventArgs.OldAuditStatus == null) { eventOperationType = EventOperationType.Instance().Create(); } else { eventOperationType = EventOperationType.Instance().Approved(); } } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Microblog_DeleteMicroblog(); if (eventArgs.NewAuditStatus == null) { eventOperationType = EventOperationType.Instance().Delete(); } else { eventOperationType = EventOperationType.Instance().Disapproved(); } } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "微博", Tunynet.Utilities.HtmlUtility.TrimHtml(sender.Body, 15)); pointService.GenerateByRole(sender.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == sender.UserId); } }
/// <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 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> /// <param name="sender">微博实体</param> /// <param name="eventArgs">事件参数</param> private void MicroblogActivityModule_After(MicroblogEntity sender, AuditEventArgs eventArgs) { ActivityService activityService = new ActivityService(); bool? auditDirection = new AuditService().ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { var microblogUrlGetter = MicroblogUrlGetterFactory.Get(sender.TenantTypeId); if (microblogUrlGetter == null) return; Activity actvity = Activity.New(); actvity.ActivityItemKey = ActivityItemKeys.Instance().CreateMicroblog(); actvity.ApplicationId = MicroblogConfig.Instance().ApplicationId; actvity.HasImage = sender.HasPhoto; actvity.HasMusic = sender.HasMusic; actvity.HasVideo = sender.HasVideo; actvity.IsOriginalThread = !sender.IsForward; actvity.IsPrivate = false; actvity.SourceId = sender.MicroblogId; actvity.TenantTypeId = TenantTypeIds.Instance().Microblog(); actvity.UserId = sender.UserId; //生成Owner为用户的动态 if (microblogUrlGetter.ActivityOwnerType == ActivityOwnerTypes.Instance().User()) { Activity actvityOfUser = Activity.New(); actvityOfUser.ActivityItemKey = actvity.ActivityItemKey; actvityOfUser.ApplicationId = actvity.ApplicationId; actvityOfUser.HasImage = actvity.HasImage; actvityOfUser.HasMusic = actvity.HasMusic; actvityOfUser.HasVideo = actvity.HasVideo; actvityOfUser.IsOriginalThread = actvity.IsOriginalThread; actvityOfUser.IsPrivate = actvity.IsPrivate; actvityOfUser.UserId = actvity.UserId; actvityOfUser.ReferenceId = actvity.ReferenceId; actvityOfUser.SourceId = actvity.SourceId; actvityOfUser.TenantTypeId = actvity.TenantTypeId; actvityOfUser.OwnerId = sender.UserId; actvityOfUser.OwnerName = sender.User.DisplayName; actvityOfUser.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(actvityOfUser, true); } else { actvity.OwnerId = sender.OwnerId; actvity.OwnerType = microblogUrlGetter.ActivityOwnerType; actvity.OwnerName = microblogUrlGetter.GetOwnerName(sender.OwnerId); activityService.Generate(actvity, false); //生成Owner为用户的动态 if (!microblogUrlGetter.IsPrivate(sender.OwnerId)) { Activity actvityOfUser = Activity.New(); actvityOfUser.ActivityItemKey = actvity.ActivityItemKey; actvityOfUser.ApplicationId = actvity.ApplicationId; actvityOfUser.HasImage = actvity.HasImage; actvityOfUser.HasMusic = actvity.HasMusic; actvityOfUser.HasVideo = actvity.HasVideo; actvityOfUser.IsOriginalThread = actvity.IsOriginalThread; actvityOfUser.IsPrivate = actvity.IsPrivate; actvityOfUser.UserId = actvity.UserId; actvityOfUser.ReferenceId = actvity.ReferenceId; actvityOfUser.SourceId = actvity.SourceId; actvityOfUser.TenantTypeId = actvity.TenantTypeId; actvityOfUser.OwnerId = sender.UserId; actvityOfUser.OwnerName = sender.User.DisplayName; actvityOfUser.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(actvityOfUser, false); } } } else if (auditDirection == false) //删除动态 { activityService.DeleteSource(TenantTypeIds.Instance().Microblog(), sender.MicroblogId); } }
/// <summary> /// 审核状态发生变化时处理积分 /// </summary> /// <param name="sender">微博实体</param> /// <param name="eventArgs">时间参数</param> private void MicroblogPointModule_After(MicroblogEntity sender, AuditEventArgs eventArgs) { string pointItemKey = string.Empty, eventOperationType = string.Empty; ActivityService activityService = new ActivityService(); AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //加积分 { pointItemKey = PointItemKeys.Instance().Microblog_CreateMicroblog(); if (eventArgs.OldAuditStatus == null) eventOperationType = EventOperationType.Instance().Create(); else eventOperationType = EventOperationType.Instance().Approved(); } else if (auditDirection == false) //减积分 { pointItemKey = PointItemKeys.Instance().Microblog_DeleteMicroblog(); if (eventArgs.NewAuditStatus == null) eventOperationType = EventOperationType.Instance().Delete(); else eventOperationType = EventOperationType.Instance().Disapproved(); } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventOperationType), "微博", Tunynet.Utilities.HtmlUtility.TrimHtml(sender.Body, 15)); pointService.GenerateByRole(sender.UserId, pointItemKey, description, eventOperationType == EventOperationType.Instance().Create() || eventOperationType == EventOperationType.Instance().Delete() && eventArgs.OperatorInfo.OperatorUserId == sender.UserId); } }
/// <summary> /// 更新索引 /// </summary> /// <param name="microblog">待更新的微博</param> public void Update(MicroblogEntity microblog) { Document doc = MicroblogIndexDocument.Convert(microblog); searchEngine.Update(doc, microblog.MicroblogId.ToString(), MicroblogIndexDocument.MicroblogId); }
/// <summary> /// 添加索引 /// </summary> /// <param name="microblog">待添加的微博</param> public void Insert(MicroblogEntity microblog) { Insert(new MicroblogEntity[] { microblog }); }
/// <summary> /// 是否具有删除Microblog的权限 /// </summary> /// <param name="authorizer">被扩展对象</param> /// <param name="microblog">微博实体</param> /// <returns></returns> public static bool Microblog_Delete(this Authorizer authorizer, MicroblogEntity microblog) { if (microblog == null) return false; IUser currentUser = UserContext.CurrentUser; if (currentUser == null) return false; if (microblog.UserId == currentUser.UserId || authorizer.IsAdministrator(MicroblogConfig.Instance().ApplicationId)) return true; return false; }
/// <summary> /// 微博动态 /// </summary> /// <param name="sender">微博实体</param> /// <param name="eventArgs">事件参数</param> private void MicroblogActivityModule_After(MicroblogEntity sender, AuditEventArgs eventArgs) { ActivityService activityService = new ActivityService(); bool? auditDirection = new AuditService().ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { var microblogUrlGetter = MicroblogUrlGetterFactory.Get(sender.TenantTypeId); if (microblogUrlGetter == null) { return; } Activity actvity = Activity.New(); actvity.ActivityItemKey = ActivityItemKeys.Instance().CreateMicroblog(); actvity.ApplicationId = MicroblogConfig.Instance().ApplicationId; actvity.HasImage = sender.HasPhoto; actvity.HasMusic = sender.HasMusic; actvity.HasVideo = sender.HasVideo; actvity.IsOriginalThread = !sender.IsForward; actvity.IsPrivate = false; actvity.SourceId = sender.MicroblogId; actvity.TenantTypeId = TenantTypeIds.Instance().Microblog(); actvity.UserId = sender.UserId; //生成Owner为用户的动态 if (microblogUrlGetter.ActivityOwnerType == ActivityOwnerTypes.Instance().User()) { Activity actvityOfUser = Activity.New(); actvityOfUser.ActivityItemKey = actvity.ActivityItemKey; actvityOfUser.ApplicationId = actvity.ApplicationId; actvityOfUser.HasImage = actvity.HasImage; actvityOfUser.HasMusic = actvity.HasMusic; actvityOfUser.HasVideo = actvity.HasVideo; actvityOfUser.IsOriginalThread = actvity.IsOriginalThread; actvityOfUser.IsPrivate = actvity.IsPrivate; actvityOfUser.UserId = actvity.UserId; actvityOfUser.ReferenceId = actvity.ReferenceId; actvityOfUser.SourceId = actvity.SourceId; actvityOfUser.TenantTypeId = actvity.TenantTypeId; actvityOfUser.OwnerId = sender.UserId; actvityOfUser.OwnerName = sender.User.DisplayName; actvityOfUser.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(actvityOfUser, true); } else { actvity.OwnerId = sender.OwnerId; actvity.OwnerType = microblogUrlGetter.ActivityOwnerType; actvity.OwnerName = microblogUrlGetter.GetOwnerName(sender.OwnerId); activityService.Generate(actvity, false); //生成Owner为用户的动态 if (!microblogUrlGetter.IsPrivate(sender.OwnerId)) { Activity actvityOfUser = Activity.New(); actvityOfUser.ActivityItemKey = actvity.ActivityItemKey; actvityOfUser.ApplicationId = actvity.ApplicationId; actvityOfUser.HasImage = actvity.HasImage; actvityOfUser.HasMusic = actvity.HasMusic; actvityOfUser.HasVideo = actvity.HasVideo; actvityOfUser.IsOriginalThread = actvity.IsOriginalThread; actvityOfUser.IsPrivate = actvity.IsPrivate; actvityOfUser.UserId = actvity.UserId; actvityOfUser.ReferenceId = actvity.ReferenceId; actvityOfUser.SourceId = actvity.SourceId; actvityOfUser.TenantTypeId = actvity.TenantTypeId; actvityOfUser.OwnerId = sender.UserId; actvityOfUser.OwnerName = sender.User.DisplayName; actvityOfUser.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(actvityOfUser, false); } } } else if (auditDirection == false) //删除动态 { activityService.DeleteSource(TenantTypeIds.Instance().Microblog(), sender.MicroblogId); } }
/// <summary> /// 创建微博 /// </summary> /// <param name="microblog">待创建微博实体</param> /// <returns></returns> public long Create(MicroblogEntity microblog) { EventBus<MicroblogEntity>.Instance().OnBefore(microblog, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(microblog.UserId, microblog); string videoAlias = string.Empty, audioAlias = string.Empty; microblog.Body = parsedMediaService.ResolveBodyForEdit(microblog.Body, out videoAlias, out audioAlias); microblog.HasVideo = !string.IsNullOrEmpty(videoAlias); microblog.HasMusic = !string.IsNullOrEmpty(audioAlias); microblog.VideoAlias = videoAlias; microblog.AudioAlias = audioAlias; long id = 0; long.TryParse(microblogRepository.Insert(microblog).ToString(), out id); if (id > 0) { string tenantTypeId = TenantTypeIds.Instance().Microblog(); OwnerDataService ownerDataService = new OwnerDataService(microblog.TenantTypeId); ownerDataService.Change(microblog.OwnerId, OwnerDataKeys.Instance().ThreadCount(), 1); //将临时附件转换为正式附件 attachmentService.ToggleTemporaryAttachments(microblog.UserId, tenantTypeId, id); AtUserService atUserService = new AtUserService(tenantTypeId); atUserService.ResolveBodyForEdit(microblog.Body, microblog.UserId, microblog.MicroblogId); TagService tagService = new TagService(tenantTypeId); tagService.ResolveBodyForEdit(microblog.Body, microblog.OwnerId, microblog.MicroblogId, tenantTypeId); EventBus<MicroblogEntity>.Instance().OnAfter(microblog, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus<MicroblogEntity, AuditEventArgs>.Instance().OnAfter(microblog, new AuditEventArgs(null, microblog.AuditStatus)); } return id; }
/// <summary> /// 转发微博 /// </summary> /// <param name="microblog">微博实体</param> /// <param name="isCommnet">是否对被转发微博进行评论</param> /// <param name="isCommentOriginal">是否对微博原文进行评论</param> /// <param name="toUserId">评论拥有者Id</param> /// <param name="toOriginalUserId">源引微博评论拥有者Id</param> /// <param name="microblogId">返回新的microblogId</param> /// <returns>是否创建成功,成功为-true</returns> public bool Forward(MicroblogEntity microblog, bool isCommnet, bool isCommentOriginal, long toUserId, long toOriginalUserId, out long microblogId) { microblogId = Create(microblog); bool isSuccess = microblogId > 0; if (!isSuccess) return isSuccess; if (isCommnet) { Comment comment = Comment.New(); comment.UserId = microblog.UserId; comment.TenantTypeId = TenantTypeIds.Instance().Microblog(); comment.CommentedObjectId = microblog.ForwardedMicroblogId; comment.OwnerId = toUserId; comment.Author = microblog.Author; comment.Body = microblog.Body; commentService.Create(comment); } if (isCommentOriginal) { Comment comment = Comment.New(); comment.UserId = microblog.UserId; comment.TenantTypeId = TenantTypeIds.Instance().Microblog(); comment.CommentedObjectId = microblog.OriginalMicroblogId; comment.OwnerId = toOriginalUserId; comment.Author = microblog.Author; comment.Body = microblog.Body; commentService.Create(comment); } return isSuccess; }