1. using System;
  2. using System.Web;
  3. using System.Text;
  4.  
  5. namespace CustomerManagement.css
  6. {
  7.     /// <summary>
  8.     /// Summary description for svg
  9.     /// </summary>
  10.     public class svg : IHttpHandler
  11.     {
  12.  
  13.         public void ProcessRequest(HttpContext context)
  14.         {
  15.             context.Response.ContentType = "image/svg+xml";
  16.  
  17.             string str = Input.GetQueryString<string>("stops");
  18.             string[] values = str.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.             var sb = new StringBuilder();
  21.             sb.Append("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"100%\" height=\"100%\">");
  22.             sb.AppendLine();
  23.             sb.Append("<defs>");
  24.             sb.AppendLine();
  25.             sb.Append("<linearGradient id=\"linear-gradient\" x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\">");
  26.             sb.AppendLine();
  27.  
  28.             foreach (var val in values)
  29.             {
  30.                 string[] items = val.Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  31.                 sb.Append("<stop offset=\"" + items[1] + "\" stop-color=\"" + items[0] + "\" stop-opacity=\"1\"/>");
  32.                 sb.AppendLine();                
  33.             }
  34.  
  35.             sb.Append("</linearGradient>");
  36.             sb.AppendLine();
  37.             sb.Append("</defs>");
  38.             sb.AppendLine();
  39.             sb.Append("<rect width=\"100%\" height=\"100%\" fill=\"url(#linear-gradient)\"/>");
  40.             sb.AppendLine();
  41.             sb.Append("</svg>");
  42.             sb.AppendLine();
  43.  
  44.             context.Response.Write(sb.ToString());
  45.         }
  46.  
  47.         public bool IsReusable
  48.         {
  49.             get
  50.             {
  51.                 return false;
  52.             }
  53.         }
  54.     }
  55.  
  56.     public static class Input
  57.     {
  58.         public static T GetQueryString<T>(string key) where T : IConvertible
  59.         {
  60.             T result = default(T);
  61.  
  62.             if (String.IsNullOrEmpty(HttpContext.Current.Request.QueryString[key]) == false)
  63.             {
  64.                 string value = HttpContext.Current.Request.QueryString[key];
  65.  
  66.                 try
  67.                 {
  68.                     result = (T)Convert.ChangeType(value, typeof(T));
  69.                 }
  70.                 catch
  71.                 {
  72.                     //Could not convert.  Pass back default value...
  73.                     result = default(T);
  74.                 }
  75.             }
  76.  
  77.             return result;
  78.         }
  79.     }
  80. }
  81.