void ReleaseDesignerOutlets()
        {
            if (ConversionStatus != null)
            {
                ConversionStatus.Dispose();
                ConversionStatus = null;
            }

            if (ConversionProgress != null)
            {
                ConversionProgress.Dispose();
                ConversionProgress = null;
            }

            if (FileToConvert != null)
            {
                FileToConvert.Dispose();
                FileToConvert = null;
            }

            if (ConvertButton != null)
            {
                ConvertButton.Dispose();
                ConvertButton = null;
            }

            if (OpenButton != null)
            {
                OpenButton.Dispose();
                OpenButton = null;
            }
        }
示例#2
0
        private static string FormatForOutputWindow(ConversionProgress s)
        {
            string preMessage = Environment.NewLine;

            switch (s.NestingLevel)
            {
            case 0:
                return(preMessage + Environment.NewLine + s.Message);

            case 1:
                return(preMessage + "* " + s.Message);
            }

            return("");
        }
 private void FFmpegConverter_ProgressChanged(object sender, int e)
 {
     App.DebugLog("FFmpegConverter_ProgressChanged IsConverting");
     ConversionProgress?.Invoke(e);
 }
示例#4
0
 /// <summary>
 /// This raises the <see cref="ConversionProgress"/> event.
 /// </summary>
 /// <param name="e">The event arguments</param>
 protected virtual void OnConversionProgress(ConversionProgressEventArgs e)
 {
     ConversionProgress?.Invoke(this, e);
 }
        public void MakePdf(string inputHtmlPath, string outputPdfPath, string paperSizeName,
                            bool landscape, Control owner, BackgroundWorker worker, DoWorkEventArgs doWorkEventArgs)
        {
            ConversionProgress progress = null;

            try
            {
                var tempOutput = TempFile.WithExtension(".pdf");                 //we don't want to dispose of this (since we will move it)
                File.Delete(tempOutput.Path);

                var conversionOrder = new ConversionOrder()
                {
                    BottomMarginInMillimeters = 0,
                    TopMarginInMillimeters    = 0,
                    LeftMarginInMillimeters   = 0,
                    RightMarginInMillimeters  = 0,
                    EnableGraphite            = true,
                    Landscape     = landscape,
                    InputHtmlPath = inputHtmlPath,
                    OutputPdfPath = tempOutput.Path,
                    PageSizeName  = paperSizeName
                };
                using (var waitHandle = new AutoResetEvent(false))
                {
                    var mainThreadTask = (Action)(() => {
                        progress = new ConversionProgress(conversionOrder);
                        progress.Finished += (sender, args) => {
                            if (!File.Exists(tempOutput.Path))
                            {
                                throw new ApplicationException(
                                    string.Format("Bloom was not able to create the PDF.{0}{0}" +
                                                  "Details: GeckofxHtmlToPdf (command line) did not produce the expected document.",
                                                  Environment.NewLine));
                            }
                            try
                            {
                                File.Move(tempOutput.Path, outputPdfPath);
                                waitHandle.Set();
                            }
                            catch (IOException e)
                            {
                                //I can't figure out how it happened (since GetPdfPath makes sure the file name is unique),
                                //but we had a report (BL-211) of that move failing.
                                throw new ApplicationException(
                                    string.Format(
                                        "Bloom tried to save the file to {0}, but Windows said that it was locked. Please try again.{2}{2}Details: {1}",
                                        outputPdfPath, e.Message, Environment.NewLine));
                            }
                        };
                        progress.Show(owner);
                    });
                    if (owner == null)                     // typically tests; should be the main UI thread.
                    {
                        mainThreadTask();
                    }
                    else
                    {
                        owner.Invoke(mainThreadTask);
                    }

                    while (true)
                    {
                        // The background thread can't actually do any work...all happens in the gecko
                        // component on the UI thread...but it must wait until we're done.
                        if (waitHandle.WaitOne(100))
                        {
                            break;                             // background thread signaled that it is finished
                        }
                        if (progress != null && worker != null && worker.CancellationPending)
                        {
                            owner.Invoke((Action)(progress.Cancel));
                            doWorkEventArgs.Cancel = true;
                            break;
                        }
                    }
                }
            }
            finally
            {
                if (progress != null)
                {
                    progress.Dispose();
                }
            }
        }
示例#6
0
 public ThreadedCalculationManager(FdsStartInfo fdsStartInfo, ILogger logger, ConversionProgress conversionProgressForm)
 {
     log               = logger;
     progressWindow    = conversionProgressForm;
     this.fdsStartInfo = fdsStartInfo;
 }
