protected void GeneratePreview() { int prevHash = this.GetPreviewHash(); if (this.prevImageHash == prevHash) { return; } this.prevImageHash = prevHash; if (this.prevImage != null) { this.prevImage.Dispose(); } this.prevImage = null; this.Height = 22; if (this.component != null) { this.prevImage = PreviewProvider.GetPreviewImage(this.component, this.ClientRectangle.Width - 4 - 22, 64 - 4, PreviewSizeMode.FixedHeight); if (this.prevImage != null) { this.Height = 64; var avgColor = this.prevImage.GetAverageColor(); this.prevImageLum = avgColor.GetLuminance(); } } }
protected void GeneratePreviewImage() { if (this.prevImageValue == this.value) { return; } this.prevImageValue = this.value; if (this.prevImage != null) { this.prevImage.Dispose(); } this.prevImage = null; if (this.value != null) { this.prevImage = PreviewProvider.GetPreviewImage(this.value, this.ClientRectangle.Width - 2, this.ClientRectangle.Height - 2, PreviewSizeMode.FixedHeight); if (this.prevImage != null) { var avgColor = this.prevImage.GetAverageColor(); this.prevImageLum = avgColor.GetLuminance(); } } this.Invalidate(); }
protected override Bitmap GeneratePreviewFrame(int frameIndex) { if (this.value == null) { return(null); } else if (frameIndex == -1) { return(PreviewProvider.GetPreviewImage( this.value, this.ClientRectangle.Width - 2, Math.Min(BigHeight - 2, this.value.Height), PreviewSizeMode.FixedHeight)); } else { if (this.value.MainLayer == null) { return(null); } Rect pxRect; this.value.LookupAtlas(frameIndex, out pxRect); Pixmap.Layer subImage = this.value.MainLayer.CloneSubImage((int)pxRect.X, (int)pxRect.Y, (int)pxRect.W, (int)pxRect.H); return(subImage.ToBitmap()); } }
protected void GeneratePreview() { int prevHash = this.GetPreviewHash(); if (this.prevImageHash == prevHash) return; this.prevImageHash = prevHash; this.StopPreviewSound(); if (this.prevSound != null) this.prevSound.Dispose(); this.prevSound = null; if (this.prevImage != null) this.prevImage.Dispose(); this.prevImage = null; this.Height = 22; Resource res = (this.DisplayedValue as IContentRef).Res; if (res != null) { this.prevImage = PreviewProvider.GetPreviewImage(res, this.ClientRectangle.Width - 4 - 22, 64 - 4, PreviewSizeMode.FixedHeight); if (this.prevImage != null) { this.Height = 64; var avgColor = this.prevImage.GetAverageColor(); this.prevImageLum = avgColor.GetLuminance(); } this.prevSound = PreviewProvider.GetPreviewSound(res); } }
protected override void GeneratePreview() { base.GeneratePreview(); this.StopPreviewSound(); if (this.prevSound != null) { this.prevSound.Dispose(); } this.prevSound = null; if (this.prevImage != null) { this.prevImage.Dispose(); } this.prevImage = null; this.Height = 22; if (this.component != null) { this.prevImage = PreviewProvider.GetPreviewImage(this.component, this.ClientRectangle.Width - 4 - 22, 64 - 4, PreviewSizeMode.FixedHeight); if (this.prevImage != null) { this.Height = 64; var avgColor = this.prevImage.GetAverageColor(); this.prevImageLum = avgColor.GetLuminance(); } this.prevSound = PreviewProvider.GetPreviewSound(this.component); } }
public static string GetMessageWithAttachInfo(PostpramsInfo postPramsInfo, int allowGetAttach, string[] hideAttachIdArray, Int32 pid, Int32 posterid, Attachment attachInfo, string message) { if (Utils.InArray(attachInfo.ID.ToString(), hideAttachIdArray)) { return(message); } if ((attachInfo.ReadPerm <= postPramsInfo.Usergroupreadaccess || posterid == postPramsInfo.CurrentUserid) && allowGetAttach == 1) { attachInfo.AllowRead = true; } else { attachInfo.AllowRead = false; } attachInfo.Getattachperm = allowGetAttach; attachInfo.FileName = attachInfo.FileName.ToString().Replace("\\", "/"); if (message.IndexOf("[attach]" + attachInfo.ID + "[/attach]") != -1 || message.IndexOf("[attachimg]" + attachInfo.ID + "[/attachimg]") != -1) { string attachReplacement = Attachments.GetAttachReplacement(postPramsInfo, allowGetAttach, attachInfo); Regex regex = new Regex(string.Format("\\[attach\\]{0}\\[/attach\\]|\\[attachimg\\]{0}\\[/attachimg\\]", attachInfo.ID)); message = regex.Replace(message, attachReplacement, 1); message = message.Replace("[attach]" + attachInfo.ID + "[/attach]", string.Empty); message = message.Replace("[attachimg]" + attachInfo.ID + "[/attachimg]", string.Empty); if (attachInfo.Pid == pid) { attachInfo.Inserted = true; } } else { if (attachInfo.Pid == pid) { //attachInfo.Attachimgpost = (Attachment.IsImgFilename(attachInfo.Name) ? 1 : 0); var instance = PreviewProvider.GetInstance(Path.GetExtension(attachInfo.FileName).Remove(0, 1).Trim()); if (instance != null) { if (attachInfo.FileName.StartsWith("http://") || attachInfo.FileName.StartsWith("ftp://")) { instance.UseFTP = true; attachInfo.Preview = instance.GetPreview(attachInfo.FileName, attachInfo); } else { instance.UseFTP = false; string fileName = ""; if (!attachInfo.FileName.Contains("://")) { fileName = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/" + attachInfo.FileName); } attachInfo.Preview = instance.GetPreview(fileName, attachInfo); } } } } return(message); }
public PreviewableFileEntryContext(FileEntryContext context, PreviewProvider previewProvider) { this.Name = context.Name; this.Length = context.Length; this.ModifiedDate = context.ModifiedDate; this.FolderId = context.FolderId; this.Path = context.Path; this.PreviewProvider = previewProvider; }
private PhotoAttachmentViewModel(PhotoAttachmentModel photoModel, bool isReadonly) : base(photoModel, isReadonly) { if (photoModel.PreviewDataBlob?.Any() ?? false) { DispatcherHelper.InvokeOnDispatcher(() => //DispatcherHelper.BeginInvokeOnDispatcher(() => { PreviewProvider.SetPreview(photoModel); Preview.SetPreviewSource(PreviewProvider.GetPreview(photoModel.Id)); }); } }
private void UpdatePreview() { PreviewImage.Image = null; var previewImage = PreviewProvider.GetPreviewImage(SelectedObject, PreviewImage.Width, PreviewImage.Height, PreviewSizeMode.FixedBoth); if (previewImage != null) { PreviewImage.Image = previewImage; } PathLabel.Text = SelectedObject.Path; }
protected void GeneratePreview() { int ovLen = this.value != null && this.value.OggVorbisData != null ? this.value.OggVorbisData.Length : 0; if (this.prevImageValue == ovLen) { return; } this.prevImageValue = ovLen; this.StopPreviewSound(); if (this.prevSound != null) { this.prevSound.Dispose(); } this.prevSound = null; if (this.prevImage != null) { this.prevImage.Dispose(); } this.prevImage = null; if (this.value != null) { this.prevImage = PreviewProvider.GetPreviewImage(this.value, this.ClientRectangle.Width - 2, this.ClientRectangle.Height - 2, PreviewSizeMode.FixedHeight); if (this.prevImage != null) { var avgColor = this.prevImage.GetAverageColor(); this.prevImageLum = avgColor.GetLuminance(); } this.prevSound = PreviewProvider.GetPreviewSound(this.value); } this.Invalidate(); }
public PreviewableFileEntryContext(FileInfo file, string id, string path, PreviewProvider previewProvider) : base(file, id, path) { PreviewProvider = previewProvider; }
protected override bool IsAcceptableFileType(string filePath) { return(PreviewProvider.IsImage(filePath)); }
public string PreviewRefactoring() => PreviewProvider?.Preview(this) ?? string.Empty;
/// <summary> /// 保存上传的文件 /// </summary> /// <param name="categoryid">商品分类id</param> /// <param name="MaxAllowFileCount">最大允许的上传文件个数</param> /// <param name="MaxSizePerDay">每天允许的附件大小总数</param> /// <param name="MaxFileSize">单个最大允许的文件字节数</param>/// /// <param name="TodayUploadedSize">今天已经上传的附件字节总数</param> /// <param name="AllowFileType">允许的文件类型, 以string[]形式提供</param> /// <param name="config">附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/论坛存入不同目录 2=按论坛存入不同目录 3=按文件类型存入不同目录</param> /// <param name="watermarkstatus">图片水印位置</param> /// <param name="filekey">File控件的Key(即Name属性)</param> /// <returns>文件信息结构</returns> public static Goodsattachmentinfo[] SaveRequestFiles(int categoryId, int MaxAllowFileCount, int MaxSizePerDay, int MaxFileSize, int TodayUploadedSize, string AllowFileType, int waterMarkStatus, GeneralConfigInfo config, string fileKey) { string[] tmp = Utils.SplitString(AllowFileType, "\r\n"); string[] AllowFileExtName = new string[tmp.Length]; int[] MaxSize = new int[tmp.Length]; for (int i = 0; i < tmp.Length; i++) { AllowFileExtName[i] = Utils.CutString(tmp[i], 0, tmp[i].LastIndexOf(",")); MaxSize[i] = Utils.StrToInt(Utils.CutString(tmp[i], tmp[i].LastIndexOf(",") + 1), 0); } int saveFileCount = 0; int fCount = HttpContext.Current.Request.Files.Count; for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(fileKey)) { saveFileCount++; } } Goodsattachmentinfo[] attachmentInfo = new Goodsattachmentinfo[saveFileCount]; if (saveFileCount > MaxAllowFileCount) { return(attachmentInfo); } saveFileCount = 0; Random random = new Random(unchecked ((int)DateTime.Now.Ticks)); for (int i = 0; i < fCount; i++) { if (!HttpContext.Current.Request.Files[i].FileName.Equals("") && HttpContext.Current.Request.Files.AllKeys[i].Equals(fileKey)) { string fileName = Path.GetFileName(HttpContext.Current.Request.Files[i].FileName); string fileExtName = Utils.CutString(fileName, fileName.LastIndexOf(".") + 1).ToLower(); string fileType = HttpContext.Current.Request.Files[i].ContentType.ToLower(); int fileSize = HttpContext.Current.Request.Files[i].ContentLength; string newFileName = ""; attachmentInfo[saveFileCount] = new Goodsattachmentinfo(); attachmentInfo[saveFileCount].Sys_noupload = ""; // 判断 文件扩展名/文件大小/文件类型 是否符合要求 if (!(Utils.IsImgFilename(fileName) && !fileType.StartsWith("image"))) { int extNameId = Utils.GetInArrayID(fileExtName, AllowFileExtName); if (extNameId >= 0 && (fileSize <= MaxSize[extNameId]) && (MaxFileSize >= fileSize /*|| MaxAllSize == 0*/) && (MaxSizePerDay - TodayUploadedSize >= fileSize)) { TodayUploadedSize = TodayUploadedSize + fileSize; string UploadDir = Utils.GetMapPath(BaseConfigs.GetForumPath + "upload/mall/"); StringBuilder saveDir = new StringBuilder(""); //附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/论坛存入不同目录 2=按论坛存入不同目录 3=按文件类型存入不同目录 if (config.Attachsave == 1) { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(categoryId.ToString()); saveDir.Append(Path.DirectorySeparatorChar); } else if (config.Attachsave == 2) { saveDir.Append(categoryId); saveDir.Append(Path.DirectorySeparatorChar); } else if (config.Attachsave == 3) { saveDir.Append(fileExtName); saveDir.Append(Path.DirectorySeparatorChar); } else { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append(Path.DirectorySeparatorChar); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append(Path.DirectorySeparatorChar); } newFileName = (Environment.TickCount & int.MaxValue).ToString() + i + random.Next(1000, 9999) + "." + fileExtName; //临时文件名称变量. 用于当启动远程附件之后,先上传到本地临时文件夹的路径信息 string tempFileName = ""; //当支持FTP上传附件且不保留本地附件时 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { // 如果指定目录不存在则建立临时路径 if (!Directory.Exists(UploadDir + "temp\\")) { Utils.CreateDir(UploadDir + "temp\\"); } tempFileName = "temp\\" + newFileName; } else { // 如果指定目录不存在则建立 if (!Directory.Exists(UploadDir + saveDir.ToString())) { Utils.CreateDir(UploadDir + saveDir.ToString()); } } newFileName = saveDir.ToString() + newFileName; try { // 如果是bmp jpg png图片类型 if ((fileExtName == "bmp" || fileExtName == "jpg" || fileExtName == "jpeg" || fileExtName == "png") && fileType.StartsWith("image")) { Image img = Image.FromStream(HttpContext.Current.Request.Files[i].InputStream); if (config.Attachimgmaxwidth > 0 && img.Width > config.Attachimgmaxwidth) { attachmentInfo[saveFileCount].Sys_noupload = "图片宽度为" + img.Width + ", 系统允许的最大宽度为" + config.Attachimgmaxwidth; } if (config.Attachimgmaxheight > 0 && img.Height > config.Attachimgmaxheight) { attachmentInfo[saveFileCount].Sys_noupload = "图片高度为" + img.Width + ", 系统允许的最大高度为" + config.Attachimgmaxheight; } if (attachmentInfo[saveFileCount].Sys_noupload == "") { if (waterMarkStatus == 0) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); } else { HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } attachmentInfo[saveFileCount].Filesize = fileSize; } else { if (config.Watermarktype == 1 && File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic))) { //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { ForumUtils.AddImageSignPic(img, UploadDir + tempFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); } else { ForumUtils.AddImageSignPic(img, UploadDir + newFileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "watermark/" + config.Watermarkpic), config.Watermarkstatus, config.Attachimgquality, config.Watermarktransparency); } } else { string watermarkText; watermarkText = config.Watermarktext.Replace("{1}", config.Forumtitle); watermarkText = watermarkText.Replace("{2}", "http://" + DNTRequest.GetCurrentFullHost() + "/"); watermarkText = watermarkText.Replace("{3}", Utils.GetDate()); watermarkText = watermarkText.Replace("{4}", Utils.GetTime()); //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { ForumUtils.AddImageSignText(img, UploadDir + tempFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); } else { ForumUtils.AddImageSignText(img, UploadDir + newFileName, watermarkText, config.Watermarkstatus, config.Attachimgquality, config.Watermarkfontname, config.Watermarkfontsize); } } //当支持FTP上传附件且不保留本地附件模式时,则读取临时目录下的文件信息 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + tempFileName).Length; } else { attachmentInfo[saveFileCount].Filesize = new FileInfo(UploadDir + newFileName).Length; } } } } else { attachmentInfo[saveFileCount].Filesize = fileSize; //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); } else { HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } } catch { //当上传目录和临时文件夹都没有上传的文件时 if (!(Utils.FileExists(UploadDir + tempFileName)) && (!(Utils.FileExists(UploadDir + newFileName)))) { attachmentInfo[saveFileCount].Filesize = fileSize; //当支持FTP上传附件且不保留本地附件模式时,则先上传到临时目录下 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { HttpContext.Current.Request.Files[i].SaveAs(UploadDir + tempFileName); } else { HttpContext.Current.Request.Files[i].SaveAs(UploadDir + newFileName); } } } try { //加载文件预览类指定方法 IPreview preview = PreviewProvider.GetInstance(fileExtName.Trim()); if (preview != null) { preview.UseFTP = (FTPs.GetMallAttachInfo.Allowupload == 1) ? true : false; //当支持FTP上传附件且不保留本地附件模式时 if (FTPs.GetMallAttachInfo.Allowupload == 1 && FTPs.GetMallAttachInfo.Reservelocalattach == 0) { preview.OnSaved(UploadDir + tempFileName); } else { preview.OnSaved(UploadDir + newFileName); } } } catch { } //当支持FTP上传附件时,使用FTP上传远程附件 if (FTPs.GetMallAttachInfo.Allowupload == 1) { FTPs ftps = new FTPs(); //当不保留本地附件模式时,在上传完成之后删除本地tempfilename文件 if (FTPs.GetMallAttachInfo.Reservelocalattach == 0) { ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + tempFileName, FTPs.FTPUploadEnum.ForumAttach); } else { ftps.UpLoadFile(newFileName.Substring(0, newFileName.LastIndexOf("\\")), UploadDir + newFileName, FTPs.FTPUploadEnum.ForumAttach); } } } else { if (extNameId < 0) { attachmentInfo[saveFileCount].Sys_noupload = "文件格式无效"; } else if (MaxSizePerDay - TodayUploadedSize < fileSize) { attachmentInfo[saveFileCount].Sys_noupload = "文件大于今天允许上传的字节数"; } else if (fileSize > MaxSize[extNameId]) { attachmentInfo[saveFileCount].Sys_noupload = "文件大于该类型附件允许的字节数"; } else { attachmentInfo[saveFileCount].Sys_noupload = "文件大于单个文件允许上传的字节数"; } } } else { attachmentInfo[saveFileCount].Sys_noupload = "文件格式无效"; } //当支持FTP上传附件时 if (FTPs.GetMallAttachInfo.Allowupload == 1) { attachmentInfo[saveFileCount].Filename = FTPs.GetMallAttachInfo.Remoteurl + "/" + newFileName.Replace("\\", "/"); } else { attachmentInfo[saveFileCount].Filename = "mall/" + newFileName; } attachmentInfo[saveFileCount].Description = fileExtName; attachmentInfo[saveFileCount].Filetype = fileType; attachmentInfo[saveFileCount].Attachment = fileName; attachmentInfo[saveFileCount].Postdatetime = DateTime.Now.ToString(); attachmentInfo[saveFileCount].Sys_index = i; saveFileCount++; } } return(attachmentInfo); }