Example #1
0
        private void ConvertImmediatelyButton_Click(object sender, EventArgs e)
        {
            if (DefaultOutputPathTextBox.Text == "")
            {
                StatusRichTextBox.Text = "Неверно задан каталог для выходного файла!";
                OutputFileTextBox.Focus();
                return;
            }

            StatusRichTextBox.Text = "";

            string fileName;
            var    url = Clipboard.GetText(TextDataFormat.Text);

            if (GetImmediatelyTitleFromUrlСheckBox.Checked)
            {
                if (!int.TryParse(ResponseTimeoutTextBox.Text, out var timeout))
                {
                    timeout = 15000;
                }

                fileName = ResponseTagHelper.GetWebPageTitle(url, timeout);
                if (fileName == "")
                {
                    fileName = Path.Combine(DefaultOutputPathTextBox.Text,
                                            DateTime.Now.ToShortDateString() + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" +
                                            DateTime.Now.Second + "-" + DateTime.Now.Millisecond + ".pdf");
                }
                else
                {
                    fileName = Path.Combine(DefaultOutputPathTextBox.Text, fileName + ".pdf");
                }
            }
            else
            {
                fileName = Path.Combine(DefaultOutputPathTextBox.Text,
                                        DateTime.Now.ToShortDateString() + "-" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" +
                                        DateTime.Now.Second + "-" + DateTime.Now.Millisecond + ".pdf");
            }

            var oldFileName = fileName;
            var findNull    = fileName.IndexOf('\0');

            if (findNull >= 0)
            {
                fileName = fileName.Remove(findNull);
            }

            if (!string.Equals(fileName, oldFileName))
            {
                StatusRichTextBox.Text += "Выходное имя файла \"" + oldFileName + "\" изменено на \"" + fileName + "\"\n";
            }

            Convert(url, fileName, true,
                    OpenPdfFileCheckBox.Checked);
        }
Example #2
0
        private void UrlsToConvertDataGridView_DragDrop(object sender, DragEventArgs e)
        {
            var files = (string[])e.Data.GetData(DataFormats.FileDrop);

            if (!int.TryParse(ResponseTimeoutTextBox.Text, out var timeout))
            {
                timeout = 15000;
            }

            var counter = 0;

            foreach (var filePath in files)
            {
                string line;
                var    file = new StreamReader(filePath);
                while ((line = file.ReadLine()) != null)
                {
                    foreach (var l in line.Split(' '))
                    {
                        var r = new Regex(@"(?<Protocol>\w+):\/\/(?<Domain>[\w@][\w.:@]+)\/?[\w\.?=%&=\-@/$,]*");
                        var m = r.Match(l);
                        if (!m.Success)
                        {
                            continue;
                        }
                        if (GetTitleFromFileUrlsСheckBox.Checked)
                        {
                            var title = ResponseTagHelper.GetWebPageTitle(l.Trim(), timeout);
                            UrlsToConvert.Add(title != ""
                                ? new UrlToConvert(l.Trim(), title, false)
                                : new UrlToConvert(l.Trim(), false));
                        }
                        else
                        {
                            UrlsToConvert.Add(new UrlToConvert(l.Trim(), false));
                        }

                        UrlsListGroupBox.Text = "Список адресов для конвертирования - " + UrlsToConvert.Count;
                    }
                    counter++;
                }
                file.Close();
            }

            StatusRichTextBox.Text += "Всего считано: " + counter + " строк.\n";
        }
Example #3
0
        private void ConvertUrlsListButton_Click(object sender, EventArgs e)
        {
            if (DefaultOutputPathTextBox.Text == "")
            {
                StatusRichTextBox.Text = "Неверно задан каталог для выходного файла!";
                OutputFileTextBox.Focus();
                return;
            }

            StatusRichTextBox.Text = "";

            if (ConvertAllCheckBox.Checked)
            {
                UrlsToConvertDataGridView.SelectAll();
            }

            if (!int.TryParse(ResponseTimeoutTextBox.Text, out var timeout))
            {
                timeout = 15000;
            }

            var count = 0;

            foreach (DataGridViewRow row in UrlsToConvertDataGridView.SelectedRows)
            {
                count++;
                var realDataRow = (UrlToConvert)row.DataBoundItem;

                var r = new Regex(@"(?<Protocol>\w+):\/\/(?<Domain>[\w@][\w.:@]+)\/?[\w\.?=%&=\-@/$,]*");
                var m = r.Match(realDataRow.Url);
                if (!m.Success)
                {
                    StatusRichTextBox.Text += "Неверно задан URL html-страницы: " + realDataRow.Url + "\n";
                    HtmlPageTextBox.Focus();
                    continue;
                }

                var url = FixUrlsList(realDataRow.Url);

                var fileName = realDataRow.Name;
                if (GetTitleFromUrlСheckBox.Checked)
                {
                    StatusRichTextBox.Text += "Идет получение Title по Url...\n";
                    var title = ResponseTagHelper.GetWebPageTitle(url, timeout);
                    if (title != "")
                    {
                        fileName = title;
                    }
                }

                fileName = fileName.Replace('/', '_');
                fileName = fileName.Replace('\\', '_');
                fileName = fileName.Replace(':', '_');
                fileName = fileName.Replace('*', '_');
                fileName = fileName.Replace('?', '_');
                fileName = fileName.Replace('«', '_');
                fileName = fileName.Replace('<', '_');
                fileName = fileName.Replace('>', '_');
                fileName = fileName.Replace('|', '_');

                if (!string.Equals(fileName, realDataRow.Name))
                {
                    StatusRichTextBox.Text += "Выходное имя файла \"" + realDataRow.Name + "\" изменено на \"" + fileName + "\"\n";
                }

                if (NumerateOutputPdfFileNamesCheckBox.Checked)
                {
                    fileName = count + " - " + fileName;
                }

                Convert(url, Path.Combine(DefaultOutputPathTextBox.Text, fileName + ".pdf"),
                        true, realDataRow.Open);
            }
        }