public static Attachment AttachCloudEntry(ArgPoint Point, StorageSelectionEntry selEntry) { var a = new Attachment { Name = selEntry.Title }; try { a.Format = (int)GetImgFmt(selEntry.Title); //may throw exception in case of unsupported file format } catch (Exception) { throw new IncorrectAttachmentFormat(); } a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(selEntry.PathName)); a.Title = "";// selEntry.Title; a.Link = selEntry.Title; if (a.Format == (int)AttachmentFormat.Pdf) { a.Thumb = TryCreatePdfThumb(selEntry.PathName); } if (Point != null) { a.ArgPoint = Point; } return(a); }
public static Attachment AttachScreenshot(ArgPoint Point, Bitmap screenshot) { var screenPath = Utils.RandomFilePath(".png"); screenshot.Save(screenPath, ImageFormat.Png); var a = new Attachment(); a.Name = screenPath; a.Format = (int)AttachmentFormat.PngScreenshot; a.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(screenPath)); a.Title = "Screenshot, " + Environment.MachineName + " " + DateTime.Now; a.Link = a.Title; if (Point != null) { a.ArgPoint = Point; } return(a); }
//if URL==null, shows URL input dialog. else uses provided URL, no dialog private static Attachment AttachPdfFromURL(ArgPoint Point, string Url) { string UrlToUse = Url; if (UrlToUse == null) { InpDialog dlg = new InpDialog(); dlg.ShowDialog(); UrlToUse = dlg.Answer; UrlToUse = UrlToUse.ToLower(); if (UrlToUse == null || !UrlToUse.StartsWith("http://") || UrlToUse.EndsWith(".pdf")) { return(null); } } string tmpFile = DownloadPdfFromUrl(UrlToUse); if (tmpFile == null) { return(null); } Attachment res = new Attachment(); res.Name = UrlToUse; res.Format = (int)AttachmentFormat.Pdf; res.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(tmpFile)); res.Title = ""; res.Thumb = TryCreatePdfThumb(tmpFile); res.Link = Url; if (Point != null) { Point.Attachment.Add(res); } ///PublicBoardCtx.Get().SaveChanges(); return(res); }
//if URL==null, shows URL input dialog. else uses provided URL, no dialog private static Attachment AttachFromURL(ArgPoint Point, string Url) { string UrlToUse = Url; if (UrlToUse == null) { InpDialog dlg = new InpDialog(); dlg.ShowDialog(); UrlToUse = dlg.Answer; if (UrlToUse == null || !UrlToUse.StartsWith("http://")) { return(null); } } string tmpFile = DownloadImageFromURL(UrlToUse); if (tmpFile == null) { return(null); } Attachment res = new Attachment(); res.Name = UrlToUse; res.Format = (int)AttachmentFormat.Jpg; //all downloads are jpg res.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(tmpFile)); res.Title = ""; res.Link = Url; if (Point != null) { Point.Attachment.Add(res); } //PublicBoardCtx.Get().SaveChanges(); return(res); }
private static Attachment AttachAsBlob(string filter, AttachmentFormat format, bool autoInferenceOfFormat, ArgPoint Point) { var openFileDialog1 = new OpenFileDialog { Filter = filter, RestoreDirectory = true }; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string attachmentName = Path.GetFileName(openFileDialog1.FileName); var a = new Attachment { Name = attachmentName, Title = attachmentName, Link = openFileDialog1.FileName }; if (autoInferenceOfFormat) { format = GetImgFmt(openFileDialog1.FileName); } switch (format) { case AttachmentFormat.Pdf: a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(openFileDialog1.FileName)); a.Thumb = TryCreatePdfThumb(openFileDialog1.FileName); break; case AttachmentFormat.Jpg: a.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(openFileDialog1.FileName)); break; case AttachmentFormat.Png: a.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(openFileDialog1.FileName)); break; case AttachmentFormat.Bmp: a.MediaData = DaoUtils.CreateMediaData(ImgFileToBytes(openFileDialog1.FileName)); break; case AttachmentFormat.ExcelDocSet: a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(openFileDialog1.FileName)); break; case AttachmentFormat.WordDocSet: a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(openFileDialog1.FileName)); break; case AttachmentFormat.PowerPointDocSet: a.MediaData = DaoUtils.CreateMediaData(AnyFileToBytes(openFileDialog1.FileName)); break; } a.Format = (int)format; a.Name = attachmentName; if (Point != null) { Point.Attachment.Add(a); } return(a); } return(null); }