public AdminVM() { BlogPosts = new List <BlogPost>(); Users = new List <ApplicationUser>(); Pages = new List <StaticPage>(); RolesList = new List <SelectListItem>(); Roles = new List <IdentityRole>(); User = new ApplicationUser(); Role = new IdentityRole(); BlogStats = new BlogStats(); }
public BlogStats GetBlogStats() { BlogStats blogStats = new BlogStats(); using (SqlConnection cn = new SqlConnection(Settings.ConnectionString)) { SqlCommand cmd = new SqlCommand(); //Total Users cmd.CommandText = "select count(AspNetUsers.Id) from AspNetUsers"; cmd.Connection = cn; cn.Open(); blogStats.TotalUsers = int.Parse(cmd.ExecuteScalar().ToString()); //Total Admins cmd.CommandText = "select count(AspNetUserRoles.RoleId) from AspNetUserRoles where RoleId = 1"; blogStats.TotalAdmins = int.Parse(cmd.ExecuteScalar().ToString()); //Total Posts cmd.CommandText = "select count(BlogPosts.BlogPostID) from BlogPosts"; blogStats.TotalPosts = int.Parse(cmd.ExecuteScalar().ToString()); //Total Active Posts cmd.CommandText = "select count(BlogPosts.BlogPostID) from BlogPosts where [Status] = 1"; blogStats.TotalActivePosts = int.Parse(cmd.ExecuteScalar().ToString()); //Total Hashtags cmd.CommandText = "select count(BlogPostHashtags.HashTagID) from BlogPostHashtags"; blogStats.TotalHashtags = int.Parse(cmd.ExecuteScalar().ToString()); //Total Static Pages cmd.CommandText = "select count(StaticPages.StaticPageID) from StaticPages where [Status] = 1"; blogStats.TotalStaticPages = int.Parse(cmd.ExecuteScalar().ToString()); //Hashtag Stats cmd.CommandText = "select ht.HashtagID, ht.HashtagTitle, count(bp.HashtagID) As NumHts from BlogPostHashtags bp " + "inner join Hashtags ht on bp.HashtagID = ht.HashtagID group by bp.HashtagID, ht.HashtagID, ht.HashtagTitle Order By NumHts Desc"; using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { blogStats.Hashtags.Add(PopulateHashtagsFromReader(dr)); } } } return(blogStats); }
private static BlogStats CreateBlogStatsFromPhotos(List <PhotoIndexEntity> photoIndexEntities, string blogname) { BlogStats currentBlog = new BlogStats(blogname); foreach (PhotoIndexEntity entity in photoIndexEntities) { if (entity.Uri.Contains("/thumb-")) { continue; // process only originals } if (entity.Uri.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase) || entity.Uri.EndsWith(".jpeg", StringComparison.OrdinalIgnoreCase)) { currentBlog.Jpgs += 1; } else if (entity.Uri.EndsWith(".gif", StringComparison.OrdinalIgnoreCase)) { currentBlog.Gifs += 1; } else if (entity.Uri.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) { currentBlog.Pngs += 1; } else { throw new InvalidOperationException("Unexpected ending"); } currentBlog.PhotosCount += 1; if (entity.Width > 0) { currentBlog.PhotosWithWidthCount += 1; currentBlog.TotalWidth += entity.Width; // ReSharper disable once PossibleLossOfFraction - fraction not needed here currentBlog.AverageWidth = currentBlog.TotalWidth / currentBlog.PhotosWithWidthCount; } } return(currentBlog); }
public HomeVM() { BlogPosts = new List <BlogPost>(); BlogStats = new BlogStats(); Categories = new List <Category>(); }
public static async Task Run([QueueTrigger(Constants.BlogToIndexQueueName, Connection = "AzureWebJobsStorage")] string myQueueItem, TraceWriter log) { Startup.Init(); BlogToIndex blogToIndex = JsonConvert.DeserializeObject <BlogToIndex>(myQueueItem); PhotoIndexTableAdapter photoIndexTableAdapter = new PhotoIndexTableAdapter(); photoIndexTableAdapter.Init(); PostsTableAdapter postsTableAdapter = new PostsTableAdapter(); postsTableAdapter.Init(log); ReversePostsTableAdapter reversePostsTableAdapter = new ReversePostsTableAdapter(); reversePostsTableAdapter.Init(log); PostToGetQueueAdapter postToGetQueueAdapter = new PostToGetQueueAdapter(); postToGetQueueAdapter.Init(); BlogInfoTableAdapter blogInfoTableAdapter = new BlogInfoTableAdapter(); blogInfoTableAdapter.Init(); MediaToDownloadQueueAdapter mediaToDownloadQueueAdapter = new MediaToDownloadQueueAdapter(); mediaToDownloadQueueAdapter.Init(log); List <PhotoIndexEntity> photoIndexEntities = photoIndexTableAdapter.GetAll(blogToIndex.Blogname); log.Info("Loaded " + photoIndexEntities.Count + " photo index entities"); BlogEntity blogEntity = await blogInfoTableAdapter.GetBlog(blogToIndex.Blogname); Dictionary <string, List <Model.Site.Photo> > photosByBlogById = CreatePhotosByBlogById(photoIndexEntities); BlogStats blogStats = CreateBlogStatsFromPhotos(photoIndexEntities, blogToIndex.Blogname); blogStats.UpdateFromBlogEntity(blogEntity); List <PostEntity> postEntities = postsTableAdapter.GetAll(blogToIndex.Blogname); UpdateBlogStatsFromPosts(blogStats, postEntities); UpdateMonthIndex(blogToIndex.Blogname, postEntities, blogInfoTableAdapter); log.Info("Loaded " + postEntities.Count + " post entities"); foreach (PostEntity postEntity in postEntities) { if (!string.IsNullOrEmpty(postEntity.PhotoBlobUrls)) { try { Model.Site.Photo[] photos = JsonConvert.DeserializeObject <Model.Site.Photo[]>(postEntity.PhotoBlobUrls); if (photos.Any(x => !x.Name.Contains("_"))) { SendToReprocessing(postEntity.PartitionKey, mediaToDownloadQueueAdapter, log, postEntity); } } catch (Exception e) { log.Error("Error: " + e.Message); throw; } } } blogStats.DisplayablePosts = InsertReversePosts(blogToIndex.Blogname, photosByBlogById, postEntities, reversePostsTableAdapter, postsTableAdapter, photoIndexTableAdapter, mediaToDownloadQueueAdapter, log); blogInfoTableAdapter.InsertBlobStats(blogStats); }
private static void UpdateBlogStatsFromPosts(BlogStats blogStats, List <PostEntity> postEntities) { foreach (PostEntity post in postEntities) { switch (post.Type) { case "Text": { if (!string.IsNullOrEmpty(post.VideoBlobUrls)) { blogStats.Video++; } else if (!string.IsNullOrEmpty(post.PhotoBlobUrls)) { blogStats.Photo++; } else { blogStats.Text++; } break; } case "Quote": { blogStats.Quote++; break; } case "Link": { blogStats.Link++; break; } case "Answer": { blogStats.Answer++; break; } case "Video": { blogStats.Video++; break; } case "Audio": { blogStats.Audio++; break; } case "Photo": { blogStats.Photo++; break; } case "Chat": { blogStats.Chat++; break; } } blogStats.TotalPosts++; } }
public void InsertBlobStats(BlogStats blogStats) { TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(blogStats); blogsTable.Execute(insertOrMergeOperation); }