From 4127b44bc44476f5b74f7427ba324e52d3d1b268 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Mon, 13 Jun 2016 01:22:48 +0200 Subject: [PATCH] Use JSONWriter instead of string concatenation --- VAR.Focus.Web/Controls/CardBoardControl.cs | 45 +++++++++-------- VAR.Focus.Web/Controls/ChatControl.cs | 58 ++++++++++++---------- 2 files changed, 55 insertions(+), 48 deletions(-) diff --git a/VAR.Focus.Web/Controls/CardBoardControl.cs b/VAR.Focus.Web/Controls/CardBoardControl.cs index 1b7dd74..063c2d4 100644 --- a/VAR.Focus.Web/Controls/CardBoardControl.cs +++ b/VAR.Focus.Web/Controls/CardBoardControl.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; +using VAR.Focus.Web.Code.JSON; namespace VAR.Focus.Web.Controls { @@ -89,32 +91,33 @@ namespace VAR.Focus.Web.Controls private void InitializeControls() { - string strCfgName = string.Format("{0}_cfg", this.ClientID); - Panel divBoard = new Panel { ID = "divBoard", CssClass = "divBoard" }; Controls.Add(divBoard); + string strCfgName = string.Format("{0}_cfg", this.ClientID); + Dictionary cfg = new Dictionary + { + {"divBoard", divBoard.ClientID}, + {"IDBoard", _idBoard}, + {"UserName", _userName}, + {"IDCardEvent", string.Empty}, + {"ServiceUrl", _serviceUrl}, + {"TimePoolData", _timePoolData}, + {"TimeRefresh", _timeRefresh}, + {"TimeRefreshDisconnected", _timeRefreshDisconnected}, + {"TimeMoveAnimation", _timeMoveAnimation}, + {"Texts", new Dictionary { + {"Toolbox", "Toolbox"}, + {"AddCard", "+ Add card"}, + {"Accept", "Accept"}, + {"Cancel", "Cancel"}, + {"ConfirmDelete", "Are you sure to delete?"}, + } }, + }; + JSONWriter jsonWriter = new JSONWriter(); StringBuilder sbCfg = new StringBuilder(); sbCfg.AppendFormat("\n"); LiteralControl liScript = new LiteralControl(sbCfg.ToString()); diff --git a/VAR.Focus.Web/Controls/ChatControl.cs b/VAR.Focus.Web/Controls/ChatControl.cs index d68e7dd..5216c96 100644 --- a/VAR.Focus.Web/Controls/ChatControl.cs +++ b/VAR.Focus.Web/Controls/ChatControl.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; +using VAR.Focus.Web.Code.JSON; namespace VAR.Focus.Web.Controls { @@ -98,7 +100,7 @@ namespace VAR.Focus.Web.Controls private void InitializeControls() { - string strCfgName = string.Format("{0}_cfg", this.ClientID); + string strCfgName = string.Format("{0}_cfg", ClientID); _divChatWindow = new Panel { ID = "divChatWindow", CssClass = "divChatWindow" }; Controls.Add(_divChatWindow); @@ -123,38 +125,40 @@ namespace VAR.Focus.Web.Controls var txtText = new TextBox { ID = "txtText", CssClass = "chatTextBox" }; txtText.Attributes.Add("autocomplete", "off"); - txtText.Attributes.Add("onkeydown", String.Format("if(event.keyCode==13){{SendChat({0}); return false;}}", strCfgName)); + txtText.Attributes.Add("onkeydown", string.Format("if(event.keyCode==13){{SendChat({0}); return false;}}", strCfgName)); 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}); return false;", strCfgName)); - + btnSend.Attributes.Add("onclick", string.Format("SendChat({0}); return false;", strCfgName)); + + Dictionary cfg = new Dictionary + { + {"divChatWindow", _divChatWindow.ClientID}, + {"divChatTitleBar", _divChatTitleBar.ClientID}, + {"lblTitle", lblTitle.ClientID}, + {"divChatContainer", _divChatContainer.ClientID}, + {"divChatContainerWidth", _width.ToString()}, + {"divChatContainerHeight", _height.ToString()}, + {"divChat", divChat.ClientID}, + {"txtText", txtText.ClientID}, + {"btnSend", btnSend.ClientID}, + {"IDMessageBoard", _idMessageBoard}, + {"UserName", _userName}, + {"IDMessage", 0}, + {"ServiceUrl", _serviceUrl}, + {"TimePoolData", _timePoolData}, + {"Texts", new Dictionary { + {"Chat", "Chat"}, + {"Close", "Close X"}, + {"NewMessages", "New messages"}, + {"Disconnected", "Disconnected"}, + } }, + }; + JSONWriter jsonWriter = new JSONWriter(); StringBuilder sbCfg = new StringBuilder(); sbCfg.AppendFormat("\n"); LiteralControl liScript = new LiteralControl(sbCfg.ToString());