Esempio n. 1
0
        //
        // GET: /Generate/
        public ActionResult Index(string options, string associationId, string format)
        {
            StackFlairOptions flairOptions = new StackFlairOptions() {NoBeta = false, Format = "png", Only = "", Theme = "default"};
            bool noBeta = false;

            if (RouteData.Values["options"] != null) {
                //string optionsValue = RouteData.Values["options"].ToString();
                var optionsArgs = options.Split(',');
                foreach (var option in optionsArgs) {
                    var o = option.Split('=');
                    if (o[0].Equals("nobeta", StringComparison.InvariantCultureIgnoreCase)) { flairOptions.NoBeta = true; }
                    if (o[0].Equals("theme", StringComparison.InvariantCultureIgnoreCase)) { flairOptions.Theme = o[1]; }
                    if (o[0].Equals("only", StringComparison.InvariantCultureIgnoreCase)) { flairOptions.Only = o[1]; }
                }
            }

            //var associationId = RouteData.Values["associationId"] as string;
            flairOptions.Format = format;// (string)(RouteData.Values["format"] ?? Request.QueryString["format"]) ?? "png";
            if (flairOptions.Format.Equals("image", StringComparison.InvariantCultureIgnoreCase)) {
                flairOptions.Format = "png";
            }
            flairOptions.Format = flairOptions.Format.ToLower();
            if (!string.IsNullOrEmpty(associationId)) {
                var guidValue = new Guid(associationId);
                var stackData = GetStackData(guidValue, noBeta);
                if (Utility.ImageFormats.ContainsKey(flairOptions.Format)) {
                    GenerateImageFlair(stackData, flairOptions);
                } else {
                    GenerateHtmlFlair(stackData, flairOptions);
                }
            } else {
                Response.Redirect("~/");
            }
            return null;
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        private void GenerateHtmlFlair(StackData stackData, StackFlairOptions flairOptions)
        {
            ITemplate template = GetTemplate(flairOptions, stackData);
            string flair = template.GenerateHtml();

            Response.Clear();
            Response.Write(flair);
            Response.End();
        }
Esempio n. 4
0
        private void GenerateHtmlFlair(StackData stackData, StackFlairOptions flairOptions)
        {
            ITemplate template = GetTemplate(flairOptions, stackData);
            string    flair    = template.GenerateHtml();

            Response.Clear();
            Response.Write(flair);
            Response.End();
        }
Esempio n. 5
0
        //
        // GET: /Generate/

        public ActionResult Index(string options, string associationId, string format)
        {
            StackFlairOptions flairOptions = new StackFlairOptions()
            {
                NoBeta = false, Format = "png", Only = "", Theme = "default"
            };
            bool noBeta = false;

            if (RouteData.Values["options"] != null)
            {
                //string optionsValue = RouteData.Values["options"].ToString();
                var optionsArgs = options.Split(',');
                foreach (var option in optionsArgs)
                {
                    var o = option.Split('=');
                    if (o[0].Equals("nobeta", StringComparison.InvariantCultureIgnoreCase))
                    {
                        flairOptions.NoBeta = true;
                    }
                    if (o[0].Equals("theme", StringComparison.InvariantCultureIgnoreCase))
                    {
                        flairOptions.Theme = o[1];
                    }
                    if (o[0].Equals("only", StringComparison.InvariantCultureIgnoreCase))
                    {
                        flairOptions.Only = o[1];
                    }
                }
            }

            //var associationId = RouteData.Values["associationId"] as string;
            flairOptions.Format = format;// (string)(RouteData.Values["format"] ?? Request.QueryString["format"]) ?? "png";
            if (flairOptions.Format.Equals("image", StringComparison.InvariantCultureIgnoreCase))
            {
                flairOptions.Format = "png";
            }
            flairOptions.Format = flairOptions.Format.ToLower();
            if (!string.IsNullOrEmpty(associationId))
            {
                var guidValue = new Guid(associationId);
                var stackData = GetStackData(guidValue, noBeta);
                if (Utility.ImageFormats.ContainsKey(flairOptions.Format))
                {
                    GenerateImageFlair(stackData, flairOptions);
                }
                else
                {
                    GenerateHtmlFlair(stackData, flairOptions);
                }
            }
            else
            {
                Response.Redirect("~/");
            }
            return(null);
        }
Esempio n. 6
0
 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))
         };
     }
 }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
 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",
         TopLineSize = 10,
         MiddleLineSize = 9,
         ModColor = Color.White,
         NameColor = Color.White,
         RepColor = Color.White
     };
 }
Esempio n. 9
0
 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"
     };
 }
Esempio n. 10
0
 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",
         TopLineSize     = 10,
         MiddleLineSize  = 9,
         ModColor        = Color.White,
         NameColor       = Color.White,
         RepColor        = Color.White
     };
 }
Esempio n. 11
0
 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",
         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
     };
 }
Esempio n. 12
0
 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",
         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
     };
 }
Esempio n. 13
0
 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",
         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
     };
 }
Esempio n. 14
0
 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"
     };
 }
Esempio n. 15
0
        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();
        }
Esempio n. 16
0
 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",
         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
     };
 }
Esempio n. 17
0
 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;
 }
Esempio n. 18
0
 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)) };
     }
 }
Esempio n. 19
0
 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",
         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
     };
 }
Esempio n. 20
0
 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",
         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
     };
 }