Move GetRequestParm and ResponseObject to extension methods
This commit is contained in:
33
VAR.Focus.Web/Code/ExtensionMethods.cs
Normal file
33
VAR.Focus.Web/Code/ExtensionMethods.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Web;
|
||||
using VAR.Focus.Web.Code.JSON;
|
||||
|
||||
namespace VAR.Focus.Web.Code
|
||||
{
|
||||
public static class ExtensionMethods
|
||||
{
|
||||
#region HttpContext
|
||||
|
||||
public static string GetRequestParm(this 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;
|
||||
}
|
||||
|
||||
public static void ResponseObject(this HttpContext context, object obj)
|
||||
{
|
||||
var jsonWritter = new JSONWriter(true);
|
||||
context.Response.ContentType = "text/json";
|
||||
string strObject = jsonWritter.Write(obj);
|
||||
context.Response.Write(strObject);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using VAR.Focus.Web.Code;
|
||||
using VAR.Focus.Web.Code.BusinessLogic;
|
||||
using VAR.Focus.Web.Code.Entities;
|
||||
using VAR.Focus.Web.Code.JSON;
|
||||
|
||||
namespace VAR.Focus.Web.Controls
|
||||
{
|
||||
@@ -30,7 +30,7 @@ namespace VAR.Focus.Web.Controls
|
||||
{
|
||||
if (context.Request.RequestType == "GET")
|
||||
{
|
||||
if (string.IsNullOrEmpty(GetRequestParm(context, "IDCardEvent")))
|
||||
if (string.IsNullOrEmpty(context.GetRequestParm("IDCardEvent")))
|
||||
{
|
||||
ProcessInitializationReciver(context);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace VAR.Focus.Web.Controls
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ResponseObject(context, new OperationStatus { IsOK = false, Message = ex.Message, });
|
||||
context.ResponseObject(new OperationStatus { IsOK = false, Message = ex.Message, });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace VAR.Focus.Web.Controls
|
||||
|
||||
private void ProcessInitializationReciver(HttpContext context)
|
||||
{
|
||||
int idBoard = Convert.ToInt32(GetRequestParm(context, "IDBoard"));
|
||||
int idBoard = Convert.ToInt32(context.GetRequestParm("IDBoard"));
|
||||
CardBoard cardBoard;
|
||||
if (_cardBoards.ContainsKey(idBoard) == false)
|
||||
{
|
||||
@@ -85,7 +85,7 @@ namespace VAR.Focus.Web.Controls
|
||||
{
|
||||
listEvents = new List<ICardEvent>();
|
||||
}
|
||||
ResponseObject(context, listEvents);
|
||||
context.ResponseObject(listEvents);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +109,9 @@ namespace VAR.Focus.Web.Controls
|
||||
|
||||
private void ProcessEventReciver(HttpContext context)
|
||||
{
|
||||
int idBoard = Convert.ToInt32(GetRequestParm(context, "IDBoard"));
|
||||
int idCardEvent = Convert.ToInt32(GetRequestParm(context, "IDCardEvent"));
|
||||
string strTimePoolData = GetRequestParm(context, "TimePoolData");
|
||||
int idBoard = Convert.ToInt32(context.GetRequestParm("IDBoard"));
|
||||
int idCardEvent = Convert.ToInt32(context.GetRequestParm("IDCardEvent"));
|
||||
string strTimePoolData = context.GetRequestParm("TimePoolData");
|
||||
int timePoolData = Convert.ToInt32(string.IsNullOrEmpty(strTimePoolData) ? "0" : strTimePoolData);
|
||||
|
||||
CardBoard cardBoard = GetCardBoard(idBoard);
|
||||
@@ -122,7 +122,7 @@ namespace VAR.Focus.Web.Controls
|
||||
if (listMessages.Count > 0)
|
||||
{
|
||||
mustWait = false;
|
||||
ResponseObject(context, listMessages);
|
||||
context.ResponseObject(listMessages);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -131,16 +131,16 @@ namespace VAR.Focus.Web.Controls
|
||||
lock (_monitor) { Monitor.Wait(_monitor, timePoolData); }
|
||||
}
|
||||
} while (mustWait);
|
||||
ResponseObject(context, new List<Message>());
|
||||
context.ResponseObject(new List<Message>());
|
||||
}
|
||||
|
||||
private void ProcessEventSender(HttpContext context)
|
||||
{
|
||||
Session session = Sessions.Current.Session_GetCurrent(context);
|
||||
string currentUserName = session.UserName;
|
||||
string strIDBoard = GetRequestParm(context, "IDBoard");
|
||||
string strIDBoard = context.GetRequestParm("IDBoard");
|
||||
int idBoard = Convert.ToInt32(string.IsNullOrEmpty(strIDBoard) ? "0" : strIDBoard);
|
||||
string command = GetRequestParm(context, "Command");
|
||||
string command = context.GetRequestParm("Command");
|
||||
int idCard = 0;
|
||||
bool done = false;
|
||||
CardBoard cardBoard = GetCardBoard(idBoard);
|
||||
@@ -148,32 +148,32 @@ namespace VAR.Focus.Web.Controls
|
||||
{
|
||||
if (command == "Create")
|
||||
{
|
||||
string title = GetRequestParm(context, "Title");
|
||||
string body = GetRequestParm(context, "Body");
|
||||
int x = Convert.ToInt32(GetRequestParm(context, "X"));
|
||||
int y = Convert.ToInt32(GetRequestParm(context, "Y"));
|
||||
string title = context.GetRequestParm("Title");
|
||||
string body = context.GetRequestParm("Body");
|
||||
int x = Convert.ToInt32(context.GetRequestParm("X"));
|
||||
int y = Convert.ToInt32(context.GetRequestParm("Y"));
|
||||
idCard = cardBoard.Card_Create(title, body, x, y, currentUserName);
|
||||
done = true;
|
||||
}
|
||||
if (command == "Move")
|
||||
{
|
||||
idCard = Convert.ToInt32(GetRequestParm(context, "IDCard"));
|
||||
int x = Convert.ToInt32(GetRequestParm(context, "X"));
|
||||
int y = Convert.ToInt32(GetRequestParm(context, "Y"));
|
||||
idCard = Convert.ToInt32(context.GetRequestParm("IDCard"));
|
||||
int x = Convert.ToInt32(context.GetRequestParm("X"));
|
||||
int y = Convert.ToInt32(context.GetRequestParm("Y"));
|
||||
cardBoard.Card_Move(idCard, x, y, currentUserName);
|
||||
done = true;
|
||||
}
|
||||
if (command == "Edit")
|
||||
{
|
||||
idCard = Convert.ToInt32(GetRequestParm(context, "IDCard"));
|
||||
string title = GetRequestParm(context, "Title");
|
||||
string body = GetRequestParm(context, "Body");
|
||||
idCard = Convert.ToInt32(context.GetRequestParm("IDCard"));
|
||||
string title = context.GetRequestParm("Title");
|
||||
string body = context.GetRequestParm("Body");
|
||||
cardBoard.Card_Edit(idCard, title, body, currentUserName);
|
||||
done = true;
|
||||
}
|
||||
if (command == "Delete")
|
||||
{
|
||||
idCard = Convert.ToInt32(GetRequestParm(context, "IDCard"));
|
||||
idCard = Convert.ToInt32(context.GetRequestParm("IDCard"));
|
||||
cardBoard.Card_Delete(idCard, currentUserName);
|
||||
done = true;
|
||||
}
|
||||
@@ -181,7 +181,7 @@ namespace VAR.Focus.Web.Controls
|
||||
if (done)
|
||||
{
|
||||
NotifyAll();
|
||||
ResponseObject(context, new OperationStatus
|
||||
context.ResponseObject(new OperationStatus
|
||||
{
|
||||
IsOK = true,
|
||||
Message = "Update successfully",
|
||||
@@ -194,27 +194,7 @@ namespace VAR.Focus.Web.Controls
|
||||
{
|
||||
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";
|
||||
string strObject = jsonWritter.Write(obj);
|
||||
context.Response.Write(strObject);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
using VAR.Focus.Web.Code;
|
||||
using VAR.Focus.Web.Code.BusinessLogic;
|
||||
using VAR.Focus.Web.Code.Entities;
|
||||
using VAR.Focus.Web.Code.JSON;
|
||||
|
||||
namespace VAR.Focus.Web.Controls
|
||||
{
|
||||
@@ -42,9 +42,9 @@ namespace VAR.Focus.Web.Controls
|
||||
|
||||
private void ProcessReciver(HttpContext context)
|
||||
{
|
||||
string idMessageBoard = GetRequestParm(context, "IDMessageBoard");
|
||||
int idMessage = Convert.ToInt32(GetRequestParm(context, "IDMessage"));
|
||||
string strTimePoolData = GetRequestParm(context, "TimePoolData");
|
||||
string idMessageBoard = context.GetRequestParm("IDMessageBoard");
|
||||
int idMessage = Convert.ToInt32(context.GetRequestParm("IDMessage"));
|
||||
string strTimePoolData = context.GetRequestParm("TimePoolData");
|
||||
int timePoolData = Convert.ToInt32(string.IsNullOrEmpty(strTimePoolData) ? "0" : strTimePoolData);
|
||||
|
||||
MessageBoard messageBoard;
|
||||
@@ -70,7 +70,7 @@ namespace VAR.Focus.Web.Controls
|
||||
if (listMessages.Count > 0)
|
||||
{
|
||||
mustWait = false;
|
||||
ResponseObject(context, listMessages);
|
||||
context.ResponseObject(listMessages);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -79,19 +79,19 @@ namespace VAR.Focus.Web.Controls
|
||||
lock (_monitor) { Monitor.Wait(_monitor, timePoolData); }
|
||||
}
|
||||
} while (mustWait);
|
||||
ResponseObject(context, new List<Message>());
|
||||
context.ResponseObject(new List<Message>());
|
||||
}
|
||||
|
||||
private void ProcessSender(HttpContext context)
|
||||
{
|
||||
string text = Convert.ToString(GetRequestParm(context, "Text"));
|
||||
string idMessageBoard = GetRequestParm(context, "IDMessageBoard");
|
||||
string text = Convert.ToString(context.GetRequestParm("Text"));
|
||||
string idMessageBoard = context.GetRequestParm("IDMessageBoard");
|
||||
if (string.IsNullOrEmpty(idMessageBoard)) { idMessageBoard = "root"; }
|
||||
string userName = Convert.ToString(GetRequestParm(context, "UserName"));
|
||||
string userName = Convert.ToString(context.GetRequestParm("UserName"));
|
||||
Session session = Sessions.Current.Session_GetCurrent(context);
|
||||
if (session.UserName.ToLower() != userName.ToLower())
|
||||
{
|
||||
ResponseObject(context, new OperationStatus { IsOK = false, Message = "User mismatch" });
|
||||
context.ResponseObject(new OperationStatus { IsOK = false, Message = "User mismatch" });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,29 +110,9 @@ namespace VAR.Focus.Web.Controls
|
||||
messageBoard.Message_Add(userName, text);
|
||||
lock (_monitor) { Monitor.PulseAll(_monitor); }
|
||||
}
|
||||
ResponseObject(context, new OperationStatus { IsOK = true, Message = "Message sent" });
|
||||
context.ResponseObject(new OperationStatus { IsOK = true, Message = "Message sent" });
|
||||
}
|
||||
|
||||
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";
|
||||
string strObject = jsonWritter.Write(obj);
|
||||
context.Response.Write(strObject);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Web.UI.WebControls;
|
||||
using VAR.Focus.Web.Code;
|
||||
using VAR.Focus.Web.Code.BusinessLogic;
|
||||
using VAR.Focus.Web.Code.Entities;
|
||||
using VAR.Focus.Web.Controls;
|
||||
@@ -28,7 +28,7 @@ namespace VAR.Focus.Web.Pages
|
||||
|
||||
void FrmBoard_Init(object sender, EventArgs e)
|
||||
{
|
||||
string strIDBoard = GetRequestParm(Context, "idBoard");
|
||||
string strIDBoard = Context.GetRequestParm("idBoard");
|
||||
if (String.IsNullOrEmpty(strIDBoard) == false)
|
||||
{
|
||||
_idBoard = Convert.ToInt32(strIDBoard);
|
||||
@@ -133,19 +133,7 @@ namespace VAR.Focus.Web.Pages
|
||||
};
|
||||
Controls.Add(chatControl);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
<Compile Include="Code\Entities\Board.cs" />
|
||||
<Compile Include="Code\Entities\Card.cs" />
|
||||
<Compile Include="Code\Entities\CardEvents.cs" />
|
||||
<Compile Include="Code\ExtensionMethods.cs" />
|
||||
<Compile Include="Controls\CardBoardControl.cs" />
|
||||
<Compile Include="Controls\CardBoardHandler.cs" />
|
||||
<Compile Include="Controls\CButton.cs" />
|
||||
|
||||
Reference in New Issue
Block a user