using System;
using System.Web;
using System.Text;
namespace CustomerManagement.css
{
/// <summary>
/// Summary description for svg
/// </summary>
public class svg : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/svg+xml";
string str = Input.GetQueryString<string>("stops");
string[] values = str.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var sb = new StringBuilder();
sb.Append("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"100%\" height=\"100%\">");
sb.AppendLine();
sb.Append("<defs>");
sb.AppendLine();
sb.Append("<linearGradient id=\"linear-gradient\" x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\">");
sb.AppendLine();
foreach (var val in values)
{
string[] items = val.Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
sb.Append("<stop offset=\"" + items[1] + "\" stop-color=\"" + items[0] + "\" stop-opacity=\"1\"/>");
sb.AppendLine();
}
sb.Append("</linearGradient>");
sb.AppendLine();
sb.Append("</defs>");
sb.AppendLine();
sb.Append("<rect width=\"100%\" height=\"100%\" fill=\"url(#linear-gradient)\"/>");
sb.AppendLine();
sb.Append("</svg>");
sb.AppendLine();
context.Response.Write(sb.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
public static class Input
{
public static T GetQueryString<T>(string key) where T : IConvertible
{
T result = default(T);
if (String.IsNullOrEmpty(HttpContext.Current.Request.QueryString[key]) == false)
{
string value = HttpContext.Current.Request.QueryString[key];
try
{
result = (T)Convert.ChangeType(value, typeof(T));
}
catch
{
//Could not convert. Pass back default value...
result = default(T);
}
}
return result;
}
}
}