private void UpdateStats(TorrentInfo t) { using (var db = new NnmContext()) { var uri = new Uri("http://nnmclub.to/" + t.Ref); var query = HttpUtility.ParseQueryString(uri.Query); var tt = query.Get("t"); t.ID = int.Parse(tt); db.InsertOrReplace(t); } if (!UserInfos.ContainsKey(t.User)) { UserInfos.Add(t.User, new Stats { Count = 1, Likes = t.Likes }); using (var db = new NnmContext()) { db.Insert(new UserInfo { Name = t.User }); } } else { UserInfos[t.User].Count += 1; UserInfos[t.User].Likes += t.Likes; } if (!CatInfos.ContainsKey(t.Category)) { CatInfos.Add(t.Category, new Stats { Count = 1, Likes = t.Likes }); using (var db = new NnmContext()) { db.Insert(new CategoryInfo { Name = t.Category }); } } else { CatInfos[t.Category].Count += 1; CatInfos[t.Category].Likes += t.Likes; } if (!MonthInfos.ContainsKey(new MonthYear(t.Published))) { MonthInfos.Add(new MonthYear(t.Published), new Stats { Count = 1, Likes = t.Likes }); } else { MonthInfos[new MonthYear(t.Published)].Count += 1; MonthInfos[new MonthYear(t.Published)].Likes += t.Likes; } }
private void Form1_Load(object sender, EventArgs e) { splitContainer1.SplitterDistance = Settings.Default.TreeViewWidth; using (var db = new NnmContext()) { (from t in db.Torrents group t by t.Category into g select new { Category = g.Key, Count = g.Count(), Likes = g.Sum(t => t.Likes) } ).ToList().ForEach(c => { CatInfos.Add(c.Category, new Stats { Count = c.Count, Likes = c.Likes }); }); (from t in db.Torrents group t by t.User into g select new { User = g.Key, Count = g.Count(), Likes = g.Sum(u => u.Likes) } ).ToList().ForEach(c => { UserInfos.Add(c.User, new Stats { Count = c.Count, Likes = c.Likes }); }); } }