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); } }
/// <summary> /// Main program. /// </summary> /// <param name="args">Command Line arguments</param> public static void Main(String[] args) { // math, dialogika: Comment this out as we need the culture info for the list of TOC. // Moreover, changing the culture info only for the command-line-tool changes the // behaviour between add-in and command-line-tool which makes detecting and fixing bugs more difficult // System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; try { ConversionOptions options = OdfConverter.ParseCommandLine(args); #if !MONO if (_ngenAssemblies && !IsRunningOnMono()) { Console.WriteLine("Native images are being generated in the background." + Path.GetFileName(Assembly.GetExecutingAssembly().Location)); ngenAssemblies(); Console.WriteLine("Exiting."); return; } #endif // complete / correct conversion options options.Generator = OdfConverter.GENERATOR; if (string.IsNullOrEmpty(options.InputFullName)) { throw new InvalidConversionOptionsException("Input is missing"); } if (UriLoader.IsRemote(options.InputFullName)) { // download document if URI has been specified as input document if (string.IsNullOrEmpty(options.OutputFullName)) { throw new InvalidConversionOptionsException("Output filename or folder must be specified when converting remote files."); } options.InputFullNameOriginal = options.InputFullName; options.InputFullName = UriLoader.DownloadFile(options.InputFullName); options.InputBaseFolder = Path.GetDirectoryName(options.InputFullName); } else { options.InputFullName = Path.GetFullPath(options.InputFullName); } if (!string.IsNullOrEmpty(options.OutputFullName)) { options.OutputFullName = Path.GetFullPath(options.OutputFullName); } if (options.ConversionMode == ConversionMode.Batch) { options.InputBaseFolder = options.InputFullName; options.OutputBaseFolder = options.OutputFullName; } else { options.InputBaseFolder = Path.GetDirectoryName(options.InputFullName); options.OutputBaseFolder = Path.GetDirectoryName(options.OutputFullName); } OdfConverter converter = new OdfConverter(); converter.proceed(options); Console.WriteLine("Done."); } catch (OdfCommandLineException ex) { Environment.ExitCode = 1; Console.WriteLine("Error when parsing command line: " + ex.Message); Console.WriteLine(); usage(); return; } catch (InvalidConversionOptionsException ex) { Environment.ExitCode = 1; Console.WriteLine("Incorrect or missing conversion parameters: " + ex.Message); Console.WriteLine(); usage(); return; } catch (WebException ex) { Environment.ExitCode = 1; Console.WriteLine("Error accessing URI: " + ex.Message); return; } catch (PathTooLongException ex) { Environment.ExitCode = 1; Console.WriteLine("Error: " + ex.Message); return; } catch (System.IO.IOException ex) { Environment.ExitCode = 1; Console.WriteLine("Error accessing input or output document: " + ex.Message); return; } catch (Exception ex) { Environment.ExitCode = 1; Console.WriteLine("An unexpected error occurred: " + ex.Message); return; } }