public void Succeeded(string currentUrl, string htmlContent, int level, List <string> urls) { Task task1 = new Task(() => { List <string> existUrls = UrlOperate.GetExistUrls(_rootUrl, urls); if (existUrls != null && existUrls.Count > 0) { urls.RemoveAll(u => existUrls.Contains(u)); } UrlOperate.AddUrls(_rootUrl, urls, level); }); Task task2 = new Task(() => { if (UrlOperate.IsLocalization(_rootUrl, currentUrl)) { return; } string fileName = _fileOperate.Save(_rootUrl, currentUrl, htmlContent); UrlOperate.UpdateLocalization(_rootUrl, currentUrl, fileName); }); task1.Start(); task2.Start(); Task.WaitAll(task1, task2); Console.Write(currentUrl + " " + level + " " + (urls != null ? urls.Count : 0) + "\r\n"); }
/// <summary> /// 拖动选择文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="obj"></param> private void u_DragDropFileto(object sender, EventArgs e, UrlReplace obj) { var p = ((Array)((DragEventArgs)e).Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); obj.LocalPath = p; UrlOperate.PushUrl(obj.ToUrlInfo()); DataHistoryOperate.AddLog(obj.ToUrlInfo()); }
private void u_ClickReplaceEvent(object sender, EventArgs e, UrlReplace obj) { if (ofd_file.ShowDialog() == DialogResult.OK) { obj.LocalPath = ofd_file.FileName; UrlOperate.PushUrl(obj.ToUrlInfo()); DataHistoryOperate.AddLog(obj.ToUrlInfo()); } }
public string getTopic(object MessageItemGuid, object Title, object HandleUrl) { string strHandleUrl = HandleUrl.ToString(); if (strHandleUrl.IndexOf("?") > 0) { strHandleUrl += "&MessageItemGuid=" + MessageItemGuid.ToString(); } else { strHandleUrl += "?MessageItemGuid=" + MessageItemGuid.ToString(); } return("<a class=\"HomeTitle\" href =\"javascript:OpenWindow('" + UrlOperate.GetHandlelUrl(strHandleUrl) + "')\" title=\"" + Title + "\">" + Title + "</a>"); }
/// <summary> /// 检查是否有Html标签 /// </summary> /// <param name="html">Html源码</param> /// <returns>存在为True</returns> public static bool CheckHtml(string html) { html = UrlOperate.URLDecode(html); string filter = "<[\\s\\S]*?>"; if (Regex.IsMatch(html, filter)) { return(true); } filter = "[<>][\\s\\S]*?"; if (Regex.IsMatch(html, filter)) { return(true); } return(false); }
/// <summary> /// 返回过滤掉所有的Html标签后的字符串 /// </summary> /// <param name="html">Html源码</param> /// <returns>过滤Html标签后的字符串</returns> public static string FilterAllHtml(string html) { string filter = "<[\\s\\S]*?>"; html = UrlOperate.URLDecode(html); if (Regex.IsMatch(html, filter)) { html = Regex.Replace(html, filter, ""); } filter = "[<>][\\s\\S]*?"; if (Regex.IsMatch(html, filter)) { html = Regex.Replace(html, filter, ""); } return(html); }
public void Process() { UrlStoreModel firstUrl = UrlOperate.GetFirstUrl(this._ruleConfig.Url); if (firstUrl == null) { return; } Console.WriteLine("Current url {0}.", firstUrl.Url); ArticleModel model = null; try { string htmlContent = this.GetLocalContent(firstUrl); if (string.IsNullOrEmpty(htmlContent)) { Console.WriteLine("Load html content from url."); model = this._articleBuilder.BuildModel(firstUrl.Url, this._currentRule); } else { Console.WriteLine("Load html content from local."); model = this._articleBuilder.BuildModel(firstUrl.Url, htmlContent, this._currentRule); } Console.WriteLine("Current article title : {0}.", model != null ? model.Title : ""); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Article build failed : " + ex.Message); Console.ResetColor(); LogHelper.WriteError("Url store info : " + JsonConvert.SerializeObject(firstUrl) + "/r/nArticle build failed : " + ex.Message); } //db int articleId = this._sqlOperate.AddArticleModel(model); Console.WriteLine("Insert article {0} to db.", articleId); UrlOperate.MoveUrl(this._ruleConfig.Url, firstUrl); Console.WriteLine("Move url {0}.", firstUrl.Url); this.Process(); }
private void u_EnableLixian(object sender, EventArgs e, UrlReplace obj) { DataHistoryOperate.AddLog(obj.ToUrlInfo()); UrlOperate.PushLixianUrl(obj.PsnUrl, obj.LixianUrl); }
private void QueryHandle(string query) { HeaderFields = ParseQuery(query); if ((HeaderFields == null) || !HeaderFields.ContainsKey("Host")) { SendBadRequest(); } else { int num; string requestedPath; int index; if (HttpRequestType.ToUpper().Equals("CONNECT")) { index = RequestedPath.IndexOf(":"); if (index >= 0) { requestedPath = RequestedPath.Substring(0, index); num = RequestedPath.Length > (index + 1) ? int.Parse(RequestedPath.Substring(index + 1)) : 443; } else { requestedPath = RequestedPath; num = 80; } } else { index = HeaderFields["Host"].IndexOf(":"); if (index > 0) { requestedPath = HeaderFields["Host"].Substring(0, index); num = int.Parse(HeaderFields["Host"].Substring(index + 1)); } else { requestedPath = HeaderFields["Host"]; num = 80; } if (HttpRequestType.ToUpper().Equals("POST")) { int tempnum = query.IndexOf("\r\n\r\n"); _mHttpPost = query.Substring(tempnum + 4); } } var localFile = String.Empty; if (MonitorLog.RegexUrl(RequestedUrl)) { localFile = UrlOperate.MatchFile(RequestedUrl); } _uinfo.PsnUrl = string.IsNullOrEmpty(_uinfo.PsnUrl) ? RequestedUrl : _uinfo.PsnUrl; if (!HttpRequestType.ToUpper().Equals("CONNECT") && localFile != string.Empty && File.Exists(localFile)) { _uinfo.ReplacePath = localFile; _updataUrlLog(_uinfo); SendLocalFile(localFile, HeaderFields.ContainsKey("Range") ? HeaderFields["Range"] : null, HeaderFields.ContainsKey("Proxy-Connection") ? HeaderFields["Proxy-Connection"] : null); } else { try { bool iscdn; IPAddress hostIp = CdnOperate.GetCdnAddress(requestedPath, out iscdn); var remoteEp = new IPEndPoint(hostIp, num); DestinationSocket = new Socket(remoteEp.AddressFamily, SocketType.Stream, ProtocolType.Tcp); if (HeaderFields.ContainsKey("Proxy-Connection") && HeaderFields["Proxy-Connection"].ToLower().Equals("keep-alive")) { DestinationSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1); } DestinationSocket.BeginConnect(remoteEp, OnConnected, DestinationSocket); _uinfo.Host = hostIp.ToString(); _uinfo.IsCdn = iscdn; _uinfo.ReplacePath = string.Empty; _updataUrlLog(_uinfo); } catch { SendBadRequest(); } } } }
private Dictionary <string, string> ParseQuery(string query) { //离线加速 if (AppConfig.Instance().EnableLixian) { query = UrlOperate.GetQuery(query, ref _uinfo); } int index; var dictionary = new Dictionary <string, string>(); var strArray = query.Replace("\r\n", "\n").Split(new[] { '\n' }); if (strArray.Length > 0) { index = strArray[0].IndexOf(' '); if (index > 0) { HttpRequestType = strArray[0].Substring(0, index); strArray[0] = strArray[0].Substring(index).Trim(); } index = strArray[0].LastIndexOf(' '); if (index > 0) { HttpVersion = strArray[0].Substring(index).Trim(); RequestedUrl = strArray[0].Substring(0, index); } else { RequestedUrl = strArray[0]; } if (!String.IsNullOrEmpty(RequestedUrl) && RequestedUrl.ToLower().StartsWith("http")) { if (RequestedUrl.ToLower().StartsWith("http://")) { index = RequestedUrl.IndexOf('/', 7); } else if (RequestedUrl.ToLower().StartsWith("https://")) { index = RequestedUrl.IndexOf('/', 8); } RequestedPath = index == -1 ? "/" : RequestedUrl.Substring(index); } else { RequestedPath = RequestedUrl; } } for (int i = 1; i < strArray.Length; i++) { index = strArray[i].IndexOf(":"); if ((index <= 0) || (index >= (strArray[i].Length - 1))) { continue; } try { dictionary.Add(strArray[i].Substring(0, index), strArray[i].Substring(index + 1).Trim()); } catch { } } return(dictionary); }