//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); }
//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); }