Exemplo n.º 1
0
        private void SourceLTDFilesNextPage()
        {
            // Check if any of the added LTD files in the list matches the globally selected
            // LTD document type from the combo box, if non, then stay on this page.
            LtdDocumentType globalLTDType      = (LtdDocumentType)_ltdDocumentTypeComboBox.SelectedIndex;
            bool            validLTDFilesFound = false;

            foreach (ListViewItem item in _sourceLTDFileListView.Items)
            {
                LtdDocumentInfo ltdFileInfo = DocumentWriter.GetLtdInfo(item.Text);
                if (ltdFileInfo.Type == globalLTDType)
                {
                    validLTDFilesFound = true;
                    break;
                }
            }

            if (validLTDFilesFound)
            {
                _mainWizardControl.SelectedTab = _outputOptionsTabPage;
            }
            else
            {
                Messager.ShowInformation(this, "Non of the source LTD files you added matches the chosen global LTD document type.\nYou can either change the global LTD document type to match the type of your LTD files or add some LTD files that matches the global LTD document type to be able to move to the next page.");
            }
        }
Exemplo n.º 2
0
        private void _nextButton_Click(object sender, EventArgs e)
        {
            if (_mainWizardControl.SelectedTab == _sourceLTDFilesTabPage)
            {
                SourceLTDFilesNextPage();
                UpdateUIState(false);
            }
            else if (_mainWizardControl.SelectedTab == _outputOptionsTabPage)
            {
                _abort = false;
                if (_nextButton.Text.Equals("&Abort"))
                {
                    _abort = true;
                }

                if (!_abort)
                {
                    _nextButton.Text = "&Abort";
                    Application.DoEvents();

                    _documentFormatOptionsControl.UpdateDocumentWriterOptions();
                    DocumentFormat format            = _documentFormatOptionsControl.SelectedDocumentFormat;
                    string         outputFileName    = _outputFileNameTextBox.Text;
                    bool           viewFinalDocument = _viewDocumentCheckBox.Checked;
                    List <string>  sourceLTDFiles    = new List <string>();

                    LtdDocumentType globalLTDType   = (LtdDocumentType)_ltdDocumentTypeComboBox.SelectedIndex;
                    int             totalPagesCount = 0;
                    foreach (ListViewItem item in _sourceLTDFileListView.Items)
                    {
                        LtdDocumentInfo ltdFileInfo = DocumentWriter.GetLtdInfo(item.Text);
                        if (ltdFileInfo.Type == globalLTDType)
                        {
                            sourceLTDFiles.Add(item.Text);
                            totalPagesCount += ltdFileInfo.PageCount;
                        }
                    }

                    _progressBar.Maximum = totalPagesCount + 2 /* The document writer provides progress for two extra operations (BeginDocument and EndDocument) and hence the number 2 */;

                    ThreadPool.QueueUserWorkItem((object sender1) =>
                    {
                        MergeLTDFiles(format, outputFileName, sourceLTDFiles.ToArray(), viewFinalDocument, globalLTDType);
                    });

                    UpdateUIState(true);
                }
            }
        }
Exemplo n.º 3
0
        private void MergeLTDFiles(DocumentFormat format, string outputFileName, string[] sourceLTDFiles, bool viewFinalDocument, LtdDocumentType globalLTDType)
        {
            // If the output format is LTD then use the same target LTD file path specified by the user, otherwise create a temp file
            string mergedLTDFileName = null;

            if (format != DocumentFormat.Ltd)
            {
                mergedLTDFileName = Guid.NewGuid().ToString().Replace("-", null) + "." + "ltd";
                mergedLTDFileName = Path.Combine(Path.GetTempPath(), mergedLTDFileName);
            }
            else
            {
                mergedLTDFileName = outputFileName;
                if (File.Exists(outputFileName))
                {
                    File.Delete(outputFileName);
                }
            }

            bool errorOccurred = false;

            try
            {
                if (sourceLTDFiles.Length > 0)
                {
                    foreach (string fileName in sourceLTDFiles)
                    {
                        if (_abort)
                        {
                            break;
                        }

                        _docWriter.AppendLtd(fileName, mergedLTDFileName);
                    }

                    if (format != DocumentFormat.Ltd)
                    {
                        _docWriter.Convert(mergedLTDFileName, outputFileName, format);
                    }
                }
                else
                {
                    errorOccurred = true;
                    OnError("Non of the source LTD files you added matches the chosen global LTD document type from the previous page.");
                }
            }
            catch (Exception ex)
            {
                errorOccurred = true;
                OnError(ex.Message);
            }
            finally
            {
                OnDone(format, mergedLTDFileName, outputFileName, viewFinalDocument, errorOccurred);
            }
        }