Example #1
0
        private void SaveConfig(bool quiesceDeal)
        {
            string fileName = "{2}{0} - {1}.xml".FormatWith(txtTaskName.Text, txtSourceName.Text, SysConfig.TaskConfigPath);
            //如果已存在同名的文件,则提示是否覆盖,如果选择覆盖,则继续。
            bool isRecover = quiesceDeal;

            if (!quiesceDeal && File.Exists(fileName))
            {
                if (MessageBox.Show("输入的任务名称已经存在,是否覆盖。", "网络采集器", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    isRecover = true;
                }
                else
                {
                    txtTaskName.Focus();
                    return;
                }
            }
            try
            {
                TextWriter writer = new StreamWriter(fileName, false);
                //--序列化到XML
                _xmlSerializer.Serialize(writer, GetTaskModelFromInput());
                writer.Close();
                if (!isRecover)
                {
                    string[] items = cmbTaskList.DataSource as string[];
                    if (items != null)
                    {
                        string[] newItems = new string[items.Length + 1];
                        newItems[0] = fileName;
                        items.CopyTo(newItems, 1);
                        cmbTaskList.DataSource = newItems;
                    }
                }
                if (!quiesceDeal)
                {
                    UpdateWorkMessage("任务已保存\n");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(StringFormat.FormatExceptionString(ex), "网络采集器", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        /// <summary>
        /// 根据选择的已保存任务加载采集配置
        /// </summary>
        private void LoadGatherConfig()
        {
            try
            {
                Task t = _xmlSerializer.Deserialize(new MemoryStream(File.ReadAllBytes(cmbTaskList.Text))) as Task;
                if (t == null)
                {
                    MessageBox.Show("配置错误,无法加载", "网络采集器", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                //--设置数据类属性

                txtTaskName.Text   = t.TaskName;
                txtSourceName.Text = t.SourceName;
                SetGatherModelSelect(t.GatherModel);
                txtStartUrl.Text                  = t.StartUrl;
                txtListPageUrl.Text               = t.ListPageUrl;//HttpUtility.UrlDecode(
                txtWebTitle.Text                  = t.WebTitle;
                txtWebContent.Text                = t.WebContent;
                txtContentPageUrl.Text            = t.ContentPageUrl;
                txtSavePath.Text                  = t.SavePath;
                ckbIsSaveOnlyFile.Checked         = t.IsSaveOnlyFile;
                ckbIsStartClearMessageBox.Checked = t.IsStartClearMessageBox;

                nudGatherCountMax.Value = t.GatherCountMax < nudGatherCountMax.Minimum ? nudGatherCountMax.Minimum : t.GatherCountMax;
                if (cmbDefaultEncode.Items.Contains(t.DefaultEncode))
                {
                    cmbDefaultEncode.Text = t.DefaultEncode;
                }
                else
                {
                    MessageBox.Show("默认编码不在编码列表中,已被设置为程序默认。", "网络采集器", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cmbDefaultEncode.Focus();
                }
                ckbIsDealSamePage.Checked = t.IsDealSamePage;
                txtFirstPageMark.Text     = HttpUtility.UrlDecode(t.FirstPageMark);
                txtSamePageMark.Text      = HttpUtility.UrlDecode(t.SamePageMark);
            }
            catch (Exception ex)
            {
                MessageBox.Show(StringFormat.FormatExceptionString(ex), "网络采集器", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
 private void w_OnError(Exception ex, ErrorType errorType, string curUrl)
 {
     MessageBox.Show("采集发送错误,错误类型:" + errorType.ToString() + "详情:\n" + StringFormat.FormatExceptionString(ex), "网络采集器", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }