Exemple #1
0
        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)
                {
                }
            }
        }
Exemple #2
0
        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);
        }