コード例 #1
0
        public static void Run(NoticeSource source)
        {
            try
            {
                if (string.IsNullOrEmpty(source.NoticePath))
                {
                    return;
                }
                string result = RequestHelper.GetHttpWebRequest(source.NoticePath);
                //string p = "<li class=\"\">\\s*<a aria-selected=\"false\" href=\"(.*?)\"(?:.*?)>(.*?)</a>";

                //string result2 = HttpUtility.HtmlEncode(p);//将HTML代码转码

                string pattern = HttpUtility.HtmlDecode(source.RegexRule).Replace(@"\\", @"\");
                Regex  reg     = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                MatchCollection mc = reg.Matches(result);

                using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
                {
                    var predicate = Predicates.Field <Notice>(f => f.Source, Operator.Eq, source.Name);
                    IEnumerable <Notice> existNoticeList = cn.GetList <Notice>(predicate);
                    IList <Notice>       noticeList      = new List <Notice>();
                    foreach (Match m in mc)
                    {
                        DateTime now    = DateTime.Now;
                        var      link   = string.Format(source.Domain, m.Groups[1].Value);
                        Notice   notice = new Notice()
                        {
                            Title      = m.Groups[2].Value,
                            Link       = link,
                            CreateDate = now,
                            Source     = source.Name
                        };

                        noticeList.Add(notice);
                    }
                    var newNoticeList = noticeList.Except(existNoticeList, new NoticeComparer()).ToList();
                    foreach (var n in newNoticeList)
                    {
                        cn.Insert <Notice>(n);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #2
0
 public ActionResult SaveSource(NoticeSource source)
 {
     using (IDbConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
     {
         if (source.Id == 0)
         {
             source.RegexRule = HttpUtility.HtmlEncode(source.RegexRule);
             var result = conn.Insert(source);
         }
         else
         {
             conn.Update(source);
         }
     }
     RecurringJob.AddOrUpdate(source.Name, () => NoticeSpider.Run(source), Cron.Minutely);
     return(RedirectToAction("Sources"));
 }
コード例 #3
0
        /// <summary>
        /// 构建函数
        /// </summary>
        /// <param name="source">通知来源</param>
        /// <param name="notice">如果此参数不为空表示是更新通知,否则为添加</param>
        public FormUpdateNotice(NoticeSource source, Flow_Notice notice)
        {
            InitializeComponent();

            cmbSource.Enabled = false;
            cmbSource.Items.AddRange(Enum.GetNames(typeof(NoticeSource)));
            cmbSource.Text = source.ToString();
            m_notice       = notice;

            if (notice != null)
            {
                this.Text = "更新通知";

                cmbPriority.Text      = notice.优先级;
                m_oldReceivedPersonal = txtReceivedPersonal.Text = notice.接收人;
                txtTitle.Text         = notice.标题;

                txtContent.Text = notice.内容.Substring(notice.内容.IndexOf(":") + 1);
            }
            else
            {
                cmbPriority.SelectedIndex = 0;
            }
        }
コード例 #4
0
        /// <summary>
        /// 处理通知类消息
        /// </summary>
        /// <param name="mode">初始化模式</param>
        /// <param name="source">消息源</param>
        private void InitNodiceMessage(InitMode mode, NoticeSource source)
        {
            List <Flow_Notice> dataSource =
                (from r in m_flowNotice.GetNotice(BasicInfo.LoginID, source)
                 orderby r.标题, r.发送时间, r.发送人
                 select r).ToList();

            if (source == NoticeSource.日常事务)
            {
                treeView.Nodes.Find("通知_日常事务", true)[0].Text = string.Format("日常事务({0})", dataSource.Count);
            }
            else if (source == NoticeSource.单据处理后知会)
            {
                treeView.Nodes.Find("通知_单据处理后知会", true)[0].Text = string.Format("单据处理后知会({0})", dataSource.Count);
            }

            if (mode == InitMode.刷新数据显示)
            {
                dataGridView1.DataSource = new BindingCollection <Flow_Notice>(dataSource);

                DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();

                column.Visible    = true;
                column.Name       = "天数";
                column.HeaderText = "天数";
                column.ValueType  = typeof(int);
                column.ReadOnly   = true;
                column.Width      = 40;

                dataGridView1.Columns[1].Width = 60;
                dataGridView1.Columns[2].Width = 80;
                dataGridView1.Columns[4].Width = 80;
                dataGridView1.Columns[5].Width = 80;

                dataGridView1.Columns.Insert(0, column);

                column = new DataGridViewTextBoxColumn();

                column.Visible    = true;
                column.Name       = "接收人姓名";
                column.HeaderText = "接收人姓名";
                column.ValueType  = typeof(string);
                column.ReadOnly   = true;
                dataGridView1.Columns.Insert(5, column);

                dataGridView1.Tag = dataSource;

                dataGridView1.Columns["发送人"].Visible = false;
                dataGridView1.Columns["接收人"].Visible = false;

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (dataGridView1.Columns.Contains("接收方类型") &&
                        dataGridView1.Columns.Contains("接收方姓名") &&
                        dataGridView1.Columns.Contains("接收方") &&
                        dataGridView1.Columns.Contains("状态"))
                    {
                        dataGridView1.Rows[i].Cells["接收人姓名"].Value =
                            m_user.GetUser(dataGridView1.Rows[i].Cells["接收人"].Value.ToString()).姓名;

                        dataGridView1.Rows[i].Cells["状态"].Value = dataGridView1.Rows[i].Cells["状态"].Value.ToString();
                        dataGridView1.Rows[i].Cells["天数"].Value = (ServerModule.ServerTime.Time -
                                                                   (DateTime)dataGridView1.Rows[i].Cells["发送时间"].Value).Days;
                    }
                }
            }
        }
コード例 #5
0
        public ActionResult CreateSource()
        {
            NoticeSource source = new NoticeSource();

            return(View("CreateOrUpdateSource", source));
        }