private void AddBlogtoQueue(List <TumblrBlog> bin, CancellationToken ct) { // Cancellation causes OCE. try { if (this.lvBlog.SelectedItems.Count > 0) { foreach (ListViewItem eachItem in this.lvBlog.SelectedItems) { TumblrBlog blog = this.LoadBlog(this.ExtractBlogname(eachItem.SubItems[2].Text)); string text = eachItem.SubItems[2].Text; //blog.Links.Clear(); //this.worker = new Thread(new ParameterizedThreadStart(this.RunParser)); //success = bin.TryAdd(blog, 2, ct); bin.Add(blog); this.addToQueueUI(blog); } } } catch (OperationCanceledException exception) { MessageBox.Show(exception.Message); } }
private void AddBlogtoQueue(BlockingCollection <TumblrBlog> bin, CancellationToken ct) { bool success = false; // Cancellation causes OCE. try { if (this.lvBlog.SelectedItems.Count > 0) { TumblrBlog blog = this.LoadBlog(this.ExtractBlogname(this.lvBlog.SelectedItems[0].SubItems[2].Text)); string text = this.lvBlog.SelectedItems[0].SubItems[2].Text; //blog.Links.Clear(); //this.worker = new Thread(new ParameterizedThreadStart(this.RunParser)); //success = bin.TryAdd(blog, 2, ct); success = bin.TryAdd(blog); if (success) { this.addToQueueUI(blog); } } } catch (OperationCanceledException exception) { MessageBox.Show(exception.Message); } }
private void AddBlog(object sender, EventArgs e) { ListViewItem lvItem; string str = this.ExtractBlogname(this.tBlogUrl.Text); if (str != null) { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text.Equals(str)) { MessageBox.Show("The entered URL is already in the library!", Application.ProductName); this.tBlogUrl.Text = string.Empty; return; } } lvItem = new ListViewItem(); { TumblrBlog newBlog = new TumblrBlog { _Name = str, _URL = this.ExtractUrl(this.tBlogUrl.Text), _DateAdded = DateTime.Now, _DownloadedImages = 0, _TotalCount = 0, _LastCrawled = System.DateTime.MinValue, _finishedCrawl = false }; lvItem.Text = newBlog._Name; lvItem.SubItems.Add(""); lvItem.SubItems.Add(""); lvItem.SubItems.Add(newBlog._URL); lvItem.SubItems.Add("0.00"); lvItem.SubItems.Add(newBlog._DateAdded.ToString()); lvItem.SubItems.Add("Not yet completely crawled!"); //lvItem.SubItems.Add(newBlog._finishedCrawl.ToString()); this.lvBlog.Items.Add(lvItem); this.SaveBlog(newBlog); newBlog = null; } this.tBlogUrl.Text = "http://"; if (Directory.Exists(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/")) { if (Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/", "*.tumblr").Count<string>() > 0) { this.toolShowExplorer.Enabled = true; this.toolRemoveBlog.Enabled = true; this.toolCrawl.Enabled = true; } else { this.toolShowExplorer.Enabled = false; this.toolRemoveBlog.Enabled = false; this.toolCrawl.Enabled = false; } } } }
private void AddBlog(object sender, EventArgs e) { ListViewItem lvItem; string str = this.ExtractBlogname(this.tBlogUrl.Text); if (str != null) { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text.Equals(str)) { MessageBox.Show("The entered URL is already in the library!", Application.ProductName); this.tBlogUrl.Text = string.Empty; return; } } lvItem = new ListViewItem(); { TumblrBlog newBlog = new TumblrBlog { _Name = str, _URL = this.ExtractUrl(this.tBlogUrl.Text), _DateAdded = DateTime.Now, _DownloadedImages = 0, _TotalCount = 0, _LastCrawled = System.DateTime.MinValue, _finishedCrawl = false }; lvItem.Text = newBlog._Name; lvItem.SubItems.Add(""); lvItem.SubItems.Add(""); lvItem.SubItems.Add(newBlog._URL); lvItem.SubItems.Add(newBlog._DateAdded.ToString()); lvItem.SubItems.Add("Not yet completely crawled!"); //lvItem.SubItems.Add(newBlog._finishedCrawl.ToString()); this.lvBlog.Items.Add(lvItem); this.SaveBlog(newBlog); newBlog = null; } this.tBlogUrl.Text = "http://"; if (Directory.Exists(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/")) { if (Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/", "*.tumblr").Count <string>() > 0) { this.toolShowExplorer.Enabled = true; this.toolRemoveBlog.Enabled = true; this.toolCrawl.Enabled = true; } else { this.toolShowExplorer.Enabled = false; this.toolRemoveBlog.Enabled = false; this.toolCrawl.Enabled = false; } } } }
public void LoadLibrary() { this.lvBlog.Items.Clear(); this.lblProcess.Text = ""; this.lblUrl.Text = ""; if (Directory.Exists(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/")) { string[] files = Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/", "*.tumblr"); if (files.Count <string>() > 0) { this.toolShowExplorer.Enabled = true; this.toolRemoveBlog.Enabled = true; this.toolCrawl.Enabled = true; } else { this.toolShowExplorer.Enabled = false; this.toolRemoveBlog.Enabled = false; this.toolCrawl.Enabled = false; } foreach (string str in files) { TumblrBlog blog = this.LoadBlog(Path.GetFileNameWithoutExtension(str)); if ((blog != null) && (blog._URL != null)) { //blog.TOTAL_COUNT = Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + blog._Name + "/").Length; ListViewItem item = new ListViewItem { Text = blog._Name }; if (blog._DownloadedImages > 0) { item.SubItems.Add(blog._DownloadedImages.ToString()); } else { item.SubItems.Add("Not yet crawled!"); } item.SubItems.Add(blog._TotalCount.ToString()); item.SubItems.Add(blog._URL); item.SubItems.Add(blog._DateAdded.ToString()); if (blog._LastCrawled == System.DateTime.MinValue) { item.SubItems.Add("Not yet completely crawled!"); } else { item.SubItems.Add(blog._LastCrawled.ToString()); } //item.SubItems.Add(blog._finishedCrawl.ToString()); this.lvBlog.Items.Add(item); blog = null; } } } }
private void addToQueueUI(TumblrBlog _blog) { //Update UI ListViewItem lvQueueItem = new ListViewItem(); lvQueueItem.Text = _blog._Name; //lvQueueItem.SubItems.Add(""); lvQueueItem.SubItems.Add("queued"); this.lvQueue.Items.Add(lvQueueItem); }
private void RemoveBlogFromQueue(BlockingCollection <TumblrBlog> bin, CancellationToken ct) { // IsCompleted == (IsAddingCompleted && Count == 0) if (bin.Count != 0) { TumblrBlog nextBlog = null; bin.TryTake(out nextBlog, 0, ct); this.lvQueue.Items.RemoveAt(0); //this.TumblrList.RemoveAt(TumblrList.Count - 1); //this.lvQueue.Items.RemoveAt(lvQueue.Items.Count - 1); } }
private TumblrBlog LoadBlog(string blogname) { TumblrBlog blog = new TumblrBlog(); try { using (Stream stream = new FileStream(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/" + blogname + ".tumblr", FileMode.Open, FileAccess.Read, FileShare.Read)) { IFormatter formatter = new BinaryFormatter(); blog = (TumblrBlog)formatter.Deserialize(stream); } } catch (Exception exception) { MessageBox.Show(exception.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); } return(blog); }
private bool Download(TumblrBlog blog, string fileLocation, string url, string filename) { if (!blog.Links.Contains(new Post(url, filename))) { try { using (WebClient client = new WebClient()) { client.DownloadFile(url, fileLocation); } } catch (Exception) { return(true); } return(true); } return(false); }
private bool SaveBlog(TumblrBlog newBlog) { if (newBlog == null) { return(false); } this.CreateDataFolder(newBlog._Name); try { using (Stream stream = new FileStream(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/" + newBlog._Name + ".tumblr", FileMode.Create, FileAccess.Write, FileShare.None)) { IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, newBlog); } } catch (Exception) { MessageBox.Show("The blog cannot be saved to disk!\nBe sure, that you have enough memory and proper file permissions", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); return(false); } return(true); }
private void ClipboardMonitor_OnClipboardChange(ClipboardFormat format, object data) { // Do Something... if (format.ToString() == "Text") { string[] URLs = data.ToString().Split(new char[0]); foreach (string _url in URLs) { ListViewItem lvItem; bool blogExists = false; string str = this.ExtractBlogname_paste(_url); if (str != null) { this.Invoke((Action)delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text.Equals(str)) { blogExists = true; return; } } }); if (blogExists) { } else { lvItem = new ListViewItem(); { TumblrBlog newBlog = new TumblrBlog { _Name = str, _URL = this.ExtractUrl(_url), _DateAdded = DateTime.Now, _DownloadedImages = 0, _TotalCount = 0, _LastCrawled = System.DateTime.MinValue, _finishedCrawl = false }; lvItem.Text = newBlog._Name; lvItem.SubItems.Add(""); lvItem.SubItems.Add(""); lvItem.SubItems.Add(newBlog._URL); lvItem.SubItems.Add("0.00"); lvItem.SubItems.Add(newBlog._DateAdded.ToString()); lvItem.SubItems.Add("Not yet completely crawled!"); //lvItem.SubItems.Add(newBlog._finishedCrawl.ToString()); this.SaveBlog(newBlog); newBlog = null; this.Invoke((Action)delegate { this.lvBlog.Items.Add(lvItem); }); } if (Directory.Exists(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/")) { if (Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/", "*.tumblr").Count<string>() > 0) { this.Invoke((Action)delegate { this.toolShowExplorer.Enabled = true; this.toolRemoveBlog.Enabled = true; this.toolCrawl.Enabled = true; }); } else { this.Invoke((Action)delegate { this.toolShowExplorer.Enabled = false; this.toolRemoveBlog.Enabled = false; this.toolCrawl.Enabled = false; }); } } } } } } }
private bool Download(TumblrBlog blog, string fileLocation, string url, string filename) { if (!blog.Links.Contains(new Post(url, filename))) { try { using (WebClient client = new WebClient()) { client.DownloadFile(url, fileLocation); } } catch (Exception) { return true; } return true; } return false; }
private void RunParser(TumblrBlog _blog) { MethodInvoker method = null; MethodInvoker invoker3 = null; int num = 0; int num2 = 0; int num3 = 0; //string blogname = ExtractBlogname(ApiUrl.ToString()); String ApiUrl = _blog._URL ; if (ApiUrl.Last<char>() != '/') { ApiUrl = ApiUrl + "/api/read?start="; } else { ApiUrl = ApiUrl + "api/read?start="; } this.CreateDataFolder(_blog._Name); this.BeginInvoke((Action)delegate { this.pgBar.Minimum = 0; this.pgBar.Maximum = _blog.TOTAL_COUNT; }); while (true) { this.wait_handle.WaitOne(); XDocument document = null; try { document = XDocument.Load(ApiUrl.ToString() + num.ToString() + "&num=50"); } catch (WebException) { //this.toolStop_Click(this, null); break; } if (num == 0) { try { foreach (var type in from data in document.Descendants("posts") select new { Total = data.Attribute("total").Value }) { _blog.TOTAL_COUNT = Convert.ToInt32(type.Total.ToString()); } if (method == null) { method = delegate { this.pgBar.Minimum = 0; this.pgBar.Maximum = _blog.TOTAL_COUNT; }; } this.BeginInvoke(method); } catch { _blog.TOTAL_COUNT = 0; //this.toolStop_Click(this, null); break; } } using (IEnumerator<XElement> enumerator2 = (from s in document.Descendants("photo-url") where (s.HasAttributes && s.Attribute("max-width").Value.Equals(Properties.Settings.Default.configImageSize.ToString())) && !s.Value.Contains("www.tumblr.com") select s).GetEnumerator()) { while (enumerator2.MoveNext()) { XElement p = enumerator2.Current; MethodInvoker invoker = null; string FileLocation; this.wait_handle.WaitOne(); string fileName = Path.GetFileName(new Uri(p.Value).LocalPath); if (!this.chkGIF.Checked || (Path.GetExtension(fileName).ToLower() != ".gif")) { FileLocation = Properties.Settings.Default.configDownloadLocation.ToString() + _blog._Name + "/" + fileName; _blog.Links.Add(new Post(p.Value, fileName)); if (invoker3 == null) { invoker3 = delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { item.SubItems[1].Text = Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + _blog._Name + "/").Length.ToString(); break; } } }; } this.BeginInvoke(invoker3); try { if (this.Download(FileLocation, p.Value)) { num2++; if (invoker == null) { invoker = delegate { this.lblUrl.Text = p.Value; this.smallImage.ImageLocation = FileLocation; if ((this.pgBar.Value + 1) < (this.pgBar.Maximum + 1)) { this.pgBar.Value++; } }; } this.BeginInvoke(invoker); } } catch (Exception) { continue; } num3++; } } } if (num3 == 0) { //this.toolStop_Click(this, null); // Finished Blog _blog._LastCrawled = DateTime.Now; _blog._finishedCrawl = true; // Update UI this.BeginInvoke((MethodInvoker)delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { // Update Listview about completed blog item.SubItems[4].Text = DateTime.Now.ToString(); item.SubItems[5].Text = "True"; // Update current crawling progress label int indexBlogInProgress = crawlingBlogs.IndexOf(_blog._Name); int lengthBlogInProgress = _blog._Name.Length; this.crawlingBlogs = crawlingBlogs.Remove(indexBlogInProgress, (lengthBlogInProgress+1)); this.lblProcess.Text = "Crawling Blogs - " + this.crawlingBlogs; } } }); return; } num += num3; num3 = 0; } }
private void RunParser(TumblrBlog _blog) { MethodInvoker method = null; bool readingDataBase = false; int numberOfPostsCrawled = 0; int numberOfPagesCrawled = 0; //string blogname = ExtractBlogname(ApiUrl.ToString()); String ApiUrl = _blog._URL ; if (ApiUrl.Last<char>() != '/') { ApiUrl = ApiUrl + "/api/read?start="; } else { ApiUrl = ApiUrl + "api/read?start="; } this.CreateDataFolder(_blog._Name); while (true) { this.wait_handle.WaitOne(); XDocument document = null; try { document = XDocument.Load(ApiUrl.ToString() + numberOfPostsCrawled.ToString() + "&num=50"); } catch (WebException) { //this.toolStop_Click(this, null); break; } if (numberOfPostsCrawled == 0) { try { foreach (var type in from data in document.Descendants("posts") select new { Total = data.Attribute("total").Value }) { _blog._TotalCount = Convert.ToInt32(type.Total.ToString()); } if (method == null) { if (TumblrActiveList.Count > 1) { method = delegate { try { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { item.SubItems[2].Text = _blog._TotalCount.ToString(); break; } } this.pgBar.Style = ProgressBarStyle.Marquee; this.pgBar.Minimum = 0; this.pgBar.Maximum = _blog._TotalCount; this.pgBar.Value = _blog._DownloadedImages; } catch (ArgumentOutOfRangeException) { this.pgBar.Style = ProgressBarStyle.Marquee; } }; } else { method = delegate { try { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { item.SubItems[2].Text = _blog._TotalCount.ToString(); break; } } this.pgBar.Style = ProgressBarStyle.Continuous; this.pgBar.Minimum = 0; this.pgBar.Maximum = _blog._TotalCount; this.pgBar.Value = _blog._DownloadedImages; } catch (ArgumentOutOfRangeException) { this.pgBar.Style = ProgressBarStyle.Marquee; } }; } } this.BeginInvoke(method); } catch { _blog._TotalCount = 0; //this.toolStop_Click(this, null); break; } } using (IEnumerator<XElement> enumerator2 = (from n in document.Descendants("post") where n.Elements("photo-url").Where(x => x.Attribute("max-width").Value == Properties.Settings.Default.configImageSize.ToString()).Any() && !n.Elements("photo-url").Where(x => x.Value == "www.tumblr.com").Any() from m in n.Descendants("photo-url") where m.Attribute("max-width").Value == Properties.Settings.Default.configImageSize.ToString() select m).GetEnumerator()) { numberOfPagesCrawled++; numberOfPostsCrawled = 50 * numberOfPagesCrawled; try { while (enumerator2.MoveNext()) { XElement p = enumerator2.Current; MethodInvoker invoker = null; string FileLocation; this.wait_handle.WaitOne(); string fileName = Path.GetFileName(new Uri(p.Value).LocalPath); if (!Properties.Settings.Default.configChkGIFState || (Path.GetExtension(fileName).ToLower() != ".gif")) { FileLocation = Properties.Settings.Default.configDownloadLocation.ToString() + _blog._Name + "/" + fileName; try { if (this.Download(_blog, FileLocation, p.Value, fileName)) { _blog.Links.Add(new Post(p.Value, fileName)); _blog._DownloadedImages = _blog.Links.Count; if (invoker == null) { invoker = delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { item.SubItems[1].Text = _blog.Links.Count.ToString(); double progress = (double) _blog._DownloadedImages / (double) _blog._TotalCount * 100; if (progress < 101) { progress = System.Math.Round(progress, 2); item.SubItems[4].Text = progress.ToString(); } else { item.SubItems[4].Text = "Inf"; } break; } } this.lblUrl.Text = p.Value; this.smallImage.ImageLocation = FileLocation; if ((this.pgBar.Value + 1) < (this.pgBar.Maximum + 1)) { this.pgBar.Value++; } }; } this.BeginInvoke(invoker); readingDataBase = false; } else { if (!readingDataBase) { readingDataBase = true; this.BeginInvoke((MethodInvoker)delegate { this.lblUrl.Text = "Skipping previously downloaded images - " + _blog._Name; }); } } } catch (Exception) { continue; } } } } catch (Exception) { continue; } } if (numberOfPostsCrawled >= _blog._TotalCount) { //this.toolStop_Click(this, null); // Finished Blog _blog._LastCrawled = DateTime.Now; _blog._finishedCrawl = true; this.SaveBlog(_blog); TumblrActiveList.Remove(_blog); // Update UI this.BeginInvoke((MethodInvoker)delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { // Update Listview about completed blog item.SubItems[6].Text = DateTime.Now.ToString(); //item.SubItems[7].Text = "True"; // Update current crawling progress label int indexBlogInProgress = crawlingBlogs.IndexOf(_blog._Name); int lengthBlogInProgress = _blog._Name.Length; this.crawlingBlogs = crawlingBlogs.Remove(indexBlogInProgress, (lengthBlogInProgress+1)); this.lblProcess.Text = "Crawling Blogs - " + this.crawlingBlogs; } } }); // remove index from listview after completed crawl if (Properties.Settings.Default.configRemoveFinishedBlogs) { this.BeginInvoke((MethodInvoker)delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { string path = Properties.Settings.Default.configDownloadLocation.ToString() + "Index/" + item.Text + ".tumblr"; if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } //this.LoadLibrary(); // Update UI item.Remove(); } } }); } if (TumblrActiveList.Count == 1) { this.BeginInvoke((MethodInvoker)delegate { this.pgBar.Style = ProgressBarStyle.Continuous; }); } if (TumblrActiveList.Count == 0) { this.BeginInvoke((MethodInvoker)delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { // Update current crawling progress label this.smallImage.ImageLocation = ""; this.crawlingBlogs = ""; this.lblUrl.Text = ""; this.lblProcess.Text = "Queue finished"; } } }); } return; } } }
private void RunParser(TumblrBlog _blog) { MethodInvoker method = null; bool readingDataBase = false; int numberOfPostsCrawled = 0; int numberOfPagesCrawled = 0; int lastCrawledPageReached = 0; //string blogname = ExtractBlogname(ApiUrl.ToString()); String ApiUrl = _blog._URL; if (ApiUrl.Last <char>() != '/') { ApiUrl = ApiUrl + "/api/read?start="; } else { ApiUrl = ApiUrl + "api/read?start="; } this.CreateDataFolder(_blog._Name); while (true) { this.wait_handle.WaitOne(); XDocument document = null; try { document = XDocument.Load(ApiUrl.ToString() + numberOfPostsCrawled.ToString() + "&num=50"); } catch (WebException) { //this.toolStop_Click(this, null); break; } if (numberOfPostsCrawled == 0) { try { foreach (var type in from data in document.Descendants("posts") select new { Total = data.Attribute("total").Value }) { _blog._TotalCount = Convert.ToInt32(type.Total.ToString()); } if (method == null) { if (TumblrActiveList.Count > 1) { method = delegate { try { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { item.SubItems[2].Text = _blog._TotalCount.ToString(); break; } } this.pgBar.Style = ProgressBarStyle.Marquee; this.pgBar.Minimum = 0; this.pgBar.Maximum = _blog._TotalCount; this.pgBar.Value = _blog._DownloadedImages; } catch (ArgumentOutOfRangeException) { this.pgBar.Style = ProgressBarStyle.Marquee; } }; } else { method = delegate { try { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { item.SubItems[2].Text = _blog._TotalCount.ToString(); break; } } this.pgBar.Style = ProgressBarStyle.Continuous; this.pgBar.Minimum = 0; this.pgBar.Maximum = _blog._TotalCount; this.pgBar.Value = _blog._DownloadedImages; } catch (ArgumentOutOfRangeException) { this.pgBar.Style = ProgressBarStyle.Marquee; } }; } } this.BeginInvoke(method); } catch { _blog._TotalCount = 0; //this.toolStop_Click(this, null); break; } } using (IEnumerator <XElement> enumerator2 = (from n in document.Descendants("post") where n.Elements("photo-url").Where(x => x.Attribute("max-width").Value == Properties.Settings.Default.configImageSize.ToString()).Any() && !n.Elements("photo-url").Where(x => x.Value == "www.tumblr.com").Any() select n.Element("photo-url")).GetEnumerator()) { numberOfPagesCrawled++; numberOfPostsCrawled = 50 * numberOfPagesCrawled; try { while (enumerator2.MoveNext()) { XElement p = enumerator2.Current; MethodInvoker invoker = null; string FileLocation; this.wait_handle.WaitOne(); string fileName = Path.GetFileName(new Uri(p.Value).LocalPath); if (!this.chkGIF.Checked || (Path.GetExtension(fileName).ToLower() != ".gif")) { FileLocation = Properties.Settings.Default.configDownloadLocation.ToString() + _blog._Name + "/" + fileName; try { if (this.Download(_blog, FileLocation, p.Value, fileName)) { _blog.Links.Add(new Post(p.Value, fileName)); _blog._DownloadedImages = _blog.Links.Count; if (invoker == null) { invoker = delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { item.SubItems[1].Text = _blog.Links.Count.ToString(); break; } } this.lblUrl.Text = p.Value; this.smallImage.ImageLocation = FileLocation; if ((this.pgBar.Value + 1) < (this.pgBar.Maximum + 1)) { this.pgBar.Value++; } }; } this.BeginInvoke(invoker); readingDataBase = false; } else { if (!readingDataBase) { readingDataBase = true; this.BeginInvoke((MethodInvoker) delegate { this.lblUrl.Text = "Skipping previously downloaded images - " + _blog._Name; }); } } } catch (Exception) { continue; } } } } catch (Exception) { continue; } } if (numberOfPostsCrawled >= _blog._TotalCount) { //this.toolStop_Click(this, null); // Finished Blog _blog._LastCrawled = DateTime.Now; _blog._finishedCrawl = true; this.SaveBlog(_blog); TumblrActiveList.Remove(_blog); // Update UI this.BeginInvoke((MethodInvoker) delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { // Update Listview about completed blog item.SubItems[5].Text = DateTime.Now.ToString(); //item.SubItems[6].Text = "True"; // Update current crawling progress label int indexBlogInProgress = crawlingBlogs.IndexOf(_blog._Name); int lengthBlogInProgress = _blog._Name.Length; this.crawlingBlogs = crawlingBlogs.Remove(indexBlogInProgress, (lengthBlogInProgress + 1)); this.lblProcess.Text = "Crawling Blogs - " + this.crawlingBlogs; } } }); if (TumblrActiveList.Count == 1) { this.BeginInvoke((MethodInvoker) delegate { this.pgBar.Style = ProgressBarStyle.Continuous; }); } if (TumblrActiveList.Count == 0) { this.BeginInvoke((MethodInvoker) delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { // Update current crawling progress label this.smallImage.ImageLocation = ""; this.crawlingBlogs = ""; this.lblUrl.Text = ""; this.lblProcess.Text = "Queue finished"; } } }); } return; } } }
private void ClipboardMonitor_OnClipboardChange(ClipboardFormat format, object data) { // Do Something... if (format.ToString() == "Text") { string[] URLs = data.ToString().Split(new char[0]); foreach (string _url in URLs) { ListViewItem lvItem; bool blogExists = false; string str = this.ExtractBlogname_paste(_url); if (str != null) { this.Invoke((Action) delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text.Equals(str)) { blogExists = true; return; } } }); if (blogExists) { } else { lvItem = new ListViewItem(); { TumblrBlog newBlog = new TumblrBlog { _Name = str, _URL = this.ExtractUrl(_url), _DateAdded = DateTime.Now, _DownloadedImages = 0, _TotalCount = 0, _LastCrawled = System.DateTime.MinValue, _finishedCrawl = false }; lvItem.Text = newBlog._Name; lvItem.SubItems.Add(""); lvItem.SubItems.Add(""); lvItem.SubItems.Add(newBlog._URL); lvItem.SubItems.Add(newBlog._DateAdded.ToString()); lvItem.SubItems.Add("Not yet completely crawled!"); //lvItem.SubItems.Add(newBlog._finishedCrawl.ToString()); this.SaveBlog(newBlog); newBlog = null; this.Invoke((Action) delegate { this.lvBlog.Items.Add(lvItem); }); } if (Directory.Exists(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/")) { if (Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/", "*.tumblr").Count <string>() > 0) { this.Invoke((Action) delegate { this.toolShowExplorer.Enabled = true; this.toolRemoveBlog.Enabled = true; this.toolCrawl.Enabled = true; }); } else { this.Invoke((Action) delegate { this.toolShowExplorer.Enabled = false; this.toolRemoveBlog.Enabled = false; this.toolCrawl.Enabled = false; }); } } } } } } }
private TumblrBlog LoadBlog(string blogname) { TumblrBlog blog = new TumblrBlog(); try { using (Stream stream = new FileStream(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/" + blogname + ".tumblr", FileMode.Open, FileAccess.Read, FileShare.Read)) { IFormatter formatter = new BinaryFormatter(); blog = (TumblrBlog)formatter.Deserialize(stream); } } catch (SerializationException SerializationException) { using (Stream stream = new FileStream(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/" + blogname + ".tumblr", FileMode.Open, FileAccess.Read, FileShare.Read)) { IFormatter formatter = new BinaryFormatter(); //Set formatters binder property to TumblOne 1.0.4.0 Version formatter.Binder = new TumblOne.Typeconvertor(); blog = (TumblrBlog)formatter.Deserialize(stream); } } catch (Exception exception) { MessageBox.Show(exception.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); } return blog; }
private void AddBlog(object sender, EventArgs e) { ListViewItem lvItem; string str = this.ExtractBlogname(this.tBlogUrl.Text); if (str != null) { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text.Equals(str)) { MessageBox.Show("The entered URL is already in the library!", Application.ProductName); this.tBlogUrl.Text = string.Empty; return; } } lvItem = new ListViewItem(); if ((this.worker != null) && !this.worker.IsCompleted) { TumblrBlog ThreadBlog = new TumblrBlog(); this.Invoke((Action) delegate { ThreadBlog._URL = this.ExtractUrl(this.tBlogUrl.Text); ThreadBlog.TOTAL_COUNT = 0; ThreadBlog._Name = this.ExtractBlogname(this.tBlogUrl.Text); ThreadBlog._DateAdded = DateTime.Now; lvItem.Text = ThreadBlog._Name; lvItem.SubItems.Add(""); lvItem.SubItems.Add(this.tBlogUrl.Text); lvItem.SubItems.Add(ThreadBlog._DateAdded.ToString("G")); lvItem.SubItems.Add(ThreadBlog._LastCrawled.ToString("G")); lvItem.SubItems.Add(ThreadBlog._finishedCrawl.ToString()); this.lvBlog.Items.Add(lvItem); }); this.SaveBlog(ThreadBlog); ThreadBlog = null; } else { TumblrBlog newBlog = new TumblrBlog { _Name = str, _URL = this.ExtractUrl(this.tBlogUrl.Text), _DateAdded = DateTime.Now, //_LastCrawled = "", _finishedCrawl = false }; lvItem.Text = newBlog._Name; lvItem.SubItems.Add(""); lvItem.SubItems.Add(newBlog._URL); lvItem.SubItems.Add(newBlog._DateAdded.ToString("G")); lvItem.SubItems.Add(newBlog._LastCrawled.ToString("G")); lvItem.SubItems.Add(newBlog._finishedCrawl.ToString()); this.lvBlog.Items.Add(lvItem); this.SaveBlog(newBlog); newBlog = null; } this.tBlogUrl.Text = "http://"; if (Directory.Exists(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/")) { if (Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/", "*.tumblr").Count <string>() > 0) { this.toolShowExplorer.Enabled = true; this.toolRemoveBlog.Enabled = true; this.toolCrawl.Enabled = true; } else { this.toolShowExplorer.Enabled = false; this.toolRemoveBlog.Enabled = false; this.toolCrawl.Enabled = false; } } } }
private void AddBlog(object sender, EventArgs e) { ListViewItem lvItem; string str = this.ExtractBlogname(this.tBlogUrl.Text); if (str != null) { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text.Equals(str)) { MessageBox.Show("The entered URL is already in the library!", Application.ProductName); this.tBlogUrl.Text = string.Empty; return; } } lvItem = new ListViewItem(); if ((this.worker != null) && !this.worker.IsCompleted) { TumblrBlog ThreadBlog = new TumblrBlog(); this.Invoke((Action)delegate { ThreadBlog._URL = this.ExtractUrl(this.tBlogUrl.Text); ThreadBlog.TOTAL_COUNT = 0; ThreadBlog._Name = this.ExtractBlogname(this.tBlogUrl.Text); ThreadBlog._DateAdded = DateTime.Now; lvItem.Text = ThreadBlog._Name; lvItem.SubItems.Add(""); lvItem.SubItems.Add(this.tBlogUrl.Text); lvItem.SubItems.Add(ThreadBlog._DateAdded.ToString("G")); lvItem.SubItems.Add(ThreadBlog._LastCrawled.ToString("G")); lvItem.SubItems.Add(ThreadBlog._finishedCrawl.ToString()); this.lvBlog.Items.Add(lvItem); }); this.SaveBlog(ThreadBlog); ThreadBlog = null; } else { TumblrBlog newBlog = new TumblrBlog { _Name = str, _URL = this.ExtractUrl(this.tBlogUrl.Text), _DateAdded = DateTime.Now, //_LastCrawled = "", _finishedCrawl = false }; lvItem.Text = newBlog._Name; lvItem.SubItems.Add(""); lvItem.SubItems.Add(newBlog._URL); lvItem.SubItems.Add(newBlog._DateAdded.ToString("G")); lvItem.SubItems.Add(newBlog._LastCrawled.ToString("G")); lvItem.SubItems.Add(newBlog._finishedCrawl.ToString()); this.lvBlog.Items.Add(lvItem); this.SaveBlog(newBlog); newBlog = null; } this.tBlogUrl.Text = "http://"; if (Directory.Exists(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/")) { if (Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/", "*.tumblr").Count<string>() > 0) { this.toolShowExplorer.Enabled = true; this.toolRemoveBlog.Enabled = true; this.toolCrawl.Enabled = true; } else { this.toolShowExplorer.Enabled = false; this.toolRemoveBlog.Enabled = false; this.toolCrawl.Enabled = false; } } } }
private bool SaveBlog(TumblrBlog newBlog) { if (newBlog == null) { return false; } this.CreateDataFolder(newBlog._Name); try { using (Stream stream = new FileStream(Properties.Settings.Default.configDownloadLocation.ToString() + "Index/" + newBlog._Name + ".tumblr", FileMode.Create, FileAccess.Write, FileShare.None)) { IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, newBlog); } } catch (Exception) { MessageBox.Show("The blog index file cannot be saved to disk!\nBe sure, that you have enough free space and proper file permissions.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Hand); return false; } return true; }
private void RunParser(TumblrBlog _blog) { MethodInvoker method = null; MethodInvoker invoker3 = null; int num = 0; int num2 = 0; int num3 = 0; //string blogname = ExtractBlogname(ApiUrl.ToString()); String ApiUrl = _blog._URL; if (ApiUrl.Last <char>() != '/') { ApiUrl = ApiUrl + "/api/read?start="; } else { ApiUrl = ApiUrl + "api/read?start="; } this.CreateDataFolder(_blog._Name); this.BeginInvoke((Action) delegate { this.pgBar.Minimum = 0; this.pgBar.Maximum = _blog.TOTAL_COUNT; }); while (true) { this.wait_handle.WaitOne(); XDocument document = null; try { document = XDocument.Load(ApiUrl.ToString() + num.ToString() + "&num=50"); } catch (WebException) { //this.toolStop_Click(this, null); break; } if (num == 0) { try { foreach (var type in from data in document.Descendants("posts") select new { Total = data.Attribute("total").Value }) { _blog.TOTAL_COUNT = Convert.ToInt32(type.Total.ToString()); } if (method == null) { method = delegate { this.pgBar.Minimum = 0; this.pgBar.Maximum = _blog.TOTAL_COUNT; }; } this.BeginInvoke(method); } catch { _blog.TOTAL_COUNT = 0; //this.toolStop_Click(this, null); break; } } using (IEnumerator <XElement> enumerator2 = (from s in document.Descendants("photo-url") where (s.HasAttributes && s.Attribute("max-width").Value.Equals(Properties.Settings.Default.configImageSize.ToString())) && !s.Value.Contains("www.tumblr.com") select s).GetEnumerator()) { while (enumerator2.MoveNext()) { XElement p = enumerator2.Current; MethodInvoker invoker = null; string FileLocation; this.wait_handle.WaitOne(); string fileName = Path.GetFileName(new Uri(p.Value).LocalPath); if (!this.chkGIF.Checked || (Path.GetExtension(fileName).ToLower() != ".gif")) { FileLocation = Properties.Settings.Default.configDownloadLocation.ToString() + _blog._Name + "/" + fileName; _blog.Links.Add(new Post(p.Value, fileName)); if (invoker3 == null) { invoker3 = delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { item.SubItems[1].Text = Directory.GetFiles(Properties.Settings.Default.configDownloadLocation.ToString() + _blog._Name + "/").Length.ToString(); break; } } }; } this.BeginInvoke(invoker3); try { if (this.Download(FileLocation, p.Value)) { num2++; if (invoker == null) { invoker = delegate { this.lblUrl.Text = p.Value; this.smallImage.ImageLocation = FileLocation; if ((this.pgBar.Value + 1) < (this.pgBar.Maximum + 1)) { this.pgBar.Value++; } }; } this.BeginInvoke(invoker); } } catch (Exception) { continue; } num3++; } } } if (num3 == 0) { //this.toolStop_Click(this, null); // Finished Blog _blog._LastCrawled = DateTime.Now; _blog._finishedCrawl = true; // Update UI this.BeginInvoke((MethodInvoker) delegate { foreach (ListViewItem item in this.lvBlog.Items) { if (item.Text == _blog._Name) { // Update Listview about completed blog item.SubItems[4].Text = DateTime.Now.ToString(); item.SubItems[5].Text = "True"; // Update current crawling progress label int indexBlogInProgress = crawlingBlogs.IndexOf(_blog._Name); int lengthBlogInProgress = _blog._Name.Length; this.crawlingBlogs = crawlingBlogs.Remove(indexBlogInProgress, (lengthBlogInProgress + 1)); this.lblProcess.Text = "Crawling Blogs - " + this.crawlingBlogs; } } }); return; } num += num3; num3 = 0; } }