private ITemplate GetTemplate(StackFlairOptions flairOptions, StackData stackData) { ITemplate template = null; switch (flairOptions.Theme.ToLower()) { case "glitter": template = new GlitterTemplate(stackData, flairOptions); break; case "black": template = new BlackTemplate(stackData, flairOptions); break; case "hotdog": template = new HotDogTemplate(stackData, flairOptions); break; case "holy": template = new HoLyTemplate(stackData, flairOptions); break; case "nimbus": template = new NimbusTemplate(stackData, flairOptions); break; default: template = new DefaultTemplate(stackData, flairOptions); break; } return(template); }
public static StackData GetFlairData(Guid associationId) { var stackAuthClient = new StackAuthClient(new UrlClient(), new JsonProtocol()); var associatedUsers = stackAuthClient.GetAssociatedUsers(associationId); associatedUsers = associatedUsers.OrderByDescending(au => au.Reputation).Where(au => au.Site.State != SiteState.Linked_Meta); int totalRep = associatedUsers.Sum(ai => ai.Reputation); string html = ""; AssociatedUser topUser = associatedUsers.First(); StackData data = new StackData() { DisplayHash = topUser.EmailHash, DisplayId = topUser.Id, DisplayName = topUser.DisplayName, DisplayUrl = topUser.Site.SiteUrl, Sites = (from u in associatedUsers select new StackSiteData() { SiteName = u.Site.Name, SiteState = u.Site.State, Reputation = u.Reputation, Url = u.Site.SiteUrl, UserId = u.Id, IsMod = u.Type == UserType.Moderator, Badges = Utility.GetBadgeCounts(u.Site, u.Id) }).ToList(), //TotalBadges = GetBadgeCounts(associatedUsers), }; return(data); }
private void GenerateHtmlFlair(StackData stackData, StackFlairOptions flairOptions) { ITemplate template = GetTemplate(flairOptions, stackData); string flair = template.GenerateHtml(); Response.Clear(); Response.Write(flair); Response.End(); }
protected Template(StackData data, StackFlairOptions flairOptions) { FlairOptions = flairOptions; Data = data; if (FlairOptions.NoBeta) { Data.Sites = Data.Sites.Where(s => s.SiteState == SiteState.Normal).ToList(); } if (!String.IsNullOrEmpty(FlairOptions.Only)) { Data.Sites = new List <StackSiteData>() { Data.Sites.Single(s => s.SiteName.Replace(" ", "").Equals(FlairOptions.Only, StringComparison.InvariantCultureIgnoreCase)) }; } }
public static StackData GetFlairData(Guid associationId) { var stackAuthClient = new StackAuthClient(new UrlClient(), new JsonProtocol()); var associatedUsers = stackAuthClient.GetAssociatedUsers(associationId); associatedUsers = associatedUsers.OrderByDescending(au => au.Reputation).Where(au => au.Site.State != SiteState.Linked_Meta); int totalRep = associatedUsers.Sum(ai => ai.Reputation); string html = ""; AssociatedUser topUser = associatedUsers.First(); StackData data = new StackData() { DisplayHash = topUser.EmailHash, DisplayId = topUser.Id, DisplayName = topUser.DisplayName, DisplayUrl = topUser.Site.SiteUrl, Sites = (from u in associatedUsers select new StackSiteData() { SiteName = u.Site.Name, SiteState=u.Site.State, Reputation = u.Reputation, Url = u.Site.SiteUrl, UserId = u.Id, IsMod = u.Type == UserType.Moderator, Badges = Utility.GetBadgeCounts(u.Site,u.Id)}).ToList(), //TotalBadges = GetBadgeCounts(associatedUsers), }; return data; }
public DefaultTemplate(StackData data, StackFlairOptions flairOptions) : base(data, flairOptions) { TemplateOptions = new TemplateOptions() { GravatarSize = 48, Spacing = 5, NameColor = Color.FromArgb(119, 119, 204), BackgroundColor = Color.FromArgb(221, 221, 221), GoldColor = Color.FromArgb(221, 153, 34), SilverColor = Color.FromArgb(119, 119, 119), BronzeColor = Color.FromArgb(205, 127, 50), BorderWidth = 1, BorderColor = Color.FromArgb(136, 136, 136), ModColor = Color.FromArgb(51, 51, 51), TopLineSize = 10, MiddleLineSize = 9, RepColor = Color.FromArgb(51, 51, 51), FontFamily = "Helvetica" }; }
public BlackTemplate(StackData data, StackFlairOptions flairOptions) : base(data, flairOptions) { TemplateOptions = new TemplateOptions() { GravatarSize = 48, Spacing = 5, BorderColor = Color.Black, BackgroundColor = Color.FromArgb(34, 34, 34), BorderWidth = 1, GoldColor = Color.FromArgb(255, 204, 0), SilverColor = Color.FromArgb(119, 119, 119), BronzeColor = Color.FromArgb(205, 127, 50), FontFamily = "Helvetica, sans-serif", TopLineSize = 10, MiddleLineSize = 9, ModColor = Color.White, NameColor = Color.White, RepColor = Color.White }; }
public GlitterTemplate(StackData data, StackFlairOptions flairOptions) : base(data, flairOptions) { TemplateOptions = new TemplateOptions() { GravatarSize = 159, Spacing = 5, NameColor = Color.FromArgb(119, 119, 204), BackgroundColor = Color.FromArgb(221, 221, 221), GoldColor = Color.FromArgb(221, 153, 34), SilverColor = Color.FromArgb(119, 119, 119), BronzeColor = Color.FromArgb(205, 127, 50), BorderWidth = 1, BorderColor = Color.FromArgb(136, 136, 136), ModColor = Color.FromArgb(51, 51, 51), TopLineSize = 10, MiddleLineSize = 42, RepColor = Color.FromArgb(51, 51, 51), FontFamily = "Helvetica, sans-serif" }; }
public NimbusTemplate(StackData data, StackFlairOptions flairOptions) : base(data, flairOptions) { TemplateOptions = new TemplateOptions() { GravatarSize = 48, Spacing = 5, BorderColor = Color.FromArgb(181, 190, 189), BackgroundColor = Color.FromArgb(214, 223, 222), BorderWidth = 1, BronzeColor = Color.FromArgb(214, 113, 16), FontFamily = "Helvetica,sans-serif", GoldColor = Color.FromArgb(221, 153, 34), MiddleLineSize = 9, ModColor = Color.FromArgb(74, 56, 66), NameColor = Color.FromArgb(74, 56, 66), RepColor = Color.FromArgb(74, 56, 66), SilverColor = Color.FromArgb(119, 119, 119), TopLineSize = 10 }; }
public HoLyTemplate(StackData data, StackFlairOptions flairOptions) : base(data, flairOptions) { TemplateOptions = new TemplateOptions() { GravatarSize = 48, Spacing = 5, BorderColor = Color.Black, BackgroundColor = Color.FromArgb(222, 150, 16), BorderWidth = 1, BronzeColor = Color.FromArgb(77, 68, 0), FontFamily = "Helvetica,sans-serif", GoldColor = Color.FromArgb(255, 204, 0), MiddleLineSize = 9, ModColor = Color.FromArgb(222, 81, 0), NameColor = Color.FromArgb(82, 81, 181), RepColor = Color.FromArgb(222, 81, 0), SilverColor = Color.FromArgb(119, 119, 119), TopLineSize = 10 }; }
public HotDogTemplate(StackData data, StackFlairOptions flairOptions) : base(data, flairOptions) { TemplateOptions = new TemplateOptions() { GravatarSize = 48, Spacing = 5, BorderColor = Color.Black, BackgroundColor = Color.Red, BorderWidth = 1, BronzeColor = Color.FromArgb(77, 68, 0), FontFamily = "Helvetica, sans-serif", GoldColor = Color.FromArgb(255, 204, 0), MiddleLineSize = 9, ModColor = Color.Yellow, NameColor = Color.Yellow, RepColor = Color.Yellow, SilverColor = Color.FromArgb(198, 198, 198), TopLineSize = 10 }; }
private void GenerateImageFlair(StackData stackData, StackFlairOptions flairOptions) { ITemplate template = GetTemplate(flairOptions, stackData); Image flair = template.GenerateImage(); Response.Clear(); Response.ContentType = "image/" + flairOptions.Format.ToString().ToLower(); var cache = Response.Cache; cache.SetValidUntilExpires(true); cache.SetCacheability(HttpCacheability.Public); cache.SetExpires(DateTime.Now.AddHours(int.Parse(cfg.AppSettings["FlairDuration"]) / 2)); var ms = new MemoryStream(); flair.Save(ms, Utility.ImageFormats[flairOptions.Format]); ms.WriteTo(Response.OutputStream); ms.Dispose(); flair.Dispose(); Response.End(); }
private StackData GetStackData(Guid associationId, bool noBeta = false) { StackData stackData = null; XmlSerializer xmlSerializer = new XmlSerializer(typeof(StackData)); // Check for existing flair var ctx = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString); var existingFlair = ctx.StackFlairs.Where(f => f.Guid == associationId).SingleOrDefault(); if (existingFlair != null) { // Check for expiration DateTime storedTimestamp = existingFlair.Timestamp; DateTime expiryTimestamp = storedTimestamp.AddHours(Int32.Parse(ConfigurationManager.AppSettings["FlairDuration"])); if (expiryTimestamp > DateTime.Now) { stackData = (StackData)xmlSerializer.Deserialize(new StringReader(existingFlair.Flair)); } else { stackData = StackFlair.GetFlairData(associationId); existingFlair.Flair = stackData.Serialize(); existingFlair.Timestamp = DateTime.Now; ctx.SubmitChanges(); } } else { stackData = StackFlair.GetFlairData(associationId); ctx.StackFlairs.InsertOnSubmit(new Data.StackFlair() { Flair = stackData.Serialize(), Guid = associationId, Timestamp = DateTime.Now }); ctx.SubmitChanges(); } return(stackData); }
protected Template(StackData data, StackFlairOptions flairOptions) { FlairOptions = flairOptions; Data = data; if (FlairOptions.NoBeta) { Data.Sites = Data.Sites.Where(s => s.SiteState == SiteState.Normal).ToList(); } if (!String.IsNullOrEmpty(FlairOptions.Only)) { Data.Sites = new List<StackSiteData>() { Data.Sites.Single(s => s.SiteName.Replace(" ", "").Equals(FlairOptions.Only, StringComparison.InvariantCultureIgnoreCase)) }; } }