public static string GetPastableHtml(Attachment a, string baseUrl) { if (IsGraphicFormat((AttachmentFormat)a.Format)) { var imgThumbUrl = string.Format("{0}/discsvc.svc/Attachment({1})/$value", baseUrl, a.Id); return string.Format("<img src=\"{0}\">", imgThumbUrl); } if (a.Format == (int)AttachmentFormat.Youtube) { //return // string.Format( // "<iframe width=\"640\" height=\"360\" src=\"{0}\" frameborder=\"0\" allowfullscreen></iframe>", // a.VideoEmbedURL); return string.Format("<img src=\"{0}\" style=\"max-width:800px\">", a.VideoThumbURL); } if (a.Format == (int)AttachmentFormat.Pdf && a.Thumb!=null) { var base64img = Convert.ToBase64String(a.Thumb); return string.Format("<img src=\"data:image/jpeg;base64,{0}\" style=\"max-width:800px\">", base64img); } return ""; }
public static YouTubeInfo AttachToYtInfo(Attachment a) { YouTubeInfo info = new YouTubeInfo(); info.ThumbNailUrl = a.VideoThumbURL; info.EmbedUrl = a.VideoEmbedURL; info.LinkUrl = a.VideoLinkURL; return info; }
public static bool IsGraphicFormat(Attachment a) { return a.Format == (int) AttachmentFormat.Bmp || a.Format == (int) AttachmentFormat.Jpg || a.Format == (int) AttachmentFormat.Png || a.Format == (int) AttachmentFormat.PngScreenshot; }
public static string GetAttachmentLink(Attachment a, string baseUrl, int i) { var target = getAttachmentLink(a, baseUrl); if (a.Format == (int)AttachmentFormat.PngScreenshot) return string.Format("<a target=\"_blank\" href=\"{0}\">{1}. {2}</a>",target, i, a.Title); return string.Format("<a target=\"_blank\" href=\"{1}\">{0}. {1}</a>", i, target); }
public static BitmapSource GetAttachmentBitmap2(Attachment a) { switch (a.Format) { case (int) AttachmentFormat.Jpg: case (int) AttachmentFormat.Png: case (int) AttachmentFormat.Bmp: case (int) AttachmentFormat.PngScreenshot: return LoadImageFromBlob(a.MediaData.Data); } return null; }
private void AttachFile(ArgPoint ap, string command) { if (_d == null) return; Attachment a = new Attachment(); if (AttachmentManager.ProcessAttachCmd(null, AttachCmd.ATTACH_IMG_OR_PDF, ref a) != null) { a.Discussion = _d; a.Person = getFreshPerson(); insertMedia(a); } }
private static string GetPastableHtml(Attachment a) { var imgThumbUrl = string.Format("http://{0}/discsvc/discsvc.svc/Attachment({1})/$value", ConfigManager.ServiceServer, a.Id); if (AttachmentManager.IsGraphicFormat(a)) { return string.Format("<p>\n <img src=\"{0}\"/> \n</p>\n", imgThumbUrl); } else if (a.Format == (int) AttachmentFormat.Youtube) { return string.Format( "<iframe width=\"640\" height=\"360\" src=\"{0}\" frameborder=\"0\" allowfullscreen></iframe>", a.VideoEmbedURL); } return ""; }
public static string GetPastableHtml(Attachment a, string baseUrl) { var imgThumbUrl = string.Format("{0}/discsvc.svc/Attachment({1})/$value", baseUrl, a.Id); if (IsGraphicFormat((AttachmentFormat)a.Format)) { return string.Format("<img src=\"{0}\">", imgThumbUrl); } if (a.Format == (int)AttachmentFormat.Youtube) { return string.Format( "<iframe width=\"640\" height=\"360\" src=\"{0}\" frameborder=\"0\" allowfullscreen></iframe>", a.VideoEmbedURL); } return ""; }
public SOutAttachment(Attachment attachment, bool includeMediaData) { Id = attachment.Id; Name = attachment.Name; Format = attachment.Format; VideoThumbURL = attachment.VideoThumbURL; VideoEmbedURL = attachment.VideoEmbedURL; VideoLinkURL = attachment.VideoLinkURL; Link = attachment.Link; Title = attachment.Title; Thumb = attachment.Thumb; OrderNumber = attachment.OrderNumber; ArgPointId = attachment.ArgPoint != null ? attachment.ArgPoint.Id : (int?)null; PersonId = attachment.Person.Id; DiscussionId = attachment.Discussion != null ? attachment.Discussion.Id : (int?)null; PersonWithAvatarId = attachment.PersonWithAvatar != null ? attachment.PersonWithAvatar.Id : (int?)null; MediaDataId = attachment.MediaData.Id; MediaData = includeMediaData ? attachment.MediaData.Data : null; }
public static bool IsGraphicFormat(Attachment a) { return IsGraphicFormat((AttachmentFormat)a.Format); }
public static object RunViewer(Attachment a, bool localRequest) { if (a == null) return null; if (a.Format == (int)AttachmentFormat.Pdf && a.MediaData != null) { string pdfPathName = Utils.RandomFilePath(".pdf"); try { using (var fs = new FileStream(pdfPathName, FileMode.Create)) { fs.Write(a.MediaData.Data, 0, a.MediaData.Data.Length); } //Process.Start(pdfPathName); Utils.ReportMediaOpened(StEvent.PdfOpened, a); var pdfReader = ReaderWindow2.Instance(pdfPathName, a.Id, a.ArgPoint != null ? (int?)a.ArgPoint.Topic.Id : null, localRequest); pdfReader.Show(); return pdfReader; } catch { } } else if (MiniAttachmentManager.IsGraphicFormat(a)) { if (a.Format == (int) AttachmentFormat.PngScreenshot) Utils.ReportMediaOpened(StEvent.ScreenshotOpened, a); else Utils.ReportMediaOpened(StEvent.ImageOpened, a); if (a.MediaData.Data != null) { if (!ExplanationModeMediator.Inst.ImageViewerOpen) { var wnd = ImageWindow.Instance(a.Id, a.ArgPoint != null ? a.ArgPoint.Topic.Id : -1, localRequest); wnd.img.Source = LoadImageFromBlob(a.MediaData.Data); wnd.Show(); wnd.Activate(); return wnd; } } } else { //office file var ext = Path.GetExtension(a.Link).ToLower(); string pathName = Utils.RandomFilePath(ext); try { using (var fs = new FileStream(pathName, FileMode.Create)) { fs.Write(a.MediaData.Data, 0, a.MediaData.Data.Length); } Process.Start(pathName); } catch (Exception e) { MessageDlg.Show(e.ToString(), "Error"); } } return null; }
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; }
/// <summary> /// Deprecated Method for adding a new object to the Attachment EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToAttachment(Attachment attachment) { base.AddObject("Attachment", attachment); }
public Discussion cloneDiscussion(DiscCtx ctx, Discussion original, Person moderator, int i) { var d = new Discussion(); d.Subject = injectNumber(original.Subject, i); //copy background d.Background = new RichText(); d.Background.Text = original.Background.Text; foreach (var src in original.Background.Source) { var s = new Source(); s.Text = src.Text; s.OrderNumber = src.OrderNumber; d.Background.Source.Add(s); } foreach (var media in original.Attachment) { var attach = new Attachment(); attach.Discussion = d; attach.Format = media.Format; attach.Link = media.Link; attach.Name = media.Name; attach.Title = media.Title; attach.VideoEmbedURL = media.VideoEmbedURL; attach.VideoLinkURL = media.VideoLinkURL; attach.VideoThumbURL = media.VideoThumbURL; attach.OrderNumber = media.OrderNumber; if (media.Thumb != null) attach.Thumb = (byte[]) media.Thumb.Clone(); if (media.MediaData != null && media.MediaData.Data != null) { var mediaClone = new MediaData(); mediaClone.Data = (byte[]) media.MediaData.Data.Clone(); attach.MediaData = mediaClone; } attach.Person = moderator; d.Attachment.Add(attach); } d.HtmlBackground = original.HtmlBackground; foreach (var topic in original.Topic) { var t = new Topic(); t.Name = injectNumber(topic.Name, i); t.Person.Add(moderator); d.Topic.Add(t); } return d; }
private static ImageSource ProcessCommand2(ArgPoint Point, AttachCmd cmd, string Url, ref Attachment a) { a = null; try { switch (cmd) { case AttachCmd.ATTACH_IMG_OR_PDF: a = AttachmentManager.AttachLocalFile(Point); if (a != null) return GetAttachmentBitmap3(a); break; case AttachCmd.ATTACH_PDF: a = AttachmentManager.AttachPDF(Point); if (a != null) return GetAttachmentBitmap3(a); break; case AttachCmd.ATTACH_PDF_FROM_URL: a = AttachmentManager.AttachPdfFromURL(Point, Url); if (a != null) return GetAttachmentBitmap3(a); break; case AttachCmd.ATTACH_IMAGE: a = AttachmentManager.AttachPicture(Point); if (a != null) return GetAttachmentBitmap3(a); break; case AttachCmd.ATTACH_IMAGE_URL: a = AttachmentManager.AttachFromURL(Point, Url); if (a != null) return GetAttachmentBitmap3(a); break; case AttachCmd.ATTACH_YOUTUBE: a = AttachmentManager.AttachFromYoutube(Point, Url); if (a != null) return new BitmapImage(); //returning stub for external error-checking break; } } catch (Exception) { MessageDlg.Show( "Cannot process attachment. If it's link, check it's correct. If it's file, ensure program has permissions to access it", "Error"); return null; } return null; }
//asks for URL public static ImageSource ProcessAttachCmd(ArgPoint Point, AttachCmd cmd, ref Attachment a) { return ProcessCommand2(Point, cmd, null, ref a); }
//uses provided URL public static ImageSource ProcessAttachCmd(ArgPoint Point, string Url, ref Attachment a) { var cmd = DeriveCmdFromUrl(Url); return ProcessCommand2(Point, cmd, Url, ref a); }
public static BitmapSource GetAttachmentBitmap3(Attachment a) { if (a == null) return null; switch (a.Format) { case (int) AttachmentFormat.Pdf: if (a.Thumb != null) return LoadImageFromBlob(a.Thumb); else return PdfIcon; case (int) AttachmentFormat.ExcelDocSet: return ExcelIcon; case (int) AttachmentFormat.WordDocSet: return WordIcon; case (int) AttachmentFormat.PowerPointDocSet: return PowerPointIcon; case (int) AttachmentFormat.Jpg: case (int) AttachmentFormat.Png: case (int) AttachmentFormat.PngScreenshot: case (int) AttachmentFormat.Bmp: return LoadImageFromBlob(a.MediaData.Data); case (int) AttachmentFormat.Youtube: if (a.Thumb != null) return LoadImageFromBlob(a.Thumb); else return GetYoutubeThumb(a.VideoThumbURL); } return null; }
public Stream GetWriteStream(object entity, string etag, bool? checkETagForEquality, DataServiceOperationContext operationContext) { if (checkETagForEquality != null) { // This stream provider implementation does not support ETags associated with BLOBs. // This means that we do not track concurrency for a media resource // and last-in wins on updates. throw new DataServiceException(400, "This demo does not support ETags associated with BLOBs"); } Attachment attach = entity as Attachment; if (attach == null) { throw new DataServiceException(500, "Internal Server Error: " + "the Media Link Entry could not be determined."); } String contentType = operationContext.RequestHeaders["Content-Type"]; if (contentType == "image/jpeg") { attach.Format = (int) AttachmentFormat.Jpg; } else if (contentType == "application/pdf") { attach.Format = (int) AttachmentFormat.Pdf; } else { attach.Format = (int) AttachmentFormat.None; } attach.Name = "Name"; attach.Title = "title"; attach.Link = "Link"; if (attach.MediaData == null) { //if media data doesn't exist, it's POST request and attach is newly created MLE. we create the media data attach.MediaData = new MediaData(); } //handle POST and PUT _cachedEntity = attach; _mediaStream = new MemoryStream(); return _mediaStream; }
private void btnAttachFromUrl_Click_1(object sender, RoutedEventArgs e) { if (_d == null) return; InpDialog dlg = new InpDialog(); dlg.ShowDialog(); string URL = dlg.Answer; if (URL == null) return; Attachment a = new Attachment(); if (AttachmentManager.ProcessAttachCmd(null, URL, ref a) != null) { a.Discussion = _d; a.Person = getFreshPerson(); insertMedia(a); } }
//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; }
//swaps current source with its neighbour public bool swapWithNeib(bool withTopNeib, Attachment current) { if (current == null) return false; IEnumerable<Attachment> media = null; //there is no neighbour, nothing to do if (current.ArgPoint != null) { media = current.ArgPoint.Attachment; if (current.ArgPoint.Attachment.Count <= 1) return false; } else { if (current.Discussion == null) return false; media = current.Discussion.Attachment; if (current.Discussion.Attachment.Count <= 1) return false; } //ensure strong ordering var orderNr = 0; foreach (var att in media.OrderBy(at0 => at0.OrderNumber)) { att.OrderNumber = orderNr++; } if (withTopNeib) { Attachment topNeib = null; foreach (var a in media.OrderBy(a0 => a0.OrderNumber)) { if (a == current) break; else topNeib = a; } //current attachment is topmost, nothing to do if (topNeib == null) return false; var tmp = topNeib.OrderNumber; topNeib.OrderNumber = current.OrderNumber; current.OrderNumber = tmp; return true; } else { Attachment botNeib = null; foreach (var a in media.OrderBy(a0 => a0.OrderNumber).Reverse()) { if (a == current) break; else botNeib = a; } //current attachment is bottommost, nothing to do if (botNeib == null) return false; var tmp = botNeib.OrderNumber; botNeib.OrderNumber = current.OrderNumber; current.OrderNumber = tmp; return true; } }
static string getAttachmentLink(Attachment a, string baseUrl) { var mediaUrl = string.Format("{0}/discsvc.svc/Attachment({1})/$value", baseUrl, a.Id); if (IsGraphicFormat((AttachmentFormat)a.Format) && a.Format!=(int)AttachmentFormat.PngScreenshot) { if (a.Format != (int)AttachmentFormat.PngScreenshot && !string.IsNullOrWhiteSpace(a.Link)) return a.Link; } if (a.Format == (int)AttachmentFormat.Youtube) { return a.VideoLinkURL; } if (a.Format == (int)AttachmentFormat.Pdf) { if (!string.IsNullOrWhiteSpace(a.Link)) return a.Link; return mediaUrl; } return mediaUrl; }
//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; }
public void onAttachmentUpDown(object sender, RoutedEventArgs e) { try { _attachmentToReposition = ((FrameworkElement) e.OriginalSource).DataContext as Attachment; medPopup.IsOpen = true; HwndSource hwndSource = (HwndSource) PresentationSource.FromVisual((Visual) VisualTreeHelper.GetParent(medPopup.Child)); hwndSource.EnableSurfaceInput(); } catch (Exception) { _attachmentToReposition = null; } }
//if Url!=null, uses it. otherwice asks for URL private static Attachment AttachFromYoutube(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; } BusyWndSingleton.Show("Processing Youtube attachment..."); Attachment res = new Attachment(); try { YouTubeInfo videoInfo = YouTubeProvider.LoadVideo(URLToUse); if (videoInfo == null) return null; res.Format = (int) AttachmentFormat.Youtube; res.VideoEmbedURL = videoInfo.EmbedUrl; res.VideoThumbURL = videoInfo.ThumbNailUrl; res.VideoLinkURL = videoInfo.LinkUrl; res.Link = videoInfo.LinkUrl; res.Title = videoInfo.VideoTitle; res.Name = URLToUse; res.Thumb = ImageToBytes(GetYoutubeThumb(videoInfo.ThumbNailUrl), new JpegBitmapEncoder()); if (Point != null) Point.Attachment.Add(res); ///PublicBoardCtx.Get().SaveChanges(); } finally { BusyWndSingleton.Hide(); } return res; }
/// <summary> /// Create a new Attachment object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="format">Initial value of the Format property.</param> /// <param name="link">Initial value of the Link property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="orderNumber">Initial value of the OrderNumber property.</param> public static Attachment CreateAttachment(global::System.Int32 id, global::System.String name, global::System.Int32 format, global::System.String link, global::System.String title, global::System.Int32 orderNumber) { Attachment attachment = new Attachment(); attachment.Id = id; attachment.Name = name; attachment.Format = format; attachment.Link = link; attachment.Title = title; attachment.OrderNumber = orderNumber; return attachment; }
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; }
void EmitMediaCell(Attachment a, int i) { if(a==null) return; #line default #line hidden #line 228 "C:\Users\User\Documents\Visual Studio 2013\Projects\TDS4\discussions\DiscSvc2\Reporting\Report.tt" this.Write("\t\t<div style=\"padding-top:40px\">\r\n\t\t\t"); #line default #line hidden #line 230 "C:\Users\User\Documents\Visual Studio 2013\Projects\TDS4\discussions\DiscSvc2\Reporting\Report.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Helpers.GetPastableHtml(a, BaseUrl))); #line default #line hidden #line 230 "C:\Users\User\Documents\Visual Studio 2013\Projects\TDS4\discussions\DiscSvc2\Reporting\Report.tt" this.Write("\t\r\n\t\t\t\r\n\t\t\t<p> "); #line default #line hidden #line 232 "C:\Users\User\Documents\Visual Studio 2013\Projects\TDS4\discussions\DiscSvc2\Reporting\Report.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Helpers.GetAttachmentLink(a, BaseUrl, i))); #line default #line hidden #line 232 "C:\Users\User\Documents\Visual Studio 2013\Projects\TDS4\discussions\DiscSvc2\Reporting\Report.tt" this.Write(" </p>\t\r\n\t\t</div> \r\n\t\t"); #line default #line hidden #line 234 "C:\Users\User\Documents\Visual Studio 2013\Projects\TDS4\discussions\DiscSvc2\Reporting\Report.tt" }
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; }