/// <summary> /// 分析网址列表 /// </summary> private void Run_Task(int index, int threadindex) { if (modelTask == null) { return; } if (modelTask.IsSpiderUrl == 1) { try { MessageOut("正在分析采集列表个数!"); foreach (string linkUrl in modelTask.CollectionContent.Split(new string[] { "$$$$" }, StringSplitOptions.RemoveEmptyEntries)) { try { List <string> TestListLinkUrl = _gatherWork.SplitWebUrl(linkUrl); foreach (string str in TestListLinkUrl) { GetAllLinkUrl(str); //暂停 Thread.Sleep(1 * 1000); } } catch (Exception ex1) { Log4Helper.Write(V5_Utility.Utility.LogLevel.Error, ex1.StackTrace, ex1); continue; } } } catch (Exception ex) { //MessageOut("分析网页列表出错!" + ex.Message); Log4Helper.Write(V5_Utility.Utility.LogLevel.Error, ex.StackTrace, ex); } } }
public static XmlDocument GetToolboxItemsConfigFile() { try { //load config info string configFile = Path.Combine(Application.StartupPath, MainConstants.FILE_TOOLBOXITEMS); if (!File.Exists(configFile)) { throw new FileNotFoundException("File not found", configFile); } XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.Load(configFile); return(objXmlDoc); } catch (FileNotFoundException fx) { Log4Helper.Write("GetToolboxItemsConfigFile", fx.FileName, fx, LogSeverity.Error); return(null); } catch (Exception ex) { Log4Helper.Write("GetToolboxItemsConfigFile", ex); return(null); } }
private void StartLocal() { try { string str = string.Empty; string LocalSQLiteName = "Data\\Collection\\" + Model.TaskName + "\\SpiderResult.db"; DataTable dtData = DbHelper.Query(LocalSQLiteName, "Select * From Content").Tables[0]; if (!Directory.Exists(Model.SaveDirectory2)) { Directory.CreateDirectory(Model.SaveDirectory2); } var outPut = PluginUtility.ListIOutputFormatPlugin.Where(x => x.Format == Model.SaveFileFormat2); if (outPut != null) { foreach (var item in outPut) { var r = item.RunSave(dtData, Model); if (r.IsOk) { gatherEv.Message = "保存成功!" + r.Message; PublishCompalteDelegate?.Invoke(this, gatherEv); } else { gatherEv.Message = "错误!" + r.Message; PublishCompalteDelegate?.Invoke(this, gatherEv); } } } } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); } }
public static XmlDocument GetCGConfigFile() { try { //load config info string configFile = Path.Combine(Application.StartupPath, Constants.FILE_CGCONFIG); if (!File.Exists(configFile)) { string configContent = UtilityHelper.GetCgConfig(); StreamWriter sw = new StreamWriter(configFile); sw.Write(configContent); sw.Close(); sw = null; } XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.Load(configFile); return(objXmlDoc); } catch (Exception ex) { Log4Helper.Write("ConfigCtrl.GetCGConfigFile", ex); throw; } }
protected void ExecuteTryCatchBlock(TryCatchBlock method, string ErrorMsg) { try { method(); } catch (ThreadAbortException) { SetMessageLn("Execution Aborted!"); if (OperationFailed != null) { OperationFailed(); } } catch (ThreadInterruptedException) { SetMessageLn("Execution Aborted!"); if (OperationFailed != null) { OperationFailed(); } } catch (Exception ex) { Log4Helper.Write(ErrorMsg + this.Caption, ex); SetMessageLn(ErrorMsg + "Error:" + ex.Message); if (OperationFailed != null) { OperationFailed(); } } }
private static XmlDocument GetTaskConfigFile(string taskid, string taskname) { try { //load config info string folder = Path.Combine(Application.StartupPath, Constants.FOLDER_TASKS); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string configFile = Path.Combine(folder, String.Concat(taskid, ".xml")); if (!File.Exists(configFile)) { string configContent = UtilityHelper.GetTaskConfig(taskid, taskname); StreamWriter sw = new StreamWriter(configFile); sw.Write(configContent); sw.Close(); sw = null; } XmlDocument objXmlDoc = new XmlDocument(); objXmlDoc.Load(configFile); return(objXmlDoc); } catch (Exception ex) { Log4Helper.Write("ConfigCtrl.GetTaskConfigFile:" + taskname, ex); throw; } }
public static string DeleteTask(TaskInfo task) { try { XmlDocument objXmlDoc = GetCGConfigFile(); if (objXmlDoc == null) { return("Config file does not exist!"); } DeleteTaskNode(objXmlDoc, task); SetCGConfigFile(objXmlDoc); //delete task file string folder = Path.Combine(Application.StartupPath, Constants.FOLDER_TASKS); string taskFile = Path.Combine(folder, String.Concat(task.TaskId, ".xml")); File.Delete(taskFile); return(Constants.STATUS_SUCCESS); } catch (Exception ex) { Log4Helper.Write("ConfigCtrl.DeleteTask:" + task.TaskName, ex); return(Constants.STATUS_FAIL); } }
/// <summary> /// 加载插件 /// </summary> public static void LoadAllDlls() { #region 发布 try { ListIPublish.Clear(); string[] publishFiles = Directory.GetFiles(PublishModulesPath, "*Modules.dll"); foreach (string str2 in publishFiles) { try { Assembly assembly = Assembly.LoadFrom(str2); FileInfo fi = new FileInfo(str2); string ff = fi.Name.Replace(fi.Extension, ""); ff = ff.Replace("V5.", ""); IPublish item = (IPublish)Activator.CreateInstance(assembly.GetType("V5.DataPlugins." + ff)); ListIPublish.Add(item); continue; } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); continue; } } } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); } #endregion #region PublishContent try { ListIPublishContent.Clear(); string[] publiscContentDirs = Directory.GetDirectories(BaseDirectory + "\\Plugins\\V5.DataPublish.PublishContent\\"); foreach (string dir in publiscContentDirs) { string[] filess = Directory.GetFiles(dir, "*PublishContent.dll"); try { if (filess.Length == 0) { break; } string file = filess[0]; Assembly assembly = Assembly.LoadFrom(file); FileInfo fi = new FileInfo(file); string ff = fi.Name.Replace(fi.Extension, ""); ff = ff.Replace("V5.", ""); IPublishContent item = (IPublishContent)Activator.CreateInstance(assembly.GetType("V5.DataPlugins." + ff)); ListIPublishContent.Add(item); } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); continue; } } } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); } #endregion }
private void WorkMethod(int taskindex, int threadindex) { string Title = string.Empty, Content = string.Empty; StringBuilder sbContent = new StringBuilder(); if (Model != null) { IPublish iPublish = Utility.GetIPublishByName(Model.PublishName); iPublish.Publish_Init(Model.WebSiteUrl, Model.WebSiteLoginUrl, Model.LoginUserName, Model.LoginUserPwd, 0, string.Empty); iPublish.Publish_OutResult = OPR_SendData; string[] files = Directory.GetFiles(Model.FileSourcePath, "*.html"); int lLen = files.Length; for (int i = 0; i < lLen; i++) { if (IsOpen) { IsOpen = false; try { string file = files[i]; FileInfo fiFile = new FileInfo(file); Title = fiFile.Name.Replace(fiFile.Extension, ""); int l = fiFile.Name.LastIndexOf("_"); if (l > -1) { Title = Title.Substring(0, l); } StreamReader sr = new StreamReader(file, Encoding.Default); sbContent.Append(sr.ReadToEnd()); sr.Close(); if (sbContent.Length >= 300) { //发布文章 ModelGatherItem mGatherItem = new ModelGatherItem(); mGatherItem.Title = Title; mGatherItem.Content = sbContent.ToString(); ModelClassItem mClassList = new ModelClassItem(); mClassList.ClassID = "1"; mClassList.ClassName = "美容知识"; iPublish.Publish_PostData(mGatherItem, mClassList); } sbContent.Remove(0, sbContent.Length); // File.Delete(file); Thread.Sleep(1000);//这个可以自定义时间 } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, "文件发布错误!", ex); continue; } } else { Thread.Sleep(5000); } } } }
protected override void OnException(ExceptionContext filterContext) { base.OnException(filterContext); var ex = filterContext.Exception; Log4Helper.Write(ex.ToString(), LogMessageType.Error); }
/// <summary> /// 登陆后台 /// </summary> private void ToolStripMenuItem_LoginAdmin_Click(object sender, EventArgs e) { try { string WebSiteID = Get_DataViewID(); } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); MessageBox.Show("后台登陆失败!" + ex.Message); } }
public static void ShowMessageBox(string module, string troubleshooting, Exception ex) { Log4Helper.Write(module, ex); //MessageBox.Show(strMsg, Constants.MSG_SYSTEMERROR, MessageBoxButtons.OK, MessageBoxIcon.Error); FrmMessageBox frmMsg = new FrmMessageBox(); frmMsg.Module = module; frmMsg.Exception = ex; frmMsg.TroubleShooting = troubleshooting; frmMsg.ShowDialog(); }
/// <summary> /// 任务开始 /// </summary> private void ToolStripMenuItem_TaskStart_Click(object sender, EventArgs e) { try { DALTask dal = new DALTask(); ModelTask model = new ModelTask(); int ID = Get_DataViewID(); if (listGatherTask.ContainsKey(ID.ToString())) { var Spider = listGatherTask.FirstOrDefault().Value; if (Spider.Stopped) { Spider.Start(); } } else { model = dal.GetModelSingleTask(ID); if (model.Status != 1) { MainEvents.OutPutWindowEventArgs ev = new MainEvents.OutPutWindowEventArgs(); ev.Message = "任务关闭中.不可采集..."; OutPutWindowDelegate?.Invoke(this, ev); return; } string baseDir = AppDomain.CurrentDomain.BaseDirectory + "Data\\Collection\\"; string SQLiteName = baseDir + model.TaskName + "\\SpiderResult.db"; if (!File.Exists(SQLiteName)) { CreateDataFile(model.TaskName, ID); } var Spider = new SpiderHelper(); Spider.modelTask = model; Spider.GatherWorkDelegate = OutUrl; Spider.GatherComplateDelegate = GatherOverDelegate; Spider.OutPutTaskProgressBarDelegate = OutPutTaskProgressBarDelegate; Spider.TaskIndex = this.dataGridView_TaskList.SelectedRows[0].Index; Spider.Start(); lock (listGatherTask) { if (!listGatherTask.ContainsKey(ID.ToString())) { listGatherTask.Add(ID.ToString(), Spider); } } } } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex.StackTrace, ex); } }
private static bool SetCGConfigFile(XmlDocument xmldoc) { try { string configFile = Path.Combine(Application.StartupPath, Constants.FILE_CGCONFIG); xmldoc.Save(configFile); return(true); } catch (Exception ex) { Log4Helper.Write("ConfigCtrl.SetCGConfigFile", ex); return(false); } }
public void StopThread() { try { if (_threadMain != null && _threadMain.ThreadState != ThreadState.Stopped) { _threadMain.Abort(); } } catch (Exception ex) { Log4Helper.Write("KaixinBase.StopThread", ex); throw; } }
private void PublishDataToDB(int taskindex, int threadindex) { string LocalSQLiteName = "Data\\Collection\\" + ModelTask.TaskName + "\\SpiderResult.db"; DataTable dtData = SQLiteHelper.Query1(LocalSQLiteName, "Select * From Content").Tables[0]; int saveDateType = ModelTask.SaveDataType3.Value; string connectionString = ModelTask.SaveDataUrl3; string exeSQL = ModelTask.SaveDataSQL3; string sql = string.Empty; switch (saveDateType) { case 1: break; case 2: foreach (DataRow dr in dtData.Rows) { try { sql = exeSQL; foreach (ModelTaskLabel mTaskLabel in ModelTask.ListTaskLabel) { sql = sql.Replace("[" + mTaskLabel.LabelName + "]", dr[mTaskLabel.LabelName].ToString().Replace("'", "''")); } sql = sql.Replace("[Guid]", Guid.NewGuid().ToString()); sql = sql.Replace("[Url]", dr["HrefSource"].ToString()); DbHelperSQL.connectionString = ModelTask.SaveDataUrl3; DbHelperSQL.ExecuteSql(sql); gatherEv.Message = dr["HrefSource"].ToString() + ":保存数据库成功!"; PublishCompalteDelegate(this, gatherEv); } catch (Exception ex) { Log4Helper.Write(V5_Utility.Utility.LogLevel.Error, dr["HrefSource"].ToString() + ":保存数据库失败!", ex); continue; } } break; case 3: break; case 4: break; case 5: break; } }
/// <summary> /// 发送数据 /// </summary> private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { this.Invoke(new MethodInvoker(delegate() { try { Title = this.txtTitle.Text; ModelGatherItem m_GatherItem = new ModelGatherItem(); m_GatherItem.Title = Title; m_GatherItem.Content = Content; m_GatherItem.CreateTime = DateTime.Now.ToString(); } catch (Exception ex) { MessageBox.Show(this, "文章发布出错!" + ex.Message + ex.InnerException + ex.StackTrace + ex.Source, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); Log4Helper.Write(LogLevel.Error, ex); } })); }
public static string GenerateEntityXml(string outputPath, EntityInfo entity) { string ret = String.Empty; if (entity == null || !Directory.Exists(outputPath)) { return(ret); } Log4Helper.Write("GenerateEntityXml", String.Format("Process of entity {0} starts at {1}.", entity.ClassName, System.DateTime.Now.ToString("s")), LogSeverity.Info); using (System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(System.IO.Path.Combine(outputPath, String.Concat(entity.ClassName, ".xml")), System.Text.Encoding.UTF8)) { xtw.Formatting = System.Xml.Formatting.Indented; xtw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); //generate entity calss xtw.WriteStartElement("entity"); xtw.WriteAttributeString("namespace", entity.NameSpace); xtw.WriteAttributeString("name", entity.ClassName); #region columns/properties //generate property node xtw.WriteStartElement("fields"); foreach (FieldInfo field in entity.Fileds) { xtw.WriteStartElement("property"); xtw.WriteAttributeString("type", field.Type); xtw.WriteAttributeString("name", field.Name); xtw.WriteAttributeString("privateFieldName", field.PrivateFieldName); xtw.WriteAttributeString("paramName", field.ParamName); xtw.WriteAttributeString("propetyName", field.PropertyName); xtw.WriteAttributeString("csharpType", field.CSharpType); xtw.WriteEndElement(); } xtw.WriteEndElement(); #endregion ret = xtw.ToString(); xtw.WriteEndElement(); xtw.Flush(); xtw.Close(); } Log4Helper.Write("GenerateEntityXmlFromTable", String.Format("Process of table {0} ends at {1}.", entity.ClassName, System.DateTime.Now.ToString("s")), LogSeverity.Info); return(ret); }
/// <summary> /// 登陆后台 /// </summary> private void ToolStripMenuItem_LoginAdmin_Click(object sender, EventArgs e) { try { string WebSiteID = Get_DataViewID(); //ModelWebSiteItem model = new DALWebSite().GetModle(ID); //IPublish p = Utility.GetIPublishByName(model.PublishName); //if (p != null) { // string loginUrl = p.Publish_GetLoginAdminUrl(model.WebSiteUrl, // model.WebSiteLoginUrl); // System.Diagnostics.Process.Start(loginUrl); //} } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); MessageBox.Show("后台登陆失败!" + ex.Message); } }
public static void ShowMessageBox(string module, string troubleshooting, Exception ex) { //ex.TargetSite() //string strMsg = ""; //strMsg = "Message:" + ex.Message + "\r\n"; //strMsg += "Source:" + ex.Source + "\r\n"; //strMsg += "TargetSite:" + ex.TargetSite + "\r\n"; //strMsg += "StackTrace:" + ex.StackTrace + "\r\n"; //MessageBox.Show(strMsg, Constants.MSG_SYSTEMERROR, MessageBoxButtons.OK, MessageBoxIcon.Error); Log4Helper.Write(module, ex); FrmMessageBox frmMsg = new FrmMessageBox(); frmMsg.Module = module; frmMsg.Exception = ex; frmMsg.TroubleShooting = troubleshooting; frmMsg.ShowDialog(); }
public void Initial(bool newhttp) { try { } catch (ThreadAbortException) { throw; } catch (ThreadInterruptedException) { throw; } catch (Exception ex) { Log4Helper.Write("KaixinBase.Initial", ex); throw; } }
private static bool SetTaskConfigFile(XmlDocument xmldoc, string taskid) { try { string folder = Path.Combine(Application.StartupPath, Constants.FOLDER_TASKS); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string configFile = Path.Combine(folder, String.Concat(taskid, ".xml")); xmldoc.Save(configFile); return(true); } catch (Exception ex) { Log4Helper.Write("ConfigCtrl.SetTaskConfigFile" + taskid, ex); return(false); } }
/// <summary> /// 发布信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorker_Send_DoWork(object sender, DoWorkEventArgs e) { try { this.btnSave.Invoke(new MethodInvoker(delegate() { this.Save_CheckBoxList(); int num = 0; for (int i = 0; i < checkedListBox_WebSiteClassList.Items.Count; i++) { if (checkedListBox_WebSiteClassList.GetItemChecked(i)) { num++; ModelWebSiteChecked model = (ModelWebSiteChecked)this.checkedListBox_WebSiteClassList.Items[0]; string[] ArrValue = model.Value.Split(new string[] { "→" }, StringSplitOptions.None); WebSiteHelper ModelSite = Common.GetList <WebSiteHelper>(p => p.Uuid == ArrValue[1]).SingleOrDefault(); string[] ArrClassName = model.Name.Split(new string[] { "→" }, StringSplitOptions.None); ListItem LiClassList = new ListItem(ArrValue[2], ArrClassName[2]); PublishTask PublishTask = new PublishTask(); PublishTask.PublishOP = PublishOP; PublishTask.CommonSendContent(ModelSite, this.Title, this.Content, LiClassList.Text, LiClassList.Value); } } if (num == 0) { if (MessageBox.Show("你没有选择一个选择保存文章!确定要这样!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK) { this.Close(); this.Dispose(); } } else { this.Close(); this.Dispose(); } })); } catch (Exception ex) { MessageBox.Show("文章发布出错!" + ex.Message + ex.InnerException + ex.StackTrace + ex.Source, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); Log4Helper.Write(LogLevel.Error, ex); } }
public static string EditTask(TaskInfo task) { try { XmlDocument objXmlDoc = GetCGConfigFile(); if (objXmlDoc == null) { return("Config file does not exist!"); } if (task.TaskId == null || task.TaskId == string.Empty) { Random rd = new Random(); int num = rd.Next(1, 999999999); DateTime now = DateTime.Now; //获取系统时间 string taskId = now.Year.ToString() + now.Month.ToString() + now.Day.ToString() + now.Hour.ToString() + now.Minute.ToString() + now.Second.ToString() + now.Millisecond.ToString() + "_" + num.ToString(); task.TaskId = taskId; InsertTaskNode(objXmlDoc, task); } else { EditTaskNode(objXmlDoc, task); } bool ret = SetCGConfigFile(objXmlDoc); if (ret) { return(Constants.STATUS_SUCCESS); } else { return(Constants.STATUS_FAIL); } } catch (Exception ex) { Log4Helper.Write("ConfigCtrl.EditTask:" + task.TaskName, ex); return(Constants.STATUS_FAIL); } }
public void TaskStart() { try { _module = Constants.MSG_TASK; TaskRun(); if (ExecutionFinished != null) { ExecutionFinished(_taskid, _taskname); } } catch (ThreadAbortException) { //LogHelper.Write("TaskManager.TaskStart", "ThreadAbortException", LogSeverity.Info); SetMessageLn("Execution Aborted!"); if (Task.WriteLogToFile) { WriteLogToFile(Task.TaskName, this.ExecutionLog.ToString()); } } catch (ThreadInterruptedException) { //LogHelper.Write("TaskManager.TaskStart", "ThreadInterruptedException", LogSeverity.Info); SetMessageLn("Execution Aborted!"); if (Task.WriteLogToFile) { WriteLogToFile(Task.TaskName, this.ExecutionLog.ToString()); } } catch (Exception ex) { Log4Helper.Write("TaskManager.TaskStart", ex); SetMessageLn("Exception occurs, task is aborted! Error:" + ex.Message); if (Task.WriteLogToFile) { WriteLogToFile(Task.TaskName, this.ExecutionLog.ToString()); } } }
/// <summary> /// 绑定发布文章内容插件 /// </summary> private void Bind_LoadSendContentPlugins() { try { string[] publiscContentDirs = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory + "\\Plugins\\V5.DataPublish.PublishContent\\"); foreach (string dir in publiscContentDirs) { try { string file = Directory.GetFiles(dir, "*PublishContent.dll")[0]; FileInfo fiName = new FileInfo(file); ListViewItem lvItem = new ListViewItem(fiName.Name); this.listView_PublishContentPlugins.Items.Add(lvItem); } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex); continue; } } } catch (Exception) { return; } }
/// <summary> /// 分析列表 /// </summary> public void AnalyzeAllList() { OutMessageHandler?.Invoke("正在分析采集列表个数!"); if (Model.IsSource == 1) { AnalyzeSingleList(Model.DemoListUrl); } else { foreach (string linkUrl in Model.CollectionContent.Split(new string[] { "$$$$" }, StringSplitOptions.RemoveEmptyEntries)) { try { AnalyzeSingleList(linkUrl); } catch (Exception ex1) { Log4Helper.Write(LogLevel.Error, ex1.StackTrace, ex1); continue; } } } }
/// <summary> /// 发送数据 /// </summary> private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { this.Invoke(new MethodInvoker(delegate() { try { Title = this.txtTitle.Text; //Content = this.txtContent.InnerHtml; ModelGatherItem m_GatherItem = new ModelGatherItem(); m_GatherItem.Title = Title; m_GatherItem.Content = Content; m_GatherItem.CreateTime = DateTime.Now.ToString(); //for (int i = 0; i < checkedListBox_WebSiteClassList.Items.Count; i++) { // if (checkedListBox_WebSiteClassList.GetItemChecked(i)) { // ModelWebSiteChecked model = (ModelWebSiteChecked)this.checkedListBox_WebSiteClassList.Items[i]; // string[] ArrValue = model.Value.Split(new string[] { "→" }, StringSplitOptions.None); // string[] ArrClassName = model.Name.Split(new string[] { "→" }, StringSplitOptions.None); // WebSiteHelper ModelSite = Common.GetList<WebSiteHelper>(p => p.Uuid == ArrValue[1]).SingleOrDefault(); // ModelClassItem m_ClassItem = new ModelClassItem(); // m_ClassItem.ClassID = ArrValue[2]; // m_ClassItem.ClassName = ArrClassName[2]; // IPublish iPublish = Utility.GetIPublishByName(ModelSite.PublishName); // iPublish.Publish_Type = PublishType.PostData; // iPublish.Publish_Init(ModelSite.WebSiteUrl, "admin", ModelSite.LoginUserName, ModelSite.LoginUserPwd, 0, string.Empty); // iPublish.Publish_PostData(m_GatherItem, m_ClassItem); // } //} //if (MessageBox.Show(this, "站点信息发布完成!是否关闭本窗口~", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.OK) { // this.Close(); // this.Dispose(); //} } catch (Exception ex) { MessageBox.Show(this, "文章发布出错!" + ex.Message + ex.InnerException + ex.StackTrace + ex.Source, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); Log4Helper.Write(LogLevel.Error, ex); } })); }
/// <summary> /// 任务开始 /// </summary> private void ToolStripMenuItem_TaskStart_Click(object sender, EventArgs e) { try { DALTask dal = new DALTask(); ModelTask model = new ModelTask(); int ID = Get_DataViewID(); //检查目录是否存在 //model = dal.GetModelSingleTask(ID); if (listGatherTask.ContainsKey(ID.ToString())) { SpiderHelper Spider = listGatherTask.FirstOrDefault().Value; if (Spider.Stopped) { Spider.Start(); } } else { model = dal.GetModelSingleTask(ID); SpiderHelper Spider = new SpiderHelper(); Spider.modelTask = model; Spider.GatherWorkDelegate = OutUrl; Spider.GatherComplateDelegate = GatherOverDelegate; Spider.OutPutTaskProgressBarDelegate = OutPutTaskProgressBarDelegate; Spider.TaskIndex = this.dataGridView_TaskList.SelectedRows[0].Index; Spider.Start(); lock (listGatherTask) { if (!listGatherTask.ContainsKey(ID.ToString())) { listGatherTask.Add(ID.ToString(), Spider); } } } } catch (Exception ex) { Log4Helper.Write(LogLevel.Error, ex.StackTrace, ex); } }
/// <summary> /// 成为开发者的第一步,验证并相应服务器的数据 /// </summary> public void Auth() { string token = Config.WeixinToken; if (string.IsNullOrEmpty(token)) { Log4Helper.Write(string.Format("WeixinToken 配置项没有配置!"), LogMessageType.Error); } string echoString = HttpContext.Current.Request.QueryString["echoStr"]; string signature = HttpContext.Current.Request.QueryString["signature"]; string timestamp = HttpContext.Current.Request.QueryString["timestamp"]; string nonce = HttpContext.Current.Request.QueryString["nonce"]; if (CheckSignature(token, signature, timestamp, nonce)) { if (!string.IsNullOrEmpty(echoString)) { HttpContext.Current.Response.Write(echoString); HttpContext.Current.Response.End(); } } }