private void ClbTaskList_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) { e.Effect = DragDropEffects.Copy; nmTaskId.Text = string.Empty; var a = e.Data.GetData(DataFormats.Text).ToString(); tbSourceUrl.Text = a; Uri uriA = new Uri(a); string formattedUrl = URLParser.Tokenize(uriA); tbUrlFormat.Text = formattedUrl; uriA = new Uri(formattedUrl); tbDestinationFormat.Text = uriA.Segments.LastOrDefault(); MessageBox.Show($"Drag and drop of {a}"); var htmlFragment = e.Data.GetData(DataFormats.Html).ToString().Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); var source = htmlFragment[8]; RetrieveBrowserData(source); //var testing = TestOfDragDropFormats(e); } else { e.Effect = DragDropEffects.None; MessageBox.Show("Invalid type for drag and drop."); } }
public DownloadReservation(string saveDir, string videoURL, string name) { SaveDir = saveDir; VideoURL = videoURL; Name = name; VideoID = URLParser.ExtractVideoID(videoURL); }
/// <summary> /// Parses the message. /// </summary> /// <param name="message">The message.</param> private void ParseMessage(Message message) { var urlParser = new URLParser(); var emailParser = new EMailParser(); var mathParser = new MathParser(); message.NewContent = mathParser.Parse(emailParser.Parse(urlParser.Parse(message.NewContent))); }
private void Tokenize(MyDownloadTask d) { var destinationFormat = URLParser.Tokenize(d.SourceUrl); Uri destFormat = new Uri(destinationFormat); var f = destFormat.Segments; var fileFormat = HttpUtility.UrlDecode(f[f.Length - 1]); tbDestinationFormat.Text = fileFormat; }
static void Main(string[] args) { URLParser parser = new URLParser(); parser.ExportDataFromFile(System.IO.Directory.GetCurrentDirectory() + "Test.txt"); Console.WriteLine("Data was serialized"); Console.ReadLine(); }
static void Main(string[] args) { string file = "file.txt"; URLsContainer container = new URLsContainer(file); URLSerializer.SaveXml(URLParser.Parse(container.URLs), "result.txt"); Console.Read(); }
static void Main(string[] args) { var URLs = URLParser.ParseFile(@""); //foreach(var url in URLs.Where(x => x.IsImage && !x.IsImageHoster).OrderBy(x => x.ToString())) foreach (var url in URLs.Where(x => !x.IsVideoURL && !x.IsImageHoster).OrderBy(x => x.ToString())) { Console.WriteLine(url); } Console.ReadKey(); }
/// <summary> /// Gets post's content with HTML tags. New lines and URLs are repleced by HTML tags. /// </summary> /// <param name="postText">Plain post text.</param> /// <returns>Post text with HTML tags.</returns> private string GetPostTextHTML(string postText) { string result = HTMLHelper.HTMLEncodeLineBreaks(HTMLHelper.HTMLEncode(postText)); URLParser urlParser = new URLParser(); result = urlParser.Replace(result, match => { string href = String.IsNullOrEmpty(match.Protocol) ? URLHelper.AddHTTPToUrl(match.URL) : match.URL; return String.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", href, match.URL); }); return result; }
/// <summary> /// Gets post's content with HTML tags. New lines and URLs are replaced by HTML tags. /// </summary> /// <param name="postText">Plain post text.</param> /// <returns>Post text with HTML tags.</returns> private string GetPostTextHTML(string postText) { string result = HTMLHelper.HTMLEncodeLineBreaks(HTMLHelper.HTMLEncode(postText)); URLParser urlParser = new URLParser(); result = urlParser.Replace(result, match => { string href = String.IsNullOrEmpty(match.Protocol) ? URLHelper.AddHTTPToUrl(match.URL) : match.URL; return(String.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>", href, match.URL)); }); return(result); }
public static void Main(string[] args) { /*var urlChecker = new URLChecker * { * ShemeRegex = @"", * HostRegex = @"", * PathRegex = @"", * ParametersRegex = @"" * };*/ using (var fs = new FileStream("../../url_list.txt", FileMode.Open, FileAccess.Read)) { XDocument document = URLParser.BuildXDocument(fs, Console.Out); document.Save("../../url_result.xml"); } }
static void Main(string[] args) { URLTxtReader urls = new URLTxtReader("input.txt"); URLSerialize.SaveXml(URLParser.Parse(urls.URLs), "result.txt"); }
// Operation : Add MyDownloadTask to List<MyDownloadTask>. public static List <MyDownloadTask> AddOrUpdateTasks(MyDownloadTask t) { List <MyDownloadTask> returnValue = new List <MyDownloadTask>(); using (Helper db = new Helper()) { var records = db.DownloadTasks .Include(b => b.Link) .Include(c => c.Exchange) .SingleOrDefault(a => a.Id == t.DownloadTaskId); int count = records != null ? 1 : 0; bool isExistingTask = (count > 0) ? true : false; if (isExistingTask) { //Id records.Name = t.TaskName; records.Link.Name = $"{t.TaskName} Link"; records.Link.SourceURL = t.SourceUrl; records.Link.FormattedURL = t.UrlFormat; records.Link.Destination = t.DownloadLocation; records.Link.DestinationFormat = t.DestinationFileFormat; db.SaveChanges(); } else { //Add a new record with this TaskName. Link l = new Link { Name = $"{t.TaskName} Link", SourceURL = t.SourceUrl, FormattedURL = t.UrlFormat, Destination = t.DownloadLocation, DestinationFormat = t.DestinationFileFormat }; db.Links.Add(l); Download download = new Download { At = DateTime.Today, LinkId = l.Id, Progress = 0, Status = "Pending", SourceLink = URLParser.getThisDownloadsUrl(t.UrlFormat, DateTime.Today) }; db.Downloads.Add(download); Exchange exchange = new Exchange(); if (l.SourceURL.ToLower().Contains("nseindia")) { exchange = db.Exchanges.SingleOrDefault(x => x.Name == "NSE"); } else if (l.SourceURL.ToLower().Contains("bseindia")) { exchange = db.Exchanges.SingleOrDefault(x => x.Name == "BSE"); } else { Uri j = new Uri(l.SourceURL); exchange = new Exchange { Name = j.Host }; db.Exchanges.Add(exchange); db.SaveChanges(); } db.SaveChanges(); DownloadTask dt = new DownloadTask { Name = t.TaskName, LinkId = l.Id, ExchangeId = exchange.Id }; db.DownloadTasks.Add(dt); db.SaveChanges(); } returnValue = GetTaskList(); } return(returnValue); }
/// <summary> /// 指定した板の移転を追跡 /// </summary> /// <param name="board">追跡する板</param> /// <param name="recursive">移転先がさらに移転していた場合、再起追跡するかどうか</param> /// <returns>追跡できればtrue、失敗すればfalseを返す</returns> public bool Trace(BoardInfo board, bool recursive) { if (board == null) { throw new ArgumentNullException("board"); } traceList.Clear(); result = null; Check: // Htmlデータを取得 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(board.Url); req.UserAgent = TwinDll.UserAgent; req.AddRange(0, 499); HttpWebResponse res = (HttpWebResponse)req.GetResponse(); string html; using (StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("Shift_Jis"))) html = sr.ReadToEnd(); res.Close(); // サーバー移転 if (html.IndexOf("2chbbs..") >= 0) { TwinDll.Output("{0} が移転しています。", board.Url); // 移転先のURLを取得 Match m = Regex.Match(html, "<a href=\"(?<url>.+?)\">GO !</a>", RegexOptions.IgnoreCase); if (m.Success) { string newUrl = m.Groups["url"].Value; TwinDll.Output("移転先 {0} を発見しました。", newUrl); result = URLParser.ParseBoard(m.Groups["url"].Value); if (result != null) { result.Name = board.Name; traceList.Add(result); OnTracing(new ServerChangeEventArgs(board, result)); if (recursive) { board = result; html = null; goto Check; } } } } // 追跡終了した場合は板名を取得 else if (result != null) { if (String.IsNullOrEmpty(result.Name)) { Match m = Regex.Match(html, "<title>(?<t>.+?)</title>", RegexOptions.IgnoreCase); if (m.Success) { result.Name = m.Groups["t"].Value; } } TwinDll.Output("{0} の追跡に成功しました。", result.Name); } return((result != null) ? true : false); }