Пример #1
0
        private void DoConvert()
        {
            try
            {
                _converter.RemoveMessageListeners();
                _converter.AddProgressMessageListener(new AbstractConverter.MessageListener(ProgressMessageInterceptor));
                _converter.AddFeedbackMessageListener(new AbstractConverter.MessageListener(FeedbackMessageInterceptor));
                _converter.DirectTransform = this._options.IsDirectTransform;

                if (UriLoader.IsRemote(this._options.InputFullName))
                {
                    this._options.InputFullNameOriginal = this._options.InputFullName;
                    this._options.InputFullName         = UriLoader.DownloadFile(this._options.InputFullName);
                    this._options.InputBaseFolder       = Path.GetDirectoryName(this._options.InputFullName);
                }

                this._computeSize = true;
                this._converter.ComputeSize(this._options.InputFullName);
                this.progressBar1.Maximum = this._size;
                this._computeSize         = false;
                _converter.Transform(this._options.InputFullName, this._options.OutputFullName, this._options);
                WorkComplete(null);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
                WorkComplete(ex);
            }
        }
Пример #2
0
        // for backward compatibility remain parameter showUserInterface
        // remove this parameter once method void OdfToOox(string inputFile, string outputFile, bool showUserInterface) is no longer used.
        private void odfToOox(string inputFile, string outputFile, bool showUserInterface, ConversionOptions options)
        {
            if (showUserInterface)
            {
                try
                {
                    // create a temporary file

                    // call the converter
                    using (ConverterForm form = new ConverterForm(this.converter, inputFile, outputFile, this.resourceManager, options))
                    {
                        if (System.Windows.Forms.DialogResult.OK == form.ShowDialog())
                        {
                            if (form.HasLostElements)
                            {
                                string fidelityValue = Microsoft.Win32.Registry.GetValue(this.addin.RegistryKeyUser, ConfigForm.FidelityValue, "false") as string;

                                if (fidelityValue == null)
                                {
                                    fidelityValue = "false";
                                }

                                if (fidelityValue.Equals("false", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    InfoBox infoBox = new InfoBox(this.addin, this.resourceManager, true, "FeedbackLabel", form.LostElements);
                                    infoBox.ShowDialog();
                                }
                            }
                        }
                        else
                        {
                            if (File.Exists(outputFile))
                            {
                                File.Delete(outputFile);
                            }
                            if (form.Exception != null)
                            {
                                throw form.Exception;
                            }
                        }
                    }
                }
                catch (EncryptedDocumentException)
                {
                    InfoBox infoBox = new InfoBox(this.addin, this.resourceManager, false, "EncryptedDocumentLabel", "EncryptedDocumentDetail");
                    infoBox.ShowDialog();
                }
                catch (NotAnOdfDocumentException)
                {
                    InfoBox infoBox = new InfoBox(this.addin, this.resourceManager, false, "NotAnOdfDocumentLabel", "NotAnOdfDocumentDetail");
                    infoBox.ShowDialog();
                }
                catch (OdfZipUtils.ZipCreationException)
                {
                    InfoBox infoBox = new InfoBox(this.addin, this.resourceManager, false, "UnableToCreateOutputLabel", "UnableToCreateOutputDetail");
                    infoBox.ShowDialog();
                }
                catch (OdfZipUtils.ZipException)
                {
                    InfoBox infoBox = new InfoBox(this.addin, this.resourceManager, false, "CorruptedInputFileLabel", "CorruptedInputFileDetail");
                    infoBox.ShowDialog();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.ToString());
                    if (ex.InnerException != null && ex.InnerException is System.Xml.XmlException)
                    {
                        // An xsl exception may embed an xml exception. In this case we have a non well formed xml document.
                        List <string> messages = new List <string>();
                        messages.Add("CorruptedInputFileDetail");
                        messages.Add("");
                        messages.Add(ex.Message);
                        messages.Add("InnerException: " + ex.InnerException.Message);
                        InfoBox infoBox = new InfoBox(this.addin, this.resourceManager, false, "CorruptedInputFileLabel", (string[])messages.ToArray());
                        infoBox.ShowDialog();
                    }
                    else
                    {
                        InfoBox infoBox = new InfoBox(this.addin, this.resourceManager, false, "OdfUnexpectedError", ex.GetType() + ": " + ex.Message + " (" + ex.StackTrace + ")");
                        infoBox.ShowDialog();
                    }
                    if (File.Exists(outputFile))
                    {
                        File.Delete(outputFile);
                    }
                }
            }
            else
            {
                try
                {
                    converter.DirectTransform = true;
                    converter.Transform(inputFile, outputFile, options);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine(ex.ToString());

                    if (File.Exists(outputFile))
                    {
                        File.Delete(outputFile);
                    }
                    throw;
                }
            }
        }