Пример #1
0
        /// <summary>
        /// Convert HTML to file
        /// </summary>
        private void WordToFile()
        {
            if (null != _htmlFiles && _htmlFiles.Count > 0)
            {
                int id = 0;
                this.toolStripProgressBar.Maximum = _htmlFiles.Count;
                foreach (var file in _htmlFiles)
                {
                    this.listView.Items[id].SubItems[1].Text = Status.Processing.ToString();
                    try
                    {
                        string filename = Path.GetFileNameWithoutExtension(file);
                        // Generate output filename
                        string outputFilename = Path.Combine(_outputFolder, filename + "." + _targetExt.ToString());
                        if (!File.Exists(outputFilename))
                        {
                            // Initialize word
                            _wordOperation = new WordOperation(file);
                            // Generate HTML
                            _wordOperation.WordToFile(outputFilename, _targetExt);
                            // Close word
                            _wordOperation.ReleaseDoc();
                            this.listView.Items[id].SubItems[1].Text = Status.Finished.ToString();
                        }
                        else
                        {
                            this.listView.Items[id].SubItems[1].Text = Status.Exist.ToString();
                        }
                        this.listView.Items[id].SubItems[3].Text = outputFilename;
                    }
                    catch (Exception ex)
                    {
                        //TODO exception
                        if (null != _wordOperation)
                        {
                            _wordOperation.Release();
                        }
                        this.listView.Items[id].SubItems[1].Text = Status.Error.ToString();
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        id++;
                        this.toolStripProgressBar.Value++;
                    }
                }
            }
            else
            {
                MessageBox.Show("Please Open input folder containing HTML files.");
            }

            if (null != _wordOperation)
            {
                _wordOperation.Release();
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
            timer.Stop();
        }
Пример #2
0
 /// <summary>
 /// Stop progress
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void StopToolStripMenuItem_Click(object sender, EventArgs e)
 {
     _processThread.Abort();
     if (null != _wordOperation)
     {
         _wordOperation.ReleaseDoc();
         _wordOperation.Release();
         _wordOperation = null;
     }
     SetLabelValue(toolStripStatusLabelStatusValue, Status.Stop.ToString());
 }