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); } } } }
private void OPR_SendData(object sender, PublishType pt, bool isLogin, string Msg, object oResult) { if (pt == PublishType.PostDataOver) { IsOpen = true; ModelGatherItem modelArticle = (ModelGatherItem)oResult; ope.Message = modelArticle.Title + "_" + Msg; if (PublishOP != null) { PublishOP(this, ope); } } }
private void SendArticleContent(WebSiteHelper model, string Title, string Content, string ClassName, string ClassID) { ModelWebSite = model; try { LoadPublishModule(ModelWebSite.PublishName); if (iPublish != null) { //OutFalseOriginal(ref Title, ref Content); Title = Title.Replace("'", "''"); Content = Content.Replace("'", "''"); mGatherItem = new ModelGatherItem(); mGatherItem.Title = Title; mGatherItem.Content = Content; mClassList = new ModelClassItem(); mClassList.ClassID = ClassID; mClassList.ClassName = ClassName; iPublish.Publish_OutResult = OPR_SendData; iPublish.Publish_Init(ModelWebSite.WebSiteUrl, ModelWebSite.WebSiteLoginUrl, ModelWebSite.LoginUserName, ModelWebSite.LoginUserPwd, 0, string.Empty); iPublish.Publish_Type = PublishType.PostData; iPublish.Publish_PostData(mGatherItem, mClassList); } else { MeOutPut.Message = string.Format("插件不存在!或者插件有误!"); if (PublishOP != null) { PublishOP(this, MeOutPut); } } } catch (Exception ex) { MeOutPut.Message = string.Format("网站名称:{0} 网站地址:{1} 信息:{2} 发布失败!", ModelWebSite.WebSiteName, ModelWebSite.WebSiteUrl, ex.Message); if (PublishOP != null) { PublishOP(this, MeOutPut); } } }
/// <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); } })); }
/// <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); } })); }