/// <summary> /// 下载远程图片 /// </summary> /// <param name="imageUrl">将要下载的图片地址</param> /// <param name="microblogId">微博Id</param> private void DownloadRemoteImage(string imageUrl, long microblogId) { if (UserContext.CurrentUser == null || microblogId <= 0 || string.IsNullOrEmpty(imageUrl)) { return; } try { WebRequest webRequest = WebRequest.Create(SiteUrls.FullUrl(imageUrl)); HttpWebResponse httpWebResponse = (HttpWebResponse)webRequest.GetResponse(); Stream stream = httpWebResponse.GetResponseStream(); MemoryStream ms = new MemoryStream(); stream.CopyTo(ms); string friendlyFileName = imageUrl.Substring(imageUrl.LastIndexOf("/") + 1); string contentType = MimeTypeConfiguration.GetMimeType(friendlyFileName); bool isImage = contentType.StartsWith("image"); if (!isImage || stream == null || !stream.CanRead) { return; } Attachment attachment = new Attachment(ms, contentType, friendlyFileName); attachment.FileLength = httpWebResponse.ContentLength; attachment.AssociateId = microblogId; attachment.UserId = UserContext.CurrentUser.UserId; attachment.UserDisplayName = UserContext.CurrentUser.DisplayName; attachment.TenantTypeId = TenantTypeIds.Instance().Microblog(); var attachmentService = new AttachmentService(TenantTypeIds.Instance().Microblog()); attachmentService.Create(attachment, ms); ms.Dispose(); ms.Close(); } catch { } }
/// <summary> /// 照片圈人通知 /// </summary> /// <param name="photoLabel"></param> /// <param name="eventArgs"></param> public void PhotoLabelNotice_After(PhotoLabel photoLabel, CommonEventArgs eventArgs) { if (photoLabel.Photo == null) { return; } //圈人的操作人 IUser user = DIContainer.Resolve <UserService>().GetUser(photoLabel.UserId); if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { //排除掉照片主人自己 if (photoLabel.UserId == photoLabel.Photo.UserId) { return; } //通知照片作者 Notice notice = Notice.New(); notice.UserId = photoLabel.Photo.UserId; notice.ApplicationId = PhotoConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = user.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().Home(user.UserName)); notice.RelativeObjectName = photoLabel.Photo.Description; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().PhotoDetail(photoLabel.Photo.PhotoId)); notice.TemplateName = NoticeTemplateNames.Instance().PhotoLabelNotice(); noticeService.Create(notice); } }
/// <summary> /// 处理加精操作加积分 /// </summary> /// <param name="blogThread">日志</param> /// <param name="eventArgs">事件</param> private void BlogThreadPointModuleForManagerOperation_After(BlogThread blogThread, CommonEventArgs eventArgs) { NoticeService noticeService = new NoticeService(); string pointItemKey = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().SetEssential()) { pointItemKey = PointItemKeys.Instance().EssentialContent(); PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "日志", blogThread.ResolvedSubject); pointService.GenerateByRole(blogThread.UserId, pointItemKey, description); if (blogThread.UserId > 0) { Notice notice = Notice.New(); notice.UserId = blogThread.UserId; notice.ApplicationId = BlogConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = blogThread.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(blogThread.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(blogThread.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().BlogDetail(blogThread.User.UserName, blogThread.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetEssential(); noticeService.Create(notice); } } }
/// <summary> /// 通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void ContentItemNoticeModule_After(ContentItem sender, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { long toUserId = sender.UserId; NoticeService noticeService = Tunynet.DIContainer.Resolve <NoticeService>(); Notice notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = CmsConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Manage(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectId = sender.ContentItemId; notice.RelativeObjectName = sender.Title; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ContentItemDetail(sender.ContentItemId)); notice.TemplateName = NoticeTemplateNames.Instance().ContributeAccepted(); noticeService.Create(notice); } }
private void RewardAndPunishmentUser_After(IUser sender, RewardAndPunishmentUserEventArgs eventArgs) { PointSettings pointSettings = pointSettingsManger.Get(); int totalPoints = pointSettings.CalculateIntegratedPoint(sender.ExperiencePoints, sender.ReputationPoints); //更新用户等级 //if (eventArgs.ExperiencePoints <= 0 && eventArgs.ReputationPoints <= 0) // return; IUserService userService = DIContainer.Resolve <IUserService>(); UserRankService userRankService = new UserRankService(); SortedList <int, UserRank> userRanks = userRankService.GetAll(); UserRank maxUserRank = null; if (userRanks != null && userRanks.Count > 0) { maxUserRank = userRanks.First().Value; } foreach (KeyValuePair <int, UserRank> userRank in userRanks) { if (totalPoints > userRank.Value.PointLower && userRank.Value.PointLower > maxUserRank.PointLower) { maxUserRank = userRank.Value; } } userService.UpdateRank(sender.UserId, maxUserRank.Rank); //自动解除管制 var user = userService.GetFullUser(sender.UserId); if (user.IsModerated && !user.IsForceModerated) { UserSettings userSettings = userSettingsManager.Get(); if (totalPoints > userSettings.NoModeratedUserPoint) { userService.NoModeratedUser(user.UserId); } } //发送通知 if (sender == null) { return; } Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = 0; notice.TypeId = NoticeTypeIds.Instance().Hint(); if (eventArgs.ExperiencePoints < 0 || eventArgs.ReputationPoints < 0 || eventArgs.TradePoints < 0) { notice.Body = "您被系统扣除经验:" + -eventArgs.ExperiencePoints + "、威望:" + -eventArgs.ReputationPoints + "、金币:" + -eventArgs.TradePoints; } else { notice.Body = "您收到系统奖励经验:" + eventArgs.ExperiencePoints + "、威望:" + eventArgs.ReputationPoints + "、金币:" + eventArgs.TradePoints; } notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().ListNotices(sender.UserName, null, null)); noticeService.Create(notice); }
/// <summary> /// 验证邮箱 /// </summary> /// <param name="emailBuilder"></param> /// <param name="user"></param> /// <returns></returns> public static MailMessage RegisterValidateEmail(this EmailBuilder emailBuilder, IUser user) { string templateName = "RegisterValidateEmail"; dynamic model = emailBuilder.GetUserEmailModel(user); model.EmailValidateUrl = SiteUrls.FullUrl(SiteUrls.Instance().RegisterValidateEmail(user.UserId)); return(emailBuilder.Resolve(templateName, model, new string[] { user.AccountEmail })); }
/// <summary> /// 邀请好友加入站点 /// </summary> /// <param name="emailBuilder"></param> /// <param name="email"></param> /// <param name="invitationBody">邀请附注</param> /// <param name="inviteUrl">邀请链接</param> /// <returns></returns> public static MailMessage InviteFriend(this EmailBuilder emailBuilder, string email, string inviteUrl, string invitationBody) { string templateName = "InviteFriend"; IAuthenticationService authenticationService = DIContainer.ResolvePerHttpRequest <IAuthenticationService>(); IUser user = authenticationService.GetAuthenticatedUser(); dynamic model = emailBuilder.GetUserEmailModel(user); model.InviteUrl = SiteUrls.FullUrl(inviteUrl); model.InvitationBody = invitationBody; return(emailBuilder.Resolve(templateName, model, new string[] { email })); }
/// <summary> /// 兑换商品时处理积分,动态 /// </summary> /// <param name="record">兑换申请</param> /// <param name="eventArgs"></param> public void RecordAcitivityEventModule_After(PointGiftExchangeRecord record, CommonEventArgs eventArgs) { //生成动态 ActivityService activityService = new ActivityService(); if (eventArgs.EventOperationType == EventOperationType.Instance().Approved()) { //初始化Owner为用户的动态 Activity activity = Activity.New(); activity.ActivityItemKey = ActivityItemKeys.Instance().ExchangeGift(); activity.ApplicationId = PointMallConfig.Instance().ApplicationId; activity.HasImage = true; activity.HasMusic = false; activity.HasVideo = false; activity.IsOriginalThread = true; activity.IsPrivate = false; activity.UserId = record.PayerUserId; activity.ReferenceId = record.GiftId; activity.ReferenceTenantTypeId = TenantTypeIds.Instance().PointGift(); activity.SourceId = record.RecordId; activity.TenantTypeId = TenantTypeIds.Instance().PointGiftExchangeRecord(); activity.OwnerId = record.PayerUserId; activity.OwnerName = record.Payer; activity.OwnerType = ActivityOwnerTypes.Instance().User(); activityService.Generate(activity, true); //通知 Notice notice = Notice.New(); notice.UserId = record.PayerUserId; notice.ApplicationId = PointMallConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = record.Payer; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(record.PayerUserId)); notice.RelativeObjectName = record.GiftName; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GiftDetail(record.GiftId)); notice.TemplateName = NoticeTemplateNames.Instance().ApplyRecord(); noticeService.Create(notice); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { //通知 Notice notice = Notice.New(); notice.UserId = record.PayerUserId; notice.ApplicationId = PointMallConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = record.Payer; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(record.PayerUserId)); notice.RelativeObjectName = record.GiftName; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GiftDetail(record.GiftId)); notice.TemplateName = NoticeTemplateNames.Instance().CancelRecord(); noticeService.Create(notice); } }
/// <summary> /// 通知处理 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void CommentNoticeEventModule_After(Comment sender, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) { var urlGetter = CommentUrlGetterFactory.Get(sender.TenantTypeId); var commentedObject = urlGetter.GetCommentedObject(sender.CommentedObjectId); var senderUser = sender.User(); if (urlGetter == null || commentedObject == null) { return; } //文章有新评论时,自动通知原作者 var toUserIds = new List <long>(); //评论相关的atuserid List <long> userids = new AtUserService(TenantTypeIds.Instance().Comment()).GetAtUserIds(sender.Id); if (!userids.Contains(commentedObject.UserId)) { toUserIds.Add(commentedObject.UserId); } if (sender.ParentId > 0 && !userids.Contains(sender.ToUserId)) { toUserIds.Add(sender.ToUserId); } foreach (var toUserId in toUserIds) { //通知的对象排除掉自己 if (toUserId == sender.UserId) { continue; } Notice notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = 0; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActor = senderUser != null ? senderUser.DisplayName : "匿名用户"; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserIdToUserNameDictionary.GetUserName(sender.UserId))); notice.RelativeObjectName = StringUtility.Trim(commentedObject.Name, 60); notice.RelativeObjectId = sender.Id; notice.RelativeObjectUrl = SiteUrls.FullUrl(urlGetter.GetCommentDetailUrl(sender.CommentedObjectId, sender.Id, commentedObject.UserId)) ?? string.Empty; notice.TemplateName = sender.ParentId > 0 ? NoticeTemplateNames.Instance().NewReply() : NoticeTemplateNames.Instance().NewComment(); new NoticeService().Create(notice); } } }
/// <summary> /// 获取被评论对象名称 /// </summary> /// <param name="commentedObjectId">被评论对象Id</param> /// <param name="tenantTypeId">租户类型Id</param> /// <returns></returns> public string GetCommentedObjectName(long commentedObjectId, string tenantTypeId) { if (tenantTypeId == TenantTypeIds.Instance().Photo()) { Photo photo = new PhotoService().GetPhoto(commentedObjectId); if (photo != null) { return(SiteUrls.FullUrl(SiteUrls.Instance().PhotoDetail(commentedObjectId))); } } return(string.Empty); }
/// <summary> /// 处理加精、置顶等操作 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarThreadPointModuleForManagerOperation_After(BarThread sender, CommonEventArgs eventArgs) { NoticeService noticeService = new NoticeService(); if (eventArgs.OperatorInfo == null) { return; } string pointItemKey = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().SetEssential()) { pointItemKey = PointItemKeys.Instance().EssentialContent(); if (sender.UserId > 0 && sender.UserId != eventArgs.OperatorInfo.OperatorUserId) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ThreadDetail(sender.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetEssential(); noticeService.Create(notice); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().SetSticky()) { pointItemKey = PointItemKeys.Instance().StickyContent(); if (sender.UserId > 0 && sender.UserId != eventArgs.OperatorInfo.OperatorUserId) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ThreadDetail(sender.ThreadId)); notice.TemplateName = NoticeTemplateNames.Instance().ManagerSetSticky(); noticeService.Create(notice); } } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "帖子", sender.Subject); pointService.GenerateByRole(sender.UserId, pointItemKey, description); } }
/// <summary> /// 获取邮件模板的全局数据字典 /// </summary> /// <param name="emailBuilder"></param> /// <returns></returns> public static dynamic GetCommonEmailModel(this EmailBuilder emailBuilder) { ISettingsManager <SiteSettings> siteSettingsManager = DIContainer.Resolve <ISettingsManager <SiteSettings> >(); SiteSettings siteSettings = siteSettingsManager.Get(); dynamic model = new ExpandoObject(); model.SiteName = siteSettings.SiteName; model.AdminAddress = "*****@*****.**"; model.LoginUrl = SiteUrls.FullUrl(SiteUrls.Instance().Login()); model.HomeUrl = SiteUrls.FullUrl(SiteUrls.Instance().SiteHome()); model.DateCreated = DateTime.Now.ToString(); return(model); }
/// <summary> /// 添加BBTag实体 /// </summary> /// <param name="htmlTemplate">html模板</param> /// <param name="attachment">带替换附件</param> /// <returns></returns> private BBTag AddBBTagForMobile(string htmlTemplate, Attachment attachment) { BBAttribute bbAttribute = new BBAttribute("attachTemplate", "", n => { return(string.Format(htmlTemplate, attachment.FriendlyFileName, SiteUrls.FullUrl(SiteUrls.Instance().AttachmentUrl(attachment.AttachmentId, TenantTypeIds.Instance().BlogThread())), attachment.FriendlyFileLength)); }, HtmlEncodingMode.UnsafeDontEncode); return(new BBTag("attach:" + attachment.AttachmentId, "${attachTemplate}", "", false, BBTagClosingStyle.LeafElementWithoutContent, null, bbAttribute)); }
/// <summary> /// 通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void BarPostNoticeModule_After(BarPost sender, AuditEventArgs eventArgs) { AuditService auditService = new AuditService(); bool? auditDirection = auditService.ResolveAuditDirection(eventArgs.OldAuditStatus, eventArgs.NewAuditStatus); if (auditDirection == true) //创建回帖发通知 { BarThreadService barThreadService = new BarThreadService(); BarThread barThread = barThreadService.Get(sender.ThreadId); if (barThread == null) { return; } long toUserId = barThread.UserId; //自己给自己的帖子进行回帖,不必通知 if (sender.UserId == barThread.UserId) { return; } if (sender.ParentId > 0) { BarPostService barPostService = new BarPostService(); BarPost parentPost = barPostService.Get(sender.ParentId); if (parentPost == null || (parentPost.UserId == sender.UserId)) { return; } toUserId = parentPost.UserId; } NoticeService noticeService = Tunynet.DIContainer.Resolve <NoticeService>(); Notice notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectId = sender.PostId; notice.RelativeObjectName = HtmlUtility.TrimHtml(barThread.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ThreadDetailGotoPost(sender.PostId)); notice.TemplateName = NoticeTemplateNames.Instance().NewReply(); noticeService.Create(notice); } }
/// <summary> /// 获取被评论对象(部分) /// </summary> /// <param name="commentedObjectId"></param> /// <returns></returns> public CommentedObject GetCommentedObject(long commentedObjectId) { Photo photo = new PhotoService().GetPhoto(commentedObjectId); if (photo != null) { CommentedObject commentedObject = new CommentedObject(); commentedObject.DetailUrl = SiteUrls.Instance().PhotoDetail(commentedObjectId); commentedObject.Name = SiteUrls.FullUrl(SiteUrls.Instance().PhotoDetail(commentedObjectId)); commentedObject.Author = photo.Author; commentedObject.UserId = photo.UserId; return(commentedObject); } return(null); }
/// <summary> /// 首次上传头像加分 /// </summary> /// <param name="sender">用户实体</param> /// <param name="eventArgs">事件参数</param> public void AutoNoModeratedUserNoticeEventModule_After(User sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().AutoNoModeratedUser()) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = 0; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.TemplateName = "AutoNoModeratedUser"; notice.RelativeObjectName = "我的权限"; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().UserModerated(sender.UserName)); notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().ListNotices(sender.UserName, null, null)); noticeService.Create(notice); } }
/// <summary> /// 推荐积分处理 /// </summary> /// <param name="sender">推荐实体</param> /// <param name="eventArgs">事件参数</param> void RecommendPointModule_After(RecommendItem sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType != EventOperationType.Instance().Create()) { return; } string pointItemKey = string.Empty; PointService pointService = new PointService(); string description = string.Empty; TenantTypeService tenantTypeService = new TenantTypeService(); var urlGetter = RecommendUrlGetterFactory.Get(sender.TenantTypeId); NoticeService noticeService = new NoticeService(); Notice notice = Notice.New(); notice.TypeId = NoticeTypeIds.Instance().Hint(); //notice.TemplateName = "FollowUser"; notice.UserId = sender.UserId; notice.LeadingActorUserId = sender.ReferrerId; notice.LeadingActor = sender.ReferrerName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.ReferrerId)); notice.RelativeObjectId = sender.UserId; notice.RelativeObjectName = sender.ItemName; notice.RelativeObjectUrl = sender.DetailUrl; if (sender.TenantTypeId == TenantTypeIds.Instance().User()) { pointItemKey = PointItemKeys.Instance().RecommendUser(); description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendUser")); notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommendedUser(); } else { pointItemKey = PointItemKeys.Instance().RecommendContent(); TenantType tenantType = tenantTypeService.Get(sender.TenantTypeId); if (tenantType == null) { return; } description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_RecommendContent"), tenantType.Name, sender.ItemName); notice.TemplateName = NoticeTemplateNames.Instance().ManagerRecommended(); } noticeService.Create(notice); pointService.GenerateByRole(sender.UserId, pointItemKey, description); }
/// <summary> /// 生成通知 /// </summary> /// <param name="sender">关注实体</param> /// <param name="eventArgs">事件参数</param> void FollowNoticeModule_After(FollowEntity sender, CommonEventArgs eventArgs) { if (EventOperationType.Instance().Create() == eventArgs.EventOperationType) { if (sender.IsQuietly) { return; } IUserService userService = DIContainer.Resolve <IUserService>(); //关注用户 IUser user = userService.GetUser(sender.UserId); if (user == null) { return; } IUser followedUser = userService.GetUser(sender.FollowedUserId); if (followedUser == null) { return; } NoticeService service = new NoticeService(); Notice notice = Notice.New(); notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.TemplateName = "FollowUser"; notice.UserId = followedUser.UserId; notice.LeadingActorUserId = user.UserId; notice.LeadingActor = user.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(user.UserName)); notice.RelativeObjectId = followedUser.UserId; notice.RelativeObjectName = followedUser.DisplayName; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(followedUser.UserName)); service.Create(notice); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { NoticeService service = new NoticeService(); IEnumerable <Notice> notices = service.GetTops(sender.FollowedUserId, 20).Where(n => n.TemplateName == "FollowUser").Where(n => n.LeadingActorUserId == sender.UserId); foreach (var notice in notices) { service.Delete(notice.Id); } } }
/// <summary> /// 获取用户邮件模板的数据字典 /// </summary> /// <param name="emailBuilder"></param> /// <param name="user"></param> /// <returns></returns> public static dynamic GetUserEmailModel(this EmailBuilder emailBuilder, IUser user) { IInviteFriendSettingsManager manager = DIContainer.Resolve <IInviteFriendSettingsManager>(); dynamic model = emailBuilder.GetCommonEmailModel();//合并全局数据字典 model.UserName = user.UserName; model.UserDisplayName = user.DisplayName; model.PublicEmail = "PublicEmail"; model.LastLogin = SiteUrls.FullUrl(SiteUrls.Instance().Login()); model.ProfileUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(user.UserName)); model.ChangePasswordUrl = SiteUrls.FullUrl(SiteUrls.Instance().ChangePassword(user.UserName)); model.UserAvatarUrl = SiteUrls.FullUrl(SiteUrls.Instance().UserAvatarUrl(user, AvatarSizeType.Medium, false)); model.ResetPassword = SiteUrls.FullUrl(SiteUrls.Instance().ResetPassword(user.UserId)); model.ExpirationTime = DateTime.Now.AddDays(manager.Get().InvitationCodeTimeLiness).ToFriendlyDate(); model.InvitationCodeTimeLiness = manager.Get().InvitationCodeTimeLiness; return(model); }
/// <summary> /// 设置/取消管理员通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void SetManagerNoticeEventModule_After(GroupMember sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType != EventOperationType.Instance().SetGroupManager() && eventArgs.EventOperationType != EventOperationType.Instance().CancelGroupManager()) { return; } GroupService groupService = new GroupService(); GroupEntity entity = groupService.Get(sender.GroupId); if (entity == null) { return; } User senderUser = DIContainer.Resolve <IUserService>().GetFullUser(sender.UserId); if (senderUser == null) { return; } NoticeService noticeService = DIContainer.Resolve <NoticeService>(); Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = GroupConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActorUserId = 0; notice.LeadingActor = string.Empty; notice.LeadingActorUrl = string.Empty; notice.RelativeObjectId = sender.GroupId; notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey)); if (eventArgs.EventOperationType == EventOperationType.Instance().SetGroupManager()) { notice.TemplateName = NoticeTemplateNames.Instance().SetGroupManager(); } else { notice.TemplateName = NoticeTemplateNames.Instance().CannelGroupManager(); } noticeService.Create(notice); }
/// <summary> /// 帖吧申请处理结果通知 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> void BarSectionNoticeEventModule_After(BarSection sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { IUserService userService = DIContainer.Resolve <IUserService>(); NoticeService noticeService = DIContainer.Resolve <NoticeService>(); User toUser = userService.GetFullUser(sender.UserId); if (toUser == null) { return; } Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = BarConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = toUser.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(toUser.UserName)); notice.RelativeObjectId = sender.SectionId; notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Name, 64); if (eventArgs.EventOperationType == EventOperationType.Instance().Approved()) { //通知吧主,其申请的帖吧通过了审核 notice.TemplateName = NoticeTemplateNames.Instance().ManagerApproved(); } else { //通知吧主,其申请的帖吧未通过审核 notice.TemplateName = NoticeTemplateNames.Instance().ManagerDisapproved(); } notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().SectionDetail(sender.SectionId)); noticeService.Create(notice); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection()); IEnumerable <long> userIds = subscribeService.GetTopUserIdsOfObject(sender.SectionId, int.MaxValue); foreach (long userId in userIds) { subscribeService.CancelSubscribe(sender.SectionId, userId); } } }
/// <summary> /// At用户通知 /// </summary> /// <param name="sender">用户名集合</param> /// <param name="eventArgs">事件参数</param> private void AtUserNoticeEventModule_After(IEnumerable <long> sender, AtUserEventArgs eventArgs) { if (sender.Count() == 0) { return; } NoticeService service = new NoticeService(); IUserService userService = DIContainer.Resolve <IUserService>(); User eventArgsUser = userService.GetFullUser(eventArgs.UserId); foreach (var userId in sender) { //关注用户 IUser user = userService.GetUser(userId); if (user == null || user.UserId == eventArgs.UserId) { continue; } IAtUserAssociatedUrlGetter urlGetter = AtUserAssociatedUrlGetterFactory.Get(eventArgs.TenantTypeId); if (urlGetter == null) { continue; } AssociatedInfo ai = urlGetter.GetAssociatedInfo(eventArgs.AssociateId); Notice notice = Notice.New(); notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.UserId = user.UserId; notice.LeadingActorUserId = eventArgs.UserId; notice.LeadingActor = eventArgsUser.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(eventArgs.UserId)); notice.RelativeObjectId = eventArgs.AssociateId; notice.RelativeObjectName = HtmlUtility.TrimHtml(ai.Subject, 12); notice.RelativeObjectUrl = SiteUrls.FullUrl(ai.DetailUrl); notice.Owner = urlGetter.GetOwner(); notice.TemplateName = "AtUser"; service.Create(notice); } }
/// <summary> /// 生成多媒体内容标签 /// </summary> /// <param name="shrotUrl">短网址</param> /// <param name="parsedMedia">多媒体连接实体</param> private string ParsedMediaTagGenerateForMobile(string shrotUrl, ParsedMedia parsedMedia) { if (parsedMedia == null) { return(string.Empty); } if (parsedMedia.MediaType == MediaType.Audio) { string musicHtml = "<p><a href=\"{1}\" ntype='mediaPlay'>点击播放音乐</a></p>"; ShortUrlEntity shortUrlEntity = new ShortUrlService().Get(parsedMedia.Alias); return(string.Format(musicHtml, SiteUrls.FullUrl(SiteUrls.Instance()._MusicDetail(parsedMedia.Alias)), shortUrlEntity == null ? null : shortUrlEntity.Url)); } else if (parsedMedia.MediaType == MediaType.Video) { string videoHtml = "<p><a href=\"{1}\" ntype=\"mediaPlay\">{1}<img src=\"{2}\"></a></p>"; ShortUrlEntity shortUrlEntity = new ShortUrlService().Get(parsedMedia.Alias); return(string.Format(videoHtml, SiteUrls.FullUrl(SiteUrls.Instance()._VideoDetail(parsedMedia.Alias)), shortUrlEntity == null ? null : shortUrlEntity.Url, parsedMedia.ThumbnailUrl)); } return(string.Empty); }
/// <summary> /// 处理置顶操作 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void ContentItemPointModuleForManagerOperation_After(ContentItem sender, CommonEventArgs eventArgs) { NoticeService noticeService = new NoticeService(); string pointItemKey = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().SetGlobalSticky() || eventArgs.EventOperationType == EventOperationType.Instance().SetFolderSticky()) { pointItemKey = PointItemKeys.Instance().CMS_StickyNews(); if (sender.UserId > 0) { Notice notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = CmsConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = sender.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectName = sender.Title; notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().ContentItemDetail(sender.ContentItemId)); if (eventArgs.EventOperationType == EventOperationType.Instance().SetGlobalSticky()) { notice.TemplateName = NoticeTemplateNames.Instance().ContributeGlobalStickied(); } else { notice.TemplateName = NoticeTemplateNames.Instance().ContributeFolderStickied(); } noticeService.Create(notice); } } if (!string.IsNullOrEmpty(pointItemKey)) { PointService pointService = new PointService(); string description = string.Format(ResourceAccessor.GetString("PointRecord_Pattern_" + eventArgs.EventOperationType), "资讯", sender.Title); pointService.GenerateByRole(sender.UserId, pointItemKey, description); } }
/// <summary> /// 通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void GroupMemberNoticeModule_After(GroupMember sender, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType != EventOperationType.Instance().Delete() && eventArgs.EventOperationType != EventOperationType.Instance().Create() && sender != null) { return; } GroupService groupService = new GroupService(); GroupEntity entity = groupService.Get(sender.GroupId); if (entity == null) { return; } User senderUser = DIContainer.Resolve <IUserService>().GetFullUser(sender.UserId); if (senderUser == null) { return; } NoticeService noticeService = DIContainer.Resolve <NoticeService>(); Notice notice; List <long> toUserIds = new List <long>(); toUserIds.Add(entity.UserId); toUserIds.AddRange(entity.GroupManagers.Select(n => n.UserId)); //删除群组成员通知群管理员 if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { foreach (var toUserId in toUserIds) { if (toUserId == sender.UserId) { continue; } notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = GroupConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = senderUser.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectId = sender.GroupId; notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey)); notice.TemplateName = NoticeTemplateNames.Instance().MemberQuit(); noticeService.Create(notice); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) //添加群成员时向群管理员发送通知 { foreach (var toUserId in toUserIds) { if (toUserId == sender.UserId) { continue; } notice = Notice.New(); notice.UserId = toUserId; notice.ApplicationId = GroupConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = senderUser.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectId = sender.GroupId; notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey)); notice.TemplateName = NoticeTemplateNames.Instance().MemberJoin(); noticeService.Create(notice); } //向加入者发送通知 notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = GroupConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActorUserId = sender.UserId; notice.LeadingActor = senderUser.DisplayName; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId)); notice.RelativeObjectId = sender.GroupId; notice.RelativeObjectName = StringUtility.Trim(entity.GroupName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().GroupHome(entity.GroupKey)); notice.TemplateName = NoticeTemplateNames.Instance().MemberApplyApproved(); noticeService.Create(notice); } }
public ContentResult Rss(string spaceKey) { User user = userService.GetFullUser(spaceKey); if (user == null) { return(Content(string.Empty)); } ISiteSettingsManager siteSettingsManager = DIContainer.Resolve <ISiteSettingsManager>(); SyndicationFeed feed = new SyndicationFeed(user.DisplayName + "的日志 - " + siteSettingsManager.Get().SiteName, string.Empty, new Uri(SiteUrls.FullUrl(SiteUrls.Instance().Blog(spaceKey)))); feed.Authors.Add(new SyndicationPerson(user.DisplayName)); feed.LastUpdatedTime = DateTime.Now.ConvertToUserDate(); List <SyndicationItem> items = new List <SyndicationItem>(); IEnumerable <BlogThread> blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), user.UserId, false, true, null, null, false, blogSettings.RssPageSize, 1); foreach (BlogThread blog in blogs) { string url = SiteUrls.FullUrl(SiteUrls.Instance().BlogDetail(spaceKey, blog.ThreadId)); string content = string.Empty; if (blogSettings.ShowSummaryInRss) { if (!string.IsNullOrEmpty(blog.Summary)) { content = blog.Summary + "......<a href='" + url + "'>>>点击查看日志原文</a>"; } } else { content = blog.GetResolvedBody(); } SyndicationItem item = new SyndicationItem(blog.ResolvedSubject, content, new Uri(url), blog.ThreadId.ToString(), blog.DateCreated.ConvertToUserDate()); //item.BaseUri =new Uri(WebUtility.HostPath(Request.Url)); item.Authors.Add(new SyndicationPerson(blog.Author)); IEnumerable <string> ownerCategoryNames = blog.OwnerCategoryNames; if (ownerCategoryNames != null) { foreach (string ownerCategoryName in ownerCategoryNames) { item.Categories.Add(new SyndicationCategory(ownerCategoryName)); } } item.PublishDate = blog.DateCreated.ConvertToUserDate(); items.Add(item); } feed.Items = items; //输出XML string rss = string.Empty; using (MemoryStream stream = new MemoryStream()) { XmlWriter rssWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8); Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(feed); rssFormatter.WriteTo(rssWriter); rssWriter.Close(); rss = Encoding.UTF8.GetString(stream.ToArray()); } return(Content(rss, "text/xml")); }
/// <summary> /// 回答增删改等触发的事件 /// </summary> private void AskAnswerEventModule_After(AskAnswer answer, CommonEventArgs eventArgs) { if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { //向关注该问题的用户发送通知 IEnumerable <long> userIds = subscribeService.GetUserIdsOfObject(answer.QuestionId); AskQuestion question = answer.Question; foreach (var userId in userIds) { //通知的对象排除掉自己 if (userId == answer.UserId) { continue; } Notice notice = Notice.New(); notice.UserId = userId; notice.ApplicationId = AskConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Reply(); notice.LeadingActor = answer.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(answer.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId)); notice.TemplateName = NoticeTemplateNames.Instance().NewAnswer(); noticeService.Create(notice); } //自动关注(回答者自动关注[订阅]该问题) if (!subscribeService.IsSubscribed(question.QuestionId, answer.UserId)) { subscribeService.Subscribe(question.QuestionId, answer.UserId); //问题关注数计数,用于“可能感兴趣的问题”关联表查询 countService.ChangeCount(CountTypes.Instance().QuestionFollowerCount(), question.QuestionId, question.UserId, 1, false); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete()) { //删除回答者对问题的关注 subscribeService.CancelSubscribe(answer.QuestionId, answer.UserId); } else if (eventArgs.EventOperationType == EventOperationType.Instance().Update()) { AskQuestion question = new AskService().GetQuestion(answer.QuestionId); if (answer.IsBest && question.Status == QuestionStatus.Resolved && !question.IsTrated) { //如果问题有悬赏则悬赏分值转移到回答者的帐户(如有交易税,需要扣除) if (question.Reward > 0) { pointService.Trade(question.UserId, answer.UserId, question.Reward, string.Format(Resource.PointRecord_Pattern_QuestionReward, question.Subject), false); } askService.SetTradeStatus(question, true); //处理采纳回答相关的积分和威望 string pointItemKey_AcceptedAnswer = PointItemKeys.Instance().Ask_AcceptedAnswer(); //采纳回答时产生积分 string description_AcceptedAnswer = string.Format(Resource.PointRecord_Pattern_AcceptedAnswer, question.Subject); pointService.GenerateByRole(question.UserId, pointItemKey_AcceptedAnswer, description_AcceptedAnswer); //记录用户的威望 PointItem pointItem_AcceptedAnswer = pointService.GetPointItem(pointItemKey_AcceptedAnswer); ownerDataService.Change(question.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem_AcceptedAnswer.ReputationPoints); //处理回答被采纳相关的积分和威望 string pointItemKey_AnswerWereAccepted = PointItemKeys.Instance().Ask_AnswerWereAccepted(); //回答被采纳时产生积分 string description_AnswerWereAccepted = string.Format(Resource.PointRecord_Pattern_AnswerWereAccepted, question.Subject); pointService.GenerateByRole(answer.UserId, pointItemKey_AnswerWereAccepted, description_AnswerWereAccepted); //记录用户的威望 PointItem pointItem_AnswerWereAccepted = pointService.GetPointItem(pointItemKey_AnswerWereAccepted); ownerDataService.Change(answer.UserId, OwnerDataKeys.Instance().UserAskReputation(), pointItem_AnswerWereAccepted.ReputationPoints); //向关注该问题的用户发送通知 IEnumerable <long> userIds = subscribeService.GetUserIdsOfObject(answer.QuestionId); foreach (var userId in userIds) { //通知的对象排除掉自己 if (userId == question.UserId) { continue; } Notice notice = Notice.New(); notice.UserId = userId; notice.ApplicationId = AskConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); notice.LeadingActor = question.Author; notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskUser(UserIdToUserNameDictionary.GetUserName(question.UserId))); notice.RelativeObjectName = HtmlUtility.TrimHtml(question.Subject, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().AskQuestionDetail(question.QuestionId)); notice.TemplateName = NoticeTemplateNames.Instance().SetBestAnswer(); noticeService.Create(notice); } } } }
/// <summary> /// 处理地址 /// </summary> /// <param name="userId"></param> /// <returns></returns> public string GetProcessUrl(long userId) { return(SiteUrls.FullUrl(SiteUrls.Instance().ListMessageSessions(UserIdToUserNameDictionary.GetUserName(userId), null))); }
/// <summary> /// 通知处理程序 /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> private void TopicMemberApplyNoticeModule_After(TopicMemberApply sender, CommonEventArgs eventArgs) { TopicService groupService = new TopicService(); TopicEntity entity = groupService.Get(sender.TopicId); if (entity == null) { return; } User senderUser = DIContainer.Resolve <IUserService>().GetFullUser(sender.UserId); if (senderUser == null) { return; } InvitationService invitationService = new InvitationService(); Invitation invitation; NoticeService noticeService = DIContainer.Resolve <NoticeService>(); Notice notice; if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) { if (sender.ApplyStatus == TopicMemberApplyStatus.Pending) { List <long> toUserIds = new List <long>(); toUserIds.Add(entity.UserId); toUserIds.AddRange(entity.TopicManagers.Select(n => n.UserId)); foreach (var toUserId in toUserIds) { //申请加入专题的请求 if (!groupService.IsMember(sender.TopicId, sender.UserId)) { invitation = Invitation.New(); invitation.ApplicationId = TopicConfig.Instance().ApplicationId; invitation.InvitationTypeKey = InvitationTypeKeys.Instance().ApplyJoinTopic(); invitation.UserId = toUserId; invitation.SenderUserId = sender.UserId; invitation.Sender = senderUser.DisplayName; invitation.SenderUrl = SiteUrls.Instance().SpaceHome(sender.UserId); invitation.RelativeObjectId = sender.TopicId; invitation.RelativeObjectName = entity.TopicName; invitation.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey)); invitation.Remark = sender.ApplyReason; invitationService.Create(invitation); } } } } string noticeTemplateName = string.Empty; if (eventArgs.EventOperationType == EventOperationType.Instance().Approved()) { if (sender.ApplyStatus == TopicMemberApplyStatus.Approved) { noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyApproved(); } } else if (eventArgs.EventOperationType == EventOperationType.Instance().Disapproved()) { if (sender.ApplyStatus == TopicMemberApplyStatus.Disapproved) { noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyDisapproved(); } } if (string.IsNullOrEmpty(noticeTemplateName)) { return; } notice = Notice.New(); notice.UserId = sender.UserId; notice.ApplicationId = TopicConfig.Instance().ApplicationId; notice.TypeId = NoticeTypeIds.Instance().Hint(); //notice.LeadingActorUserId = UserContext.CurrentUser.UserId; //notice.LeadingActor = UserContext.CurrentUser.DisplayName; //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserContext.CurrentUser.UserId)); notice.RelativeObjectId = sender.TopicId; notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64); notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey)); notice.TemplateName = noticeTemplateName; noticeService.Create(notice); }
/// <summary> /// Uploadify的Helper方法用于非附件上传 /// </summary> /// <param name="htmlHelper"></param> /// <param name="name">名称</param> /// <param name="allowedFileExtensions">允许的文件类型 /// 格式为(jpg,txt,doc)</param> /// <param name="fileSizeLimit">允许上传文件大小(单位KB)</param> /// <param name="uploadFileOptions">指定上传配置类</param> /// <param name="buttonOptions">指定按钮属性的类</param> /// <returns></returns> public static MvcHtmlString Uploadify(this HtmlHelper htmlHelper, string name, string allowedFileExtensions, int fileSizeLimit, UploadFileOptions uploadFileOptions, ButtonOptions buttonOptions = null) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(allowedFileExtensions) || fileSizeLimit <= 0 || uploadFileOptions == null) { throw new ExceptionFacade("参数不能为空"); } if (fileSizeLimit <= 0) { throw new ExceptionFacade("参数不能小于等于0"); } //data属性字典 Dictionary <string, object> data = new Dictionary <string, object>(); //定义属性字典 Dictionary <string, object> result = new Dictionary <string, object>(); //参数 Dictionary <string, object> formData = new Dictionary <string, object>(); //文件流标识名 string fileobjName = "Filedata"; #region uploadify设置 if (uploadFileOptions != null) { if (uploadFileOptions.AdditionalCallBacks != null) { result = new Dictionary <string, object>(uploadFileOptions.AdditionalCallBacks); } //定义上传文件标示名称 if (!string.IsNullOrEmpty(uploadFileOptions.FileObjName)) { result.TryAdd("fileObjName", uploadFileOptions.FileObjName); fileobjName = uploadFileOptions.FileObjName; } //设置是否自动上传 if (uploadFileOptions.IsAuto != null) { result.TryAdd("auto", uploadFileOptions.IsAuto); } //设置可多选文件属性 if (uploadFileOptions.IsMultiple != null) { result.TryAdd("multi", uploadFileOptions.IsMultiple); } //设置都否缓存SWF文件 if (uploadFileOptions.PreventCaching != null) { result.TryAdd("preventCaching", uploadFileOptions.PreventCaching); } //设置显示进度的样式 if (!string.IsNullOrEmpty(uploadFileOptions.ProgressData)) { result.TryAdd("progressData", uploadFileOptions.ProgressData); } //设置队列展示容器的ID if (!string.IsNullOrEmpty(uploadFileOptions.QueueId)) { result.TryAdd("queueID", uploadFileOptions.QueueId); } //设置队列可允许的个数 result.TryAdd("queueSizeLimit", uploadFileOptions.QueueSizeLimit); //设置完成后是否移除属性 if (uploadFileOptions.RemoveCompleted != null) { result.TryAdd("removeCompleted", uploadFileOptions.RemoveCompleted); } //设置移除的延时属性 if (uploadFileOptions.RemoveTimeout > 0) { result.TryAdd("removeTimeout", uploadFileOptions.RemoveTimeout); } //设置于服务器端的成功上传的延时属性 if (uploadFileOptions.SuccessTimeout > 0) { result.TryAdd("successTimeout", uploadFileOptions.SuccessTimeout); } //设置可上传的文件数量限制 result.TryAdd("uploadLimit", uploadFileOptions.UploadLimit); if (uploadFileOptions.AdditionalFormDatas != null) { formData = new Dictionary <string, object>(uploadFileOptions.AdditionalFormDatas); } else { formData.TryAdd("requestName", fileobjName); } result.TryAdd("formData", formData); //URL long userId = UserContext.CurrentUser != null ? UserContext.CurrentUser.UserId : 0; string uploadUrl = SiteUrls.Instance().UploadFile(userId); if (!string.IsNullOrEmpty(uploadFileOptions.UploaderUrl)) { uploadUrl = uploadFileOptions.UploaderUrl + ((uploadFileOptions.UploaderUrl.Contains("?") ? "&" : "?") + "CurrentUserIdToken=" + Utility.EncryptTokenForUploadfile(0.1, userId)); } result.TryAdd("uploader", uploadUrl); } //设置可允许上传的类型 属性 string fileTypeExts = FileTypeExts(allowedFileExtensions); if (string.IsNullOrEmpty(fileTypeExts)) { fileTypeExts = uploadFileOptions.FileTypeExts; } if (string.IsNullOrEmpty(fileTypeExts)) { fileTypeExts = "*.*"; } result.TryAdd("fileTypeExts", fileTypeExts); //设置文件限制大小属性 if (fileSizeLimit <= 0) { fileSizeLimit = uploadFileOptions.FileSizeLimit; } result.TryAdd("fileSizeLimit", fileSizeLimit); if (!string.IsNullOrEmpty(uploadFileOptions.FileTypeDescription)) { result.TryAdd("fileTypeDesc", uploadFileOptions.FileTypeDescription); } //设置SWF路径 string swfStr = SiteUrls.FullUrl("~/Scripts/jquery/uploadify/uploadify.swf"); result.TryAdd("swf", swfStr); #endregion uploadify设置 if (buttonOptions != null) { #region ButtonOptions设置 //添加按钮的额外样式 if (!string.IsNullOrEmpty(buttonOptions.CssClass)) { result.TryAdd("buttonClass", buttonOptions.CssClass); } //设置按钮的高度 if (buttonOptions.Height != 0) { result.TryAdd("height", buttonOptions.Height); } //设置按钮的宽度 if (buttonOptions.Width != 0) { result.TryAdd("width", buttonOptions.Width); } //设置按钮的显示背景图 if (!string.IsNullOrEmpty(buttonOptions.ImageUrl)) { result.TryAdd("buttonImage", buttonOptions.ImageUrl); } //设置按钮的文本 if (!string.IsNullOrEmpty(buttonOptions.Text)) { result.TryAdd("buttonText", buttonOptions.Text); } #endregion ButtonOptions设置 } TagBuilder builder = new TagBuilder("div"); //脚本操作标识 data["plugin"] = "uploadify"; data.TryAdd("data", Json.Encode(result)); builder.MergeAttributes(data); builder.MergeAttribute("id", name); return(MvcHtmlString.Create(builder.ToString().Replace(""[", "").Replace("]"", ""))); }