示例#7
0
        public void RunCalculationInFds()
        {
            // Todo : Bad practice to use such kind of exception handling.
            try
            {
                #region Check if config exists

                var pluginConfig = new DefaultFactory(Log).CreateFdsConfig();

                if (pluginConfig == null)
                {
                    var fdsConfig = new PluginOptions(Log);
                    fdsConfig.ShowDialog();
                    pluginConfig = fdsConfig.PluginConfig;
                    fdsConfig.Dispose();
                    fdsConfig = null;
                }

                #endregion

                #region Collect information

                // Ask user to configure calculation
                var calculationInfo = new CalculationInfo();
                var dialogResult    = calculationInfo.ShowDialog();

                var calcTime   = calculationInfo.CalculationTime;
                var workingDir = calculationInfo.OutputPath;

                calculationInfo.Dispose();
                calculationInfo = null;

                if (dialogResult == DialogResult.Cancel)
                {
                    return;
                }

                EditMaterialsMappings();

                // get solids
                var selectedSolids = AcadInfoProvider.AskUserToSelectSolids();

                if (selectedSolids.Count < 1)
                {
                    return;
                }

                #endregion

                #region Start Calculations

                var fdsStartInfo = new FdsStartInfo
                {
                    // Arguments = string.Concat("\"", pathToFile, "\""),
                    CalculationTime  = calcTime,
                    DocumentName     = AcadInfoProvider.GetDocumentName(),
                    PathToFds        = pluginConfig.PathToFds,
                    SelectedSolids   = selectedSolids,
                    UsedSurfaces     = CommonHelper.GetAllUsedSurfaces(Log),
                    WorkingDirectory = workingDir
                };

                var progressWindow     = new ConversionProgress(fdsStartInfo.SelectedSolids.Count);
                var calculationManager = new ThreadedCalculationManager(fdsStartInfo, Log, progressWindow);
                progressWindow.Shown += (s, e) => calculationManager.WaitEvent.Set();
                calculationManager.StartCalculation();

                progressWindow.ShowDialog();
                progressWindow.Dispose();
                progressWindow = null;

                #endregion
            }
            catch (System.Exception exception)
            {
                Log.LogError(exception);
                UserNotifier.ShowError(exception.Message);
            }
        }
示例#8
0
        async partial void ConvertButtonClicked(NSObject sender)
        {
            _log.Debug($"Convert {FileToConvert.StringValue}");

            if (string.IsNullOrWhiteSpace(FileToConvert.StringValue))
            {
                _dialog.Info("Source file wasn't chosen", "Conversion is cancelled because the source file wasn't chosen");
                return;
            }

            if (!File.Exists(FileToConvert.StringValue))
            {
                _dialog.Info("Source file doesn't exist", "Conversion is cancelled because the source file doesn't exist");
                return;
            }

            string outputFile;
            string filename = string.IsNullOrWhiteSpace(FileToConvert.StringValue) ? string.Empty : Path.GetFileNameWithoutExtension(FileToConvert.StringValue);

            if (!_dialog.SaveFile("Save epub as file", "epub", filename, out outputFile))
            {
                _dialog.Info("Target file wasn't chosen", "Conversion is cancelled because the target file wasn't chosen");
                return;
            }

            var options = new Options(new string[]
            {
                "--inputFile", FileToConvert.StringValue,
                "--outputFile", outputFile,
            });

            OpenButton.Enabled           = false;
            ConvertButton.Enabled        = false;
            FileToConvert.Enabled        = false;
            ConversionStatus.StringValue = "Conversion started...";
            ConversionProgress.StartAnimation(null);

            try
            {
                var htmlToEpub = new HtmlToEpubConverter(
                    new Counter(_log),
                    _log,
                    options,
                    new MecabParser(),
                    new MecabReader(),
                    new MecabBackend(),
                    new XHtmlMaker(),
                    await _jmdicReaderTask,
                    new ContentsBreaker(new ChapterMarkersProvider(options, new ContentsDetector())),
                    new EpubMaker(_log, options, _resourceLocator),
                    new SentenceBreaker()
                    );

                options.Print(Console.Out);

                await htmlToEpub.Convert();
            }
            catch (Exception ex)
            {
                _dialog.UnexpectedError(ex);
            }
            finally
            {
                OpenButton.Enabled           = true;
                ConvertButton.Enabled        = true;
                FileToConvert.Enabled        = true;
                ConversionStatus.StringValue = "Conversion done";
                ConversionProgress.StopAnimation(null);

                _fileManager.OpenFileManagerAndShowFile(outputFile);
            }

            _log.Debug("end");
        }