/// <summary>
 /// Deprecated Method for adding a new object to the Websites EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToWebsites(Website website)
 {
     base.AddObject("Websites", website);
 }
Example #2
0
        private static void addTweet(VisualizationEntities db, DateTime date, string handle, string tweet, string url)
        {
            counter++;
            Debug.Print("Counter: " + counter);
            HashSet<string> seenUrls = new HashSet<string>();
            Debug.Print("Tweet: " + tweet);
            Regex linkParser = new Regex(@"\b(?:http://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            string id = url.Split('/').Last();
            DB2.Tweet newTweet = new DB2.Tweet() { TweetText = tweet, Date = date, Username = handle.Split(' ').First(), TweetID = id };
            if (!db.Tweets.Select(i => i.TweetID).Contains(id)) {
                db.Tweets.AddObject(newTweet);
                db.SaveChanges();
            } else {
                return;
            }
            foreach (Match m in linkParser.Matches(tweet)) {
                string fullUrl = "";
                string uniqueUrl = "";
                try {
                    fullUrl = m.Value.ExpandUrl();
                    uniqueUrl = fullUrl.UnuiqeUrl();
                } catch {
                    continue;
                }
                if (fullUrl.Count() > 300 || db.Websites.Any(i => i.Url == fullUrl)) {
                    continue;
                }
                Debug.Print("Website: " + fullUrl);
                string websiteUrl;
                var seen = db.Websites.Where(i => i.Url == uniqueUrl).SingleOrDefault();
                if (seen != null) {
                    seen.HitCount++;
                    websiteUrl = seen.Url;
                    db.SaveChanges();
                } else {
                    var page = new PageScraper(fullUrl);
                    var website = new DB2.Website() { Url = page.Url, Title = page.Title() };
                    db.Websites.AddObject(website);
                    db.SaveChanges();
                    foreach (var m2 in page.Media()) {
                        if (m2.Link.Count() > 300 || db.Media.Any(i => i.Url == m2.Link)) {
                            continue;
                        }
                        try {
                            DB2.Medium media = new DB2.Medium() { Type = m2.Type, Url = m2.Link, SourceSiteID = website.ID };
                            if (m2.Type == "image") {
                                var request = WebRequest.Create(m2.Link);

                                using (var response = request.GetResponse())
                                using (var stream = response.GetResponseStream())
                                using (var b = System.Drawing.Bitmap.FromStream(stream)) {
                                    media.Width = b.Width;
                                    media.Height = b.Height;
                                }
                            }
                            db.Media.AddObject(media);
                            db.SaveChanges();
                            Debug.Print("Media element: " + m2.Link);
                        } catch {

                        }
                    }
                    websiteUrl = website.Url;
                }
            }
            db.SaveChanges();
        }
 /// <summary>
 /// Create a new Website object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="title">Initial value of the Title property.</param>
 /// <param name="url">Initial value of the Url property.</param>
 /// <param name="hitCount">Initial value of the HitCount property.</param>
 /// <param name="tweetID">Initial value of the TweetID property.</param>
 public static Website CreateWebsite(global::System.Int32 id, global::System.String title, global::System.String url, global::System.Int32 hitCount, global::System.Int32 tweetID)
 {
     Website website = new Website();
     website.ID = id;
     website.Title = title;
     website.Url = url;
     website.HitCount = hitCount;
     website.TweetID = tweetID;
     return website;
 }