Change to .NET 3.5

This commit is contained in:
2015-05-29 23:26:32 +02:00
parent 453e637504
commit eef5e3dbbf
28 changed files with 2270 additions and 2217 deletions

View File

@@ -1,57 +1,57 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Scrummer.Code
{
public class Bundler
{
#region Declarations
private string _path = null;
private List<string> _files = null;
#endregion
#region Properties
private List<string> Files
{
get
{
if (_files != null) { return _files; }
DirectoryInfo dir = new DirectoryInfo(_path);
FileInfo[] files = dir.GetFiles();
_files = files.OrderBy(file => file.FullName).Select(file2 => file2.FullName).ToList();
return _files;
}
}
#endregion
#region Creator
public Bundler(string path)
{
_path = path;
}
#endregion
#region Public methods
public void WriteResponse(Stream outStream)
{
foreach (string fileName in Files)
{
string fileContent = File.ReadAllText(fileName);
byte[] byteArray = Encoding.UTF8.GetBytes(fileContent);
outStream.Write(byteArray, 0, byteArray.Length);
}
}
#endregion
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Scrummer.Code
{
public class Bundler
{
#region Declarations
private string _path = null;
private List<string> _files = null;
#endregion
#region Properties
private List<string> Files
{
get
{
if (_files != null) { return _files; }
DirectoryInfo dir = new DirectoryInfo(_path);
FileInfo[] files = dir.GetFiles();
_files = files.OrderBy(file => file.FullName).Select(file2 => file2.FullName).ToList();
return _files;
}
}
#endregion
#region Creator
public Bundler(string path)
{
_path = path;
}
#endregion
#region Public methods
public void WriteResponse(Stream outStream)
{
foreach (string fileName in Files)
{
string fileContent = File.ReadAllText(fileName);
byte[] byteArray = Encoding.UTF8.GetBytes(fileContent);
outStream.Write(byteArray, 0, byteArray.Length);
}
}
#endregion
}
}

View File

@@ -1,41 +1,41 @@
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Scrummer.Code.Controls
{
public class CLabel : Label
{
#region Declarations
private string _tagName = "span";
#endregion
#region Properties
public string Tag
{
get { return _tagName; }
set { _tagName = value; }
}
#endregion
#region Life cycle
public override void RenderBeginTag(HtmlTextWriter writer)
{
if (string.IsNullOrEmpty(_tagName) == false)
{
this.AddAttributesToRender(writer);
writer.RenderBeginTag(_tagName);
}
else
{
base.RenderBeginTag(writer);
}
}
#endregion
}
}
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Scrummer.Code.Controls
{
public class CLabel : Label
{
#region Declarations
private string _tagName = "span";
#endregion
#region Properties
public string Tag
{
get { return _tagName; }
set { _tagName = value; }
}
#endregion
#region Life cycle
public override void RenderBeginTag(HtmlTextWriter writer)
{
if (string.IsNullOrEmpty(_tagName) == false)
{
this.AddAttributesToRender(writer);
writer.RenderBeginTag(_tagName);
}
else
{
base.RenderBeginTag(writer);
}
}
#endregion
}
}

View File

@@ -1,131 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace Scrummer.Code.Controls
{
public class ChatControl : Control
{
#region Declarations
private string _serviceUrl = "ChatHandler";
private int _idBoard = 0;
private string _userName = string.Empty;
private Unit _width = new Unit(500, UnitType.Pixel);
private Unit _height = new Unit(300, UnitType.Pixel);
private Panel _divChatWindow = null;
#endregion
#region Properties
public string ServiceUrl
{
get { return _serviceUrl; }
set { _serviceUrl = value; }
}
public int IDBoard
{
get { return _idBoard; }
set { _idBoard = value; }
}
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
public Unit Width
{
get { return _width; }
set
{
_width = value;
if (_divChatWindow != null)
{
_divChatWindow.Width = value;
}
}
}
public Unit Height
{
get { return _height; }
set
{
_height = value;
if (_divChatWindow != null)
{
_divChatWindow.Height = value;
}
}
}
#endregion
#region Control Life cycle
public ChatControl()
{
Init += ChatControl_Init;
}
void ChatControl_Init(object sender, EventArgs e)
{
InitializeControls();
}
#endregion
#region Private methods
private void InitializeControls()
{
_divChatWindow = new Panel { ID = "divChatWindow", CssClass = "divChatWindow" };
Controls.Add(_divChatWindow);
_divChatWindow.Width = _width;
_divChatWindow.Height = _height;
var divChat = new Panel { ID = "divChat", CssClass = "divChat" };
_divChatWindow.Controls.Add(divChat);
var divChatControls = new Panel { ID = "divChatControls", CssClass = "divChatControls" };
_divChatWindow.Controls.Add(divChatControls);
var hidUserName = new HiddenField { ID = "hidUserName", Value = _userName };
divChatControls.Controls.Add(hidUserName);
var hidIDMessage = new HiddenField { ID = "hidIDMessage", Value = "0" };
divChatControls.Controls.Add(hidIDMessage);
var hidLastUser = new HiddenField { ID = "hidLastUser", Value = "" };
divChatControls.Controls.Add(hidLastUser);
var txtText = new TextBox { ID = "txtText", CssClass = "chatTextBox" };
txtText.Attributes.Add("autocomplete", "off");
divChatControls.Controls.Add(txtText);
var btnSend = new Button { ID = "btnSend", Text = "Send", CssClass = "chatButton" };
divChatControls.Controls.Add(btnSend);
btnSend.Attributes.Add("onclick", String.Format("SendChat('{0}', '{1}', {2}, '{3}'); return false;",
_serviceUrl, txtText.ClientID, _idBoard, hidUserName.ClientID));
LiteralControl litScript = new LiteralControl();
litScript.Text = String.Format("<script>RunChat('{0}', '{1}', {2}, '{3}', '{4}', '{5}');</script>",
_serviceUrl, divChat.ClientID, _idBoard, hidIDMessage.ClientID, hidUserName.ClientID, hidLastUser.ClientID);
Controls.Add(litScript);
}
#endregion
}
}
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Scrummer.Code.Controls
{
public class ChatControl : Control
{
#region Declarations
private string _serviceUrl = "ChatHandler";
private int _idBoard = 0;
private string _userName = string.Empty;
private Unit _width = new Unit(500, UnitType.Pixel);
private Unit _height = new Unit(300, UnitType.Pixel);
private Panel _divChatWindow = null;
#endregion
#region Properties
public string ServiceUrl
{
get { return _serviceUrl; }
set { _serviceUrl = value; }
}
public int IDBoard
{
get { return _idBoard; }
set { _idBoard = value; }
}
public string UserName
{
get { return _userName; }
set { _userName = value; }
}
public Unit Width
{
get { return _width; }
set
{
_width = value;
if (_divChatWindow != null)
{
_divChatWindow.Width = value;
}
}
}
public Unit Height
{
get { return _height; }
set
{
_height = value;
if (_divChatWindow != null)
{
_divChatWindow.Height = value;
}
}
}
#endregion
#region Control Life cycle
public ChatControl()
{
Init += ChatControl_Init;
}
void ChatControl_Init(object sender, EventArgs e)
{
InitializeControls();
}
#endregion
#region Private methods
private void InitializeControls()
{
_divChatWindow = new Panel { ID = "divChatWindow", CssClass = "divChatWindow" };
Controls.Add(_divChatWindow);
_divChatWindow.Width = _width;
_divChatWindow.Height = _height;
var divChat = new Panel { ID = "divChat", CssClass = "divChat" };
_divChatWindow.Controls.Add(divChat);
var divChatControls = new Panel { ID = "divChatControls", CssClass = "divChatControls" };
_divChatWindow.Controls.Add(divChatControls);
var hidUserName = new HiddenField { ID = "hidUserName", Value = _userName };
divChatControls.Controls.Add(hidUserName);
var hidIDMessage = new HiddenField { ID = "hidIDMessage", Value = "0" };
divChatControls.Controls.Add(hidIDMessage);
var hidLastUser = new HiddenField { ID = "hidLastUser", Value = "" };
divChatControls.Controls.Add(hidLastUser);
var txtText = new TextBox { ID = "txtText", CssClass = "chatTextBox" };
txtText.Attributes.Add("autocomplete", "off");
divChatControls.Controls.Add(txtText);
var btnSend = new Button { ID = "btnSend", Text = "Send", CssClass = "chatButton" };
divChatControls.Controls.Add(btnSend);
btnSend.Attributes.Add("onclick", String.Format("SendChat('{0}', '{1}', {2}, '{3}'); return false;",
_serviceUrl, txtText.ClientID, _idBoard, hidUserName.ClientID));
LiteralControl litScript = new LiteralControl();
litScript.Text = String.Format("<script>RunChat('{0}', '{1}', '{2}', '{3}', '{4}', '{5}');</script>",
_serviceUrl, divChat.ClientID, _idBoard, hidIDMessage.ClientID, hidUserName.ClientID, hidLastUser.ClientID);
Controls.Add(litScript);
}
#endregion
}
}

View File

@@ -1,141 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using Scrummer.Code.JSON;
namespace Scrummer.Code
{
public class Message
{
public int IDMessage { get; set; }
public string UserName { get; set; }
public string Text { get; set; }
};
public class MessageBoard
{
private List<Message> _messages = new List<Message>();
private int lastIDMessage = 0;
public List<Message> Messages_GetList(int idMessage)
{
List<Message> listMessages = new List<Message>();
for (int i = 0, n = _messages.Count; i < n; i++)
{
Message msg = _messages[i];
if (msg.IDMessage > idMessage)
{
listMessages.Insert(0, msg);
}
else
{
break;
}
}
return listMessages;
}
public void Message_Add(string userName, string text)
{
lastIDMessage++;
Message msg = new Message();
msg.IDMessage = lastIDMessage;
msg.UserName = userName;
msg.Text = text;
_messages.Insert(0, msg);
}
}
public class ChatHandler : IHttpHandler
{
private static object _monitor = new object();
private static Dictionary<int, MessageBoard> _chatBoards = new Dictionary<int, MessageBoard>();
public bool IsReusable
{
get { throw new NotImplementedException(); }
}
public void ProcessRequest(HttpContext context)
{
if (context.Request.RequestType == "GET")
{
ProcessRevicer(context);
}
if (context.Request.RequestType == "POST")
{
ProcessSender(context);
}
}
private void ProcessRevicer(HttpContext context)
{
int idBoard = Convert.ToInt32(context.Request.Params["idBoard"]);
int idMessage = Convert.ToInt32(context.Request.Params["idMessage"]);
MessageBoard messageBoard;
bool mustWait = true;
do
{
if (_chatBoards.ContainsKey(idBoard))
{
messageBoard = _chatBoards[idBoard];
List<Message> listMessages = messageBoard.Messages_GetList(idMessage);
if (listMessages.Count > 0)
{
mustWait = false;
ResponseObject(context, listMessages);
}
}
if (mustWait)
{
lock (_monitor) { Monitor.Wait(_monitor, 10000); }
}
} while (mustWait);
}
private void ProcessSender(HttpContext context)
{
string strIDBoard = GetRequestParm(context, "idBoard");
int idBoard = Convert.ToInt32(string.IsNullOrEmpty(strIDBoard) ? "0" : strIDBoard);
string userName = Convert.ToString(GetRequestParm(context, "userName"));
string text = Convert.ToString(GetRequestParm(context, "text"));
lock (_chatBoards)
{
MessageBoard messageBoard;
if (_chatBoards.ContainsKey(idBoard))
{
messageBoard = _chatBoards[idBoard];
}
else
{
messageBoard = new MessageBoard();
_chatBoards[idBoard] = messageBoard;
}
messageBoard.Message_Add(userName, text);
lock (_monitor) { Monitor.PulseAll(_monitor); }
}
}
private string GetRequestParm(HttpContext context, string parm)
{
foreach (string key in context.Request.Params.AllKeys)
{
if (string.IsNullOrEmpty(key) == false && key.EndsWith(parm))
{
return context.Request.Params[key];
}
}
return string.Empty;
}
private void ResponseObject(HttpContext context, object obj)
{
var jsonWritter = new JSONWriter(true);
context.Response.ContentType = "text/json";
context.Response.Write(jsonWritter.Write(obj));
}
}
}
using System;
using System.Collections.Generic;
using System.Threading;
using System.Web;
using Scrummer.Code.JSON;
namespace Scrummer.Code
{
public class Message
{
public int IDMessage { get; set; }
public string UserName { get; set; }
public string Text { get; set; }
public DateTime Date { get; set; }
};
public class MessageBoard
{
private List<Message> _messages = new List<Message>();
private int lastIDMessage = 0;
public List<Message> Messages_GetList(int idMessage)
{
List<Message> listMessages = new List<Message>();
for (int i = 0, n = _messages.Count; i < n; i++)
{
Message msg = _messages[i];
if (msg.IDMessage > idMessage)
{
listMessages.Insert(0, msg);
}
else
{
break;
}
}
return listMessages;
}
public void Message_Add(string userName, string text)
{
lastIDMessage++;
Message msg = new Message();
msg.IDMessage = lastIDMessage;
msg.UserName = userName;
msg.Text = text;
msg.Date = DateTime.UtcNow;
_messages.Insert(0, msg);
}
}
public class ChatHandler : IHttpHandler
{
private static object _monitor = new object();
private static Dictionary<int, MessageBoard> _chatBoards = new Dictionary<int, MessageBoard>();
public bool IsReusable
{
get { throw new NotImplementedException(); }
}
public void ProcessRequest(HttpContext context)
{
if (context.Request.RequestType == "GET")
{
ProcessRevicer(context);
}
if (context.Request.RequestType == "POST")
{
ProcessSender(context);
}
}
private void ProcessRevicer(HttpContext context)
{
int idBoard = Convert.ToInt32(context.Request.Params["idBoard"]);
int idMessage = Convert.ToInt32(context.Request.Params["idMessage"]);
MessageBoard messageBoard;
bool mustWait = true;
do
{
if (_chatBoards.ContainsKey(idBoard))
{
messageBoard = _chatBoards[idBoard];
List<Message> listMessages = messageBoard.Messages_GetList(idMessage);
if (listMessages.Count > 0)
{
mustWait = false;
ResponseObject(context, listMessages);
}
}
if (mustWait)
{
lock (_monitor) { Monitor.Wait(_monitor, 10000); }
}
} while (mustWait);
}
private void ProcessSender(HttpContext context)
{
string strIDBoard = GetRequestParm(context, "idBoard");
int idBoard = Convert.ToInt32(string.IsNullOrEmpty(strIDBoard) ? "0" : strIDBoard);
string userName = Convert.ToString(GetRequestParm(context, "userName"));
string text = Convert.ToString(GetRequestParm(context, "text"));
lock (_chatBoards)
{
MessageBoard messageBoard;
if (_chatBoards.ContainsKey(idBoard))
{
messageBoard = _chatBoards[idBoard];
}
else
{
messageBoard = new MessageBoard();
_chatBoards[idBoard] = messageBoard;
}
messageBoard.Message_Add(userName, text);
lock (_monitor) { Monitor.PulseAll(_monitor); }
}
}
private string GetRequestParm(HttpContext context, string parm)
{
foreach (string key in context.Request.Params.AllKeys)
{
if (string.IsNullOrEmpty(key) == false && key.EndsWith(parm))
{
return context.Request.Params[key];
}
}
return string.Empty;
}
private void ResponseObject(HttpContext context, object obj)
{
var jsonWritter = new JSONWriter(true);
context.Response.ContentType = "text/json";
context.Response.Write(jsonWritter.Write(obj));
}
}
}

View File

@@ -1,64 +1,64 @@
using System;
using System.Text;
using System.Web;
using Scrummer.Code.Pages;
namespace Scrummer.Code
{
public static class GlobalErrorHandler
{
#region Private methods
private static void ShowInternalError(HttpContext context, Exception ex)
{
context.Response.StatusCode = 500;
context.Response.Clear();
StringBuilder sbOutput = new StringBuilder();
sbOutput.Append("<h2>Internal error</h2>");
Exception exAux = ex;
if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
while (exAux != null)
{
sbOutput.AppendFormat("<p><b>Message:</b> {0}</p>", exAux.Message);
sbOutput.AppendFormat("<p><b>StackTrace:</b></p> <pre><code>{0}</code></pre>", exAux.StackTrace);
exAux = exAux.InnerException;
}
// Fill response to 512 bytes to avoid browser "beauty" response of errors.
long fillResponse = 512 - sbOutput.Length;
if (fillResponse > 0)
{
sbOutput.Append("<!--");
for (int i = 0; i < fillResponse; i++)
{
sbOutput.Append("A");
}
sbOutput.Append("-->");
}
context.Response.Write(sbOutput.ToString());
}
#endregion
#region Public methods
public static void HandleError(HttpContext context, Exception ex)
{
try
{
IHttpHandler frmError = new FrmError(ex);
context.Response.Clear();
context.Handler = frmError;
frmError.ProcessRequest(context);
}
catch
{
ShowInternalError(context, ex);
}
}
#endregion
}
}
using System;
using System.Text;
using System.Web;
using Scrummer.Code.Pages;
namespace Scrummer.Code
{
public static class GlobalErrorHandler
{
#region Private methods
private static void ShowInternalError(HttpContext context, Exception ex)
{
context.Response.StatusCode = 500;
context.Response.Clear();
StringBuilder sbOutput = new StringBuilder();
sbOutput.Append("<h2>Internal error</h2>");
Exception exAux = ex;
if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
while (exAux != null)
{
sbOutput.AppendFormat("<p><b>Message:</b> {0}</p>", exAux.Message);
sbOutput.AppendFormat("<p><b>StackTrace:</b></p> <pre><code>{0}</code></pre>", exAux.StackTrace);
exAux = exAux.InnerException;
}
// Fill response to 512 bytes to avoid browser "beauty" response of errors.
long fillResponse = 512 - sbOutput.Length;
if (fillResponse > 0)
{
sbOutput.Append("<!--");
for (int i = 0; i < fillResponse; i++)
{
sbOutput.Append("A");
}
sbOutput.Append("-->");
}
context.Response.Write(sbOutput.ToString());
}
#endregion
#region Public methods
public static void HandleError(HttpContext context, Exception ex)
{
try
{
IHttpHandler frmError = new FrmError(ex);
context.Response.Clear();
context.Handler = frmError;
frmError.ProcessRequest(context);
}
catch
{
ShowInternalError(context, ex);
}
}
#endregion
}
}

View File

@@ -1,411 +1,411 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Scrummer.Code.JSON
{
public class JSONParser
{
#region Declarations
private ParserContext ctx;
private bool tainted = false;
#endregion
#region Private methods
private int ParseHexShort()
{
int value = 0;
for (int i = 0; i < 4; i++)
{
char c = ctx.Next();
if (Char.IsDigit(c))
{
value = (value << 4) | (c - '0');
}
else
{
c = Char.ToLower(c);
if (c >= 'a' && c <= 'f')
{
value = (value << 4) | ((c - 'a') + 10);
}
}
}
return value;
}
private String ParseQuotedString()
{
StringBuilder scratch = new StringBuilder();
char c = ctx.SkipWhite();
if (c == '"')
{
c = ctx.Next();
}
do
{
if (c == '\\')
{
c = ctx.Next();
if (c == '"')
{
scratch.Append('"');
}
else if (c == '\\')
{
scratch.Append('\\');
}
else if (c == '/')
{
scratch.Append('/');
}
else if (c == 'b')
{
scratch.Append('\b');
}
else if (c == 'f')
{
scratch.Append('\f');
}
else if (c == 'n')
{
scratch.Append('\n');
}
else if (c == 'r')
{
scratch.Append('\r');
}
else if (c == 't')
{
scratch.Append('\t');
}
else if (c == 'u')
{
scratch.Append((char)ParseHexShort());
}
c = ctx.Next();
}
else if (c == '"')
{
break;
}
else
{
scratch.Append(c);
c = ctx.Next();
}
} while (!ctx.AtEnd());
if (c == '"')
{
ctx.Next();
}
return scratch.ToString();
}
private String ParseString()
{
char c = ctx.SkipWhite();
if (c == '"')
{
return ParseQuotedString();
}
StringBuilder scratch = new StringBuilder();
while (!ctx.AtEnd()
&& (Char.IsLetter(c) || Char.IsDigit(c) || c == '_'))
{
scratch.Append(c);
c = ctx.Next();
}
return scratch.ToString();
}
private Object ParseNumber()
{
StringBuilder scratch = new StringBuilder();
bool isFloat = false;
int numberLenght = 0;
char c;
c = ctx.SkipWhite();
// Sign
if (c == '-')
{
scratch.Append('-');
c = ctx.Next();
}
// Integer part
while (Char.IsDigit(c))
{
scratch.Append(c);
c = ctx.Next();
numberLenght++;
}
// Decimal part
if (c == '.')
{
isFloat = true;
scratch.Append('.');
c = ctx.Next();
while (Char.IsDigit(c))
{
scratch.Append(c);
c = ctx.Next();
numberLenght++;
}
}
if (numberLenght == 0)
{
tainted = true;
return null;
}
// Exponential part
if (c == 'e' || c == 'E')
{
isFloat = true;
scratch.Append('E');
c = ctx.Next();
if (c == '+' || c == '-')
{
scratch.Append(c);
}
while (Char.IsDigit(c))
{
scratch.Append(c);
c = ctx.Next();
numberLenght++;
}
}
// Build number object from the parsed string
String s = scratch.ToString();
return isFloat ? (numberLenght < 17) ? (Object)Double.Parse(s)
: Decimal.Parse(s) : (numberLenght < 19) ? (Object)System.Int32.Parse(s)
: (Object)System.Int32.Parse(s);
}
private List<object> ParseArray()
{
char c = ctx.SkipWhite();
List<object> array = new List<object>();
if (c == '[')
{
ctx.Next();
}
do
{
c = ctx.SkipWhite();
if (c == ']')
{
ctx.Next();
break;
}
else if (c == ',')
{
ctx.Next();
}
else
{
array.Add(ParseValue());
}
} while (!ctx.AtEnd());
return array;
}
private Dictionary<string, object> ParseObject()
{
char c = ctx.SkipWhite();
Dictionary<string, object> obj = new Dictionary<string, object>();
if (c == '{')
{
ctx.Next();
c = ctx.SkipWhite();
}
String attributeName;
Object attributeValue;
do
{
attributeName = ParseString();
c = ctx.SkipWhite();
if (c == ':')
{
ctx.Next();
attributeValue = ParseValue();
if (attributeName.Length > 0)
{
obj.Add(attributeName, attributeValue);
}
}
else if (c == ',')
{
ctx.Next();
c = ctx.SkipWhite();
}
else if (c == '}')
{
ctx.Next();
break;
}
else
{
// Unexpected character
tainted = true;
break;
}
} while (!ctx.AtEnd());
if (obj.Count == 0)
{
return null;
}
return obj;
}
private Object ParseValue()
{
Object token = null;
char c = ctx.SkipWhite();
switch (c)
{
case '"':
token = ParseQuotedString();
break;
case '{':
token = ParseObject();
break;
case '[':
token = ParseArray();
break;
default:
if (Char.IsDigit(c) || c == '-')
{
token = ParseNumber();
}
else
{
String aux = ParseString();
if (aux.CompareTo("true") == 0)
{
token = true;
}
else if (aux.CompareTo("false") == 0)
{
token = false;
}
else if (aux.CompareTo("null") == 0)
{
token = null;
}
else
{
// Unexpected string
if (aux.Length == 0)
{
ctx.Next();
}
tainted = true;
token = null;
}
}
break;
}
return token;
}
private String CleanIdentifier(String input)
{
int i;
char c;
i = input.Length - 1;
if (i < 0)
{
return input;
}
c = input[i];
while (Char.IsLetter(c) || Char.IsDigit(c) || c == '_')
{
i--;
if (i < 0)
{
break;
}
c = input[i];
}
return input.Substring(i + 1);
}
#endregion
#region Public methods
public Object Parse(String text)
{
// Get the first object
ctx = new ParserContext(text);
tainted = false;
ctx.Mark();
Object obj = ParseValue();
if (ctx.AtEnd())
{
return obj;
}
// "But wait, there is more!"
int idx = 0;
String name = "";
String strInvalidPrev = "";
Dictionary<string, object> superObject = new Dictionary<string, object>();
do
{
// Add the object to the superObject
if (!tainted && name.Length > 0 && obj != null)
{
if (name.Length == 0)
{
name = String.Format("{0:D2}", idx);
}
superObject.Add(name, obj);
idx++;
name = "";
}
else
{
String strInvalid = ctx.GetMarked();
strInvalid = strInvalid.Trim();
if (strInvalidPrev.Length > 0
&& "=".CompareTo(strInvalid) == 0)
{
name = CleanIdentifier(strInvalidPrev);
}
else
{
name = "";
}
strInvalidPrev = strInvalid;
}
// Check end
if (ctx.AtEnd())
{
break;
}
// Get next object
tainted = false;
ctx.Mark();
obj = ParseValue();
} while (true);
return superObject;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Scrummer.Code.JSON
{
public class JSONParser
{
#region Declarations
private ParserContext ctx;
private bool tainted = false;
#endregion
#region Private methods
private int ParseHexShort()
{
int value = 0;
for (int i = 0; i < 4; i++)
{
char c = ctx.Next();
if (Char.IsDigit(c))
{
value = (value << 4) | (c - '0');
}
else
{
c = Char.ToLower(c);
if (c >= 'a' && c <= 'f')
{
value = (value << 4) | ((c - 'a') + 10);
}
}
}
return value;
}
private String ParseQuotedString()
{
StringBuilder scratch = new StringBuilder();
char c = ctx.SkipWhite();
if (c == '"')
{
c = ctx.Next();
}
do
{
if (c == '\\')
{
c = ctx.Next();
if (c == '"')
{
scratch.Append('"');
}
else if (c == '\\')
{
scratch.Append('\\');
}
else if (c == '/')
{
scratch.Append('/');
}
else if (c == 'b')
{
scratch.Append('\b');
}
else if (c == 'f')
{
scratch.Append('\f');
}
else if (c == 'n')
{
scratch.Append('\n');
}
else if (c == 'r')
{
scratch.Append('\r');
}
else if (c == 't')
{
scratch.Append('\t');
}
else if (c == 'u')
{
scratch.Append((char)ParseHexShort());
}
c = ctx.Next();
}
else if (c == '"')
{
break;
}
else
{
scratch.Append(c);
c = ctx.Next();
}
} while (!ctx.AtEnd());
if (c == '"')
{
ctx.Next();
}
return scratch.ToString();
}
private String ParseString()
{
char c = ctx.SkipWhite();
if (c == '"')
{
return ParseQuotedString();
}
StringBuilder scratch = new StringBuilder();
while (!ctx.AtEnd()
&& (Char.IsLetter(c) || Char.IsDigit(c) || c == '_'))
{
scratch.Append(c);
c = ctx.Next();
}
return scratch.ToString();
}
private Object ParseNumber()
{
StringBuilder scratch = new StringBuilder();
bool isFloat = false;
int numberLenght = 0;
char c;
c = ctx.SkipWhite();
// Sign
if (c == '-')
{
scratch.Append('-');
c = ctx.Next();
}
// Integer part
while (Char.IsDigit(c))
{
scratch.Append(c);
c = ctx.Next();
numberLenght++;
}
// Decimal part
if (c == '.')
{
isFloat = true;
scratch.Append('.');
c = ctx.Next();
while (Char.IsDigit(c))
{
scratch.Append(c);
c = ctx.Next();
numberLenght++;
}
}
if (numberLenght == 0)
{
tainted = true;
return null;
}
// Exponential part
if (c == 'e' || c == 'E')
{
isFloat = true;
scratch.Append('E');
c = ctx.Next();
if (c == '+' || c == '-')
{
scratch.Append(c);
}
while (Char.IsDigit(c))
{
scratch.Append(c);
c = ctx.Next();
numberLenght++;
}
}
// Build number object from the parsed string
String s = scratch.ToString();
return isFloat ? (numberLenght < 17) ? (Object)Double.Parse(s)
: Decimal.Parse(s) : (numberLenght < 19) ? (Object)System.Int32.Parse(s)
: (Object)System.Int32.Parse(s);
}
private List<object> ParseArray()
{
char c = ctx.SkipWhite();
List<object> array = new List<object>();
if (c == '[')
{
ctx.Next();
}
do
{
c = ctx.SkipWhite();
if (c == ']')
{
ctx.Next();
break;
}
else if (c == ',')
{
ctx.Next();
}
else
{
array.Add(ParseValue());
}
} while (!ctx.AtEnd());
return array;
}
private Dictionary<string, object> ParseObject()
{
char c = ctx.SkipWhite();
Dictionary<string, object> obj = new Dictionary<string, object>();
if (c == '{')
{
ctx.Next();
c = ctx.SkipWhite();
}
String attributeName;
Object attributeValue;
do
{
attributeName = ParseString();
c = ctx.SkipWhite();
if (c == ':')
{
ctx.Next();
attributeValue = ParseValue();
if (attributeName.Length > 0)
{
obj.Add(attributeName, attributeValue);
}
}
else if (c == ',')
{
ctx.Next();
c = ctx.SkipWhite();
}
else if (c == '}')
{
ctx.Next();
break;
}
else
{
// Unexpected character
tainted = true;
break;
}
} while (!ctx.AtEnd());
if (obj.Count == 0)
{
return null;
}
return obj;
}
private Object ParseValue()
{
Object token = null;
char c = ctx.SkipWhite();
switch (c)
{
case '"':
token = ParseQuotedString();
break;
case '{':
token = ParseObject();
break;
case '[':
token = ParseArray();
break;
default:
if (Char.IsDigit(c) || c == '-')
{
token = ParseNumber();
}
else
{
String aux = ParseString();
if (aux.CompareTo("true") == 0)
{
token = true;
}
else if (aux.CompareTo("false") == 0)
{
token = false;
}
else if (aux.CompareTo("null") == 0)
{
token = null;
}
else
{
// Unexpected string
if (aux.Length == 0)
{
ctx.Next();
}
tainted = true;
token = null;
}
}
break;
}
return token;
}
private String CleanIdentifier(String input)
{
int i;
char c;
i = input.Length - 1;
if (i < 0)
{
return input;
}
c = input[i];
while (Char.IsLetter(c) || Char.IsDigit(c) || c == '_')
{
i--;
if (i < 0)
{
break;
}
c = input[i];
}
return input.Substring(i + 1);
}
#endregion
#region Public methods
public Object Parse(String text)
{
// Get the first object
ctx = new ParserContext(text);
tainted = false;
ctx.Mark();
Object obj = ParseValue();
if (ctx.AtEnd())
{
return obj;
}
// "But wait, there is more!"
int idx = 0;
String name = "";
String strInvalidPrev = "";
Dictionary<string, object> superObject = new Dictionary<string, object>();
do
{
// Add the object to the superObject
if (!tainted && name.Length > 0 && obj != null)
{
if (name.Length == 0)
{
name = String.Format("{0:D2}", idx);
}
superObject.Add(name, obj);
idx++;
name = "";
}
else
{
String strInvalid = ctx.GetMarked();
strInvalid = strInvalid.Trim();
if (strInvalidPrev.Length > 0
&& "=".CompareTo(strInvalid) == 0)
{
name = CleanIdentifier(strInvalidPrev);
}
else
{
name = "";
}
strInvalidPrev = strInvalid;
}
// Check end
if (ctx.AtEnd())
{
break;
}
// Get next object
tainted = false;
ctx.Mark();
obj = ParseValue();
} while (true);
return superObject;
}
#endregion
}
}

View File

@@ -1,328 +1,328 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace Scrummer.Code.JSON
{
public class JSONWriter
{
#region Declarations
private bool indent = false;
private bool useTabForIndent = false;
private int indentChars = 4;
private int indentThresold = 3;
#endregion
#region Creator
public JSONWriter() { }
public JSONWriter(int indentChars)
{
this.indent = true;
this.indentChars = indentChars;
this.useTabForIndent = false;
}
public JSONWriter(bool useTabForIndent)
{
this.indent = true;
this.useTabForIndent = useTabForIndent;
}
#endregion
#region Private methods
private bool IsValue(Object obj)
{
if (obj == null)
{
return true;
}
if ((obj is float) || (obj is double) ||
(obj is System.Int16) || (obj is System.Int32) || (obj is System.Int64)
|| (obj is String) || (obj is Boolean))
{
return true;
}
return false;
}
private void WriteIndent(StringBuilder sbOutput, int level)
{
if (!indent)
{
return;
}
sbOutput.Append('\n');
if (useTabForIndent)
{
for (int i = 0; i < level; i++) { sbOutput.Append('\t'); }
}
else
{
int n = level * indentChars;
for (int i = 0; i < n; i++) { sbOutput.Append(' '); }
}
}
private void WriteString(StringBuilder sbOutput, String str)
{
sbOutput.Append('"');
char c;
int n = str.Length;
for (int i = 0; i < n; i++)
{
c = str[i];
if (c == '"') { sbOutput.Append("\\\""); }
else if (c == '\\') { sbOutput.Append("\\\\"); }
else if (c == '/') { sbOutput.Append("\\/"); }
else if (c == '\b') { sbOutput.Append("\\b"); }
else if (c == '\f') { sbOutput.Append("\\f"); }
else if (c == '\n') { sbOutput.Append("\\n"); }
else if (c == '\r') { sbOutput.Append("\\r"); }
else if (c == '\t') { sbOutput.Append("\\t"); }
else { sbOutput.Append(c); }
// FIXME: Unicode characters
}
sbOutput.Append('"');
}
private void WriteValue(StringBuilder sbOutput, Object obj, int level, bool useReflection)
{
if (obj == null)
{
// NULL
sbOutput.Append("null");
}
else if ((obj is float) || (obj is double) ||
(obj is System.Int16) || (obj is System.Int32) || (obj is System.Int64))
{
// Numbers
sbOutput.Append(obj.ToString());
}
else if (obj is String)
{
// Strings
WriteString(sbOutput, (String)obj);
}
else if (obj is Boolean)
{
// Booleans
sbOutput.Append(((Boolean)obj) ? "true" : "false");
}
else if (obj is IDictionary)
{
// Objects
WriteObject(sbOutput, obj, level);
}
else if (obj is IEnumerable)
{
// Array/List
WriteList(sbOutput, obj, level);
}
else
{
if (useReflection)
{
// Reflected object
WriteReflectedObject(sbOutput, obj, level);
}
else
{
WriteString(sbOutput, Convert.ToString(obj));
}
}
}
private void WriteList(StringBuilder sbOutput, Object obj, int level)
{
IEnumerable list = (IEnumerable)obj;
int n = 0;
// Check if it is a leaf object
bool isLeaf = true;
foreach (object childObj in list)
{
if (!IsValue(childObj))
{
isLeaf = false;
}
n++;
}
// Empty
if (n == 0)
{
sbOutput.Append("[ ]");
return;
}
// Write array
bool first = true;
sbOutput.Append("[ ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
foreach (object childObj in list)
{
if (!first)
{
sbOutput.Append(", ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
}
first = false;
WriteValue(sbOutput, childObj, level + 1, true);
}
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level);
}
sbOutput.Append(" ]");
}
private void WriteObject(StringBuilder sbOutput, Object obj, int level)
{
IDictionary map = (IDictionary)obj;
int n = map.Count;
// Empty
if (map.Count == 0)
{
sbOutput.Append("{ }");
return;
}
// Check if it is a leaf object
bool isLeaf = true;
foreach (object value in map.Values)
{
if (!IsValue(value))
{
isLeaf = false;
break;
}
}
// Write object
bool first = true;
sbOutput.Append("{ ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
foreach (object key in map.Keys)
{
object value = map[key];
if (!first)
{
sbOutput.Append(", ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
}
first = false;
WriteString(sbOutput, Convert.ToString(key));
sbOutput.Append(": ");
WriteValue(sbOutput, value, level + 1, true);
}
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level);
}
sbOutput.Append(" }");
}
private void WriteReflectedObject(StringBuilder sbOutput, Object obj, int level)
{
Type type = obj.GetType();
PropertyInfo[] rawProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
List<PropertyInfo> properties = new List<PropertyInfo>();
foreach (PropertyInfo property in rawProperties)
{
if (property.CanRead)
{
properties.Add(property);
}
}
int n = properties.Count;
// Empty
if (n == 0)
{
sbOutput.Append("{ }");
return;
}
// Check if it is a leaf object
bool isLeaf = true;
foreach (PropertyInfo property in properties)
{
object value = property.GetValue(obj, null);
if (!IsValue(value))
{
isLeaf = false;
break;
}
}
// Write object
bool first = true;
sbOutput.Append("{ ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
foreach (PropertyInfo property in properties)
{
object value=null;
MethodInfo getMethod = property.GetMethod;
ParameterInfo[] parameters =getMethod.GetParameters();
if (parameters.Length == 0)
{
value = property.GetValue(obj, null);
}
if (!first)
{
sbOutput.Append(", ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
}
first = false;
WriteString(sbOutput, property.Name);
sbOutput.Append(": ");
WriteValue(sbOutput, value, level + 1, false);
}
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level);
}
sbOutput.Append(" }");
}
#endregion
#region Public methods
public String Write(Object obj)
{
StringBuilder sbOutput = new StringBuilder();
WriteValue(sbOutput, obj, 0, true);
return sbOutput.ToString();
}
#endregion
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
namespace Scrummer.Code.JSON
{
public class JSONWriter
{
#region Declarations
private bool indent = false;
private bool useTabForIndent = false;
private int indentChars = 4;
private int indentThresold = 3;
#endregion
#region Creator
public JSONWriter() { }
public JSONWriter(int indentChars)
{
this.indent = true;
this.indentChars = indentChars;
this.useTabForIndent = false;
}
public JSONWriter(bool useTabForIndent)
{
this.indent = true;
this.useTabForIndent = useTabForIndent;
}
#endregion
#region Private methods
private bool IsValue(Object obj)
{
if (obj == null)
{
return true;
}
if ((obj is float) || (obj is double) ||
(obj is System.Int16) || (obj is System.Int32) || (obj is System.Int64)
|| (obj is String) || (obj is Boolean))
{
return true;
}
return false;
}
private void WriteIndent(StringBuilder sbOutput, int level)
{
if (!indent)
{
return;
}
sbOutput.Append('\n');
if (useTabForIndent)
{
for (int i = 0; i < level; i++) { sbOutput.Append('\t'); }
}
else
{
int n = level * indentChars;
for (int i = 0; i < n; i++) { sbOutput.Append(' '); }
}
}
private void WriteString(StringBuilder sbOutput, String str)
{
sbOutput.Append('"');
char c;
int n = str.Length;
for (int i = 0; i < n; i++)
{
c = str[i];
if (c == '"') { sbOutput.Append("\\\""); }
else if (c == '\\') { sbOutput.Append("\\\\"); }
else if (c == '/') { sbOutput.Append("\\/"); }
else if (c == '\b') { sbOutput.Append("\\b"); }
else if (c == '\f') { sbOutput.Append("\\f"); }
else if (c == '\n') { sbOutput.Append("\\n"); }
else if (c == '\r') { sbOutput.Append("\\r"); }
else if (c == '\t') { sbOutput.Append("\\t"); }
else { sbOutput.Append(c); }
// FIXME: Unicode characters
}
sbOutput.Append('"');
}
private void WriteValue(StringBuilder sbOutput, Object obj, int level, bool useReflection)
{
if (obj == null)
{
// NULL
sbOutput.Append("null");
}
else if ((obj is float) || (obj is double) ||
(obj is System.Int16) || (obj is System.Int32) || (obj is System.Int64))
{
// Numbers
sbOutput.Append(obj.ToString());
}
else if (obj is String)
{
// Strings
WriteString(sbOutput, (String)obj);
}
else if (obj is Boolean)
{
// Booleans
sbOutput.Append(((Boolean)obj) ? "true" : "false");
}
else if (obj is IDictionary)
{
// Objects
WriteObject(sbOutput, obj, level);
}
else if (obj is IEnumerable)
{
// Array/List
WriteList(sbOutput, obj, level);
}
else
{
if (useReflection)
{
// Reflected object
WriteReflectedObject(sbOutput, obj, level);
}
else
{
WriteString(sbOutput, Convert.ToString(obj));
}
}
}
private void WriteList(StringBuilder sbOutput, Object obj, int level)
{
IEnumerable list = (IEnumerable)obj;
int n = 0;
// Check if it is a leaf object
bool isLeaf = true;
foreach (object childObj in list)
{
if (!IsValue(childObj))
{
isLeaf = false;
}
n++;
}
// Empty
if (n == 0)
{
sbOutput.Append("[ ]");
return;
}
// Write array
bool first = true;
sbOutput.Append("[ ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
foreach (object childObj in list)
{
if (!first)
{
sbOutput.Append(", ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
}
first = false;
WriteValue(sbOutput, childObj, level + 1, true);
}
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level);
}
sbOutput.Append(" ]");
}
private void WriteObject(StringBuilder sbOutput, Object obj, int level)
{
IDictionary map = (IDictionary)obj;
int n = map.Count;
// Empty
if (map.Count == 0)
{
sbOutput.Append("{ }");
return;
}
// Check if it is a leaf object
bool isLeaf = true;
foreach (object value in map.Values)
{
if (!IsValue(value))
{
isLeaf = false;
break;
}
}
// Write object
bool first = true;
sbOutput.Append("{ ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
foreach (object key in map.Keys)
{
object value = map[key];
if (!first)
{
sbOutput.Append(", ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
}
first = false;
WriteString(sbOutput, Convert.ToString(key));
sbOutput.Append(": ");
WriteValue(sbOutput, value, level + 1, true);
}
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level);
}
sbOutput.Append(" }");
}
private void WriteReflectedObject(StringBuilder sbOutput, Object obj, int level)
{
Type type = obj.GetType();
PropertyInfo[] rawProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
List<PropertyInfo> properties = new List<PropertyInfo>();
foreach (PropertyInfo property in rawProperties)
{
if (property.CanRead)
{
properties.Add(property);
}
}
int n = properties.Count;
// Empty
if (n == 0)
{
sbOutput.Append("{ }");
return;
}
// Check if it is a leaf object
bool isLeaf = true;
foreach (PropertyInfo property in properties)
{
object value = property.GetValue(obj, null);
if (!IsValue(value))
{
isLeaf = false;
break;
}
}
// Write object
bool first = true;
sbOutput.Append("{ ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
foreach (PropertyInfo property in properties)
{
object value = null;
MethodInfo getMethod = property.GetGetMethod();
ParameterInfo[] parameters = getMethod.GetParameters();
if (parameters.Length == 0)
{
value = property.GetValue(obj, null);
}
if (!first)
{
sbOutput.Append(", ");
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
}
first = false;
WriteString(sbOutput, property.Name);
sbOutput.Append(": ");
WriteValue(sbOutput, value, level + 1, false);
}
if (!isLeaf || n > indentThresold)
{
WriteIndent(sbOutput, level);
}
sbOutput.Append(" }");
}
#endregion
#region Public methods
public String Write(Object obj)
{
StringBuilder sbOutput = new StringBuilder();
WriteValue(sbOutput, obj, 0, true);
return sbOutput.ToString();
}
#endregion
}
}

View File

@@ -1,84 +1,84 @@
using System;
namespace Scrummer.Code.JSON
{
public class ParserContext
{
#region Declarations
private String text;
private int length;
private int i;
private int markStart;
#endregion
#region Creator
public ParserContext(String text)
{
this.text = text;
this.length = text.Length;
this.i = 0;
this.markStart = 0;
}
#endregion
#region Public methods
public char SkipWhite()
{
while (i < length && Char.IsWhiteSpace(text[i]))
{
i++;
}
if (AtEnd())
{
return (char)0;
}
return text[i];
}
public char Next()
{
i++;
if (AtEnd())
{
return (char)0;
}
return text[i];
}
public bool AtEnd()
{
return i >= length;
}
public void Mark()
{
markStart = this.i;
}
public String GetMarked()
{
if (i < length && markStart < length)
{
return text.Substring(markStart, i);
}
else
{
if (markStart < length)
{
return text.Substring(markStart, length);
}
else
{
return string.Empty;
}
}
}
#endregion
}
}
using System;
namespace Scrummer.Code.JSON
{
public class ParserContext
{
#region Declarations
private String text;
private int length;
private int i;
private int markStart;
#endregion
#region Creator
public ParserContext(String text)
{
this.text = text;
this.length = text.Length;
this.i = 0;
this.markStart = 0;
}
#endregion
#region Public methods
public char SkipWhite()
{
while (i < length && Char.IsWhiteSpace(text[i]))
{
i++;
}
if (AtEnd())
{
return (char)0;
}
return text[i];
}
public char Next()
{
i++;
if (AtEnd())
{
return (char)0;
}
return text[i];
}
public bool AtEnd()
{
return i >= length;
}
public void Mark()
{
markStart = this.i;
}
public String GetMarked()
{
if (i < length && markStart < length)
{
return text.Substring(markStart, i);
}
else
{
if (markStart < length)
{
return text.Substring(markStart, length);
}
else
{
return string.Empty;
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,27 @@
using System;
using Scrummer.Code.Controls;
namespace Scrummer.Code.Pages
{
public class FrmBoard : PageCommon
{
private int _idBoard = 0;
public FrmBoard()
{
Init += FrmBoard_Init;
}
void FrmBoard_Init(object sender, EventArgs e)
{
Title = "Board";
var lblTest = new CLabel { Text = "Hello World", Tag = "h2" };
Controls.Add(lblTest);
ChatControl chatControl = new ChatControl();
chatControl.IDBoard = _idBoard;
chatControl.UserName = Convert.ToString(new Random().Next());
Controls.Add(chatControl);
}
}
}

View File

@@ -1,21 +1,25 @@
using System.Web;
using Scrummer.Code.JSON;
namespace Scrummer.Code.Pages
{
public class FrmEcho : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
var jsonWritter = new JSONWriter(true);
context.Response.Write("<pre><code>");
context.Response.Write(jsonWritter.Write(context.Request));
context.Response.Write("</code></pre>");
}
}
}
using System.Web;
using Scrummer.Code.JSON;
namespace Scrummer.Code.Pages
{
public class FrmEcho : IHttpHandler
{
#region IHttpHandler
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
var jsonWritter = new JSONWriter(true);
context.Response.Write("<pre><code>");
context.Response.Write(jsonWritter.Write(context.Request));
context.Response.Write("</code></pre>");
}
#endregion
}
}

View File

@@ -1,48 +1,65 @@
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Scrummer.Code.Controls;
namespace Scrummer.Code.Pages
{
public class FrmError : PageCommon
{
Exception _ex = null;
public FrmError(Exception ex)
{
_ex = ex;
Init += FrmError_Init;
}
void FrmError_Init(object sender, EventArgs e)
{
Title = "Application Error";
CLabel lblErrorTitle = new CLabel { Text = Title, Tag = "h2" };
Controls.Add(lblErrorTitle);
Exception exAux = _ex;
if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
while (exAux != null)
{
CLabel lblMessage = new CLabel { Tag = "P" };
lblMessage.Text = String.Format("<b>{0}:</b> {1}", "Message", HttpUtility.HtmlEncode(exAux.Message));
Controls.Add(lblMessage);
CLabel lblStacktraceTitle = new CLabel { Tag = "p" };
lblStacktraceTitle.Text = String.Format("<b>{0}:</b>", "Stacktrace");
Controls.Add(lblStacktraceTitle);
Panel pnlStacktrace = new Panel();
pnlStacktrace.CssClass = "divCode";
Controls.Add(pnlStacktrace);
LiteralControl litStackTrace = new LiteralControl(
String.Format("<pre><code>{0}</code></pre>", HttpUtility.HtmlEncode(exAux.StackTrace)));
pnlStacktrace.Controls.Add(litStackTrace);
exAux = exAux.InnerException;
}
}
}
}
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Scrummer.Code.Controls;
namespace Scrummer.Code.Pages
{
public class FrmError : PageCommon
{
#region Declarations
Exception _ex = null;
#endregion
#region Page life cycle
public FrmError(Exception ex)
{
_ex = ex;
Init += FrmError_Init;
}
void FrmError_Init(object sender, EventArgs e)
{
InitializeControls();
}
#endregion
#region Private methods
private void InitializeControls()
{
Title = "Application Error";
CLabel lblErrorTitle = new CLabel { Text = Title, Tag = "h2" };
Controls.Add(lblErrorTitle);
Exception exAux = _ex;
if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
while (exAux != null)
{
CLabel lblMessage = new CLabel { Tag = "P" };
lblMessage.Text = String.Format("<b>{0}:</b> {1}", "Message", HttpUtility.HtmlEncode(exAux.Message));
Controls.Add(lblMessage);
CLabel lblStacktraceTitle = new CLabel { Tag = "p" };
lblStacktraceTitle.Text = String.Format("<b>{0}:</b>", "Stacktrace");
Controls.Add(lblStacktraceTitle);
Panel pnlStacktrace = new Panel();
pnlStacktrace.CssClass = "divCode";
Controls.Add(pnlStacktrace);
LiteralControl litStackTrace = new LiteralControl(
String.Format("<pre><code>{0}</code></pre>", HttpUtility.HtmlEncode(exAux.StackTrace)));
pnlStacktrace.Controls.Add(litStackTrace);
exAux = exAux.InnerException;
}
}
#endregion
}
}

View File

@@ -1,92 +1,92 @@
using System;
using System.Reflection;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Scrummer.Code.Controls;
namespace Scrummer.Code.Pages
{
public class PageCommon : Page
{
#region Declarations
private HtmlHead _head;
private HtmlGenericControl _body;
private HtmlForm _form;
private Panel _pnlContainer = new Panel();
#endregion
#region Properties
public new ControlCollection Controls
{
get { return _pnlContainer.Controls; }
}
#endregion
#region Life cycle
public PageCommon()
{
Init += PageCommon_Init;
PreRender += PageCommon_PreRender;
}
void PageCommon_Init(object sender, EventArgs e)
{
CreateControls();
}
void PageCommon_PreRender(object sender, EventArgs e)
{
_head.Title = string.IsNullOrEmpty(Title) ? Globals.Title : String.Format("{0}{1}{2}", Globals.Title, Globals.TitleSeparator, Title);
}
#endregion
#region Private methods
private void CreateControls()
{
Context.Response.Charset = Encoding.UTF8.WebName;
var doctype = new LiteralControl("<!DOCTYPE html>\n");
base.Controls.Add(doctype);
var html = new HtmlGenericControl("html");
base.Controls.Add(html);
_head = new HtmlHead();
html.Controls.Add(_head);
_head.Controls.Add(new HtmlMeta { HttpEquiv = "content-type", Content = "text/html; charset=utf-8" });
_head.Controls.Add(new HtmlMeta { Name = "author", Content = Globals.Author });
_head.Controls.Add(new HtmlMeta { Name = "Copyright", Content = Globals.Copyright });
Assembly asm = Assembly.GetExecutingAssembly();
string version = asm.GetName().Version.ToString();
_head.Controls.Add(new LiteralControl(String.Format("<script type=\"text/javascript\" src=\"ScriptsBundler?t={0}\"></script>\n", version)));
_head.Controls.Add(new LiteralControl(String.Format("<link href=\"StylesBundler?t={0}\" type=\"text/css\" rel=\"stylesheet\"/>\n", version)));
_body = new HtmlGenericControl("body");
html.Controls.Add(_body);
_form = new HtmlForm { ID = "formMain" };
_body.Controls.Add(_form);
var pnlHeader = new Panel { CssClass = "divHeader" };
_form.Controls.Add(pnlHeader);
var lblTitle = new CLabel { Text = Globals.Title, Tag = "h1" };
pnlHeader.Controls.Add(lblTitle);
_pnlContainer.CssClass = "divContent";
_form.Controls.Add(_pnlContainer);
}
#endregion
}
}
using System;
using System.Reflection;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Scrummer.Code.Controls;
namespace Scrummer.Code.Pages
{
public class PageCommon : Page
{
#region Declarations
private HtmlHead _head;
private HtmlGenericControl _body;
private HtmlForm _form;
private Panel _pnlContainer = new Panel();
#endregion
#region Properties
public new ControlCollection Controls
{
get { return _pnlContainer.Controls; }
}
#endregion
#region Life cycle
public PageCommon()
{
Init += PageCommon_Init;
PreRender += PageCommon_PreRender;
}
void PageCommon_Init(object sender, EventArgs e)
{
CreateControls();
}
void PageCommon_PreRender(object sender, EventArgs e)
{
_head.Title = string.IsNullOrEmpty(Title) ? Globals.Title : String.Format("{0}{1}{2}", Globals.Title, Globals.TitleSeparator, Title);
}
#endregion
#region Private methods
private void CreateControls()
{
Context.Response.Charset = Encoding.UTF8.WebName;
var doctype = new LiteralControl("<!DOCTYPE html>\n");
base.Controls.Add(doctype);
var html = new HtmlGenericControl("html");
base.Controls.Add(html);
_head = new HtmlHead();
html.Controls.Add(_head);
_head.Controls.Add(new HtmlMeta { HttpEquiv = "content-type", Content = "text/html; charset=utf-8" });
_head.Controls.Add(new HtmlMeta { Name = "author", Content = Globals.Author });
_head.Controls.Add(new HtmlMeta { Name = "Copyright", Content = Globals.Copyright });
Assembly asm = Assembly.GetExecutingAssembly();
string version = asm.GetName().Version.ToString();
_head.Controls.Add(new LiteralControl(String.Format("<script type=\"text/javascript\" src=\"ScriptsBundler?t={0}\"></script>\n", version)));
_head.Controls.Add(new LiteralControl(String.Format("<link href=\"StylesBundler?t={0}\" type=\"text/css\" rel=\"stylesheet\"/>\n", version)));
_body = new HtmlGenericControl("body");
html.Controls.Add(_body);
_form = new HtmlForm { ID = "formMain" };
_body.Controls.Add(_form);
var pnlHeader = new Panel { CssClass = "divHeader" };
_form.Controls.Add(pnlHeader);
var lblTitle = new CLabel { Text = Globals.Title, Tag = "h1" };
pnlHeader.Controls.Add(lblTitle);
_pnlContainer.CssClass = "divContent";
_form.Controls.Add(_pnlContainer);
}
#endregion
}
}

View File

@@ -1,20 +1,20 @@
using System.Web;
namespace Scrummer.Code
{
public class ScriptsBundler : IHttpHandler
{
#region IHttpHandler
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
Bundler bundler = new Bundler(context.Server.MapPath("~/Scripts/"));
context.Response.ContentType = "text/javascript";
bundler.WriteResponse(context.Response.OutputStream);
}
#endregion
}
}
using System.Web;
namespace Scrummer.Code
{
public class ScriptsBundler : IHttpHandler
{
#region IHttpHandler
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
Bundler bundler = new Bundler(context.Server.MapPath("~/Scripts/"));
context.Response.ContentType = "text/javascript";
bundler.WriteResponse(context.Response.OutputStream);
}
#endregion
}
}

View File

@@ -1,20 +1,20 @@
using System.Web;
namespace Scrummer.Code
{
public class StylesBundler : IHttpHandler
{
#region IHttpHandler
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
Bundler bundler = new Bundler(context.Server.MapPath("~/Styles/"));
context.Response.ContentType = "text/css";
bundler.WriteResponse(context.Response.OutputStream);
}
#endregion
}
}
using System.Web;
namespace Scrummer.Code
{
public class StylesBundler : IHttpHandler
{
#region IHttpHandler
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
Bundler bundler = new Bundler(context.Server.MapPath("~/Styles/"));
context.Response.ContentType = "text/css";
bundler.WriteResponse(context.Response.OutputStream);
}
#endregion
}
}