/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Blog.Resources.Resource", typeof(Spacebuilder.Blog.Resources.Resource).Assembly); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); TenantCommentSettings.RegisterSettings(tenantCommentSettingsElement); //注册日志站点设置 containerBuilder.Register(c => new BlogSettingsManager()).As <IBlogSettingsManager>().SingleInstance(); //注册日志正文解析器 containerBuilder.Register(c => new BlogBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().Blog()).SingleInstance(); //注册EventModule containerBuilder.Register(c => new BlogThreadEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BlogIndexEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BlogOperationLogEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BlogActivityReceiverGetter()).Named <IActivityReceiverGetter>(ActivityOwnerTypes.Instance().Blog().ToString()).SingleInstance(); //注册全文检索搜索器 containerBuilder.Register(c => new BlogSearcher("日志", "~/App_Data/IndexFiles/Blog", true, 3)).As <ISearcher>().Named <ISearcher>(BlogSearcher.CODE).SingleInstance(); //日志应用数据统计 containerBuilder.Register(c => new BlogApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); containerBuilder.Register(c => new BlogCommentUrlGetter()).As <ICommentUrlGetter>().SingleInstance(); containerBuilder.Register(c => new BlogRecommendUrlGetter()).As <IRecommendUrlGetter>().SingleInstance(); containerBuilder.Register(c => new BlogOwnerDataGetter()).As <IOwnerDataGetter>().SingleInstance(); containerBuilder.Register(c => new BlogAtUserAssociatedUrlGetter()).As <IAtUserAssociatedUrlGetter>().SingleInstance(); }
/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Ask.Resources.Resource", typeof(Spacebuilder.Ask.Resources.Resource).Assembly); //评论设置的注册 TenantCommentSettings.RegisterSettings(tenantCommentSettingsElement); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); //注册问答正文解析器 containerBuilder.Register(c => new AskBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().Ask()).SingleInstance(); //注册全文检索搜索器 containerBuilder.Register(c => new AskSearcher("问答", "~/App_Data/IndexFiles/Ask", true, 8)).As <ISearcher>().Named <ISearcher>(AskSearcher.CODE).SingleInstance(); //问题应用数据统计 containerBuilder.Register(c => new AskQuestionApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); //注册问题解析器 containerBuilder.Register(c => new AskBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().AskQuestion()).SingleInstance(); //注册回答解析器 containerBuilder.Register(c => new AskBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().AskAnswer()).SingleInstance(); //注册动态接收人获取器 containerBuilder.Register(c => new SubscribeQuestionActivityReceiverGetter()).Named <IActivityReceiverGetter>(ActivityOwnerTypes.Instance().AskQuestion().ToString()).SingleInstance(); containerBuilder.Register(c => new SubscribeTagActivityReceiverGetter()).Named <IActivityReceiverGetter>(ActivityOwnerTypes.Instance().AskTag().ToString()).SingleInstance(); }
/// <summary> /// Uploadify的Helper方法用于附件 /// </summary> /// <param name="htmlHelper"></param> /// <param name="name">名称</param> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="allowedFileExtensions">允许的文件类型 /// 格式为(jpg,jpeg,gif)</param> /// <param name="buttonOptions">指定按钮属性的类</param> /// <param name="uploadFileOptions">指定上传配置类</param> /// <returns></returns> public static MvcHtmlString Uploadify(this HtmlHelper htmlHelper, string name, string tenantTypeId, string allowedFileExtensions = "", ButtonOptions buttonOptions = null, UploadFileOptions uploadFileOptions = null) { if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(tenantTypeId)) { throw new ExceptionFacade("参数不能为空"); } TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(tenantTypeId); if (tenantAttachmentSettings == null) { throw new ExceptionFacade("找不到附件配置"); } if (uploadFileOptions != null && string.IsNullOrEmpty(uploadFileOptions.UploaderUrl)) { uploadFileOptions.MergeUploadifyFormData("tenantTypeId", tenantTypeId); string fileobjName = string.IsNullOrEmpty(uploadFileOptions.FileObjName) ? "Filedata" : uploadFileOptions.FileObjName; uploadFileOptions.MergeUploadifyFormData("requestName", fileobjName); uploadFileOptions.MergeUploadifyFormData("associateId", uploadFileOptions.AssociateId); } if (uploadFileOptions == null) { uploadFileOptions = new UploadFileOptions(); uploadFileOptions.MergeUploadifyFormData("tenantTypeId", tenantTypeId); uploadFileOptions.MergeUploadifyFormData("requestName", "Filedata"); uploadFileOptions.MergeUploadifyFormData("associateId", 0); } if (string.IsNullOrEmpty(allowedFileExtensions)) { return(Uploadify(htmlHelper, name, tenantAttachmentSettings.AllowedFileExtensions, tenantAttachmentSettings.MaxAttachmentLength, uploadFileOptions, buttonOptions)); } else { return(Uploadify(htmlHelper, name, allowedFileExtensions, tenantAttachmentSettings.MaxAttachmentLength, uploadFileOptions, buttonOptions)); } }
/// <summary> /// 输出html编辑器产生的内容,根据显示区域的宽度自动调整图片尺寸,并引入js脚本 /// </summary> /// <param name="htmlHelper"></param> /// <param name="tenantTypeId">租户类型id</param> /// <param name="content">html编辑器的内容</param> /// <param name="imageWidth">显示区域的图片宽度</param> /// <returns></returns> public static MvcHtmlString DisplayHtmlEditorContent(this HtmlHelper htmlHelper, string tenantTypeId, string content, int imageWidth) { if (string.IsNullOrEmpty(content)) { return(MvcHtmlString.Create(string.Empty)); } TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(tenantTypeId); content = content.Replace("width=\"" + tenantAttachmentSettings.InlinedImageWidth + "\"", "width=\"" + imageWidth + "\""); content += @"<script> $(function () { SyntaxHighlighter.defaults['toolbar'] = false; SyntaxHighlighter.all(); $(" + "\"a[rel='fancybox']\"" + @").fancybox({ 'transitionIn': 'elastic', 'transitionOut': 'elastic', 'speedIn': 600, 'speedOut': 200 }); }); </script> "; return(MvcHtmlString.Create(content)); }
/// <summary> /// 重建缩略图 /// </summary> /// <returns></returns> public ActionResult RebuildingThumbnails() { IEnumerable <TenantAttachmentSettings> tenantAttachmentSettings = TenantAttachmentSettings.GetAll(); ViewData["TenantAttachmentSettings"] = tenantAttachmentSettings; ViewData["TenantLogoSettings"] = TenantLogoSettings.GetAll(); IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>(); string rootPath = WebUtility.GetPhysicalFilePath("~"); string uploadsPath = storeProvider.StoreRootPath; if (storeProvider.StoreRootPath.StartsWith(rootPath)) { uploadsPath = uploadsPath.Replace(rootPath, ""); } ViewData["uploadsPath"] = uploadsPath; Dictionary <string, string> ApplicationName = new Dictionary <string, string>(); TenantTypeService tenantTypeService = new TenantTypeService(); IEnumerable <TenantType> tenantTypes = tenantTypeService.Gets(null, null); foreach (var item in tenantTypes) { TenantType type = tenantTypeService.Get(item.TenantTypeId); ApplicationName[item.TenantTypeId] = type != null ? type.Name : item.Name; } ViewData["ApplicationName"] = ApplicationName; return(View()); }
public ActionResult _Create_UploadImages(string spaceKey) { //reply:已修改 ViewData["TenantAttachmentSettings"] = TenantAttachmentSettings.GetRegisteredSettings(TenantTypeIds.Instance().Microblog()); return(View()); }
/// <summary> /// 为指定用户生成指定附件的拷贝 /// </summary> /// <param name="attachment">指定附件实体</param> /// <param name="userId">指定用户的id</param> /// <returns>新附件实体</returns> public T CloneForUser(T attachment, long userId) { //复制数据库记录 T newAttachment = (T) new Attachment(); newAttachment.ContentType = attachment.ContentType; newAttachment.FileLength = attachment.FileLength; newAttachment.FriendlyFileName = attachment.FriendlyFileName; newAttachment.Height = attachment.Height; newAttachment.MediaType = attachment.MediaType; newAttachment.OwnerId = userId; newAttachment.TenantTypeId = attachment.TenantTypeId; newAttachment.UserDisplayName = userService.GetUser(userId).DisplayName; newAttachment.UserId = userId; newAttachment.Width = attachment.Width; newAttachment.FileName = newAttachment.GenerateFileName(); EventBus <T> .Instance().OnBefore(newAttachment, new CommonEventArgs(EventOperationType.Instance().Create())); attachmentRepository.Insert(newAttachment); EventBus <T> .Instance().OnAfter(newAttachment, new CommonEventArgs(EventOperationType.Instance().Create())); //复制文件 Stream stream = null; try { IStoreFile file = StoreProvider.GetFile(attachment.GetRelativePath(), attachment.FileName); stream = file.OpenReadStream(); StoreProvider.AddOrUpdateFile(newAttachment.GetRelativePath(), newAttachment.FileName, stream); } catch { } finally { if (stream != null) { stream.Close(); stream.Dispose(); } } //根据不同租户类型的设置生成不同尺寸的图片,用于图片直连访问 if (newAttachment.MediaType == MediaType.Image) { TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(newAttachment.TenantTypeId); if (tenantAttachmentSettings != null && tenantAttachmentSettings.ImageSizeTypes != null && tenantAttachmentSettings.ImageSizeTypes.Count > 0) { foreach (var imageSizeType in tenantAttachmentSettings.ImageSizeTypes) { IStoreFile file = StoreProvider.GetResizedImage(newAttachment.GetRelativePath(), newAttachment.FileName, imageSizeType.Size, imageSizeType.ResizeMethod); } } } return(newAttachment); }
/// <summary> /// 构造函数 /// </summary> /// <param name="tenantTypeId">租户类型Id</param> public AttachmentService(string tenantTypeId) { this.attachmentRepository = new AttachmentRepository <T>(); this.TenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(tenantTypeId); if (this.TenantAttachmentSettings == null) { throw new ExceptionFacade("没有注册租户附件设置"); } this.StoreProvider = DIContainer.ResolveNamed <IStoreProvider>(this.TenantAttachmentSettings.StoreProviderName); }
/// <summary> /// 任务执行的内容 /// </summary> /// <param name="taskDetail">任务配置状态信息</param> public void Execute(TaskDetail taskDetail) { IEnumerable <TenantAttachmentSettings> allTenantAttachmentSettings = TenantAttachmentSettings.GetAll(); foreach (var tenantAttachmentSettings in allTenantAttachmentSettings) { AttachmentService service = new AttachmentService(tenantAttachmentSettings.TenantTypeId); service.DeleteTrashTemporaryAttachments(); } }
/// <summary> /// 照片上传 /// </summary> /// <param name="photo">照片对象</param> /// <param name="file">需上传的文件</param> private void UploadPhoto(Photo photo, HttpPostedFileBase file) { if (file == null) { throw new ExceptionFacade("请上传文件"); } TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(TenantTypeIds.Instance().Photo()); //验证图片类型 if (!tenantAttachmentSettings.ValidateFileExtensions(file.FileName)) { throw new ExceptionFacade(string.Format("只允许上传后缀名为{0}的文件", tenantAttachmentSettings.AllowedFileExtensions)); } //验证图片大小 if (!tenantAttachmentSettings.ValidateFileLength(file.ContentLength)) { throw new ExceptionFacade(string.Format("文件大小不允许超过{0}", tenantAttachmentSettings.MaxAttachmentLength)); } IStoreProvider storeProvider = DIContainer.ResolveNamed <IStoreProvider>(tenantAttachmentSettings.StoreProviderName); //根据AlbumId生成图片存储路径和新的文件名 string idString = photo.AlbumId.ToString().PadLeft(15, '0'); string relativePath = storeProvider.JoinDirectory(tenantAttachmentSettings.TenantAttachmentDirectory, idString.Substring(0, 5), idString.Substring(5, 5), idString.Substring(10, 5)); string extension = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1).ToLower(); string fileName = string.Format("{0}.{1}", Guid.NewGuid().ToString("N"), extension); //上传原始图片 using (Stream stream = file.InputStream) { storeProvider.AddOrUpdateFile(relativePath, fileName, stream); if (extension != "gif") { //根据设置生成不同尺寸的图片 if (tenantAttachmentSettings.ImageSizeTypes != null) { foreach (var imageSizeType in tenantAttachmentSettings.ImageSizeTypes) { Stream resizedStream = ImageProcessor.Resize(stream, imageSizeType.Size.Width, imageSizeType.Size.Height, imageSizeType.ResizeMethod); storeProvider.AddOrUpdateFile(relativePath, storeProvider.GetSizeImageName(fileName, imageSizeType.Size, imageSizeType.ResizeMethod), resizedStream); if (resizedStream != stream) { resizedStream.Dispose(); } } } } } photo.RelativePath = relativePath + "\\" + fileName; }
/// <summary> /// 删除照片 /// </summary> /// <remarks> /// 1.更新所属相册计数PhotoCount-1 /// 2.更新用户内容计数OwnerData-1 /// 3.如果照片是封面,需要将相册的CoverId属性重置为0 /// 4.需要调用TagService.ClearTagsFromItem删除标签关联 /// 5.需要同步删除照片圈人 /// 6.通过EventModule处理动态和积分的变化; /// 7.需要触发的事件:1)Delete的OnBefore、OnAfter;2)审核状态变更 /// </remarks> /// <param name="photo">照片对象</param> public void DeletePhoto(Photo photo) { //删除与标签的关联 TagService tagService = new TagService(TenantTypeIds.Instance().Photo()); tagService.ClearTagsFromItem(photo.PhotoId, photo.UserId); //删除照片推荐 RecommendService recommendService = new RecommendService(); recommendService.Delete(photo.PhotoId, TenantTypeIds.Instance().Photo()); //相册计数PhotoCount-1及封面 Album album = photo.Album; album.PhotoCount--; if (photo.PhotoId == album.CoverId) { album.CoverId = 0; } albumRepository.Update(album); //删除圈人 IEnumerable <PhotoLabel> photoLabels = this.GetLabelsOfPhoto(null, photo.PhotoId); foreach (PhotoLabel photolabel in photoLabels) { photoLabelRepository.Delete(photolabel); } //删除照片磁盘物理文件 if (!string.IsNullOrEmpty(photo.RelativePath)) { TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(TenantTypeIds.Instance().Photo()); IStoreProvider storeProvider = DIContainer.ResolveNamed <IStoreProvider>(tenantAttachmentSettings.StoreProviderName); string relativePath = storeProvider.GetRelativePath(photo.RelativePath, true); string fileName = photo.RelativePath.Remove(0, relativePath.Length).Trim('\\').Trim('/'); storeProvider.DeleteFiles(relativePath, fileName); } photoRepository.Delete(photo); EventBus <Photo> .Instance().OnBefore(photo, new CommonEventArgs(EventOperationType.Instance().Delete())); //用户内容计数OwnerData-1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(photo.UserId, OwnerDataKeys.Instance().PhotoCount(), -1); //通过EventModule处理动态和积分的变化; EventBus <Photo> .Instance().OnAfter(photo, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus <Photo, AuditEventArgs> .Instance().OnAfter(photo, new AuditEventArgs(photo.AuditStatus, null)); }
/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.PointMall.Resources.Resource", typeof(Spacebuilder.PointMall.Resources.Resource).Assembly); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); //问题应用数据统计 containerBuilder.Register(c => new PointMallApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); }
/// <summary> /// 设置不同尺寸的图片(附件中) /// </summary> /// <param name="attachment">附件</param> private void SetResizedAttachmentImage(Attachment attachment) { TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(attachment.TenantTypeId); if (tenantAttachmentSettings != null && tenantAttachmentSettings.ImageSizeTypes != null && tenantAttachmentSettings.ImageSizeTypes.Count > 0) { foreach (var imageSizeType in tenantAttachmentSettings.ImageSizeTypes) { IStoreFile file = storeProvider.GetResizedImage(attachment.GetRelativePath(), attachment.FileName, imageSizeType.Size, imageSizeType.ResizeMethod); } } }
/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Microblog.Resources.Resource", typeof(Spacebuilder.Microblog.Resources.Resource).Assembly); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); containerBuilder.Register(c => new MicroblogSearcher("微博", "~/App_Data/IndexFiles/Microblog", true, 2)).As <ISearcher>().Named <ISearcher>(MicroblogSearcher.CODE).SingleInstance(); containerBuilder.Register(c => new MicroblogBodyProcessor()).As <IMicroblogBodyProcessor>().SingleInstance(); containerBuilder.Register(c => new MicroblogApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); containerBuilder.Register(c => new MicroblogTenantAuthorizationHandler()).As <ITenantAuthorizationHandler>().SingleInstance(); }
public ActionResult Upgrading_Database_Ready() { SqlConnection sqlConnection = GetConnection(); //注册应用中的Application.Config foreach (var applicationConfig in ApplicationConfigManager.Instance().GetAllApplicationConfigs()) { if (applicationConfig.Element("tenantAttachmentSettings") != null) { TenantAttachmentSettings.RegisterSettings(applicationConfig.Element("tenantAttachmentSettings")); } if (applicationConfig.Element("tenantLogoSettings") != null) { TenantLogoSettings.RegisterSettings(applicationConfig.Element("tenantLogoSettings")); } } ConcurrentDictionary <string, string> messages = new ConcurrentDictionary <string, string>(); //修改3.2版本的表名 string reNameSqlFile = SetupHelper.GetUpgradeReNameFile(); try { SetupHelper.ExecuteInFile(sqlConnection, reNameSqlFile, out messages); } catch (Exception e) { if (!messages.ContainsKey("在文件:" + reNameSqlFile + " 中产生异常")) { messages["在文件:" + reNameSqlFile + " 中产生异常"] = e.Message + "\r\n"; } else { messages["在文件:" + reNameSqlFile + " 中产生异常"] += e.Message + "\r\n"; } } foreach (var message in messages) { WriteLogFile(string.Format("{0}:{1}", message.Key, message.Value)); } if (messages.Count > 0) { return(Json(new StatusMessageData(StatusMessageType.Error, "升级数据库准备失败,请查看升级日志"))); } else { return(Json(new StatusMessageData(StatusMessageType.Success, "升级数据库准备就绪。"))); } }
public ActionResult _Create_UploadImages(string spaceKey) { //reply:已修改 ViewData["TenantAttachmentSettings"] = TenantAttachmentSettings.GetRegisteredSettings(TenantTypeIds.Instance().Microblog()); //reply:已修改 IUser user = UserContext.CurrentUser; string tenantTypeId = TenantTypeIds.Instance().Microblog(); IEnumerable <Attachment> attachments = attachmentService.GetTemporaryAttachments(user.UserId, tenantTypeId); if (attachments != null && attachments.Count() > 0) { ViewData["IsHasAttachments"] = true; } return(View()); }
/// <summary> /// 重建缩略图 /// </summary> /// <param name="tenantTypeId">租户类型id</param> /// <returns></returns> public ActionResult _RebuildingThumbnails(string tenantTypeId) { TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(tenantTypeId); IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>(); if (tenantAttachmentSettings == null) { return(Content(string.Empty)); } string path = WebUtility.GetPhysicalFilePath(Path.Combine(storeProvider.StoreRootPath, tenantAttachmentSettings.TenantAttachmentDirectory)); ResetThumbnails(path, tenantAttachmentSettings); //重建缩略图的代码 return(Redirect(SiteUrls.Instance().ControlPanelSuccess("执行成功", SiteUrls.Instance().RebuildingThumbnails()))); }
/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Photo.Resources.Resource", typeof(Spacebuilder.Photo.Resources.Resource).Assembly); //评论设置的注册 TenantCommentSettings.RegisterSettings(tenantCommentSettingsElement); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); //注册全文检索搜索器 containerBuilder.Register(c => new PhotoSearcher("相册", "~/App_Data/IndexFiles/Photo", true, 5)).As <ISearcher>().Named <ISearcher>(PhotoSearcher.CODE).SingleInstance(); //问题应用数据统计 containerBuilder.Register(c => new PhotoApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); }
/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Wiki.Resources.Resource", typeof(Spacebuilder.Wiki.Resources.Resource).Assembly); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); //注册百科正文解析器 containerBuilder.Register(c => new WikiBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().WikiPage()).SingleInstance(); containerBuilder.Register(c => new DefaultPageIdToTitleDictionary()).As <PageIdToTitleDictionary>().SingleInstance(); //注册全文检索搜索器 containerBuilder.Register(c => new WikiSearcher("百科", "~/App_Data/IndexFiles/Wiki", true, 3)).As <ISearcher>().Named <ISearcher>(WikiSearcher.CODE).SingleInstance(); containerBuilder.Register(c => new WikiApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); }
/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Bar.Resources.Resource", typeof(Spacebuilder.Bar.Resources.Resource).Assembly); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); //注册标识图设置 TenantLogoSettings.RegisterSettings(tenantLogoSettingsElement); //注册帖吧正文解析器 containerBuilder.Register(c => new BarBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().Bar()).SingleInstance(); containerBuilder.Register(c => new BarSectionActivityReceiverGetter()).Named <IActivityReceiverGetter>(ActivityOwnerTypes.Instance().BarSection().ToString()).SingleInstance(); containerBuilder.Register(c => new BarSearcher("帖吧", "~/App_Data/IndexFiles/Bar", true, 6)).As <ISearcher>().Named <ISearcher>(BarSearcher.CODE).SingleInstance(); containerBuilder.Register(c => new BarApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); containerBuilder.Register(c => new BarTenantAuthorizationHandler()).As <ITenantAuthorizationHandler>().SingleInstance(); }
/// <summary> /// 获取附件存储的相对路径 /// </summary> public virtual string GetRelativePath() { TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(this.TenantTypeId); if (tenantAttachmentSettings == null) { return(string.Empty); } IStoreProvider storeProvider = DIContainer.ResolveNamed <IStoreProvider>(tenantAttachmentSettings.StoreProviderName); if (storeProvider == null) { return(string.Empty); } string[] datePaths = new string[] { tenantAttachmentSettings.TenantAttachmentDirectory }; datePaths = datePaths.Union(this.DateCreated.ToString("yyyy-MM-dd").Split('-')).ToArray(); return(storeProvider.JoinDirectory(datePaths)); }
/// <summary> /// 输出html编辑器产生的内容,根据显示区域的宽度自动调整图片尺寸,并引入js脚本 /// </summary> /// <param name="htmlHelper"></param> /// <param name="tenantTypeId">租户类型id</param> /// <param name="content">html编辑器的内容</param> /// <param name="imageWidth">显示区域的图片宽度</param> /// <returns></returns> public static MvcHtmlString DisplayHtmlEditorContent(this HtmlHelper htmlHelper, string tenantTypeId, string content, int imageWidth) { if (string.IsNullOrEmpty(content)) { return(MvcHtmlString.Create(string.Empty)); } htmlHelper.Style("~/Bundle/Styles/CodeHighlighter"); htmlHelper.Script("~/Bundle/Scripts/CodeHighlighter"); htmlHelper.Style("~/Bundle/Styles/FancyBox"); htmlHelper.Script("~/Bundle/Scripts/FancyBox"); htmlHelper.Script("~/Scripts/tunynet/body.js"); htmlHelper.Script("~/Scripts/tunynet/insertMedia.js"); TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(tenantTypeId); content = content.Replace("width=\"" + tenantAttachmentSettings.InlinedImageWidth + "\"", "width=\"" + imageWidth + "\""); return(MvcHtmlString.Create(content)); }
/// <summary> /// 获取照片的EXIF数据 /// </summary> /// <param name="photoId">照片id</param> /// <returns>返回照片的EXIF数据</returns> public Dictionary <int, string> GetPhotoEXIFMetaData(long photoId) { Dictionary <int, string> EXIFMetaData = new Dictionary <int, string>(); Photo photo = this.GetPhoto(photoId); if (photo == null || string.IsNullOrEmpty(photo.RelativePath) || (!photo.RelativePath.ToLower().EndsWith(".jpg") && !photo.RelativePath.ToLower().EndsWith(".jpeg"))) { return(EXIFMetaData); } TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(TenantTypeIds.Instance().Photo()); IStoreProvider storeProvider = DIContainer.ResolveNamed <IStoreProvider>(tenantAttachmentSettings.StoreProviderName); IStoreFile file = storeProvider.GetFile(photo.RelativePath, ""); if (file != null) { using (Stream stream = file.OpenReadStream()) { EXIFMetaData = new EXIFMetaDataService().Read(stream); } } return(EXIFMetaData); }
/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.CMS.Resources.Resource", typeof(Spacebuilder.CMS.Resources.Resource).Assembly); //注册EventModule containerBuilder.RegisterAssemblyTypes(Assembly.Load("Spacebuilder.CMS")).Where(t => typeof(IEventMoudle).IsAssignableFrom(t)).As <IEventMoudle>().SingleInstance(); //注册全文检索搜索器 containerBuilder.Register(c => new CmsSearcher("资讯", "~/App_Data/IndexFiles/Cms", true, 4)).As <ISearcher>().Named <ISearcher>(CmsSearcher.CODE).SingleInstance(); //资讯应用数据统计 containerBuilder.Register(c => new CmsApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); //注册资讯解析器 containerBuilder.Register(c => new CmsBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().ContentItem()).SingleInstance(); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); //评论设置的注册 TenantCommentSettings.RegisterSettings(tenantCommentSettingsElement); }
/// <summary> /// 应用初始化 /// </summary> /// <param name="containerBuilder">容器构建器</param> public override void Initialize(ContainerBuilder containerBuilder) { //注册ResourceAccessor的应用资源 ResourceAccessor.RegisterApplicationResourceManager(ApplicationId, "Spacebuilder.Bar.Resources.Resource", typeof(Spacebuilder.Bar.Resources.Resource).Assembly); //注册附件设置 TenantAttachmentSettings.RegisterSettings(tenantAttachmentSettingsElement); //注册标识图设置 TenantLogoSettings.RegisterSettings(tenantLogoSettingsElement); //注册帖吧站点设置 containerBuilder.Register(c => new BarSettingsManager()).As <IBarSettingsManager>().SingleInstance(); //注册帖吧正文解析器 containerBuilder.Register(c => new BarBodyProcessor()).Named <IBodyProcessor>(TenantTypeIds.Instance().Bar()).SingleInstance(); containerBuilder.Register(c => new BarIndexEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BarRatingEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BarPostEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BarThreadEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BarSectionEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BarSectionActivityReceiverGetter()).Named <IActivityReceiverGetter>(ActivityOwnerTypes.Instance().BarSection().ToString()).SingleInstance(); containerBuilder.Register(c => new BarSearcher("帖吧", "~/App_Data/IndexFiles/Bar", true, 5)).As <ISearcher>().Named <ISearcher>(BarSearcher.CODE).SingleInstance(); containerBuilder.Register(c => new BarOperationLogEventModule()).As <IEventMoudle>().SingleInstance(); containerBuilder.Register(c => new BarApplicationStatisticDataGetter()).Named <IApplicationStatisticDataGetter>(this.ApplicationKey).SingleInstance(); containerBuilder.Register(c => new BarUrlGetter()).As <IBarUrlGetter>().SingleInstance(); containerBuilder.Register(c => new GroupUrlGetter()).As <IBarUrlGetter>().SingleInstance(); containerBuilder.Register(c => new BarCommentUrlGetter()).As <ICommentUrlGetter>().SingleInstance(); containerBuilder.Register(c => new BarOwnerDataGetter()).As <IOwnerDataGetter>().SingleInstance(); containerBuilder.Register(c => new BarPostOwnerDataGetter()).As <IOwnerDataGetter>().SingleInstance(); containerBuilder.Register(c => new BarTenantAuthorizationHandler()).As <ITenantAuthorizationHandler>().SingleInstance(); containerBuilder.Register(c => new BarThreadRecommendUrlGetter()).As <IRecommendUrlGetter>().SingleInstance(); containerBuilder.Register(c => new BarSectionRecommendUrlGetter()).As <IRecommendUrlGetter>().SingleInstance(); containerBuilder.Register(c => new BarThreadAtUserAssociatedUrlGetter()).As <IAtUserAssociatedUrlGetter>().SingleInstance(); containerBuilder.Register(c => new BarPostAtUserAssociatedUrlGetter()).As <IAtUserAssociatedUrlGetter>().SingleInstance(); }
/// <summary> /// 上传照片(页面) /// </summary> public ActionResult Upload(string spaceKey, long albumId = 0) { IUser owner = userService.GetUser(spaceKey); if (owner == null) { return(HttpNotFound()); } var user = UserContext.CurrentUser; if (user == null) { return(Redirect(SiteUrls.Instance().Login(true))); } string errorMessage = string.Empty; if (!authorizer.Photo_Upload(spaceKey, out errorMessage)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = errorMessage, Title = "没有权限", StatusMessageType = StatusMessageType.Hint }))); } TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(TenantTypeIds.Instance().Photo()); //提示可上传的图片大小、类型 ViewData["attachmentLength"] = tenantAttachmentSettings.MaxAttachmentLength; ViewData["allowedFileExtensions"] = tenantAttachmentSettings.AllowedFileExtensions; //相册下拉框 GetAlbumList(albumId); pageResourceManager.InsertTitlePart("上传照片"); return(View()); }
/// <summary> /// 可设置repository的构造函数(主要用于测试用例) /// </summary> /// <param name="attachmentRepository">附件仓储</param> /// <param name="tenantAttachmentSettings">租户附件设置</param> /// <param name="storeProvider">文件存储Provider</param> public AttachmentService(IAttachmentRepository <T> attachmentRepository, TenantAttachmentSettings tenantAttachmentSettings, IStoreProvider storeProvider) { this.attachmentRepository = attachmentRepository; this.TenantAttachmentSettings = tenantAttachmentSettings; this.StoreProvider = storeProvider; }
/// <summary> /// 重置缩略图 /// </summary> /// <param name="path"></param> /// <param name="settings"></param> private void ResetThumbnails(string path, TenantAttachmentSettings settings) { if (settings.ImageSizeTypes == null || settings.ImageSizeTypes.Count == 0) { return; } if (!Directory.Exists(path)) { return; } List <string> files = Directory.GetFiles(path).ToList(); IStoreProvider storeProvider = DIContainer.Resolve <IStoreProvider>(); List <string> originalList = new List <string>(); List <string> fileList = new List <string>(); foreach (var file in files) { string suffix = "gif,jpg,png,bmp,jpeg"; bool isContinue = true; foreach (var item in suffix.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { if (file.ToLower().EndsWith(item)) { isContinue = false; break; } } if (isContinue) { continue; } string fileName = GetUploadFileName(file); if (originalList.Contains(fileName)) { continue; } originalList.Add(fileName); foreach (var item in settings.ImageSizeTypes) { string name = Path.Combine(path, storeProvider.GetSizeImageName(fileName, item.Size, item.ResizeMethod)); if (!fileList.Contains(name)) { fileList.Add(name); } if (files.Contains(name)) { continue; } try { storeProvider.GetResizedImage(path, fileName, item.Size, item.ResizeMethod); } catch (Exception) { } } } //删除无用数据 foreach (var file in files) { string name = GetFileNameWistOutPath(file); if (!fileList.Contains(file) && GetUploadFileName(file) != name && GetOriginalFileName(file) != name) { System.IO.File.Delete(file); } } string[] paths = Directory.GetDirectories(path); foreach (var item in paths) { ResetThumbnails(item, settings); } }
/// <summary> /// 升级照片附件 /// </summary> /// <returns></returns> private bool UpdatePhotoBySQL(out string message) { SqlConnection sqlConnection = GetConnection(); List <long> photoIds = new List <long>(); List <long> albumIds = new List <long>(); Dictionary <long, List <long> > photosInAlbum = new Dictionary <long, List <long> >(); Directory.SetCurrentDirectory(currentDirectory); int allCount = 0; int moveCount = 0; bool result = false; StringBuilder messageBuilder = new StringBuilder(); try { sqlConnection.Open(); SqlCommand selectCommand = new SqlCommand("select PhotoId,AlbumId from spb_Photos", sqlConnection); SqlDataReader dr = selectCommand.ExecuteReader(CommandBehavior.CloseConnection); while (dr.Read()) { photoIds.Add(dr.GetInt64(0)); albumIds.Add(dr.GetInt64(1)); if (!photosInAlbum.ContainsKey(dr.GetInt64(1))) { photosInAlbum[dr.GetInt64(1)] = new List <long>(); } photosInAlbum[dr.GetInt64(1)].Add(dr.GetInt64(0)); } dr.Close(); sqlConnection.Close(); foreach (var albumId in albumIds) { string newPhotoRelatedPath = GetRelativePathById(albumId, "Photo"); if (!Directory.Exists(newPhotoRelatedPath)) { Directory.CreateDirectory(newPhotoRelatedPath); } foreach (var photoId in photosInAlbum[albumId]) { string oldPhotoRelatedPath = Path.Combine(currentDirectory, GetOldRelativePath("Galleries", photoId)); if (!Directory.Exists(oldPhotoRelatedPath)) { continue; } foreach (var photoFilePath in Directory.GetFiles(oldPhotoRelatedPath)) { allCount++; FileInfo oldFileInfo = new FileInfo(photoFilePath); string newPhotoFilePath = Path.Combine(currentDirectory, newPhotoRelatedPath, oldFileInfo.Name); if (!System.IO.File.Exists(newPhotoFilePath)) { System.IO.File.Move(photoFilePath, newPhotoFilePath); moveCount++; string tenantTypeId = "100302"; TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(tenantTypeId); if (tenantAttachmentSettings != null && tenantAttachmentSettings.ImageSizeTypes != null && tenantAttachmentSettings.ImageSizeTypes.Count > 0) { foreach (var imageSizeType in tenantAttachmentSettings.ImageSizeTypes) { IStoreFile file = storeProvider.GetResizedImage(newPhotoRelatedPath, oldFileInfo.Name, imageSizeType.Size, imageSizeType.ResizeMethod); } } } break; } } } } catch (Exception e) { sqlConnection.Close(); } messageBuilder.AppendFormat("{0}:一共找到{1}个可以升级的照片", storeProvider.JoinDirectory("Old", "Galleries"), allCount); if (moveCount > 0) { result = true; messageBuilder.AppendFormat(",成功升级了{0}个照片", moveCount); } message = messageBuilder.ToString(); return(result); }
/// <summary> /// 构造器 /// </summary> /// <param name="attachmentRepository"></param> /// <param name="tenantAttachmentSettings"></param> /// <param name="storeProvider"></param> public AttachmentService(IAttachmentRepository <Attachment> attachmentRepository, TenantAttachmentSettings tenantAttachmentSettings, IStoreProvider storeProvider) : base(attachmentRepository, tenantAttachmentSettings, storeProvider) { }