public static LiveJournalTarget FromString(string rawString) { Regex r = new Regex(extractionRegexString, RegexOptions.Compiled); Match m = r.Match(rawString); if (!m.Success) throw new ArgumentException(); LiveJournalTarget ret = new LiveJournalTarget(useStyleMine: false); ret.Username = m.Groups["username"].Value; ret.PostId = long.Parse(m.Groups["postId"].Value); string arguments = m.Groups["parameters"].Value; string[] kvps = arguments.Split('&', '='); for (int i = 0; i < kvps.Length - 1; i += 2) { string key = kvps[i]; string value = kvps[i + 1]; if (String.Equals(key, "style", StringComparison.OrdinalIgnoreCase)) { if (String.Equals(value, "mine", StringComparison.OrdinalIgnoreCase)) ret.UseStyleMine = true; } else if (String.Equals(key, "thread", StringComparison.OrdinalIgnoreCase)) { // Comment id. ret.CommentId = long.Parse(value); } else if (String.Equals(key, "page", StringComparison.OrdinalIgnoreCase)) { // Paget id. ret.Page = int.Parse(value); } } return ret; }
public string GetContent(LiveJournalTarget target, ILJClientData data) { Uri address = target.WithStyleMine(true).WithCutExpand().GetUri(); log.Info("Downloading " + address + "..."); var cookieContainer = new CookieContainer(); using (HttpClientHandler handler = new HttpClientHandler() { CookieContainer = cookieContainer }) using (HttpClient client = new HttpClient(handler) { BaseAddress = address }) { LJClientCookieData cookieData = (data as LJClientCookieData); if (cookieData != null) { Dictionary<string, string> cookies = cookieData.GetCookiesToUse(); foreach (var cookie in cookies) { log.DebugFormat("Using cookie {0}:{1}.", cookie.Key, cookie.Value); cookieContainer.Add(address, new Cookie(cookie.Key, cookie.Value)); } } string result = DownloadString(client, address); return result; } }
public bool SameItem(LiveJournalTarget b) { return this.PostId == b.PostId && this.CommentId == b.CommentId && this.Username == b.Username; }
/// <summary>Gets a page from a Url.</summary> public EntryPage GetFrom(LiveJournalTarget url, ILJClientData clientData) { // Gets the string. string content = Client.GetContent(url, clientData); // Parses the string as an entry page. EntryPage p = _parser.ParseAsAnEntryPage(content); return p; }