public static Dictionary <string, Item> Search(SearEntity sear, SellerInfoEntity sellerinfo) { try { bool isnum_iid = true; string reqName = ""; StringBuilder strbNumIid = new StringBuilder(); Dictionary <string, Item> itemDic = new Dictionary <string, Item>(); string type = sear.type; string num_iid = sear.numIid; string status = sear.statuss; //查询是否出售中 string sellerCat = sear.sellerCats; //查询条件宝贝分类 string strMainWord = sear.title; //查询条件宝贝关键字 int useplatform = sear.useplatform; //平台识别码 string sellerId = sellerinfo.strUserId; GetType(type, ref isnum_iid, ref reqName); if (!string.IsNullOrWhiteSpace(num_iid)) { #region 宝贝id查询 return(SearchNumIid(num_iid, sellerinfo, reqName, useplatform)); #endregion } else { //根据条件查询 return(SearchAll(status, reqName, isnum_iid, strMainWord, sellerCat, sellerinfo, useplatform)); } } catch (Exception ex) { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + ex.ToString()); return(null); } }
private void button1_Click(object sender, EventArgs e) { try { if (this.btnBegin.Text == "开启") { if (txtToolCount.Text.Trim() == "") { MessageBox.Show("工具数不能为空"); } int ii = Convert.ToInt32(txtToolCount.Text); for (int i = 0; i < ii; i++) { Form1 f1 = new Form1(i.ToString()); f1.Show(); } this.state = true; this.btnBegin.Text = "停止"; this.MainThread(); } else { this.state = false; this.btnBegin.Text = "开启"; } } catch (Exception ex) { TxtLog.WriteLine("picyc", ex.ToString()); } }
private void ShowSend(string strMsg) { try { this.listBox1.Items.Insert(0, strMsg + "(" + DateTime.Now.ToString() + ")"); } catch (Exception ex) { } //记录文本日志 if (strMsg.Contains("主线程出错:")) { TxtLog.WriteLine("宝贝属性检测MQS分配ErrorLog_", strMsg); } }
public WebBrowser GetPage(string Url) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls; WebBrowser myWB = new WebBrowser(); myWB.ScrollBarsEnabled = false; myWB.ScriptErrorsSuppressed = true; myWB.Navigate(Url); while (myWB.ReadyState != WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); TxtLog.WriteLine("请求失败", Url + "请求失败"); } TxtLog.WriteLine("请求失败", Url + "请求成功"); return(myWB); }
public static Dictionary <string, Item> SearchNumIid(string num_iid, SellerInfoEntity sellerinfo, string reqName, int useplatform) { Dictionary <string, Item> itemDic = new Dictionary <string, Item>(); #region 非全店选择批量 if (string.IsNullOrWhiteSpace(num_iid)) { return(null); } string itemid = num_iid; //商品id Regex reg = new Regex(@"(\d+,){0,19}\d+"); //正则获取每次20个 foreach (Match m in reg.Matches(itemid)) { ItemsSellerListGetRequest itemGetRequest = new ItemsSellerListGetRequest { Fields = reqName, NumIids = m.Value }; ItemsSellerListGetResponse itemGetResponse = TopClient.Execute(itemGetRequest, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform); for (int j = 0; j < 3; j++) { itemGetResponse = TopClient.Execute(itemGetRequest, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform); bool isok = string.IsNullOrWhiteSpace(itemGetResponse.SubErrMsg) ? true : false; if (isok)//没有错就跳出 有错误暂停0.5s 继续执行 { break; } else { Thread.Sleep(500); } } if (itemGetResponse.IsError) { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "===" + m.Value + ":出现异常:" + itemGetResponse.Body); continue; } foreach (Item item in itemGetResponse.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString()))) { itemDic.Add(item.NumIid.ToString(), item); } } #endregion return(itemDic); }
/// <summary> /// 检测标题和详情 /// </summary> /// <param name="dt">错误表信息</param> /// <param name="item">宝贝对象</param> /// <param name="titleword">标题错误</param> /// <param name="desc">详情错误</param> public void DetectionTitelDesc(DataTable dtuser, DataTable dt, Item item, ref string titleword, ref string desc) { try { //判断系统违禁词 foreach (DataRow dr in dt.Rows) { //宝贝标题违规词 if (!string.IsNullOrEmpty(item.Title) && item.Title.ToString().Contains(dr["proword"].ToString())) { titleword += dr["proword"].ToString() + ","; } //宝贝描述违规词 MatchCollection mc = MatchValues(item.Desc, ">", "<"); string x = "";//查出页面可视的文字; foreach (Match s in mc) { x += s; } if (!string.IsNullOrEmpty(x) && x.Contains(dr["proword"].ToString())) { desc += dr["proword"].ToString() + ","; } } //判断自定义违禁词 foreach (DataRow dr in dtuser.Rows) { //宝贝标题违规词 if (!string.IsNullOrEmpty(item.Title) && item.Title.ToString().Contains(dr["proword"].ToString())) { titleword += dr["proword"].ToString() + ","; } //宝贝描述违规词 if (!string.IsNullOrEmpty(item.Desc) && item.Desc.ToString().Contains(dr["proword"].ToString())) { desc += dr["proword"].ToString() + ","; } } } catch (Exception ex) { TxtLog.WriteLine("图片违禁词检测", ex.ToString()); } }
private void ProAttriuMqs() { try { string toolsql = string.Empty; DataTable dtMqs = dbtool.ExecuteDataTable("select * from crm_attributesprodetect where tools <>-1"); List <string> listMqs = new List <string>(); foreach (DataRow dr in dtMqs.Rows) { listMqs.Add(dr["tools"].ToString()); } DataTable dtInp = dbtool.ExecuteDataTable("select * from crm_attributesprodetect where check_state=4;");//获取图片检测和全部检测的任务 if (dtInp != null && dtInp.Rows.Count > 0) { //导入任务中站点索引 for (int c = 0; c < dtInp.Rows.Count; c++) { if (listMqs.Count == Convert.ToInt32(txtToolCount.Text.Trim())) { ShowSend("没有空余工具。"); break; } for (int i = 0; i < Convert.ToInt32(txtToolCount.Text.Trim()); i++) { if (!listMqs.Contains(i.ToString())) { ShowSend("开始分配" + dtInp.Rows[c]["id"].ToString() + "。用户:" + dtInp.Rows[c]["seller_id"].ToString()); toolsql += "update crm_attributesprodetect set check_state=1,tools=" + i.ToString() + " where id='" + dtInp.Rows[c]["id"].ToString() + "' and useplatform = '" + dtInp.Rows[c]["useplatform"].ToString() + "';\r\n"; dbtool.ExecuteNonQuery(toolsql); listMqs.Add(i.ToString()); break; } } } } } catch (Exception ex) { ShowSend("主线程出错:" + ex.ToString()); TxtLog.WriteLine("检测宝贝违规词MQS_ErrorLog", ex.ToString()); } }
void Session_End(object sender, EventArgs e) { //下面的代码是关键,可解决IIS应用程序池自动回收的问题 System.Threading.Thread.Sleep(1000); //触发事件, 写入提示信息 TxtLog.WriteLine("iis休眠"); //这里设置你的web地址,可以随便指向你的任意一个aspx页面甚至不存在的页面,目的是要激发Application_Start //使用您自己的URL string url = "http://localhost"; System.Net.HttpWebRequest myHttpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url); System.Net.HttpWebResponse myHttpWebResponse = (System.Net.HttpWebResponse)myHttpWebRequest.GetResponse(); System.IO.Stream receiveStream = myHttpWebResponse.GetResponseStream();//得到回写的字节流 // 在会话结束时运行的代码。 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 InProc 时,才会引发 Session_End 事件。 // 如果会话模式设置为 StateServer 或 SQLServer,则不会引发该事件。 }
public bool SendMain(DataTable dt) { string activityId = dt.Rows[0]["id"].ToString(); useplatform = int.Parse(dt.Rows[0]["useplatform"].ToString()); MySqlHelper dbtool = new MySqlHelper(DataType.ToolsProducts); try { //string sqlActivity = string.Format("select * from crm_attributesprodetect where id='{0}'", activityId); //DataTable dt = dbtool.ExecuteDataTable(sqlActivity); Dictionary <string, Item> dicItem = new Dictionary <string, Item>();//存储宝贝信息的集合 if (dt != null && dt.Rows.Count > 0) { ShowSend("检测开始"); SellerInfoEntity sellerinfo = GetSellerinfo(dt.Rows[0]); dicItem = GetItem(sellerinfo, dt.Rows[0]); string tabelName = sellerinfo.strUserId.Substring(sellerinfo.strUserId.Length - 1); string cpsql = string.Format("delete from crm_prohibiteword_detail{0} where mainid1 ='{1}'", tabelName, activityId); dbtool.ExecuteNonQuery(cpsql); TaskDetection(dicItem, sellerinfo, activityId, dt.Rows[0]["activity_type"].ToString()); ShowSend("检测完成"); } return(true); } catch (Exception ex) { TxtLog.WriteLine("图片违禁词检测", "主程序异常" + ex.ToString()); return(false); } finally { rch.Delete(activityId); //结束任务 string sqlactivity = string.Format("UPDATE crm_attributesprodetect SET tools ='-1', check_state = 2 WHERE id = '{0}';", activityId); dbtool.ExecuteNonQuery(sqlactivity); }; }
private void MainThread() { TxtLog.WriteLine("数据库 chl", dbsp.ConnectionString); ThreadStart threadStart = delegate { do { DataTable mqsDt = null; string mqsSql = "select * from crm_attributesprodetect where tools=" + textBox1.Text.Trim(); mqsDt = dbtool.ExecuteDataTable(mqsSql); if (mqsDt != null && mqsDt.Rows.Count > 0) { Mypic mp = new Mypic(); this.SendMain(mqsDt); } Thread.Sleep(1000 * 10);//休息10s } while (true); }; Thread thread = new Thread(threadStart); thread.IsBackground = true; thread.Start(); }
private void button1_Click(object sender, EventArgs e) { TxtLog.WriteLine("数据库 chl", dbsp.ConnectionString); MainThread(); }
public void TaskDetection(Dictionary <string, Item> dicItem, SellerInfoEntity sellerinfo, string activityId, string activityType) { try { if (dicItem == null) { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:获取宝贝为空" + sellerinfo.top_session); return; } string tableindex = sellerinfo.strUserId.Substring(sellerinfo.strUserId.Length - 1, 1); MySqlHelper dbtool = new MySqlHelper(DataType.ToolsProducts); string sql = "select proword from crm_prohibitedword where is_del='0'"; string sqluser = "******" + tableindex + " where is_del='0' and seller_id =" + sellerinfo.strUserId; DataTable dt = dbtool.ExecuteDataTable(sql); DataTable dtuser = dbtool.ExecuteDataTable(sqluser); string ItemImgsError = string.Empty; string titleword = string.Empty; //标题异常 string desc = string.Empty; //详情异常 string pictext = string.Empty; Mypic myp = new Mypic(); int itemcount = 0; foreach (var item in dicItem.Values) {//'任务类型 0,文字检测 1图片检测 3 全部检测' titleword = ""; desc = ""; ItemImgsError = ""; switch (activityType) { case "0": //文字检测 myp.DetectionTitelDesc(dtuser, dt, item, ref titleword, ref desc); break; case "1": //图片检测 myp.DetectionPIC(dtuser, dt, item, ref ItemImgsError, ref pictext); break; case "3": // 全部检测' myp.DetectionTitelDesc(dtuser, dt, item, ref titleword, ref desc); myp.DetectionPIC(dtuser, dt, item, ref ItemImgsError, ref pictext); break; default: break; } if (pictext != null && pictext.Contains("Open api daily request limit reached")) { LogApi.MonitorLog.Write(LogApi.LogType.Error, LogApi.Products.CRM, LogApi.VersionM.Standard, "图片检测欠费", sellerinfo.strUserId, sellerinfo.strUserNick, "", " 检测api欠费:活动id:" + activityId); return; } else if (pictext != null && pictext.Contains("Open api qps request limit reached")) { LogApi.MonitorLog.Write(LogApi.LogType.Error, LogApi.Products.CRM, LogApi.VersionM.Standard, "图片检测欠费", sellerinfo.strUserId, sellerinfo.strUserNick, "", " 检测api限流 活动id:" + activityId); return; } itemcount++; ShowSend("开始检测" + DateTime.Now.ToString() + "宝贝id" + item.NumIid + itemcount + "/" + dicItem.Count + "用户id" + sellerinfo.strUserId); //任务进度写进缓存 Sethc(activityId, itemcount + "/" + dicItem.Count); string errors = titleword + desc + ItemImgsError; string tabelName = sellerinfo.strUserId.Substring(sellerinfo.strUserId.Length - 1); if (!string.IsNullOrWhiteSpace(errors)) { if (!string.IsNullOrWhiteSpace(ItemImgsError)) { ItemImgsError = "[" + ItemImgsError.Substring(0, ItemImgsError.Length - 1) + "]"; } string psql = string.Format("INSERT INTO `crm_prohibiteword_detail{0}` (`id`, `mainid1`, `seller_id`, `num_id`, `title` , `pic_url`, `create_time`, `title_fail_reason`, `sellpoint_fail_reason`, `desc_fail_reason`, picture_fail_reason1,is_error) VALUES ('{1}', '{2}', '{3}', '{4}', '{5}' , '{6}', now(), '{7}', '', '{8}','{9}',{10} );", tabelName, Guid.NewGuid(), activityId, sellerinfo.strUserId, item.NumIid, item.Title.Replace("'", ""), item.PicUrl, titleword, desc, ItemImgsError, "1"); dbtool.ExecuteNonQuery(psql); } else { string psql = string.Format("INSERT INTO `crm_prohibiteword_detail{0}` (`id`, `mainid1`, `seller_id`, `num_id`, `title` , `pic_url`, `create_time`, `title_fail_reason`, `sellpoint_fail_reason`, `desc_fail_reason`, picture_fail_reason1,is_error) VALUES ('{1}', '{2}', '{3}', '{4}', '{5}' , '{6}', now(), '{7}', '', '{8}','{9}' ,{10});", tabelName, Guid.NewGuid(), activityId, sellerinfo.strUserId, item.NumIid, item.Title.Replace("'", ""), item.PicUrl, titleword, desc, ItemImgsError, "0"); dbtool.ExecuteNonQuery(psql); } } } catch (Exception ex) { TxtLog.WriteLine("图片违禁词检测", ex.ToString()); } }
/// <summary> /// 检测图片 /// </summary> /// <param name="dt"></param> /// <param name="item"></param> /// <param name="ItemImgsError"></param> /// <param name="picText"></param> public void DetectionPIC(DataTable dtuser, DataTable dt, Item item, ref string ItemImgsError, ref string picText) { try { Detectionpic dpic = new Detectionpic(); List <string> successlist = new List <string>(); //记录执行过的图片 List <string> picList = new List <string>(); //图片链接集合 string ItemImgsErrors = ""; MatchCollection obj = this.MatchValues(item.Desc, "src=\"", "\""); #region 获取当前宝贝的图片 for (int i = 0; i < item.ItemImgs.Count; i++)//判断主图违禁词 { ItemImgsErrors = ""; #region 获取每个图片的文字 去比较违禁词 记录错误图片地址和违禁词 string pictext = dpic.imageDetection(item.ItemImgs[i].Url.ToString()); foreach (DataRow dr in dt.Rows) { if (!string.IsNullOrEmpty(pictext) && pictext.ToString().Contains(dr["proword"].ToString())) { ItemImgsErrors += dr["proword"].ToString() + ","; } } foreach (DataRow dr in dtuser.Rows) { if (!string.IsNullOrEmpty(pictext) && pictext.ToString().Contains(dr["proword"].ToString())) { ItemImgsErrors += dr["proword"].ToString() + ","; } } if (!string.IsNullOrWhiteSpace(ItemImgsErrors)) { ItemImgsError += " { \"pic\":\"" + item.ItemImgs[i].Url.ToString() + "\",\"cw\":\"" + ItemImgsErrors + "\"},"; } #endregion } #endregion for (int i = 0; i < obj.Count; i++) { if (i > 30) { TxtLog.WriteLine("图片超额", item.NumIid.ToString()); return; } string pic = obj[i].ToString(); if (obj[i].ToString().Contains("gif") || successlist.Contains(pic))//过滤gif图,和重复的 { continue; } successlist.Add(pic); string pictext = dpic.imageDetection(pic); picText = pictext; TxtLog.WriteLine("图片解析", item.NumIid + "文字:" + pictext + "\r\n" + "图片" + pic); ItemImgsErrors = ""; foreach (DataRow dr in dt.Rows) { if (!string.IsNullOrEmpty(pictext) && pictext.ToString().Contains(dr["proword"].ToString())) { ItemImgsErrors += dr["proword"].ToString() + ","; } } foreach (DataRow dr in dtuser.Rows) { if (!string.IsNullOrEmpty(pictext) && pictext.ToString().Contains(dr["proword"].ToString())) { ItemImgsErrors += dr["proword"].ToString() + ","; } } if (!string.IsNullOrWhiteSpace(ItemImgsErrors)) { ItemImgsError += " { \"pic\":\"" + obj[i].ToString() + "\",\"cw\":\"" + ItemImgsErrors + "\"},"; } } } catch (Exception ex) { TxtLog.WriteLine("图片违禁词检测", ex.ToString()); } }
public static Dictionary <string, Item> SearchAll(string status, string reqName, bool isnum_iid, string strMainWord, string sellerCat, SellerInfoEntity sellerinfo, int useplatform) { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "===" + status + " ::" + sellerinfo.top_session); Dictionary <string, Item> itemDic = new Dictionary <string, Item>(); StringBuilder strbNumIid = new StringBuilder(); long totalResults = 0; //宝贝总数 int pageNo = 0; //api查询页码 int pageNo2 = 0; //api查询页码 status = status == "3" ? null : status; if (string.IsNullOrWhiteSpace(status)) { #region 获取出售中的商品 do { pageNo++; ItemsOnsaleGetRequest req = new ItemsOnsaleGetRequest(); req.Fields = reqName; req.PageSize = 200L; req.PageNo = Convert.ToInt64(pageNo); req.OrderBy = "list_time:asc"; if (strMainWord.Length > 0) { req.Q = strMainWord; } if (sellerCat.Trim().Length > 0) { req.SellerCids = sellerCat; } ItemsOnsaleGetResponse response = TopClient.Execute <ItemsOnsaleGetResponse>(req, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform); if (response.IsError) { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body); } else { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body); totalResults = response.TotalResults; foreach (Item item in response.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString()))) { if (isnum_iid) { strbNumIid.Append(item.NumIid.ToString() + ","); } else { itemDic.Add(item.NumIid.ToString(), item); } } } } while (totalResults > pageNo * 200); #endregion #region 获取仓库中的商品 do { pageNo2++; ItemsInventoryGetRequest req = new ItemsInventoryGetRequest { Fields = reqName, PageSize = 200, PageNo = pageNo2 }; if (strMainWord.Length > 0) { req.Q = strMainWord; } if (sellerCat.Trim().Length > 0) { req.SellerCids = sellerCat; } ItemsInventoryGetResponse response = TopClient.Execute(req, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform); if (response.IsError) { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body); } else { totalResults = response.TotalResults; foreach (Item item in response.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString()))) { if (isnum_iid) { strbNumIid.Append(item.NumIid.ToString() + ","); } else { itemDic.Add(item.NumIid.ToString(), item); } } } } while (totalResults > pageNo2 * 200); #endregion } else { if (status == "0") { #region 获取出售中的商品 do { pageNo++; ItemsOnsaleGetRequest req = new ItemsOnsaleGetRequest(); req.Fields = reqName; req.PageSize = 200L; req.PageNo = Convert.ToInt64(pageNo); req.OrderBy = "list_time:asc"; if (strMainWord.Length > 0) { req.Q = strMainWord; } if (sellerCat.Trim().Length > 0) { req.SellerCids = sellerCat; } ItemsOnsaleGetResponse response = TopClient.Execute <ItemsOnsaleGetResponse>(req, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform); if (response.IsError) { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body); } else { totalResults = response.TotalResults; foreach (Item item in response.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString()))) { if (isnum_iid) { strbNumIid.Append(item.NumIid.ToString() + ","); } else { itemDic.Add(item.NumIid.ToString(), item); } } } } while (totalResults > pageNo * 200); #endregion } else if (status == "1") { #region 获取仓库中的商品 do { pageNo++; ItemsInventoryGetRequest req = new ItemsInventoryGetRequest { Fields = reqName, PageSize = 200, PageNo = pageNo }; if (strMainWord.Length > 0) { req.Q = strMainWord; } if (sellerCat.Trim().Length > 0) { req.SellerCids = sellerCat; } ItemsInventoryGetResponse response = TopClient.Execute(req, sellerinfo.top_session, (TopClient.CrmPlatForm)useplatform); if (response.IsError) { TxtLog.WriteLine("getItemListErrorLog", sellerinfo.strUserNick + ":" + sellerinfo.strUserId + "=== :出现异常:" + response.Body); } else { totalResults = response.TotalResults; foreach (Item item in response.Items.Where(item => !itemDic.ContainsKey(item.NumIid.ToString()))) { if (isnum_iid) { strbNumIid.Append(item.NumIid.ToString() + ","); } else { itemDic.Add(item.NumIid.ToString(), item); } } } } while (totalResults > pageNo * 200); #endregion } } if (isnum_iid) { itemDic = SearchNumIid(strbNumIid.ToString(), sellerinfo, reqName, useplatform); } return(itemDic); }