public static void RunViewer(string pathName, int attachmentId, int?topicId, bool localRequest) { var ext = Path.GetExtension(pathName).ToLower(); if (ext == ".pdf") { var pdfReader = ReaderWindow2.Instance(pathName, attachmentId, topicId, localRequest); pdfReader.Show(); } else if (ext == ".jpg" || ext == ".jpeg" || ext == ".bmp" || ext == ".png") { if (!ExplanationModeMediator.Inst.ImageViewerOpen) { var wnd = ImageWindow.Instance(ImageWindow.NO_ATTACHMENT, ImageWindow.NO_ATTACHMENT, localRequest); var bi = new BitmapImage(new Uri(pathName)); wnd.img.Source = bi; wnd.Show(); wnd.Activate(); } } else { try { Process.Start(pathName); } catch (Exception) { } } }
static async Task WorkWithAttachmentAsync(LargeBadgeView lbv, Random rnd) { Tuple <WebkitBrowserWindow, ImageWindow, ReaderWindow2> result = await lbv.BotLaunchRandomAttachmentAsync(rnd); WebkitBrowserWindow browserWindow = result.Item1; if (browserWindow != null) { await Utils.DelayAsync(500); browserWindow.Deinit(); return; } ImageWindow imgWindow = result.Item2; if (imgWindow != null) { await Utils.DelayAsync(300); ExplanationModeMediator.Inst.LasersEnabled = true; await imgWindow.BotManipulationsAsync(); await Utils.DelayAsync(400); ExplanationModeMediator.Inst.LasersEnabled = false; await Utils.DelayAsync(1000); imgWindow.Deinit(); return; } ReaderWindow2 pdf = result.Item3; if (pdf != null) { await Utils.DelayAsync(1000); await pdf.BotScrollAsync(rnd); await Utils.DelayAsync(600); await pdf.BotLaserActivityAsync(); await Utils.DelayAsync(400); pdf.Deinit(); return; } }
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); }
//message from remote client private void __sourceView(ExplanationModeSyncMsg sm) { if (!ExplanationModeMediator.Inst.ExplanationModeEnabled) { return; } if (sm.doExpand) { switch (sm.syncMsgType) { case SyncMsgType.SourceView: var src = PublicBoardCtx.Get().Source.FirstOrDefault(s0 => s0.Id == sm.viewObjectId); var browser = WebkitBrowserWindow.Instance(src.Text, CurrentTopic != null ? CurrentTopic.Id : (int?)null); browser.Show(); browser.Activate(); break; case SyncMsgType.YoutubeView: var attach = PublicBoardCtx.Get().Attachment.FirstOrDefault(a0 => a0.Id == sm.viewObjectId); var embedUrl = AttachmentToVideoConvertor.AttachToYtInfo(attach).EmbedUrl; browser = WebkitBrowserWindow.Instance(embedUrl, CurrentTopic != null ? CurrentTopic.Id : (int?)null); browser.Show(); browser.Activate(); break; case SyncMsgType.ImageView: attach = PublicBoardCtx.Get().Attachment.FirstOrDefault(a0 => a0.Id == sm.viewObjectId); if (attach != null && !ExplanationModeMediator.Inst.IsViewerOpened(attach.Id)) { AttachmentManager.RunViewer(attach, false); } break; case SyncMsgType.PdfView: attach = PublicBoardCtx.Get().Attachment.FirstOrDefault(a0 => a0.Id == sm.viewObjectId); if (attach != null && !ExplanationModeMediator.Inst.IsViewerOpened(attach.Id)) { AttachmentManager.RunViewer(attach, false); } break; default: throw new NotImplementedException(); } } else { switch (sm.syncMsgType) { case SyncMsgType.SourceView: WebkitBrowserWindow.EnsureInstanceDeinited(); break; case SyncMsgType.ImageView: ExplanationModeMediator.Inst.EnsureInstanceClosed(sm.viewObjectId); break; case SyncMsgType.YoutubeView: WebkitBrowserWindow.EnsureInstanceDeinited(); break; case SyncMsgType.PdfView: ReaderWindow2.EnsureInstanceClosed(); break; default: throw new NotImplementedException(); } } }