Exemplo n.º 1
0
        public void ProcessFile()
        {
            m_extension = m_currfile.Split('.')[1];
            int result;

            if (!(m_extension.ToUpper() == "PDF" || m_extension.ToUpper() == "pdf"))
            {
                MessageDialog md = new MessageDialog(this,
                                                     DialogFlags.DestroyWithParent, MessageType.Question,
                                                     ButtonsType.YesNo, "Would you like to Distill this file ?");

                result = md.Run();
                md.Destroy();
                if ((ResponseType)result == ResponseType.Yes)
                {
                    AddProgressBar("Distilling");
                    if (m_ghostscript.DistillPS(m_currfile, Constants.DEFAULT_GS_RES) == gsStatus.GS_BUSY)
                    {
                        ShowMessage(NotifyType_t.MESS_STATUS, "GS currently busy");
                        return;
                    }
                    return;
                }
            }
            m_file_open = true;
            RenderThumbs();
        }
        public void ProcessFile(String FileName)
        {
            /* Before we even get started check for issues */
            /* First check if file exists and is available */
            if (!System.IO.File.Exists(FileName))
            {
                ShowMessage(NotifyType_t.MESS_STATUS, "File not found!");
                return;
            }
            if (m_viewer_state == ViewerState_t.DOC_OPEN)
            {
                /* In this case, we want to go ahead and launch a new process
                 * handing it the filename */
                /* We need to get the location */
                string path = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                try
                {
                    string Arguments = FileName + " open";
                    Process.Start(path, Arguments);
                }
                catch (InvalidOperationException)
                {
                    Console.WriteLine("InvalidOperationException");
                }
                catch (Win32Exception)
                {
                    Console.WriteLine("Win32 Exception: There was an error in opening the associated file. ");
                }
                return;
            }
            else if (m_viewer_state != ViewerState_t.NO_FILE)
            {
                return;
            }

            m_viewer_state = ViewerState_t.OPENING;

            /* If we have a ps or eps file then launch the distiller first
             * and then we will get a temp pdf file which we will open.  This is done
             * to demo both methods of doing callbacks from gs worker thread.  Either
             * progress as we distill the stream for PS or page by page for PDF */
            string extension = System.IO.Path.GetExtension(FileName);

            /* We are doing this based on the extension but like should do
             * it based upon the content */
            switch (extension.ToUpper())
            {
            case ".PS":
                m_document_type = doc_t.PS;
                break;

            case ".EPS":
                m_document_type = doc_t.EPS;
                break;

            case ".PDF":
                m_document_type = doc_t.PDF;
                break;

            case ".XPS":
                m_document_type = doc_t.XPS;
                break;

            case ".OXPS":
                m_document_type = doc_t.XPS;
                break;

            case ".BIN":
                m_document_type = doc_t.PCL;
                break;

            case ".PNG":
                m_document_type = doc_t.PNG;
                break;

            case ".JPG":
                m_document_type = doc_t.JPG;
                break;

            case ".TIF":
                m_document_type = doc_t.TIF;
                break;

            default:
            {
                m_document_type = doc_t.UNKNOWN;
                ShowMessage(NotifyType_t.MESS_STATUS, "Unknown File Type");
                m_viewer_state = ViewerState_t.NO_FILE;
                return;
            }
            }
            if (m_document_type == doc_t.PCL ||
                m_document_type == doc_t.XPS ||
                m_document_type == doc_t.PS)
            {
                MessageBoxResult result = MessageBox.Show("Would you like to distill this file?", "ghostnet", MessageBoxButton.YesNoCancel);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    xaml_DistillProgress.Value = 0;
                    m_viewer_state             = ViewerState_t.DISTILLING;
                    if (m_ghostscript.DistillPS(FileName, Constants.DEFAULT_GS_RES) == gsStatus.GS_BUSY)
                    {
                        ShowMessage(NotifyType_t.MESS_STATUS, "GS currently busy");
                        return;
                    }
                    xaml_DistillName.Text         = "Distilling";
                    xaml_CancelDistill.Visibility = System.Windows.Visibility.Visible;
                    xaml_DistillName.FontWeight   = FontWeights.Bold;
                    xaml_DistillGrid.Visibility   = System.Windows.Visibility.Visible;
                    return;

                case MessageBoxResult.No:
                    //m_doc_type_has_page_access = false;
                    break;

                case MessageBoxResult.Cancel:
                    m_viewer_state = ViewerState_t.NO_FILE;
                    return;
                }
            }
            m_currfile = FileName;
            RenderThumbs();
            return;
        }