diff --git a/.gitignore b/.gitignore index b04162d..c66e4da 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ Dotfuscated/* Published/* -VAR.Focus.Web/priv/*.json +VAR.Focus.WebApp/priv/*.json .vs packages/* diff --git a/VAR.Focus.Web/Code/WebSessions.cs b/VAR.Focus.Web/Code/WebSessions.cs deleted file mode 100644 index c876a57..0000000 --- a/VAR.Focus.Web/Code/WebSessions.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Web; -using VAR.Focus.BusinessLogic; -using VAR.Focus.BusinessLogic.Entities; - -namespace VAR.Focus.Web.Code -{ - public class WebSessions - { - #region Declarations - - private static WebSessions _currentInstance = null; - - private string _cookieName = "FocusSID"; - private int _cookieExpirationDays = 30; - - #endregion Declarations - - #region Properties - - public static WebSessions Current - { - get - { - if (_currentInstance == null) - { - _currentInstance = new WebSessions(); - } - return _currentInstance; - } - set { _currentInstance = value; } - } - - public string CookieName - { - get { return _cookieName; } - set { _cookieName = value; } - } - - public int CookieExpirationDays - { - get { return _cookieExpirationDays; } - set { _cookieExpirationDays = value; } - } - - #endregion Properties - - #region Public methods - - public void Session_SetCookie(HttpContext context, Session session) - { - HttpCookie cookie = new HttpCookie(_cookieName, session.SessionToken); - cookie.Expires = DateTime.Now.AddDays(_cookieExpirationDays); - context.Response.Cookies.Add(cookie); - } - - public void Session_Init(HttpContext context, string userName) - { - Session session = Sessions.Current.Session_Create(userName); - Session_SetCookie(context, session); - } - - public Session Session_GetCurrent(HttpContext context) - { - HttpCookie cookie = context.Request.Cookies[_cookieName]; - if (cookie == null) { return null; } - - string sessionToken = cookie.Value; - if (string.IsNullOrEmpty(sessionToken)) { return null; } - - Session session = Sessions.Current.Session_GetByToken(sessionToken); - return session; - } - - public bool Session_FinalizeCurrent(HttpContext context) - { - Session session = Session_GetCurrent(context); - if (Sessions.Current.Session_Delete(session) == false) { return false; } - - HttpCookie cookie = new HttpCookie(_cookieName); - cookie.Expires = DateTime.Now.AddDays(-1d); - context.Response.Cookies.Add(cookie); - - return true; - } - - public bool Session_IsUserAuthenticated(HttpContext context) - { - Session session = Session_GetCurrent(context); - if (session == null) { return false; } - User user = Users.Current.User_GetByName(session.UserName); - if (user == null) { return false; } - return true; - } - - public User Session_GetCurrentUser(HttpContext context) - { - Session session = Session_GetCurrent(context); - if (session == null) - { - return null; - } - User user = Users.Current.User_GetByName(session.UserName); - return user; - } - - #endregion Public methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Controls/CtrCardBoard.cs b/VAR.Focus.Web/Controls/CtrCardBoard.cs deleted file mode 100644 index 85b045b..0000000 --- a/VAR.Focus.Web/Controls/CtrCardBoard.cs +++ /dev/null @@ -1,169 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Web.UI; -using System.Web.UI.WebControls; -using VAR.Focus.Web.Pages; -using VAR.Json; -using VAR.WebForms.Common.Code; - -namespace VAR.Focus.Web.Controls -{ - public class CtrCardBoard : Control, INamingContainer - { - #region Declarations - - private string _serviceUrl = nameof(HndCardBoard); - - private int _idBoard = 0; - - private string _userName = string.Empty; - - private int _timePoolData = 10000; - - private int _timeRefresh = 20; - - private int _timeRefreshDisconnected = 5000; - - private int _timeMoveAnimation = 500; - - private int _defaultCardWidth = 200; - - private int _defaultCardHeight = 150; - - private int _defaultRegionWidth = 300; - - private int _defaultRegionHeight = 500; - - #endregion Declarations - - #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 int TimePoolData - { - get { return _timePoolData; } - set { _timePoolData = value; } - } - - public int TimeRefresh - { - get { return _timeRefresh; } - set { _timeRefresh = value; } - } - - public int TimeRefreshDisconnected - { - get { return _timeRefreshDisconnected; } - set { _timeRefreshDisconnected = value; } - } - - public int TimeMoveAnimation - { - get { return _timeMoveAnimation; } - set { _timeMoveAnimation = value; } - } - - private int DefaultCardWidth - { - get { return _defaultCardWidth; } - set { _defaultCardWidth = value; } - } - - private int DefaultCardHeight - { - get { return _defaultCardHeight; } - set { _defaultCardHeight = value; } - } - - private int DefaultRegionWidth - { - get { return _defaultRegionWidth; } - set { _defaultRegionWidth = value; } - } - - private int DefaultRegionHeight - { - get { return _defaultRegionHeight; } - set { _defaultRegionHeight = value; } - } - - #endregion Properties - - #region Control Life cycle - - public CtrCardBoard() - { - Init += ChatControl_Init; - } - - private void ChatControl_Init(object sender, EventArgs e) - { - InitializeControls(); - } - - #endregion Control Life cycle - - #region Private methods - - private void InitializeControls() - { - Panel divBoard = new Panel { ID = "divBoard", CssClass = "divBoard" }; - Controls.Add(divBoard); - - string strCfgName = string.Format("{0}_cfg", ClientID); - Dictionary cfg = new Dictionary - { - {"divBoard", divBoard.ClientID}, - {"IDBoard", _idBoard}, - {"UserName", _userName}, - {"EditBoardUrl", FrmBoardEdit.GetUrl(_idBoard)}, - {"IDCardEvent", string.Empty}, - {"ServiceUrl", _serviceUrl}, - {"TimePoolData", _timePoolData}, - {"TimeRefresh", _timeRefresh}, - {"TimeRefreshDisconnected", _timeRefreshDisconnected}, - {"TimeMoveAnimation", _timeMoveAnimation}, - {"DefaultCardWidth", _defaultCardWidth}, - {"DefaultCardHeight", _defaultCardHeight}, - {"DefaultRegionWidth", _defaultRegionWidth}, - {"DefaultRegionHeight", _defaultRegionHeight}, - {"Texts", new Dictionary { - {"Toolbox", MultiLang.GetLiteral( "Toolbox")}, - {"AddCard", MultiLang.GetLiteral("AddCard")}, - {"AddRegion", MultiLang.GetLiteral("AddRegion")}, - {"EditBoard", MultiLang.GetLiteral("Config")}, - {"Accept", MultiLang.GetLiteral("Accept")}, - {"Cancel", MultiLang.GetLiteral("Cancel")}, - {"ConfirmDelete", MultiLang.GetLiteral("ConfirmDelete")}, - } }, - }; - StringBuilder sbCfg = new StringBuilder(); - sbCfg.AppendFormat("\n"); - LiteralControl liScript = new LiteralControl(sbCfg.ToString()); - Controls.Add(liScript); - } - - #endregion Private methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Controls/CtrChat.cs b/VAR.Focus.Web/Controls/CtrChat.cs deleted file mode 100644 index 4779548..0000000 --- a/VAR.Focus.Web/Controls/CtrChat.cs +++ /dev/null @@ -1,171 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Web.UI; -using System.Web.UI.WebControls; -using VAR.Json; -using VAR.WebForms.Common.Code; -using VAR.WebForms.Common.Controls; - -namespace VAR.Focus.Web.Controls -{ - public class CtrChat : Control, INamingContainer - { - #region Declarations - - private string _serviceUrl = nameof(HndChat); - - private string _idMessageBoard = null; - - private string _userName = string.Empty; - - private int _timePoolData = 10000; - - private Unit _width = new Unit(500, UnitType.Pixel); - private Unit _height = new Unit(300, UnitType.Pixel); - - private Panel _divChatWindow = null; - private Panel _divChatContainer = null; - private Panel _divChatTitleBar = null; - - #endregion Declarations - - #region Properties - - public string ServiceUrl - { - get { return _serviceUrl; } - set { _serviceUrl = value; } - } - - public string IDMessageBoard - { - get { return _idMessageBoard; } - set { _idMessageBoard = value; } - } - - public string UserName - { - get { return _userName; } - set { _userName = value; } - } - - public int TimePoolData - { - get { return _timePoolData; } - set { _timePoolData = value; } - } - - public Unit Width - { - get { return _width; } - set - { - _width = value; - if (_divChatContainer != null) - { - _divChatContainer.Width = value; - } - } - } - - public Unit Height - { - get { return _height; } - set - { - _height = value; - if (_divChatContainer != null) - { - _divChatContainer.Height = value; - } - } - } - - #endregion Properties - - #region Control Life cycle - - public CtrChat() - { - Init += ChatControl_Init; - } - - private void ChatControl_Init(object sender, EventArgs e) - { - InitializeControls(); - } - - #endregion Control Life cycle - - #region Private methods - - private void InitializeControls() - { - string strCfgName = string.Format("{0}_cfg", ClientID); - - _divChatWindow = new Panel { ID = "divChatWindow", CssClass = "divChatWindow" }; - Controls.Add(_divChatWindow); - - _divChatTitleBar = new Panel { ID = "divChatTitleBar", CssClass = "divChatTitleBar" }; - _divChatWindow.Controls.Add(_divChatTitleBar); - - CLabel lblTitle = new CLabel(); - lblTitle.ID = "lblTitle"; - _divChatTitleBar.Controls.Add(lblTitle); - - _divChatContainer = new Panel { ID = "divChatContainer", CssClass = "divChatContainer" }; - _divChatWindow.Controls.Add(_divChatContainer); - _divChatContainer.Width = 0; - _divChatContainer.Height = 0; - - var divChat = new Panel { ID = "divChat", CssClass = "divChat" }; - _divChatContainer.Controls.Add(divChat); - - var divChatControls = new Panel { ID = "divChatControls", CssClass = "divChatControls" }; - _divChatContainer.Controls.Add(divChatControls); - - 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)); - divChatControls.Controls.Add(txtText); - - var btnSend = new Button { ID = "btnSend", Text = MultiLang.GetLiteral("ChatSend"), CssClass = "chatButton" }; - divChatControls.Controls.Add(btnSend); - 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", MultiLang.GetLiteral("Chat")}, - {"Close", MultiLang.GetLiteral("ChatClose")}, - {"NewMessages", MultiLang.GetLiteral("ChatNewMessages")}, - {"Disconnected", MultiLang.GetLiteral("Disconnected")}, - } }, - }; - StringBuilder sbCfg = new StringBuilder(); - sbCfg.AppendFormat("\n"); - LiteralControl liScript = new LiteralControl(sbCfg.ToString()); - Controls.Add(liScript); - } - - #endregion Private methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Controls/HndCardBoard.cs b/VAR.Focus.Web/Controls/HndCardBoard.cs deleted file mode 100644 index 9fd4787..0000000 --- a/VAR.Focus.Web/Controls/HndCardBoard.cs +++ /dev/null @@ -1,273 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Web; -using VAR.Focus.BusinessLogic; -using VAR.Focus.BusinessLogic.Entities; -using VAR.Focus.BusinessLogic.Persistence; -using VAR.Focus.Web.Code; -using VAR.WebForms.Common.Code; - -namespace VAR.Focus.Web.Controls -{ - public class HndCardBoard : IHttpHandler - { - #region Declarations - - private const int MaxWaitLoops = 5; - - private static object _monitor = new object(); - private static Dictionary _cardBoards = new Dictionary(); - - #endregion Declarations - - #region IHttpHandler - - public bool IsReusable - { - get { return false; } - } - - public void ProcessRequest(HttpContext context) - { - try - { - if (context.Request.RequestType == "GET") - { - if (string.IsNullOrEmpty(context.GetRequestParm("IDCardEvent"))) - { - ProcessInitializationReciver(context); - } - else - { - ProcessEventReciver(context); - } - } - if (context.Request.RequestType == "POST") - { - ProcessEventSender(context); - } - } - catch (Exception ex) - { - context.ResponseObject(new OperationStatus { IsOK = false, Message = ex.Message, }); - } - } - - #endregion IHttpHandler - - #region Private methods - - private void ProcessInitializationReciver(HttpContext context) - { - int idBoard = Convert.ToInt32(context.GetRequestParm("IDBoard")); - CardBoard cardBoard; - if (_cardBoards.ContainsKey(idBoard) == false) - { - lock (_cardBoards) - { - if (_cardBoards.ContainsKey(idBoard) == false) - { - cardBoard = new CardBoard(idBoard, new JsonFilePersistence()); - _cardBoards[idBoard] = cardBoard; - } - } - } - - if (_cardBoards.ContainsKey(idBoard)) - { - cardBoard = _cardBoards[idBoard]; - List listCards = cardBoard.Cards_Status(); - List listRegions = cardBoard.Regions_Status(); - List listEvents = new List(); - int lastIDCardEvent = cardBoard.GetLastIDCardEvent(); - int lastIDCard = cardBoard.GetLastIDCard(); - listEvents = new List(); - if (listRegions.Count > 0) - { - listEvents.AddRange(CardBoard.ConvertRegionsToEvents(listRegions, lastIDCardEvent)); - } - if (listCards.Count > 0) - { - listEvents.AddRange(CardBoard.ConvertCardsToEvents(listCards, lastIDCardEvent)); - } - context.ResponseObject(listEvents); - } - } - - private CardBoard GetCardBoard(int idBoard) - { - CardBoard cardBoard = null; - if (_cardBoards.ContainsKey(idBoard) == false) - { - lock (_cardBoards) - { - if (_cardBoards.ContainsKey(idBoard) == false) - { - cardBoard = new CardBoard(idBoard, new JsonFilePersistence()); - _cardBoards[idBoard] = cardBoard; - } - } - } - cardBoard = _cardBoards[idBoard]; - return cardBoard; - } - - private void ProcessEventReciver(HttpContext context) - { - 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); - int waitCount = (timePoolData > 0) ? MaxWaitLoops : 0; - do - { - List listMessages = cardBoard.Cards_GetEventList(idCardEvent); - if (listMessages.Count > 0) - { - waitCount = 0; - context.ResponseObject(listMessages); - return; - } - - if (waitCount > 0) - { - lock (_monitor) { Monitor.Wait(_monitor, timePoolData); } - waitCount--; - } - } while (waitCount > 0); - context.ResponseObject(new List()); - } - - private void ProcessEventSender(HttpContext context) - { - Session session = WebSessions.Current.Session_GetCurrent(context); - string currentUserName = session.UserName; - string strIDBoard = context.GetRequestParm("IDBoard"); - int idBoard = Convert.ToInt32(string.IsNullOrEmpty(strIDBoard) ? "0" : strIDBoard); - string command = context.GetRequestParm("Command"); - int idCard = 0; - int idRegion = 0; - bool done = false; - CardBoard cardBoard = GetCardBoard(idBoard); - lock (cardBoard) - { - if (command == "CardCreate") - { - string title = context.GetRequestParm("Title"); - string body = context.GetRequestParm("Body"); - int x = Convert.ToInt32(context.GetRequestParm("X")); - int y = Convert.ToInt32(context.GetRequestParm("Y")); - int width = Convert.ToInt32(context.GetRequestParm("Width")); - int height = Convert.ToInt32(context.GetRequestParm("Height")); - int locked = Convert.ToInt32(context.GetRequestParm("Locked")); - idCard = cardBoard.Card_Create(title, body, x, y, width, height, locked != 0, currentUserName); - done = true; - } - if (command == "CardMove") - { - 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 == "CardResize") - { - idCard = Convert.ToInt32(context.GetRequestParm("IDCard")); - int width = Convert.ToInt32(context.GetRequestParm("Width")); - int height = Convert.ToInt32(context.GetRequestParm("Height")); - cardBoard.Card_Resize(idCard, width, height, currentUserName); - done = true; - } - if (command == "CardEdit") - { - 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 == "CardLock") - { - idCard = Convert.ToInt32(context.GetRequestParm("IDCard")); - int locked = Convert.ToInt32(context.GetRequestParm("Locked")); - cardBoard.Card_Lock(idCard, locked != 0, currentUserName); - done = true; - } - if (command == "CardDelete") - { - idCard = Convert.ToInt32(context.GetRequestParm("IDCard")); - cardBoard.Card_Delete(idCard, currentUserName); - done = true; - } - if (command == "RegionCreate") - { - string title = context.GetRequestParm("Title"); - int x = Convert.ToInt32(context.GetRequestParm("X")); - int y = Convert.ToInt32(context.GetRequestParm("Y")); - int width = Convert.ToInt32(context.GetRequestParm("Width")); - int height = Convert.ToInt32(context.GetRequestParm("Height")); - int locked = Convert.ToInt32(context.GetRequestParm("Locked")); - idRegion = cardBoard.Region_Create(title, x, y, width, height, locked != 0, currentUserName); - done = true; - } - if (command == "RegionMove") - { - idRegion = Convert.ToInt32(context.GetRequestParm("IDRegion")); - int x = Convert.ToInt32(context.GetRequestParm("X")); - int y = Convert.ToInt32(context.GetRequestParm("Y")); - cardBoard.Region_Move(idRegion, x, y, currentUserName); - done = true; - } - if (command == "RegionResize") - { - idRegion = Convert.ToInt32(context.GetRequestParm("IDRegion")); - int width = Convert.ToInt32(context.GetRequestParm("Width")); - int height = Convert.ToInt32(context.GetRequestParm("Height")); - cardBoard.Region_Resize(idRegion, width, height, currentUserName); - done = true; - } - if (command == "RegionEdit") - { - idRegion = Convert.ToInt32(context.GetRequestParm("IDRegion")); - string title = context.GetRequestParm("Title"); - cardBoard.Region_Edit(idRegion, title, currentUserName); - done = true; - } - if (command == "RegionLock") - { - idRegion = Convert.ToInt32(context.GetRequestParm("IDRegion")); - int locked = Convert.ToInt32(context.GetRequestParm("Locked")); - cardBoard.Region_Lock(idRegion, locked != 0, currentUserName); - done = true; - } - if (command == "RegionDelete") - { - idRegion = Convert.ToInt32(context.GetRequestParm("IDRegion")); - cardBoard.Region_Delete(idRegion, currentUserName); - done = true; - } - } - if (done) - { - NotifyAll(); - context.ResponseObject(new OperationStatus - { - IsOK = true, - Message = "Update successfully", - ReturnValue = Convert.ToString(idCard) - }); - } - } - - private void NotifyAll() - { - lock (_monitor) { Monitor.PulseAll(_monitor); } - } - - #endregion Private methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Controls/HndChat.cs b/VAR.Focus.Web/Controls/HndChat.cs deleted file mode 100644 index 5f2d1d9..0000000 --- a/VAR.Focus.Web/Controls/HndChat.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Web; -using VAR.Focus.BusinessLogic; -using VAR.Focus.BusinessLogic.Entities; -using VAR.Focus.BusinessLogic.Persistence; -using VAR.Focus.Web.Code; -using VAR.WebForms.Common.Code; - -namespace VAR.Focus.Web.Controls -{ - public class HndChat : IHttpHandler - { - #region Declarations - - private const int MaxWaitLoops = 5; - - private static object _monitor = new object(); - private static Dictionary _chatBoards = new Dictionary(); - - #endregion Declarations - - #region IHttpHandler - - public bool IsReusable - { - get { return false; } - } - - public void ProcessRequest(HttpContext context) - { - try - { - if (context.Request.RequestType == "GET") - { - ProcessReciver(context); - } - if (context.Request.RequestType == "POST") - { - ProcessSender(context); - } - } - catch (Exception ex) - { - context.ResponseObject(new OperationStatus { IsOK = false, Message = ex.Message, }); - } - } - - #endregion IHttpHandler - - #region Private methods - - private void ProcessReciver(HttpContext context) - { - 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; - int waitCount = (timePoolData > 0) ? MaxWaitLoops : 0; - do - { - if (_chatBoards.ContainsKey(idMessageBoard) == false) - { - lock (_chatBoards) - { - if (_chatBoards.ContainsKey(idMessageBoard) == false) - { - messageBoard = new MessageBoard(idMessageBoard, new JsonFilePersistence()); - _chatBoards[idMessageBoard] = messageBoard; - } - } - } - - if (_chatBoards.ContainsKey(idMessageBoard)) - { - messageBoard = _chatBoards[idMessageBoard]; - List listMessages = messageBoard.Messages_GetList(idMessage); - if (listMessages.Count > 0) - { - waitCount = 0; - context.ResponseObject(listMessages); - return; - } - } - if (waitCount > 0) - { - lock (_monitor) { Monitor.Wait(_monitor, timePoolData); } - waitCount--; - } - } while (waitCount > 0); - context.ResponseObject(new List()); - } - - private void ProcessSender(HttpContext context) - { - string text = Convert.ToString(context.GetRequestParm("Text")); - string idMessageBoard = context.GetRequestParm("IDMessageBoard"); - if (string.IsNullOrEmpty(idMessageBoard)) { idMessageBoard = "root"; } - string userName = Convert.ToString(context.GetRequestParm("UserName")); - Session session = WebSessions.Current.Session_GetCurrent(context); - if (session.UserName.ToLower() != userName.ToLower()) - { - context.ResponseObject(new OperationStatus { IsOK = false, Message = "User mismatch" }); - return; - } - - lock (_chatBoards) - { - MessageBoard messageBoard; - if (_chatBoards.ContainsKey(idMessageBoard)) - { - messageBoard = _chatBoards[idMessageBoard]; - } - else - { - messageBoard = new MessageBoard(idMessageBoard, new JsonFilePersistence()); - _chatBoards[idMessageBoard] = messageBoard; - } - messageBoard.Message_Add(userName, text); - lock (_monitor) { Monitor.PulseAll(_monitor); } - } - context.ResponseObject(new OperationStatus { IsOK = true, Message = "Message sent" }); - } - - #endregion Private methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/FocusGlobalConfig.cs b/VAR.Focus.Web/FocusGlobalConfig.cs deleted file mode 100644 index d254d44..0000000 --- a/VAR.Focus.Web/FocusGlobalConfig.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Generic; -using System.Web; -using VAR.Focus.Web.Code; -using VAR.Focus.Web.Pages; -using VAR.WebForms.Common.Code; - -namespace VAR.Focus.Web -{ - public class FocusGlobalConfig : IGlobalConfig - { - public string Title { get; } = "Focus"; - public string TitleSeparator { get; } = " :: "; - public string Author { get; } = "Valeriano Alfonso Rodriguez"; - public string Copyright { get; } = "Copyright (c) 2015-2020 by Valeriano Alfonso, All Right Reserved"; - public string DefaultHandler { get; } = nameof(FrmBoard); - public string LoginHandler { get; } = nameof(FrmLogin); - public List AllowedExtensions { get; } = new List { ".png", ".jpg", ".jpeg", ".gif", ".ico", ".wav", ".mp3", ".ogg", ".mp4", ".webm", ".webp", ".mkv", ".avi" }; - - public bool IsUserAuthenticated(HttpContext context) - { - return WebSessions.Current.Session_IsUserAuthenticated(context); - } - - public void UserUnauthenticate(HttpContext context) - { - WebSessions.Current.Session_FinalizeCurrent(context); - } - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Images/BGCork.png b/VAR.Focus.Web/Images/BGCork.png deleted file mode 100644 index 2efccaf..0000000 Binary files a/VAR.Focus.Web/Images/BGCork.png and /dev/null differ diff --git a/VAR.Focus.Web/Pages/FrmBoard.cs b/VAR.Focus.Web/Pages/FrmBoard.cs deleted file mode 100644 index 1be4267..0000000 --- a/VAR.Focus.Web/Pages/FrmBoard.cs +++ /dev/null @@ -1,213 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Web; -using System.Web.UI.WebControls; -using VAR.Focus.BusinessLogic; -using VAR.Focus.BusinessLogic.Entities; -using VAR.Focus.Web.Code; -using VAR.Focus.Web.Controls; -using VAR.WebForms.Common.Code; -using VAR.WebForms.Common.Controls; -using VAR.WebForms.Common.Pages; - -namespace VAR.Focus.Web.Pages -{ - public class FrmBoard : PageCommon - { - #region Declarations - - private int _idBoard = 0; - - private CTextBox _txtTitle = new CTextBox { ID = "txtTitle", CssClassExtra = "width100pc", AllowEmpty = false, }; - private CTextBox _txtDescription = new CTextBox { ID = "txtDescription", CssClassExtra = "width100pc", TextMode = TextBoxMode.MultiLine, KeepSize = true, }; - - #endregion Declarations - - #region Life cycle - - public FrmBoard() - { - Init += FrmBoard_Init; - } - - private void FrmBoard_Init(object sender, EventArgs e) - { - string strIDBoard = Context.GetRequestParm("idBoard"); - if (string.IsNullOrEmpty(strIDBoard) == false) - { - _idBoard = Convert.ToInt32(strIDBoard); - } - if (_idBoard == 0) - { - FrmBoard_InitIndex(); - } - else - { - FrmBoard_InitBoard(); - } - } - - #endregion Life cycle - - #region UI Events - - private void btnAddBoard_Click(object sender, EventArgs e) - { - if (FormUtils.Controls_AreValid(Controls) == false) { return; } - - User user = WebSessions.Current.Session_GetCurrentUser(Context); - Board board = Boards.Current.Boards_SetBoard(0, _txtTitle.Text, _txtDescription.Text, null, user.Name); - _idBoard = board.IDBoard; - - Response.Redirect(GetUrl(_idBoard)); - } - - private void BtnView_Click(object sender, EventArgs e) - { - CButton btnView = (CButton)sender; - int idBoard = Convert.ToInt32(btnView.CommandArgument); - Response.Redirect(GetUrl(idBoard)); - } - - private void BtnEdit_Click(object sender, EventArgs e) - { - CButton btnEdit = (CButton)sender; - int idBoard = Convert.ToInt32(btnEdit.CommandArgument); - Response.Redirect(FrmBoardEdit.GetUrl(idBoard, nameof(FrmBoard))); - } - - private void BtnDelete_Click(object sender, EventArgs e) - { - CButton btnEdit = (CButton)sender; - int idBoard = Convert.ToInt32(btnEdit.CommandArgument); - - User user = WebSessions.Current.Session_GetCurrentUser(Context); - if (Boards.Current.Boards_DelBoard(idBoard, user.Name)) - { - Controls.Clear(); - FrmBoard_InitIndex(); - } - } - - #endregion UI Events - - #region Private methods - - private Panel BoardSelector_Create(Board board) - { - var pnlBoardSelector = new Panel { CssClass = "boardBanner" }; - - var lnkTitle = new HyperLink - { - NavigateUrl = GetUrl(board.IDBoard), - }; - var lblTitle = new CLabel - { - Text = board.Title, - CssClass = "title", - }; - lnkTitle.Controls.Add(lblTitle); - pnlBoardSelector.Controls.Add(lnkTitle); - - var lblDescription = new CLabel - { - Text = board.Description.Replace(" ", " ").Replace("\n", "
"), - CssClass = "description", - }; - pnlBoardSelector.Controls.Add(FormUtils.CreatePanel("", lblDescription)); - - Panel pnlButtons = (Panel)FormUtils.CreatePanel("formRow"); - var btnView = new CButton - { - ID = string.Format("btnView{0}", board.IDBoard), - Text = MultiLang.GetLiteral("View"), - }; - btnView.CommandArgument = Convert.ToString(board.IDBoard); - btnView.Click += BtnView_Click; - pnlButtons.Controls.Add(btnView); - var btnEdit = new CButton - { - ID = string.Format("btnEdit{0}", board.IDBoard), - Text = MultiLang.GetLiteral("Edit"), - }; - btnEdit.CommandArgument = Convert.ToString(board.IDBoard); - btnEdit.Click += BtnEdit_Click; - pnlButtons.Controls.Add(btnEdit); - var btnDelete = new CButton - { - ID = string.Format("btnDelete{0}", board.IDBoard), - Text = MultiLang.GetLiteral("Delete"), - }; - btnDelete.CommandArgument = Convert.ToString(board.IDBoard); - btnDelete.Click += BtnDelete_Click; - btnDelete.Attributes.Add("onclick", string.Format("return confirm('{0}');", MultiLang.GetLiteral("ConfirmDelete"))); - pnlButtons.Controls.Add(btnDelete); - pnlBoardSelector.Controls.Add(pnlButtons); - - return pnlBoardSelector; - } - - private void FrmBoard_InitIndex() - { - Title = "Boards"; - - User user = WebSessions.Current.Session_GetCurrentUser(Context); - List boards = Boards.Current.Boards_GetListForUser(user?.Name); - foreach (Board board in boards) - { - Panel pnlBoardSelector = BoardSelector_Create(board); - Controls.Add(pnlBoardSelector); - } - - // Board creator - var pnlBoardAdd = new Panel { CssClass = "boardBanner" }; - var btnAddBoard = new CButton { ID = "btnAddBoard", Text = MultiLang.GetLiteral("AddBoard") }; - btnAddBoard.Click += btnAddBoard_Click; - pnlBoardAdd.Controls.Add(FormUtils.CreatePanel("formRow", _txtTitle)); - _txtTitle.PlaceHolder = MultiLang.GetLiteral("Title"); - pnlBoardAdd.Controls.Add(FormUtils.CreatePanel("formRow", _txtDescription)); - _txtDescription.PlaceHolder = MultiLang.GetLiteral("Description"); - pnlBoardAdd.Controls.Add(FormUtils.CreatePanel("formRow", btnAddBoard)); - Controls.Add(pnlBoardAdd); - } - - private void FrmBoard_InitBoard() - { - User user = WebSessions.Current.Session_GetCurrentUser(Context); - Board board = Boards.Current.Board_GetByIDBoard(_idBoard); - - Title = board.Title; - - CtrCardBoard cardBoardControl = new CtrCardBoard - { - ID = "ctrCardBoard", - IDBoard = board.IDBoard, - UserName = user.Name, - }; - Controls.Add(cardBoardControl); - - CtrChat chatControl = new CtrChat - { - ID = "ctrChat", - IDMessageBoard = string.Format("CardBoard_{0}", board.IDBoard), - UserName = user.Name, - }; - Controls.Add(chatControl); - } - - #endregion Private methods - - #region Public methods - - public static string GetUrl(int idBoard, string returnUrl = null) - { - if (string.IsNullOrEmpty(returnUrl)) - { - return string.Format("{0}?idBoard={1}", nameof(FrmBoard), idBoard); - } - return string.Format("{0}?idBoard={1}&returnUrl={2}", nameof(FrmBoard), idBoard, HttpUtility.UrlEncode(returnUrl)); - } - - #endregion Public methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Pages/FrmBoardEdit.cs b/VAR.Focus.Web/Pages/FrmBoardEdit.cs deleted file mode 100644 index d502722..0000000 --- a/VAR.Focus.Web/Pages/FrmBoardEdit.cs +++ /dev/null @@ -1,141 +0,0 @@ -using System; -using System.Web; -using System.Web.UI.WebControls; -using VAR.Focus.BusinessLogic; -using VAR.Focus.BusinessLogic.Entities; -using VAR.Focus.Web.Code; -using VAR.WebForms.Common.Code; -using VAR.WebForms.Common.Controls; -using VAR.WebForms.Common.Pages; - -namespace VAR.Focus.Web.Pages -{ - public class FrmBoardEdit : PageCommon - { - #region Declarations - - private int _idBoard = 0; - - private CTextBox _txtTitle = new CTextBox { ID = "txtTitle", CssClassExtra = "width100pc", AllowEmpty = false }; - private CTextBox _txtDescription = new CTextBox { ID = "txtDescription", CssClassExtra = "width100pc", TextMode = TextBoxMode.MultiLine, KeepSize = true, }; - private CButton _btnSave = new CButton { ID = "btnSave" }; - private CButton _btnExit = new CButton { ID = "btnExit" }; - - #endregion Declarations - - #region Page life cycle - - public FrmBoardEdit() - { - Init += FrmBoardEdit_Init; - Load += FrmBoardEdit_Load; - } - - private void FrmBoardEdit_Load(object sender, EventArgs e) - { - if (IsPostBack == false) - { - LoadData(); - } - } - - private void FrmBoardEdit_Init(object sender, EventArgs e) - { - string strIDBoard = Context.GetRequestParm("idBoard"); - if (string.IsNullOrEmpty(strIDBoard) == false) - { - _idBoard = Convert.ToInt32(strIDBoard); - } - if (_idBoard == 0) - { - Response.Redirect(nameof(FrmBoard)); - } - InitializeComponents(); - } - - #endregion Page life cycle - - #region UI Events - - private void btnSave_Click(object sender, EventArgs e) - { - if (FormUtils.Controls_AreValid(Controls) == false) { return; } - - User user = WebSessions.Current.Session_GetCurrentUser(Context); - Board board = Boards.Current.Boards_SetBoard( - _idBoard, - _txtTitle.Text, - _txtDescription.Text, - _txtDescription.GetClientsideHeight(), - user.Name); - - // FIXME: Notify User of "Save Succesfully" - } - - private void btnExit_Click(object sender, EventArgs e) - { - string returnUrl = Context.GetRequestParm("returnUrl"); - if (string.IsNullOrEmpty(returnUrl)) - { - Response.Redirect(FrmBoard.GetUrl(_idBoard)); - } - else - { - Response.Redirect(returnUrl); - } - } - - #endregion UI Events - - #region Private methods - - private void InitializeComponents() - { - Title = MultiLang.GetLiteral("EditBoard"); - var lblTitle = new CLabel { Text = Title, Tag = "h2" }; - Controls.Add(lblTitle); - - Controls.Add(FormUtils.CreateField(MultiLang.GetLiteral("Title"), _txtTitle)); - _txtTitle.NextFocusOnEnter = _txtTitle; - _txtTitle.PlaceHolder = MultiLang.GetLiteral("Title"); - - Controls.Add(FormUtils.CreateField(MultiLang.GetLiteral("Description"), _txtDescription)); - _txtDescription.PlaceHolder = MultiLang.GetLiteral("Description"); - - _btnSave.Text = MultiLang.GetLiteral("Save"); - _btnSave.Click += btnSave_Click; - - _btnExit.Text = MultiLang.GetLiteral("Exit"); - _btnExit.Click += btnExit_Click; - - Panel pnlButtons = new Panel(); - pnlButtons.Controls.Add(_btnSave); - pnlButtons.Controls.Add(_btnExit); - Controls.Add(FormUtils.CreateField(string.Empty, pnlButtons)); - } - - private void LoadData() - { - Board board = Boards.Current.Board_GetByIDBoard(_idBoard); - - _txtTitle.Text = board.Title; - _txtDescription.Text = board.Description; - _txtDescription.SetClientsideHeight(board.DescriptionHeight); - } - - #endregion Private methods - - #region Public methods - - public static string GetUrl(int idBoard, string returnUrl = null) - { - if (string.IsNullOrEmpty(returnUrl)) - { - return string.Format("{0}?idBoard={1}", nameof(FrmBoardEdit), idBoard); - } - return string.Format("{0}?idBoard={1}&returnUrl={2}", nameof(FrmBoardEdit), idBoard, HttpUtility.UrlEncode(returnUrl)); - } - - #endregion Public methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Pages/FrmLogin.cs b/VAR.Focus.Web/Pages/FrmLogin.cs deleted file mode 100644 index d4801e5..0000000 --- a/VAR.Focus.Web/Pages/FrmLogin.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Web.UI.WebControls; -using VAR.Focus.BusinessLogic; -using VAR.Focus.Web.Code; -using VAR.WebForms.Common.Code; -using VAR.WebForms.Common.Controls; -using VAR.WebForms.Common.Pages; - -namespace VAR.Focus.Web.Pages -{ - public class FrmLogin : PageCommon - { - #region Declarations - - private CTextBox _txtNameEmail = new CTextBox { ID = "txtNameEmail", CssClassExtra = "width150px", AllowEmpty = false }; - private CTextBox _txtPassword = new CTextBox { ID = "txtPassword", CssClassExtra = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password }; - private CButton _btnLogin = new CButton { ID = "btnLogin" }; - - #endregion Declarations - - #region Page life cycle - - public FrmLogin() - { - MustBeAutenticated = false; - Init += FrmLogin_Init; - } - - private void FrmLogin_Init(object sender, EventArgs e) - { - InitializeControls(); - } - - #endregion Page life cycle - - #region UI Events - - private void btnLogin_Click(object sender, EventArgs e) - { - if (FormUtils.Controls_AreValid(Controls) == false) { return; } - - if (Users.Current.User_Authenticate(_txtNameEmail.Text, _txtPassword.Text) == false) - { - _txtPassword.Text = string.Empty; - return; - } - - WebSessions.Current.Session_Init(Context, _txtNameEmail.Text); - Response.Redirect(GlobalConfig.Get().DefaultHandler); - } - - #endregion UI Events - - #region Private methods - - private void InitializeControls() - { - Title = MultiLang.GetLiteral("Login"); - var lblTitle = new CLabel { Text = Title, Tag = "h2" }; - Controls.Add(lblTitle); - - Controls.Add(FormUtils.CreateField(MultiLang.GetLiteral("NameOrMail"), _txtNameEmail)); - _txtNameEmail.NextFocusOnEnter = _txtPassword; - _txtNameEmail.PlaceHolder = MultiLang.GetLiteral("NameOrMail"); - - Controls.Add(FormUtils.CreateField(MultiLang.GetLiteral("Password"), _txtPassword)); - _txtPassword.NextFocusOnEnter = _btnLogin; - _txtPassword.PlaceHolder = MultiLang.GetLiteral("Password"); - - Controls.Add(FormUtils.CreateField(string.Empty, _btnLogin)); - _btnLogin.Text = MultiLang.GetLiteral("Login"); - _btnLogin.Click += btnLogin_Click; - - Controls.Add(FormUtils.CreateField(string.Empty, new HyperLink { Text = MultiLang.GetLiteral("RegisterUser"), NavigateUrl = "FrmRegister" })); - } - - #endregion Private methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Pages/FrmRegister.cs b/VAR.Focus.Web/Pages/FrmRegister.cs deleted file mode 100644 index 52338d2..0000000 --- a/VAR.Focus.Web/Pages/FrmRegister.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Web.UI.WebControls; -using VAR.Focus.BusinessLogic; -using VAR.Focus.BusinessLogic.Entities; -using VAR.WebForms.Common.Code; -using VAR.WebForms.Common.Controls; -using VAR.WebForms.Common.Pages; - -namespace VAR.Focus.Web.Pages -{ - public class FrmRegister : PageCommon - { - #region Declarations - - private Panel _pnlRegister = new Panel { ID = "pnlRegister" }; - private CTextBox _txtName = new CTextBox { ID = "txtName", CssClassExtra = "width150px", AllowEmpty = false }; - private CTextBox _txtEmail = new CTextBox { ID = "txtEmail", CssClassExtra = "width150px", AllowEmpty = false }; - private CTextBox _txtPassword1 = new CTextBox { ID = "txtPassword1", CssClassExtra = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password }; - private CTextBox _txtPassword2 = new CTextBox { ID = "txtPassword2", CssClassExtra = "width150px", AllowEmpty = false, TextMode = TextBoxMode.Password }; - private CButton _btnRegister = new CButton { ID = "btnRegister" }; - private CButton _btnExit = new CButton { ID = "btnExit" }; - private Panel _pnlSuccess = new Panel { ID = "pnlSuccess" }; - private CLabel _lblSuccess = new CLabel { ID = "lblSuccess" }; - private CButton _btnExitSuccess = new CButton { ID = "btnExitSuccess" }; - - #endregion Declarations - - #region Page life cycle - - public FrmRegister() - { - MustBeAutenticated = false; - Init += FrmRegister_Init; - } - - private void FrmRegister_Init(object sender, EventArgs e) - { - InitializeComponents(); - } - - #endregion Page life cycle - - #region UI Events - - private void btnRegister_Click(object sender, EventArgs e) - { - if (FormUtils.Controls_AreValid(Controls) == false) { return; } - - // FIXME: Check Email - - // Check password - if (_txtPassword1.Text != _txtPassword2.Text) - { - _txtPassword1.MarkedInvalid = true; - _txtPassword2.MarkedInvalid = true; - _txtPassword1.Text = string.Empty; - _txtPassword2.Text = string.Empty; - return; - } - - User user = Users.Current.User_Set(_txtName.Text, _txtEmail.Text, _txtPassword1.Text); - - _pnlRegister.Visible = false; - _pnlSuccess.Visible = true; - _lblSuccess.Text = string.Format("User {0} created sucessfully", user.Name); - } - - private void btnExit_Click(object sender, EventArgs e) - { - Response.Redirect(GlobalConfig.Get().DefaultHandler); - } - - #endregion UI Events - - #region Private methods - - private void InitializeComponents() - { - Title = MultiLang.GetLiteral("RegisterUser"); - var lblTitle = new CLabel { Text = Title, Tag = "h2" }; - Controls.Add(lblTitle); - - Controls.Add(_pnlRegister); - - _pnlRegister.Controls.Add(FormUtils.CreateField(MultiLang.GetLiteral("Name"), _txtName)); - _txtName.NextFocusOnEnter = _txtEmail; - _txtName.PlaceHolder = MultiLang.GetLiteral("Name"); - - _pnlRegister.Controls.Add(FormUtils.CreateField(MultiLang.GetLiteral("Email"), _txtEmail)); - _txtEmail.NextFocusOnEnter = _txtPassword1; - _txtEmail.PlaceHolder = MultiLang.GetLiteral("Email"); - - _pnlRegister.Controls.Add(FormUtils.CreateField(MultiLang.GetLiteral("Password"), _txtPassword1)); - _txtPassword1.NextFocusOnEnter = _txtPassword2; - _txtPassword1.PlaceHolder = MultiLang.GetLiteral("Password"); - - _pnlRegister.Controls.Add(FormUtils.CreateField(string.Empty, _txtPassword2)); - _txtPassword2.NextFocusOnEnter = _btnRegister; - _txtPassword2.PlaceHolder = MultiLang.GetLiteral("Password"); - - _btnRegister.Text = MultiLang.GetLiteral("Register"); - _btnRegister.Click += btnRegister_Click; - - _btnExit.Text = MultiLang.GetLiteral("Exit"); - _btnExit.Click += btnExit_Click; - - Panel pnlButtons = new Panel(); - pnlButtons.Controls.Add(_btnRegister); - pnlButtons.Controls.Add(_btnExit); - _pnlRegister.Controls.Add(FormUtils.CreateField(string.Empty, pnlButtons)); - - Controls.Add(_pnlSuccess); - _pnlSuccess.Visible = false; - - _pnlSuccess.Controls.Add(_lblSuccess); - - _btnExitSuccess.Text = MultiLang.GetLiteral("Exit"); - _btnExitSuccess.Click += btnExit_Click; - _pnlSuccess.Controls.Add(FormUtils.CreateField(string.Empty, _btnExitSuccess)); - } - - #endregion Private methods - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Properties/AssemblyInfo.cs b/VAR.Focus.Web/Properties/AssemblyInfo.cs deleted file mode 100644 index 3e6773b..0000000 --- a/VAR.Focus.Web/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("VAR.Focus")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("VAR")] -[assembly: AssemblyProduct("VAR.Focus")] -[assembly: AssemblyCopyright("Copyright © VAR 2015-2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("4cd25e9d-237f-4a9f-89ac-35e537cf265e")] -[assembly: AssemblyVersion("1.0.0")] \ No newline at end of file diff --git a/VAR.Focus.Web/Properties/PublishProfiles/FolderProfile.pubxml b/VAR.Focus.Web/Properties/PublishProfiles/FolderProfile.pubxml deleted file mode 100644 index fc98099..0000000 --- a/VAR.Focus.Web/Properties/PublishProfiles/FolderProfile.pubxml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - FileSystem - FileSystem - Release - Any CPU - - True - False - Z:\www\VAR.Focus - False - - \ No newline at end of file diff --git a/VAR.Focus.Web/Resources/Literals.en.json b/VAR.Focus.Web/Resources/Literals.en.json deleted file mode 100644 index f1ea68e..0000000 --- a/VAR.Focus.Web/Resources/Literals.en.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "AddBoard": "Add board", - "EditBoard": "Edit board", - "Title": "Title", - "Description": "Description", - "Save": "Save", - "Exit": "Exit", - "Toolbox": "Toolbox", - "AddCard": "+ Card", - "AddRegion": "+ Region", - "Accept": "Accept", - "Cancel": "Cancel", - "ConfirmDelete": "Are you sure to delete?", - "ConfirmExit": "Are you sure to exit?", - "Config": "Config", - "Login": "Login", - "Logout": "Logout", - "NameOrMail": "Name/Mail", - "Password": "Password", - "RegisterUser": "RegisterUser", - "Name": "Name", - "Email": "Email", - "Register": "Register", - "View": "View", - "Edit": "Edit", - "Delete": "Delete", - "Chat": "Chat", - "ChatClose": "Close X", - "ChatNewMessages": "New messages", - "ChatDisconnected": "Disconnected", - "ChatSend": "Send" -} diff --git a/VAR.Focus.Web/Resources/Literals.es.json b/VAR.Focus.Web/Resources/Literals.es.json deleted file mode 100644 index 9342943..0000000 --- a/VAR.Focus.Web/Resources/Literals.es.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "AddBoard": "Añadir panel", - "EditBoard": "Editar panel", - "Title": "Titulo", - "Description": "Descripción", - "Save": "Guardar", - "Exit": "Salir", - "Toolbox": "Herramientas", - "AddCard": "+ Tarejeta", - "AddRegion": "+ Region", - "Accept": "Aceptar", - "Cancel": "Cancelar", - "ConfirmDelete": "¿Estas seguro de eliminar?", - "ConfirmExit": "¿Estas seguro de salir?", - "Config": "Config.", - "Login": "Login", - "Logout": "Cerrar sesion", - "NameOrMail": "Nombre/Mail", - "Password": "Password", - "RegisterUser": "Registrar usuario", - "Name": "Nombre", - "Email": "Email", - "Register": "Registrar", - "View": "Ver", - "Edit": "Editar", - "Delete": "Eliminar", - "Chat": "Chat", - "ChatClose": "Cerrar X", - "ChatNewMessages": "Nuevos mensages", - "ChatDisconnected": "Desconectado", - "ChatSend": "Envia" -} diff --git a/VAR.Focus.Web/Scripts/05. Cards.js b/VAR.Focus.Web/Scripts/05. Cards.js deleted file mode 100644 index 249ccd6..0000000 --- a/VAR.Focus.Web/Scripts/05. Cards.js +++ /dev/null @@ -1,1618 +0,0 @@ - - -var Toolbox = function (cfg, container) { - this.cfg = cfg; - this.X = 0; - this.Y = 0; - this.container = container; - - // Restore saved position - this.StrKeyPosition = "Toolbox_" + cfg.IDBoard + "_Position"; - try { - var pos = window.localStorage.getItem(this.StrKeyPosition); - if (pos && typeof pos === "string") { - pos = JSON.parse(pos); - this.X = parseInt(pos.X); - this.Y = parseInt(pos.Y); - } - } catch (e) { - window.localStorage.removeItem(this.StrKeyPosition); - } - - // Create DOM - this.divToolbox = document.createElement("div"); - this.divToolbox.className = "divToolbox"; - this.divToolbox.style.left = this.X + "px"; - this.divToolbox.style.top = this.Y + "px"; - - this.divTitle = document.createElement("div"); - this.divToolbox.appendChild(this.divTitle); - this.divTitle.className = "divTitle"; - this.divTitle.innerHTML = cfg.Texts.Toolbox; - - this.btnAddCard = document.createElement("button"); - this.divToolbox.appendChild(this.btnAddCard); - this.btnAddCard.className = "btnToolbox"; - this.btnAddCard.innerHTML = cfg.Texts.AddCard; - this.btnAddCard.addEventListener("click", Toolbox.prototype.btnAddCard_Click.bind(this), false); - - this.btnAddRegion = document.createElement("button"); - this.divToolbox.appendChild(this.btnAddRegion); - this.btnAddRegion.className = "btnToolbox"; - this.btnAddRegion.innerHTML = cfg.Texts.AddRegion; - this.btnAddRegion.addEventListener("click", Toolbox.prototype.btnAddRegion_Click.bind(this), false); - - this.btnEditBoard = document.createElement("button"); - this.divToolbox.appendChild(this.btnEditBoard); - this.btnEditBoard.className = "btnToolbox"; - this.btnEditBoard.innerHTML = cfg.Texts.EditBoard; - this.btnEditBoard.addEventListener("click", Toolbox.prototype.btnEditBoard_Click.bind(this), false); - - this.divOverlay = document.createElement("div"); - this.divToolbox.appendChild(this.divOverlay); - this.divOverlay.className = "divOverlay"; - - this.container.appendChild(this.divToolbox); - - // Bind mouse event handlers - this.bindedMouseDown = Toolbox.prototype.MouseDown.bind(this); - this.bindedMouseMove = Toolbox.prototype.MouseMove.bind(this); - this.bindedMouseUp = Toolbox.prototype.MouseUp.bind(this); - this.divOverlay.addEventListener("mousedown", this.bindedMouseDown, false); - - // Bind touch event handlers - this.bindedTouchStart = Toolbox.prototype.TouchStart.bind(this); - this.bindedTouchMove = Toolbox.prototype.TouchMove.bind(this); - this.bindedTouchEnd = Toolbox.prototype.TouchEnd.bind(this); - this.divOverlay.addEventListener("touchstart", this.bindedTouchStart, false); - - // temporal variables for dragging, editing and deleting - this.offsetX = 0; - this.offsetY = 0; -}; -Toolbox.prototype = { - ReInsertOnContainer: function () { - this.container.removeChild(this.divToolbox); - this.container.appendChild(this.divToolbox); - }, - GetRelativePosToContainer: function (pos) { - var tempElem = this.container; - var relPos = { x: pos.x, y: pos.y }; - while (tempElem) { - relPos.x -= tempElem.offsetLeft; - relPos.y -= tempElem.offsetTop; - tempElem = tempElem.offsetParent; - } - return relPos; - }, - SetPosition: function (x, y) { - if (x < 0) { x = 0; } - if (y < 0) { y = 0; } - this.X = x; - this.Y = y; - this.divToolbox.style.left = x + "px"; - this.divToolbox.style.top = y + "px"; - }, - SavePosition: function () { - var pos = { X: this.X, Y: this.Y }; - window.localStorage.setItem(this.StrKeyPosition, JSON.stringify(pos)); - }, - MouseDown: function (evt) { - evt.preventDefault(); - var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY }); - this.offsetX = pos.x - this.divToolbox.offsetLeft; - this.offsetY = pos.y - this.divToolbox.offsetTop; - document.addEventListener("mouseup", this.bindedMouseUp, false); - document.addEventListener("mousemove", this.bindedMouseMove, false); - return false; - }, - MouseMove: function (evt) { - evt.preventDefault(); - var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY }); - this.SetPosition(parseInt(pos.x - this.offsetX), parseInt(pos.y - this.offsetY)); - return false; - }, - MouseUp: function (evt) { - evt.preventDefault(); - this.SavePosition(); - document.removeEventListener("mouseup", this.bindedMouseUp, false); - document.removeEventListener("mousemove", this.bindedMouseMove, false); - return false; - }, - TouchStart: function (evt) { - evt.preventDefault(); - var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }); - this.offsetX = pos.x - this.divToolbox.offsetLeft; - this.offsetY = pos.y - this.divToolbox.offsetTop; - document.addEventListener("touchend", this.bindedTouchEnd, false); - document.addEventListener("touchcancel", this.bindedTouchEnd, false); - document.addEventListener("touchmove", this.bindedTouchMove, false); - return false; - }, - TouchMove: function (evt) { - evt.preventDefault(); - var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }); - this.SetPosition(parseInt(pos.x - this.offsetX), parseInt(pos.y - this.offsetY)); - return false; - }, - TouchEnd: function (evt) { - evt.preventDefault(); - this.SavePosition(); - document.removeEventListener("touchend", this.bindedTouchEnd, false); - document.removeEventListener("touchcancel", this.bindedTouchEnd, false); - document.removeEventListener("touchmove", this.bindedTouchMove, false); - return false; - }, - btnAddCard_Click: function (evt) { - evt.preventDefault(); - var pos = { x: 0, y: 0 }; - pos.x += this.divToolbox.offsetLeft; - pos.y += this.divToolbox.offsetTop + this.divToolbox.offsetHeight; - var card = new Card(this.cfg, 0, "", "", pos.x, pos.y, this.cfg.DefaultCardWidth, this.cfg.DefaultCardHeight); - card.InsertOnContainer(this.cfg.divBoard); - card.EnterEditionMode(); - return false; - }, - btnAddRegion_Click: function (evt) { - evt.preventDefault(); - var pos = { x: 0, y: 0 }; - pos.x += this.divToolbox.offsetLeft; - pos.y += this.divToolbox.offsetTop + this.divToolbox.offsetHeight; - var region = new Region(this.cfg, 0, "", pos.x, pos.y, this.cfg.DefaultRegionWidth, this.cfg.DefaultRegionHeight); - region.InsertOnContainer(this.cfg.divBoard); - region.EnterEditionMode(); - return false; - }, - btnEditBoard_Click: function (evt) { - evt.preventDefault(); - window.location.href = this.cfg.EditBoardUrl; - return false; - }, - empty: null -}; - -var Card = function (cfg, idCard, title, body, x, y, width, height, locked) { - this.cfg = cfg; - this.IDCard = idCard; - this.Title = title; - this.Body = body; - this.X = x; - this.Y = y; - this.Width = width; - this.Height = height; - this.Locked = locked; - - // Create DOM - this.container = null; - this.divCard = document.createElement("div"); - this.divCard.className = "divCard"; - this.divCard.style.left = x + "px"; - this.divCard.style.top = y + "px"; - this.divCard.style.width = width + "px"; - this.divCard.style.height = height + "px"; - - this.divTitle = document.createElement("div"); - this.divCard.appendChild(this.divTitle); - this.divTitle.className = "divTitle"; - - this.txtTitle = document.createElement("input"); - this.txtTitle.className = "txtTitle"; - this.txtTitle.value = this.Title; - this.divTitle.appendChild(this.txtTitle); - - this.divBody = document.createElement("div"); - this.divCard.appendChild(this.divBody); - this.divBody.className = "divBody"; - - this.txtBody = document.createElement("textarea"); - this.txtBody.className = "txtBody"; - this.txtBody.value = this.Body; - this.divBody.appendChild(this.txtBody); - - this.divOverlay = document.createElement("div"); - this.divCard.appendChild(this.divOverlay); - this.divOverlay.className = "divOverlay"; - this.divOverlay_MouseDownBinded = Card.prototype.divOverlay_MouseDown.bind(this); - this.divOverlay_MouseMoveBinded = Card.prototype.divOverlay_MouseMove.bind(this); - this.divOverlay_MouseUpBinded = Card.prototype.divOverlay_MouseUp.bind(this); - this.divOverlay.addEventListener("mousedown", this.divOverlay_MouseDownBinded, false); - this.divOverlay_TouchStartBinded = Card.prototype.divOverlay_TouchStart.bind(this); - this.divOverlay_TouchMoveBinded = Card.prototype.divOverlay_TouchMove.bind(this); - this.divOverlay_TouchEndBinded = Card.prototype.divOverlay_TouchEnd.bind(this); - this.divOverlay.addEventListener("touchstart", this.divOverlay_TouchStartBinded, false); - - this.btnEdit = document.createElement("button"); - this.divCard.appendChild(this.btnEdit); - this.btnEdit.className = "btnCard btnEdit"; - this.btnEdit.innerHTML = "✎"; // Unicode "Lower Right Pencil" - this.btnEdit.addEventListener("click", Card.prototype.btnEdit_Click.bind(this), false); - - this.btnDelete = document.createElement("button"); - this.divCard.appendChild(this.btnDelete); - this.btnDelete.className = "btnCard btnDelete"; - this.btnDelete.innerHTML = "X"; - this.btnDelete.addEventListener("click", Card.prototype.btnDelete_Click.bind(this), false); - - this.btnLock = document.createElement("button"); - this.divCard.appendChild(this.btnLock); - this.btnLock.className = "btnCard btnLock"; - this.btnLock.innerHTML = "🔒"; // Unicode "Lock" - this.btnLock.addEventListener("click", Region.prototype.btnLock_Click.bind(this), false); - - this.btnUnlock = document.createElement("button"); - this.divCard.appendChild(this.btnUnlock); - this.btnUnlock.className = "btnCard btnUnlock"; - this.btnUnlock.innerHTML = "🔓"; // Unicode "Open Lock" - this.btnUnlock.style.display = "none"; - this.btnUnlock.addEventListener("click", Region.prototype.btnUnlock_Click.bind(this), false); - - this.divResize = document.createElement("div"); - this.divCard.appendChild(this.divResize); - this.divResize.className = "divResize"; - this.divResize_MouseDownBinded = Card.prototype.divResize_MouseDown.bind(this); - this.divResize_MouseMoveBinded = Card.prototype.divResize_MouseMove.bind(this); - this.divResize_MouseUpBinded = Card.prototype.divResize_MouseUp.bind(this); - this.divResize.addEventListener("mousedown", this.divResize_MouseDownBinded, false); - this.divResize_TouchStartBinded = Card.prototype.divResize_TouchStart.bind(this); - this.divResize_TouchMoveBinded = Card.prototype.divResize_TouchMove.bind(this); - this.divResize_TouchEndBinded = Card.prototype.divResize_TouchEnd.bind(this); - this.divResize.addEventListener("touchstart", this.divResize_TouchStartBinded, false); - - // Temporal variables for actions - this.offsetX = 0; - this.offsetY = 0; - this.newX = this.X; - this.newY = this.Y; - this.newWidth = this.Width; - this.newHeight = this.Height; - this.newTitle = this.Title; - this.newBody = this.Body; - this.newLocked = locked; - this.Editing = false; - - // SelfInsert - if (this.IDCard > 0) { - this.cfg.Cards.push(this); - } - this.InsertOnContainer(this.cfg.divBoard); - - this.SetLock(this.Locked); -}; -Card.prototype = { - FilterText: function (text) { - text = text.split(" ").join("  "); - text = text.split("   ").join("   "); - text = text.split("\n").join("
"); - return text; - }, - CosineInterpolation: function (f) { - f = 1.0 - (Math.cos(f * Math.PI) + 1.0) / 2.0; - f = 1.0 - (Math.cos(f * Math.PI) + 1.0) / 2.0; - f = 1.0 - (Math.cos(f * Math.PI) + 1.0) / 2.0; - return f; - }, - InsertOnContainer: function (container) { - this.container = container; - this.container.appendChild(this.divCard); - this.cfg.Toolbox.ReInsertOnContainer(); - }, - RemoveFromContainer: function () { - this.container.removeChild(this.divCard); - }, - MoveFrame: function () { - if (this.animData) { - var f = (+new Date() - this.animData.startTime) / this.animData.time; - if (f < 1.0) { - f = this.CosineInterpolation(f); - var f2 = 1 - f; - var x = this.animData.X1 * f + this.animData.X0 * f2; - var y = this.animData.Y1 * f + this.animData.Y0 * f2; - this.divCard.style.left = x + "px"; - this.divCard.style.top = y + "px"; - this.animData.animationID = window.setTimeout(this.bindedMoveFrame, 16); - return; - } - } - this.divCard.style.left = this.X + "px"; - this.divCard.style.top = this.Y + "px"; - this.animData = null; - }, - ResizeFrame: function () { - if (this.animData) { - var f = (+new Date() - this.animData.startTime) / this.animData.time; - if (f < 1.0) { - f = this.CosineInterpolation(f); - var f2 = 1 - f; - var width = this.animData.Width1 * f + this.animData.Width0 * f2; - var height = this.animData.Height1 * f + this.animData.Height0 * f2; - this.divCard.style.width = width + "px"; - this.divCard.style.height = height + "px"; - this.animData.animationID = window.setTimeout(this.bindedResizeFrame, 16); - return; - } - } - this.divCard.style.width = this.Width + "px"; - this.divCard.style.height = this.Height + "px"; - this.animData = null; - }, - Move: function (x, y) { - if (x < 0) { x = 0; } - if (y < 0) { y = 0; } - this.OnMoveStart(); - this.X = x; - this.Y = y; - this.newX = x; - this.newY = y; - this.animData = { - X0: parseInt(this.divCard.style.left), - Y0: parseInt(this.divCard.style.top), - X1: x, - Y1: y, - time: this.cfg.TimeMoveAnimation, - startTime: +new Date(), - animationID: 0 - }; - this.bindedMoveFrame = Card.prototype.MoveFrame.bind(this); - this.animData.animationID = window.setTimeout(this.bindedMoveFrame, 16); - }, - Resize: function (width, height) { - if (width < 100) { x = 100; } - if (height < 100) { y = 100; } - this.OnResizeStart(); - this.Width = width; - this.Height = height; - this.newWidth = width; - this.newHeight = height; - this.animData = { - Width0: parseInt(this.divCard.style.width), - Height0: parseInt(this.divCard.style.height), - Width1: width, - Height1: height, - time: this.cfg.TimeMoveAnimation, - startTime: +new Date(), - animationID: 0 - }; - this.bindedResizeFrame = Card.prototype.ResizeFrame.bind(this); - this.animData.animationID = window.setTimeout(this.bindedResizeFrame, 16); - }, - Edit: function (title, body) { - if (this.Editing) { - this.ExitEditionMode(); - } - this.Title = title; - this.Body = body; - this.newTitle = title; - this.newBody = body; - this.txtTitle.value = this.Title; - this.txtBody.value = this.Body; - this.RemoveFromContainer(); - this.InsertOnContainer(this.cfg.divBoard); - }, - Lock: function (locked) { - this.newLocked = locked - this.SetLock(locked); - }, - SetLock: function (locked) { - if (locked) { - this.btnEdit.style.display = "none"; - this.btnDelete.style.display = "none"; - this.btnLock.style.display = "none"; - this.btnUnlock.style.display = ""; - this.divOverlay.className = "divOverlayTouchable"; - this.divOverlay.removeEventListener("mousedown", this.divOverlay_MouseDownBinded, false); - this.divOverlay.removeEventListener("touchstart", this.divOverlay_TouchStartBinded, false); - this.divResize.style.display = "none"; - } else { - this.btnEdit.style.display = ""; - this.btnDelete.style.display = ""; - this.btnLock.style.display = ""; - this.btnUnlock.style.display = "none"; - this.divOverlay.className = "divOverlay"; - this.divOverlay.addEventListener("mousedown", this.divOverlay_MouseDownBinded, false); - this.divOverlay.addEventListener("touchstart", this.divOverlay_TouchStartBinded, false); - this.divResize.style.display = ""; - } - }, - Reset: function () { - this.newX = this.X; - this.newY = this.Y; - this.newWidth = this.Width; - this.newHeight = this.Height; - this.newTitle = this.Title; - this.newBody = this.Body; - this.newLocked = this.Locked; - - this.divCard.style.left = this.X + "px"; - this.divCard.style.top = this.Y + "px"; - this.txtTitle.value = this.Title; - this.SetLock(this.Locked); - this.txtBody.value = this.Body; - }, - SetNew: function () { - this.X = this.newX; - this.Y = this.newY; - this.Width = this.newWidth; - this.Height = this.newHeight; - this.Title = this.newTitle; - this.Body = this.newBody; - this.Locked = this.newLocked; - this.Reset(); - }, - Hide: function () { - this.divCard.style.display = "none"; - }, - Show: function () { - this.divCard.style.display = ""; - }, - SendEvent: function (eventData) { - var card = this; - SendData(this.cfg.ServiceUrl, eventData, - function (responseText) { - try { - var recvData = JSON.parse(responseText); - if (recvData && recvData instanceof Object && recvData.IsOK === true) { - card.SetNew(); - } else { - card.Reset(); - } - } catch (e) { /* Empty */ } - }, function () { - card.Reset(); - }); - }, - OnCreate: function () { - if (this.cfg.Connected === false) { - this.OnDelete(); - return; - } - this.RemoveFromContainer(); - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "CardCreate", - "X": this.X, - "Y": this.Y, - "Width": this.Width, - "Height": this.Height, - "Title": this.Title, - "Body": this.Body, - "Locked": this.Locked ? 1 : 0, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - OnMoveStart: function () { - if (this.animData) { - window.clearTimeout(this.animData.animationID); - this.animData = null; - } - this.RemoveFromContainer(); - this.InsertOnContainer(this.cfg.divBoard); - }, - OnMove: function () { - if (this.cfg.Connected === false) { - this.Reset(); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "CardMove", - "IDCard": this.IDCard, - "X": this.newX, - "Y": this.newY, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - OnResizeStart: function () { - if (this.animData) { - window.clearTimeout(this.animData.animationID); - this.animData = null; - } - this.RemoveFromContainer(); - this.InsertOnContainer(this.cfg.divBoard); - }, - OnResize: function () { - if (this.cfg.Connected === false) { - this.Reset(); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "CardResize", - "IDCard": this.IDCard, - "Width": this.newWidth, - "Height": this.newHeight, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - OnEdit: function () { - if (this.Title !== this.newTitle || this.Body !== this.newBody) { - if (this.cfg.Connected === false) { - this.Reset(); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "CardEdit", - "IDCard": this.IDCard, - "Title": this.newTitle, - "Body": this.newBody, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - } - }, - OnLocked: function () { - if (this.cfg.Connected === false) { - this.Reset(); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "CardLock", - "IDCard": this.IDCard, - "Locked": this.newLocked ? 1 : 0, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - OnDelete: function () { - this.Hide(); - if (this.cfg.Connected === false) { - this.Show(); - return; - } - if (this.IDCard === 0) { - this.RemoveFromContainer(); - this.cfg.RemoveCard(this); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "CardDelete", - "IDCard": this.IDCard, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - GetRelativePosToContainer: function (pos) { - var tempElem = this.container; - var relPos = { x: pos.x, y: pos.y }; - while (tempElem) { - relPos.x -= tempElem.offsetLeft; - relPos.y -= tempElem.offsetTop; - tempElem = tempElem.offsetParent; - } - return relPos; - }, - divOverlay_MouseDown: function (evt) { - evt.preventDefault(); - - this.OnMoveStart(); - - var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY }); - this.offsetX = pos.x - this.divCard.offsetLeft; - this.offsetY = pos.y - this.divCard.offsetTop; - - document.addEventListener("mouseup", this.divOverlay_MouseUpBinded, false); - document.addEventListener("mousemove", this.divOverlay_MouseMoveBinded, false); - - return false; - }, - divOverlay_MouseMove: function (evt) { - evt.preventDefault(); - - var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY }); - this.newX = parseInt(pos.x - this.offsetX); - this.newY = parseInt(pos.y - this.offsetY); - if (this.newX < 0) { this.newX = 0; } - if (this.newY < 0) { this.newY = 0; } - this.divCard.style.left = this.newX + "px"; - this.divCard.style.top = this.newY + "px"; - - return false; - }, - divOverlay_MouseUp: function (evt) { - evt.preventDefault(); - - document.removeEventListener("mouseup", this.divOverlay_MouseUpBinded, false); - document.removeEventListener("mousemove", this.divOverlay_MouseMoveBinded, false); - - this.OnMove(); - - return false; - }, - divOverlay_TouchStart: function (evt) { - evt.preventDefault(); - - this.OnMoveStart(); - - var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }); - this.offsetX = pos.x - this.divCard.offsetLeft; - this.offsetY = pos.y - this.divCard.offsetTop; - - document.addEventListener("touchend", this.divOverlay_TouchEndBinded, false); - document.addEventListener("touchcancel", this.divOverlay_TouchEndBinded, false); - document.addEventListener("touchmove", this.divOverlay_TouchMoveBinded, false); - - return false; - }, - divOverlay_TouchMove: function (evt) { - evt.preventDefault(); - - var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }); - this.newX = parseInt(pos.x - this.offsetX); - this.newY = parseInt(pos.y - this.offsetY); - if (this.newX < 0) { this.newX = 0; } - if (this.newY < 0) { this.newY = 0; } - this.divCard.style.left = this.newX + "px"; - this.divCard.style.top = this.newY + "px"; - - return false; - }, - divOverlay_TouchEnd: function (evt) { - evt.preventDefault(); - - document.removeEventListener("touchend", this.divOverlay_TouchEndBinded, false); - document.removeEventListener("touchcancel", this.divOverlay_TouchEndBinded, false); - document.removeEventListener("touchmove", this.divOverlay_TouchMoveBinded, false); - - this.OnMove(); - - return false; - }, - divResize_MouseDown: function (evt) { - evt.preventDefault(); - - this.OnResizeStart(); - - this.offsetX = evt.clientX; - this.offsetY = evt.clientY; - - document.addEventListener("mouseup", this.divResize_MouseUpBinded, false); - document.addEventListener("mousemove", this.divResize_MouseMoveBinded, false); - - return false; - }, - divResize_MouseMove: function (evt) { - evt.preventDefault(); - - this.newWidth = this.Width + (evt.clientX - this.offsetX); - this.newHeight = this.Height + (evt.clientY - this.offsetY); - if (this.newWidth < 100) { this.newWidth = 100; } - if (this.newHeight < 100) { this.newHeight = 100; } - this.divCard.style.width = this.newWidth + "px"; - this.divCard.style.height = this.newHeight + "px"; - - return false; - }, - divResize_MouseUp: function (evt) { - evt.preventDefault(); - - document.removeEventListener("mouseup", this.divResize_MouseUpBinded, false); - document.removeEventListener("mousemove", this.divResize_MouseMoveBinded, false); - - this.OnResize(); - - return false; - }, - divResize_TouchStart: function (evt) { - evt.preventDefault(); - - this.OnResizeStart(); - - this.offsetX = evt.touches[0].clientX; - this.offsetY = evt.touches[0].clientY; - - document.addEventListener("touchend", this.divResize_TouchEndBinded, false); - document.addEventListener("touchcancel", this.divResize_TouchEndBinded, false); - document.addEventListener("touchmove", this.divResize_TouchMoveBinded, false); - - return false; - }, - divResize_TouchMove: function (evt) { - evt.preventDefault(); - - this.newWidth = this.Width + (evt.touches[0].clientX - this.offsetX); - this.newHeight = this.Height + (evt.touches[0].clientY - this.offsetY); - if (this.newWidth < 100) { this.newWidth = 100; } - if (this.newHeight < 100) { this.newHeight = 100; } - this.divCard.style.width = this.newWidth + "px"; - this.divCard.style.height = this.newHeight + "px"; - - return false; - }, - divResize_TouchEnd: function (evt) { - evt.preventDefault(); - - document.removeEventListener("touchend", this.divResize_TouchEndBinded, false); - document.removeEventListener("touchcancel", this.divResize_TouchEndBinded, false); - document.removeEventListener("touchmove", this.divResize_TouchMoveBinded, false); - - this.OnResize(); - - return false; - }, - EnterEditionMode: function () { - this.RemoveFromContainer(); - this.InsertOnContainer(this.cfg.divBoard); - - this.txtTitle.value = this.Title; - this.txtBody.value = this.Body; - - this.divOverlay.style.display = "none"; - this.divResize.style.display = "none"; - this.Editing = true; - - this.divEditBackground = document.createElement("div"); - this.divEditBackground.className = "divEditBackground"; - this.divEditBackground.addEventListener("click", Card.prototype.btnEdit_Click.bind(this), false); - this.divCard.parentElement.insertBefore(this.divEditBackground, this.divCard); - - }, - ExitEditionMode: function () { - this.divOverlay.style.display = ""; - this.divResize.style.display = ""; - this.Editing = false; - this.divEditBackground.className = ""; // Needed to remove "position: fixed" that causes to be not found on parentElement. - this.divEditBackground.parentElement.removeChild(this.divEditBackground); - }, - btnEdit_Click: function (evt) { - evt.preventDefault(); - if (this.Editing === false) { - this.EnterEditionMode(); - } else { - this.newTitle = this.txtTitle.value; - this.newBody = this.txtBody.value; - this.ExitEditionMode(); - this.txtTitle.value = this.newTitle; - this.txtBody.value = this.newBody; - if (this.IDCard > 0) { - this.OnEdit(); - } else { - this.Title = this.newTitle; - this.Body = this.newBody; - this.OnCreate(); - } - } - return false; - }, - btnDelete_Click: function (evt) { - evt.preventDefault(); - if (this.Editing === true) { - this.ExitEditionMode(); - this.Reset(); - if (this.IDCard > 0) { - return false; - } - } - if (this.IDCard === 0 || confirm(this.cfg.Texts.ConfirmDelete)) { - this.OnDelete(); - } - return false; - }, - btnLock_Click: function (evt) { - evt.preventDefault(); - this.Lock(true); - this.OnLocked(); - return false; - }, - btnUnlock_Click: function (evt) { - evt.preventDefault(); - this.Lock(false); - this.OnLocked(); - return false; - }, - empty: null -}; - -var Region = function (cfg, idRegion, title, x, y, width, height, locked) { - this.cfg = cfg; - this.IDRegion = idRegion; - this.Title = title; - this.X = x; - this.Y = y; - this.Width = width; - this.Height = height; - this.Locked = locked; - - // Create DOM - this.container = null; - this.divRegion = document.createElement("div"); - this.divRegion.className = "divRegion"; - this.divRegion.style.left = x + "px"; - this.divRegion.style.top = y + "px"; - this.divRegion.style.width = width + "px"; - this.divRegion.style.height = height + "px"; - - this.divTitle = document.createElement("div"); - this.divRegion.appendChild(this.divTitle); - this.divTitle.className = "divTitle"; - - this.txtTitle = document.createElement("input"); - this.txtTitle.className = "txtTitle"; - this.txtTitle.value = this.Title; - this.divTitle.appendChild(this.txtTitle); - - this.divOverlay = document.createElement("div"); - this.divRegion.appendChild(this.divOverlay); - this.divOverlay.className = "divOverlay"; - this.divOverlay_MouseDownBinded = Region.prototype.divOverlay_MouseDown.bind(this); - this.divOverlay_MouseMoveBinded = Region.prototype.divOverlay_MouseMove.bind(this); - this.divOverlay_MouseUpBinded = Region.prototype.divOverlay_MouseUp.bind(this); - this.divOverlay.addEventListener("mousedown", this.divOverlay_MouseDownBinded, false); - this.divOverlay_TouchStartBinded = Region.prototype.divOverlay_TouchStart.bind(this); - this.divOverlay_TouchMoveBinded = Region.prototype.divOverlay_TouchMove.bind(this); - this.divOverlay_TouchEndBinded = Region.prototype.divOverlay_TouchEnd.bind(this); - this.divOverlay.addEventListener("touchstart", this.divOverlay_TouchStartBinded, false); - - this.btnEdit = document.createElement("button"); - this.divRegion.appendChild(this.btnEdit); - this.btnEdit.className = "btnRegion btnEdit"; - this.btnEdit.innerHTML = "✎"; // Unicode "Lower Right Pencil" - this.btnEdit.addEventListener("click", Region.prototype.btnEdit_Click.bind(this), false); - - this.btnDelete = document.createElement("button"); - this.divRegion.appendChild(this.btnDelete); - this.btnDelete.className = "btnRegion btnDelete"; - this.btnDelete.innerHTML = "X"; - this.btnDelete.addEventListener("click", Region.prototype.btnDelete_Click.bind(this), false); - - this.btnLock = document.createElement("button"); - this.divRegion.appendChild(this.btnLock); - this.btnLock.className = "btnRegion btnLock"; - this.btnLock.innerHTML = "🔒"; // Unicode "Lock" - this.btnLock.addEventListener("click", Region.prototype.btnLock_Click.bind(this), false); - - this.btnUnlock = document.createElement("button"); - this.divRegion.appendChild(this.btnUnlock); - this.btnUnlock.className = "btnRegion btnUnlock"; - this.btnUnlock.innerHTML = "🔓"; // Unicode "Open Lock" - this.btnUnlock.style.display = "none"; - this.btnUnlock.addEventListener("click", Region.prototype.btnUnlock_Click.bind(this), false); - - this.divResize = document.createElement("div"); - this.divRegion.appendChild(this.divResize); - this.divResize.className = "divResize"; - this.divResize_MouseDownBinded = Region.prototype.divResize_MouseDown.bind(this); - this.divResize_MouseMoveBinded = Region.prototype.divResize_MouseMove.bind(this); - this.divResize_MouseUpBinded = Region.prototype.divResize_MouseUp.bind(this); - this.divResize.addEventListener("mousedown", this.divResize_MouseDownBinded, false); - this.divResize_TouchStartBinded = Region.prototype.divResize_TouchStart.bind(this); - this.divResize_TouchMoveBinded = Region.prototype.divResize_TouchMove.bind(this); - this.divResize_TouchEndBinded = Region.prototype.divResize_TouchEnd.bind(this); - this.divResize.addEventListener("touchstart", this.divResize_TouchStartBinded, false); - - // Temporal variables for actions - this.offsetX = 0; - this.offsetY = 0; - this.newX = this.X; - this.newY = this.Y; - this.newWidth = this.Width; - this.newHeight = this.Height; - this.newTitle = this.Title; - this.newLocked = this.Locked; - this.Editing = false; - - // Selfinsert - if (this.IDRegion > 0) { - this.cfg.Regions.push(this); - } - this.InsertOnContainer(this.cfg.divBoard); - - this.SetLock(this.Locked); -}; -Region.prototype = { - FilterText: function (text) { - text = text.split(" ").join("  "); - text = text.split("   ").join("   "); - text = text.split("\n").join("
"); - return text; - }, - CosineInterpolation: function (f) { - f = 1.0 - (Math.cos(f * Math.PI) + 1.0) / 2.0; - f = 1.0 - (Math.cos(f * Math.PI) + 1.0) / 2.0; - f = 1.0 - (Math.cos(f * Math.PI) + 1.0) / 2.0; - return f; - }, - InsertOnContainer: function (container) { - this.container = container; - this.container.insertBefore(this.divRegion, this.container.firstChild); - }, - RemoveFromContainer: function () { - this.container.removeChild(this.divRegion); - }, - MoveFrame: function () { - if (this.animData) { - var f = (+new Date() - this.animData.startTime) / this.animData.time; - if (f < 1.0) { - f = this.CosineInterpolation(f); - var f2 = 1 - f; - var x = this.animData.X1 * f + this.animData.X0 * f2; - var y = this.animData.Y1 * f + this.animData.Y0 * f2; - this.divRegion.style.left = x + "px"; - this.divRegion.style.top = y + "px"; - this.animData.animationID = window.setTimeout(this.bindedMoveFrame, 16); - return; - } - } - this.divRegion.style.left = this.X + "px"; - this.divRegion.style.top = this.Y + "px"; - this.animData = null; - }, - ResizeFrame: function () { - if (this.animData) { - var f = (+new Date() - this.animData.startTime) / this.animData.time; - if (f < 1.0) { - f = this.CosineInterpolation(f); - var f2 = 1 - f; - var width = this.animData.Width1 * f + this.animData.Width0 * f2; - var height = this.animData.Height1 * f + this.animData.Height0 * f2; - this.divRegion.style.width = width + "px"; - this.divRegion.style.height = height + "px"; - this.animData.animationID = window.setTimeout(this.bindedResizeFrame, 16); - return; - } - } - this.divRegion.style.width = this.Width + "px"; - this.divRegion.style.height = this.Height + "px"; - this.animData = null; - }, - Move: function (x, y) { - if (x < 0) { x = 0; } - if (y < 0) { y = 0; } - this.OnMoveStart(); - this.X = x; - this.Y = y; - this.newX = x; - this.newY = y; - this.animData = { - X0: parseInt(this.divRegion.style.left), - Y0: parseInt(this.divRegion.style.top), - X1: x, - Y1: y, - time: this.cfg.TimeMoveAnimation, - startTime: +new Date(), - animationID: 0 - }; - this.bindedMoveFrame = Region.prototype.MoveFrame.bind(this); - this.animData.animationID = window.setTimeout(this.bindedMoveFrame, 16); - }, - Resize: function (width, height) { - if (width < 100) { x = 100; } - if (height < 100) { y = 100; } - this.OnResizeStart(); - this.Width = width; - this.Height = height; - this.newWidth = width; - this.newHeight = height; - this.animData = { - Width0: parseInt(this.divRegion.style.width), - Height0: parseInt(this.divRegion.style.height), - Width1: width, - Height1: height, - time: this.cfg.TimeMoveAnimation, - startTime: +new Date(), - animationID: 0 - }; - this.bindedResizeFrame = Region.prototype.ResizeFrame.bind(this); - this.animData.animationID = window.setTimeout(this.bindedResizeFrame, 16); - }, - Edit: function (title) { - if (this.Editing) { - this.ExitEditionMode(); - } - this.Title = title; - this.newTitle = title; - this.txtTitle.value = this.Title; - }, - Lock: function (locked) { - this.newLocked = locked - this.SetLock(locked); - }, - SetLock: function (locked) { - if (locked) { - this.btnEdit.style.display = "none"; - this.btnDelete.style.display = "none"; - this.btnLock.style.display = "none"; - this.btnUnlock.style.display = ""; - this.divOverlay.className = "divOverlayTouchable"; - this.divOverlay.removeEventListener("mousedown", this.divOverlay_MouseDownBinded, false); - this.divOverlay.removeEventListener("touchstart", this.divOverlay_TouchStartBinded, false); - this.divResize.style.display = "none"; - } else { - this.btnEdit.style.display = ""; - this.btnDelete.style.display = ""; - this.btnLock.style.display = ""; - this.btnUnlock.style.display = "none"; - this.divOverlay.className = "divOverlay"; - this.divOverlay.addEventListener("mousedown", this.divOverlay_MouseDownBinded, false); - this.divOverlay.addEventListener("touchstart", this.divOverlay_TouchStartBinded, false); - this.divResize.style.display = ""; - } - }, - Reset: function () { - this.newX = this.X; - this.newY = this.Y; - this.newWidth = this.Width; - this.newHeight = this.Height; - this.newLocked = this.Locked; - this.newTitle = this.Title; - - this.divRegion.style.left = this.X + "px"; - this.divRegion.style.top = this.Y + "px"; - this.divRegion.style.width = this.Width + "px"; - this.divRegion.style.height = this.Height + "px"; - this.SetLock(this.Locked); - this.txtTitle.value = this.Title; - }, - SetNew: function () { - this.X = this.newX; - this.Y = this.newY; - this.Width = this.newWidth; - this.Height = this.newHeight; - this.Locked = this.newLocked; - this.Title = this.newTitle; - this.Reset(); - }, - Hide: function () { - this.divRegion.style.display = "none"; - }, - Show: function () { - this.divRegion.style.display = ""; - }, - SendEvent: function (eventData) { - var region = this; - SendData(this.cfg.ServiceUrl, eventData, - function (responseText) { - try { - var recvData = JSON.parse(responseText); - if (recvData && recvData instanceof Object && recvData.IsOK === true) { - region.SetNew(); - } else { - region.Reset(); - } - } catch (e) { /* Empty */ } - }, function () { - region.Reset(); - }); - }, - OnCreate: function () { - if (this.cfg.Connected === false) { - this.OnDelete(); - return; - } - this.RemoveFromContainer(); - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "RegionCreate", - "X": this.X, - "Y": this.Y, - "Width": this.Width, - "Height": this.Height, - "Locked": this.Locked ? 1 : 0, - "Title": this.Title, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - OnMoveStart: function () { - if (this.animData) { - window.clearTimeout(this.animData.animationID); - this.animData = null; - } - }, - OnMove: function () { - var Region = this; - if (this.cfg.Connected === false) { - Region.Reset(); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "RegionMove", - "IDRegion": this.IDRegion, - "X": this.newX, - "Y": this.newY, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - OnResizeStart: function () { - if (this.animData) { - window.clearTimeout(this.animData.animationID); - this.animData = null; - } - }, - OnResize: function () { - if (this.cfg.Connected === false) { - this.Reset(); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "RegionResize", - "IDRegion": this.IDRegion, - "Width": this.newWidth, - "Height": this.newHeight, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - OnEdit: function () { - if (this.Title !== this.newTitle) { - if (this.cfg.Connected === false) { - this.Reset(); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "RegionEdit", - "IDRegion": this.IDRegion, - "Title": this.newTitle, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - } - }, - OnLocked: function () { - if (this.cfg.Connected === false) { - this.Reset(); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "RegionLock", - "IDRegion": this.IDRegion, - "Locked": this.newLocked ? 1 : 0, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - OnDelete: function () { - this.Hide(); - if (this.cfg.Connected === false) { - this.Show(); - return; - } - if (this.IDRegion === 0) { - this.RemoveFromContainer(); - this.cfg.RemoveRegion(this); - return; - } - var data = { - "IDBoard": this.cfg.IDBoard, - "Command": "RegionDelete", - "IDRegion": this.IDRegion, - "TimeStamp": new Date().getTime() - }; - this.SendEvent(data); - }, - GetRelativePosToContainer: function (pos) { - var tempElem = this.container; - var relPos = { x: pos.x, y: pos.y }; - while (tempElem) { - relPos.x -= tempElem.offsetLeft; - relPos.y -= tempElem.offsetTop; - tempElem = tempElem.offsetParent; - } - return relPos; - }, - divOverlay_MouseDown: function (evt) { - evt.preventDefault(); - - this.OnMoveStart(); - - var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY }); - this.offsetX = pos.x - this.divRegion.offsetLeft; - this.offsetY = pos.y - this.divRegion.offsetTop; - - document.addEventListener("mouseup", this.divOverlay_MouseUpBinded, false); - document.addEventListener("mousemove", this.divOverlay_MouseMoveBinded, false); - - return false; - }, - divOverlay_MouseMove: function (evt) { - evt.preventDefault(); - - var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY }); - this.newX = parseInt(pos.x - this.offsetX); - this.newY = parseInt(pos.y - this.offsetY); - if (this.newX < 0) { this.newX = 0; } - if (this.newY < 0) { this.newY = 0; } - this.divRegion.style.left = this.newX + "px"; - this.divRegion.style.top = this.newY + "px"; - - return false; - }, - divOverlay_MouseUp: function (evt) { - evt.preventDefault(); - - document.removeEventListener("mouseup", this.divOverlay_MouseUpBinded, false); - document.removeEventListener("mousemove", this.divOverlay_MouseMoveBinded, false); - - this.OnMove(); - - return false; - }, - divOverlay_TouchStart: function (evt) { - evt.preventDefault(); - - this.OnMoveStart(); - - var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }); - this.offsetX = pos.x - this.divRegion.offsetLeft; - this.offsetY = pos.y - this.divRegion.offsetTop; - - document.addEventListener("touchend", this.divOverlay_TouchEndBinded, false); - document.addEventListener("touchcancel", this.divOverlay_TouchEndBinded, false); - document.addEventListener("touchmove", this.divOverlay_TouchMoveBinded, false); - - return false; - }, - divOverlay_TouchMove: function (evt) { - evt.preventDefault(); - - var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY }); - this.newX = parseInt(pos.x - this.offsetX); - this.newY = parseInt(pos.y - this.offsetY); - if (this.newX < 0) { this.newX = 0; } - if (this.newY < 0) { this.newY = 0; } - this.divRegion.style.left = this.newX + "px"; - this.divRegion.style.top = this.newY + "px"; - - return false; - }, - divOverlay_TouchEnd: function (evt) { - evt.preventDefault(); - - document.removeEventListener("touchend", this.divOverlay_TouchEndBinded, false); - document.removeEventListener("touchcancel", this.divOverlay_TouchEndBinded, false); - document.removeEventListener("touchmove", this.divOverlay_TouchMoveBinded, false); - - this.OnMove(); - - return false; - }, - divResize_MouseDown: function (evt) { - evt.preventDefault(); - - this.OnResizeStart(); - - this.offsetX = evt.clientX; - this.offsetY = evt.clientY; - - document.addEventListener("mouseup", this.divResize_MouseUpBinded, false); - document.addEventListener("mousemove", this.divResize_MouseMoveBinded, false); - - return false; - }, - divResize_MouseMove: function (evt) { - evt.preventDefault(); - - this.newWidth = this.Width + (evt.clientX - this.offsetX); - this.newHeight = this.Height + (evt.clientY - this.offsetY); - if (this.newWidth < 100) { this.newWidth = 100; } - if (this.newHeight < 100) { this.newHeight = 100; } - this.divRegion.style.width = this.newWidth + "px"; - this.divRegion.style.height = this.newHeight + "px"; - - return false; - }, - divResize_MouseUp: function (evt) { - evt.preventDefault(); - - document.removeEventListener("mouseup", this.divResize_MouseUpBinded, false); - document.removeEventListener("mousemove", this.divResize_MouseMoveBinded, false); - - this.OnResize(); - - return false; - }, - divResize_TouchStart: function (evt) { - evt.preventDefault(); - - this.OnResizeStart(); - - this.offsetX = evt.touches[0].clientX; - this.offsetY = evt.touches[0].clientY; - - document.addEventListener("touchend", this.divResize_TouchEndBinded, false); - document.addEventListener("touchcancel", this.divResize_TouchEndBinded, false); - document.addEventListener("touchmove", this.divResize_TouchMoveBinded, false); - - return false; - }, - divResize_TouchMove: function (evt) { - evt.preventDefault(); - - this.newWidth = this.Width + (evt.touches[0].clientX - this.offsetX); - this.newHeight = this.Height + (evt.touches[0].clientY - this.offsetY); - if (this.newWidth < 100) { this.newWidth = 100; } - if (this.newHeight < 100) { this.newHeight = 100; } - this.divRegion.style.width = this.newWidth + "px"; - this.divRegion.style.height = this.newHeight + "px"; - - return false; - }, - divResize_TouchEnd: function (evt) { - evt.preventDefault(); - - document.removeEventListener("touchend", this.divResize_TouchEndBinded, false); - document.removeEventListener("touchcancel", this.divResize_TouchEndBinded, false); - document.removeEventListener("touchmove", this.divResize_TouchMoveBinded, false); - - this.OnResize(); - - return false; - }, - EnterEditionMode: function () { - this.RemoveFromContainer(); - this.InsertOnContainer(this.cfg.divBoard); - - this.txtTitle.value = this.Title; - - this.divOverlay.style.display = "none"; - this.divResize.style.display = "none"; - this.Editing = true; - - this.divEditBackground = document.createElement("div"); - this.divEditBackground.className = "divEditBackground"; - this.divEditBackground.addEventListener("click", Region.prototype.btnEdit_Click.bind(this), false); - this.divRegion.parentElement.insertBefore(this.divEditBackground, this.divRegion); - - }, - ExitEditionMode: function () { - this.divOverlay.style.display = ""; - this.divResize.style.display = ""; - this.Editing = false; - this.divEditBackground.className = ""; // Needed to remove "position: fixed" that causes to be not found on parentElement. - this.divEditBackground.parentElement.removeChild(this.divEditBackground); - }, - btnEdit_Click: function (evt) { - evt.preventDefault(); - if (this.Editing === false) { - this.EnterEditionMode(); - } else { - this.newTitle = this.txtTitle.value; - this.ExitEditionMode(); - this.txtTitle.value = this.newTitle; - if (this.IDRegion > 0) { - this.OnEdit(); - } else { - this.Title = this.newTitle; - this.OnCreate(); - } - } - return false; - }, - btnDelete_Click: function (evt) { - evt.preventDefault(); - if (this.Editing === true) { - this.ExitEditionMode(); - this.Reset(); - if (this.IDRegion > 0) { - return false; - } - } - if (this.IDRegion === 0 || confirm(this.cfg.Texts.ConfirmDelete)) { - this.OnDelete(); - } - return false; - }, - btnLock_Click: function (evt) { - evt.preventDefault(); - this.Lock(true); - this.OnLocked(); - return false; - }, - btnUnlock_Click: function (evt) { - evt.preventDefault(); - this.Lock(false); - this.OnLocked(); - return false; - }, - empty: null -}; - -function RunCardBoard(cfg) { - cfg.divBoard = GetElement(cfg.divBoard); - - cfg.Toolbox = new Toolbox(cfg, cfg.divBoard); - - cfg.Connected = false; - - cfg.Cards = []; - - cfg.Regions = []; - - cfg.GetCardByID = function (idCard) { - for (var i = 0, n = this.Cards.length; i < n; i++) { - var card = this.Cards[i]; - if (card.IDCard === idCard) { - return card; - } - } - return null; - }; - cfg.RemoveCard = function (card) { - for (var i = 0, n = this.Cards.length; i < n; i++) { - var auxCard = this.Cards[i]; - if (auxCard === card) { - this.Cards.splice(i, 1); - return true; - } - } - return false; - }; - - cfg.GetRegionByID = function (idRegion) { - for (var i = 0, n = this.Regions.length; i < n; i++) { - var region = this.Regions[i]; - if (region.IDRegion === idRegion) { - return region; - } - } - return null; - }; - cfg.RemoveRegion = function (region) { - for (var i = 0, n = this.Regions.length; i < n; i++) { - var auxRegion = this.Regions[i]; - if (auxRegion === region) { - this.Regions.splice(i, 1); - return true; - } - } - return false; - }; - - var ProcessCardCreateEvent = function (cardEvent) { - var card = new Card(cfg, cardEvent.IDCard, cardEvent.Title, cardEvent.Body, cardEvent.X, cardEvent.Y, cardEvent.Width, cardEvent.Height, cardEvent.Locked); - }; - - var ProcessCardMoveEvent = function (cardEvent) { - var card = cfg.GetCardByID(cardEvent.IDCard); - if (card === null) { return; } - card.Move(cardEvent.X, cardEvent.Y); - }; - - var ProcessCardResizeEvent = function (cardEvent) { - var card = cfg.GetCardByID(cardEvent.IDCard); - if (card === null) { return; } - card.Resize(cardEvent.Width, cardEvent.Height); - }; - - var ProcessCardEditEvent = function (cardEvent) { - var card = cfg.GetCardByID(cardEvent.IDCard); - if (card === null) { return; } - card.Edit(cardEvent.Title, cardEvent.Body); - }; - - var ProcessCardLockEvent = function (cardEvent) { - var card = cfg.GetCardByID(cardEvent.IDCard); - if (card === null) { return; } - card.Lock(cardEvent.Locked); - }; - - var ProcessCardDeleteEvent = function (cardEvent) { - do { - var card = cfg.GetCardByID(cardEvent.IDCard); - if (card === null) { return; } - card.RemoveFromContainer(cfg.divBoard); - cfg.RemoveCard(card); - } while (true); - }; - - var ProcessRegionCreateEvent = function (cardEvent) { - var region = new Region(cfg, cardEvent.IDRegion, cardEvent.Title, cardEvent.X, cardEvent.Y, cardEvent.Width, cardEvent.Height, cardEvent.Locked); - }; - - var ProcessRegionMoveEvent = function (cardEvent) { - var region = cfg.GetRegionByID(cardEvent.IDRegion); - if (region === null) { return; } - region.Move(cardEvent.X, cardEvent.Y); - }; - - var ProcessRegionResizeEvent = function (cardEvent) { - var region = cfg.GetRegionByID(cardEvent.IDRegion); - if (region === null) { return; } - region.Resize(cardEvent.Width, cardEvent.Height); - }; - - var ProcessRegionEditEvent = function (cardEvent) { - var region = cfg.GetRegionByID(cardEvent.IDRegion); - if (region === null) { return; } - region.Edit(cardEvent.Title); - }; - - var ProcessRegionLockEvent = function (cardEvent) { - var region = cfg.GetRegionByID(cardEvent.IDRegion); - if (region === null) { return; } - region.Lock(cardEvent.Locked); - }; - - var ProcessRegionDeleteEvent = function (cardEvent) { - do { - var region = cfg.GetRegionByID(cardEvent.IDRegion); - if (region === null) { return; } - region.RemoveFromContainer(cfg.divBoard); - cfg.RemoveRegion(region); - } while (true); - }; - - var RequestCardEventData = function () { - var ReciveCardEventData = function (responseText) { - cfg.Connected = true; - - var recvData = JSON.parse(responseText); - if (recvData && recvData instanceof Array) { - for (var i = 0, n = recvData.length; i < n; i++) { - var cardEvent = recvData[i]; - if (cardEvent.IDCardEvent > cfg.IDCardEvent) { - cfg.IDCardEvent = cardEvent.IDCardEvent; - } - if (cardEvent.EventType === "CardCreate") { - ProcessCardCreateEvent(cardEvent); - } - if (cardEvent.EventType === "CardMove") { - ProcessCardMoveEvent(cardEvent); - } - if (cardEvent.EventType === "CardResize") { - ProcessCardResizeEvent(cardEvent); - } - if (cardEvent.EventType === "CardEdit") { - ProcessCardEditEvent(cardEvent); - } - if (cardEvent.EventType === "CardLock") { - ProcessCardLockEvent(cardEvent); - } - if (cardEvent.EventType === "CardDelete") { - ProcessCardDeleteEvent(cardEvent); - } - if (cardEvent.EventType === "RegionCreate") { - ProcessRegionCreateEvent(cardEvent); - } - if (cardEvent.EventType === "RegionMove") { - ProcessRegionMoveEvent(cardEvent); - } - if (cardEvent.EventType === "RegionResize") { - ProcessRegionResizeEvent(cardEvent); - } - if (cardEvent.EventType === "RegionEdit") { - ProcessRegionEditEvent(cardEvent); - } - if (cardEvent.EventType === "RegionLock") { - ProcessRegionLockEvent(cardEvent); - } - if (cardEvent.EventType === "RegionDelete") { - ProcessRegionDeleteEvent(cardEvent); - } - } - } - - // Reset pool - window.setTimeout(function () { - RequestCardEventData(); - }, cfg.TimeRefresh); - }; - var ErrorCardEventData = function () { - cfg.Connected = false; - - // Retry - window.setTimeout(function () { - RequestCardEventData(); - }, cfg.TimeRefreshDisconnected); - }; - - // Pool data - var data = { - "IDBoard": cfg.IDBoard, - "IDCardEvent": cfg.IDCardEvent, - "TimePoolData": cfg.Connected === false ? "0" : String(cfg.TimePoolData), - "TimeStamp": new Date().getTime() - }; - SendRequest(cfg.ServiceUrl, data, ReciveCardEventData, ErrorCardEventData); - }; - RequestCardEventData(); -} \ No newline at end of file diff --git a/VAR.Focus.Web/Scripts/10. Chat.js b/VAR.Focus.Web/Scripts/10. Chat.js deleted file mode 100644 index 9b50f1b..0000000 --- a/VAR.Focus.Web/Scripts/10. Chat.js +++ /dev/null @@ -1,184 +0,0 @@ -function RunChat(cfg) { - cfg.divChat = GetElement(cfg.divChat); - cfg.divChatContainer = GetElement(cfg.divChatContainer); - cfg.lblTitle = GetElement(cfg.lblTitle); - cfg.txtText = GetElement(cfg.txtText); - cfg.btnSend = GetElement(cfg.btnSend); - - cfg.LastUser = null; - - cfg.lblTitle.innerHTML = cfg.Texts.Chat; - cfg.lblTitle.className = "titleChatNormal"; - cfg.divChatContainer.style.width = 0; - cfg.divChatContainer.style.height = 0; - cfg.divChatContainer.style.opacity = 0; - - cfg.Minimized = true; - cfg.Connected = null; - cfg.FirstMessages = true; - cfg.ScrollOnRestore = true; - cfg.ScrollPosition = 0; - - cfg.lblTitle.onclick = function () { - if (cfg.Minimized) { - cfg.divChatContainer.style.width = cfg.divChatContainerWidth; - cfg.divChatContainer.style.height = cfg.divChatContainerHeight; - cfg.divChatContainer.style.opacity = 1; - if (cfg.Connected) { - cfg.lblTitle.innerHTML = cfg.Texts.Close; - cfg.lblTitle.className = "titleChatNormal"; - } - if (cfg.ScrollOnRestore) { - cfg.divChat.scrollTop = cfg.divChat.scrollHeight; - } else { - cfg.divChat.scrollTop = cfg.ScrollPosition; - } - cfg.Minimized = false; - } else { - cfg.ScrollPosition = cfg.divChat.scrollTop; - var scrollVisible = cfg.divChat.scrollHeight - cfg.divChat.offsetHeight; - cfg.ScrollOnRestore = cfg.divChat.scrollTop > scrollVisible; - cfg.divChatContainer.style.width = 0; - cfg.divChatContainer.style.height = 0; - cfg.divChatContainer.style.opacity = 0; - if (cfg.Connected) { - cfg.lblTitle.innerHTML = cfg.Texts.Chat; - cfg.lblTitle.className = "titleChatNormal"; - } - cfg.Minimized = true; - } - }; - - var CreateMessageDOM = function (message, selfMessage, showUserName) { - var divMessageRow = document.createElement("DIV"); - if (selfMessage) { - divMessageRow.className = "selfMessageRow"; - } else { - divMessageRow.className = "messageRow"; - } - - var divMessage = document.createElement("DIV"); - divMessage.className = "message"; - divMessageRow.appendChild(divMessage); - - if (showUserName) { - var divUser = document.createElement("DIV"); - divUser.className = "user"; - divUser.innerHTML = escapeHTML(message.UserName); - divMessage.appendChild(divUser); - } - - var text = message.Text; - - var divText = document.createElement("DIV"); - divText.className = "text"; - divText.innerHTML = escapeHTML(text); - divMessage.appendChild(divText); - - divMessage.title = new Date(message.Date); - - return divMessageRow; - }; - - var RequestChatData = function () { - var ReciveChatData = function (responseText) { - // Mark as connected - if (cfg.Connected === false) { - if (cfg.Minimized) { - cfg.lblTitle.innerHTML = cfg.Texts.Chat; - } else { - cfg.lblTitle.innerHTML = cfg.Texts.Close; - } - cfg.lblTitle.className = "titleChatNormal"; - cfg.txtText.disabled = false; - cfg.btnSend.disabled = false; - } - cfg.Connected = true; - - recvMsgs = JSON.parse(responseText); - if (recvMsgs) { - var msgCount = 0; - var scrollChat = false; - var scrollVisible = cfg.divChat.scrollHeight - cfg.divChat.offsetHeight; - if (cfg.Minimized === false && cfg.divChat.scrollTop > scrollVisible) { - scrollChat = true; - } - - var frag = document.createDocumentFragment(); - for (var i = 0, n = recvMsgs.length; i < n; i++) { - var msg = recvMsgs[i]; - if (cfg.IDMessage < msg.IDMessage) { - cfg.IDMessage = msg.IDMessage; - var elemMessage = CreateMessageDOM(msg, - msg.UserName === cfg.UserName, - cfg.LastUser !== msg.UserName); - cfg.LastUser = msg.UserName; - frag.appendChild(elemMessage); - msgCount++; - } - } - cfg.divChat.appendChild(frag); - if (scrollChat) { - cfg.divChat.scrollTop = cfg.divChat.scrollHeight; - } - if (cfg.Minimized && cfg.FirstMessages === false && msgCount > 0) { - cfg.lblTitle.innerHTML = cfg.Texts.NewMessages; - cfg.lblTitle.className = "titleChatAlert"; - } - } - - cfg.FirstMessages = false; - - // Reset pool - window.setTimeout(function () { - RequestChatData(); - }, 20); - }; - var ErrorChatData = function () { - // Mark as disconnected - cfg.lblTitle.innerHTML = cfg.Texts.Disconnected; - cfg.lblTitle.className = "titleChatDisconnected"; - cfg.txtText.disabled = true; - cfg.btnSend.disabled = true; - cfg.Connected = false; - - cfg.FirstMessages = false; - - // Retry - window.setTimeout(function () { - RequestChatData(); - }, 5000); - }; - - // Pool data - var isImmediate = cfg.FirstMessages || cfg.Connected === false; - var data = { - "IDMessageBoard": cfg.IDMessageBoard, - "IDMessage": cfg.IDMessage, - "TimePoolData": isImmediate ? "0" : String(cfg.TimePoolData), - "TimeStamp": new Date().getTime() - }; - SendRequest(cfg.ServiceUrl, data, ReciveChatData, ErrorChatData); - }; - RequestChatData(); -} - -function SendChat(cfg) { - cfg.txtText = GetElement(cfg.txtText); - - if (cfg.txtText.value.trim() === "") { - return; - } - - // Send data - var data = { - "Text": cfg.txtText.value, - "IDMessageBoard": cfg.IDMessageBoard, - "UserName": cfg.UserName, - "TimeStamp": new Date().getTime() - }; - SendData(cfg.ServiceUrl, data, null, null); - - cfg.txtText.value = ""; - cfg.txtText.focus(); -} \ No newline at end of file diff --git a/VAR.Focus.Web/Styles/02. Boards.css b/VAR.Focus.Web/Styles/02. Boards.css deleted file mode 100644 index 7ed7aa0..0000000 --- a/VAR.Focus.Web/Styles/02. Boards.css +++ /dev/null @@ -1,39 +0,0 @@ -.boardBanner { - border: solid 1px rgb(32, 32, 32); - border-radius: 5px; - display: inline-block; - width: 300px; - margin: 15px; - padding: 10px; - vertical-align: top; - background-color: rgb(250,250,200); - box-shadow: 0 3px 10px rgba(0,0,0,0.4); -} - - .boardBanner a { - text-decoration: none; - color: black; - display: block; - height: 30px; - } - - .boardBanner .title { - font-size: 20px; - padding-bottom: 5px; - } - - .boardBanner .description { - font-size: 14px; - display: block; - overflow: auto; - } - - .boardBanner .formRow { - margin: 0; - margin-top: 10px; - padding: 0; - } - - .boardBanner .formRow:first-child { - margin: 0; - } diff --git a/VAR.Focus.Web/Styles/05. Cards.css b/VAR.Focus.Web/Styles/05. Cards.css deleted file mode 100644 index b0c8d55..0000000 --- a/VAR.Focus.Web/Styles/05. Cards.css +++ /dev/null @@ -1,348 +0,0 @@ -.divBoard { - position: relative; - height: 100%; - background-image: url(Images/BGCork.png); - box-shadow: 0 0 10px black inset; - overflow: auto; -} - -.divToolbox { - position: absolute; - background-color: rgb(127,127,255); - box-shadow: 0 5px 15px rgba(0,0,0,0.5); - width: 200px; - padding: 5px; - border-radius: 2px; -} - - .divToolbox .divTitle { - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - font-weight: bold; - text-align: center; - display: block; - height: 20px; - line-height: 20px; - background-color: rgb(0,0,128); - color: rgb(128,128,255); - border-radius: 3px; - margin-bottom: 5px; - } - - .divToolbox .divOverlay { - opacity: 0; - background-color: rgb(127,127,255); - position: absolute; - top: 0; - left: 0; - right: 0; - height: 30px; - -ms-touch-action: none; - touch-action: none; - } - - .divToolbox .btnToolbox { - margin-top: 5px; - margin-right: 5px; - border: none; - border-radius: 3px; - box-shadow: 0 -2px 4px rgba(0,0,0,0.4) inset, 0 2px 3px rgba(255,255,255,1) inset; - color: rgb(0,0,128); - background-color: transparent; - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - cursor: pointer; - padding-bottom: 2px; - padding-top: 2px; - padding-left: 10px; - padding-right: 10px; - } - - .divToolbox .btnToolbox:hover { - color: rgb(127,127,255); - background-color: rgb(0,0,128); - } - - .divToolbox .btnToolbox:active { - box-shadow: 0 2px 4px rgba(0,0,0,0.4) inset, 0 -2px 3px rgba(255,255,255,1) inset; - } - -.divCard { - position: absolute; - background-color: rgb(255,255,127); - box-shadow: 0 3px 10px rgba(0,0,0,0.5); - padding: 5px; - border-radius: 2px; - overflow: auto; -} - - .divCard .divTitle { - padding-bottom: 5px; - padding-right: 17px; - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - font-weight: bold; - text-align: center; - height: 17px; - box-sizing: content-box; - } - - .divCard .txtTitle { - width: 100%; - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - background-color: transparent; - border: none; - font-weight: bold; - text-align: center; - } - - .divCard .divBody { - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - height: calc(100% - 17px); - } - - .divCard .txtBody { - height: 100%; - width: 100%; - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - background-color: transparent; - border: none; - resize: none; - } - - .divCard .divOverlay { - opacity: 0; - background-color: rgb(255,255,0); - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; - -ms-touch-action: none; - touch-action: none; - } - - .divCard .divOverlayTouchable { - opacity: 0; - background-color: rgb(255,255,0); - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; - } - - .divCard .divResize { - opacity: 0; - background-color: rgb(255,0,255); - position: absolute; - width: 30px; - height: 30px; - bottom: 0; - right: 0; - -ms-touch-action: none; - touch-action: none; - cursor: se-resize; - } - - .divCard .btnCard { - padding: 0; - border: none; - border-radius: 3px; - box-shadow: 0 -2px 4px rgba(0,0,0,0.4) inset, 0 2px 3px rgba(255,255,255,1) inset; - color: black; - background-color: transparent; - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - cursor: pointer; - } - - .divCard .btnCard:hover { - color: yellow; - background-color: black; - } - - .divCard .btnCard:active { - box-shadow: 0 2px 4px rgba(0,0,0,0.4) inset, 0 -2px 3px rgba(255,255,255,1) inset; - } - - .divCard .btnEdit { - margin: 0; - top: 4px; - position: absolute; - width: 16px; - height: 16px; - right: 24px; - line-height: 16px; - } - - .divCard .btnDelete { - margin: 0; - top: 4px; - position: absolute; - width: 16px; - height: 16px; - right: 4px; - line-height: 16px; - } - - .divCard .btnLock { - margin: 0; - top: 4px; - position: absolute; - width: 16px; - height: 16px; - right: 44px; - line-height: 16px; - } - - .divCard .btnUnlock { - margin: 0; - top: 4px; - position: absolute; - width: 16px; - height: 16px; - right: 4px; - line-height: 16px; - } - -.divRegion { - position: absolute; - background-color: rgba(0,0,0,0.5); - box-shadow: 0 0 0 5px rgba(0,0,0,0.5); - padding: 5px; - border-radius: 10px; - border: dashed 5px rgba(255, 255, 255, 0.5); - overflow: auto; -} - - .divRegion .divTitle { - padding-bottom: 5px; - padding-right: 17px; - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - font-weight: bold; - text-align: center; - height: 17px; - box-sizing: content-box; - } - - .divRegion .txtTitle { - width: 100%; - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 30px; - color: rgba(255, 255, 255, 0.5); - background-color: transparent; - border: none; - font-weight: bold; - text-align: center; - } - - .divRegion .divOverlay { - opacity: 0; - background-color: rgb(255,255,0); - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; - -ms-touch-action: none; - touch-action: none; - } - - .divRegion .divOverlayTouchable { - opacity: 0; - background-color: rgb(255,255,0); - position: absolute; - top: 0; - bottom: 0; - left: 0; - right: 0; - } - - .divRegion .divResize { - opacity: 0; - background-color: rgb(255,0,255); - position: absolute; - width: 30px; - height: 30px; - bottom: 0; - right: 0; - -ms-touch-action: none; - touch-action: none; - cursor: se-resize; - } - - .divRegion .btnRegion { - padding: 0; - border: none; - border-radius: 3px; - box-shadow: 0 -2px 4px rgba(0,0,0,0.4) inset, 0 2px 3px rgba(255,255,255,1) inset; - color: black; - background-color: transparent; - font-family: "Segoe UI",Tahoma,Geneva,Verdana,sans-serif; - font-size: 12px; - cursor: pointer; - } - - .divRegion .btnRegion:hover { - color: yellow; - background-color: black; - } - - .divRegion .btnRegion:active { - box-shadow: 0 2px 4px rgba(0,0,0,0.4) inset, 0 -2px 3px rgba(255,255,255,1) inset; - } - - .divRegion .btnEdit { - margin: 0; - top: 4px; - position: absolute; - width: 16px; - height: 16px; - right: 24px; - line-height: 16px; - } - - .divRegion .btnDelete { - margin: 0; - top: 4px; - position: absolute; - width: 16px; - height: 16px; - right: 4px; - line-height: 16px; - } - - .divRegion .btnLock { - margin: 0; - top: 4px; - position: absolute; - width: 16px; - height: 16px; - right: 44px; - line-height: 16px; - } - - .divRegion .btnUnlock { - margin: 0; - top: 4px; - position: absolute; - width: 16px; - height: 16px; - right: 4px; - line-height: 16px; - } - -.divEditBackground { - display: block; - position: fixed; - top: 0; - left: 0; - bottom: 0; - right: 0; - background-color: rgba(0, 0, 0, 0.3); -} diff --git a/VAR.Focus.Web/Styles/10. Chat.css b/VAR.Focus.Web/Styles/10. Chat.css deleted file mode 100644 index 080aecb..0000000 --- a/VAR.Focus.Web/Styles/10. Chat.css +++ /dev/null @@ -1,188 +0,0 @@ -.divChatWindow { - box-sizing: border-box; - overflow: hidden; - border: solid 1px rgba(0,0,0,0.5); - padding: 5px; - border-radius: 5px; - background-color: rgb(64,64,64); - box-shadow: 0 2px 10px rgba(0,0,0,0.5); - position: fixed; - bottom: 15px; - right: 15px; -} - -.divChatTitleBar { - text-align: right; -} - -.titleChatNormal { - color: white; - background-color: rgb(64,64,64); - cursor: pointer; - display: inline-block; - border-radius: 5px; - padding-top: 2px; - padding-bottom: 2px; - padding-left: 5px; - padding-right: 5px; -} - -@keyframes alert { - 0% { - background-color: red; - } - - 50% { - background-color: rgb(64,64,64); - } - - 100% { - background-color: red; - } -} - -.titleChatAlert { - color: white; - background-color: red; - animation-name: alert; - animation-duration: 1s; - animation-iteration-count: infinite; - cursor: pointer; - display: inline-block; - border-radius: 5px; - padding-top: 2px; - padding-bottom: 2px; - padding-left: 5px; - padding-right: 5px; -} - -.titleChatDisconnected { - color: rgb(192,192,192); - background-color: rgb(64,64,64); - cursor: pointer; - display: inline-block; - border-radius: 5px; - padding-top: 2px; - padding-bottom: 2px; - padding-left: 5px; - padding-right: 5px; -} - -.divChatContainer { - transition-property: width, height, opacity; - transition-duration: 0.3s; - overflow: hidden; - max-width: calc(100vw - 30px); - max-height: calc(100vh - 55px); -} - -.divChat { - box-sizing: border-box; - overflow: auto; - height: calc(100% - 29px); - margin-bottom: 5px; - border-radius: 5px; - border: solid 1px rgba(0,0,0,0.5); - box-shadow: inset 0 1px 5px rgba(0,0,0,0.5); - background-color: rgb(128,128,128); -} - -.messageRow, -.selfMessageRow { - display: block; -} - -.messageRow { - text-align: left; -} - -.selfMessageRow { - text-align: right; -} - -.message { - box-sizing: border-box; - display: inline-block; - vertical-align: top; - border: solid 1px rgba(32, 32, 32, 0.5); - background-color: rgb(220,220,220); - border-radius: 5px; - box-shadow: 0 1px 5px rgba(0,0,0,0.3), inset 0 2px 5px rgba(255,255,255,0.5), inset 0 -2px 5px rgba(128,128,128,0.5); - margin: 2px; - padding: 5px; - font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; -} - -.messageRow .message { - background-color: rgb(220,255,220); -} - -.selfMessageRow .message { - background-color: rgb(255,255,220); -} - -.message .user { - box-sizing: border-box; - color: rgb(64,64,64); - text-shadow: 0 0 1px rgba(0,0,0,0.3); - font-size: 10px; - font-weight: bold; -} - -.message .text { - box-sizing: border-box; - color: rgb(32,32,32); - text-shadow: 0 0 1px rgba(0,0,0,0.3); - font-size: 12px; -} - -.divChatControls { - font-size: 0; -} - -.chatTextBox { - box-sizing: border-box; - padding-top: 2px; - padding-left: 5px; - padding-bottom: 2px; - padding-right: 5px; - box-shadow: inset 0 1px 5px rgba(0,0,0,0.5); - width: calc(100% - 52px); - border-radius: 5px; - border: solid 1px rgba(0,0,0,0.5); - margin: 0 2px 0 0; - vertical-align: top; - height: 24px; - font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; - font-size: 12px; - text-align: left; -} - -.chatButton { - box-sizing: border-box; - padding-top: 2px; - padding-left: 5px; - padding-bottom: 2px; - padding-right: 5px; - box-shadow: 0 2px 10px rgba(0,0,0,0.5), inset 0 0px 6px rgba(0,0,0,0.5), inset 0 5px 10px rgba(255,255,255,0.4); - width: 50px; - vertical-align: top; - border-radius: 5px; - border: solid 1px rgba(0,0,0,0.5); - height: 24px; - font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; - font-size: 12px; - text-align: center; - cursor: pointer; - background-color: rgb(64,64,64); - color: white; -} - - .chatButton:hover { - background-color: rgb(92,92,92); - } - - .chatButton:active { - background-color: rgb(64,64,64); - box-shadow: inset 0 0px 6px rgba(0,0,0,0.9), inset 0 5px 10px rgba(255,255,255,0.2); - } diff --git a/VAR.Focus.Web/VAR.Focus.Web.csproj b/VAR.Focus.Web/VAR.Focus.Web.csproj deleted file mode 100644 index b913acb..0000000 --- a/VAR.Focus.Web/VAR.Focus.Web.csproj +++ /dev/null @@ -1,143 +0,0 @@ - - - - - Debug - AnyCPU - - - 2.0 - {7596FD6B-DAF0-4B22-B356-5CF4629F0436} - {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - VAR.Focus.Web - VAR.Focus.Web - v4.6.1 - true - - - - - - - - - - true - full - false - bin\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\ - TRACE - prompt - 4 - false - - - - - - ..\packages\VAR.Json.1.2.2\lib\netstandard2.0\VAR.Json.dll - - - - - - - - - - - web.config - Designer - - - web.config - Designer - - - - - - - - - - Designer - - - - - - - - - - ASPXCodeBehind - - - ASPXCodeBehind - - - ASPXCodeBehind - - - ASPXCodeBehind - - - - - - - {d88af21d-1c60-4b27-abff-a133d6afc51c} - VAR.Focus.BusinessLogic - - - {328bb4e2-58f2-4beb-a619-ce3fa842ef43} - VAR.WebForms.Common - - - - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - - - - - - True - True - 31337 - / - http://localhost:31337/VAR.Focus/ - True - http://localhost:31337/ - False - False - - - False - - - - - - \ No newline at end of file diff --git a/VAR.Focus.Web/packages.config b/VAR.Focus.Web/packages.config deleted file mode 100644 index f74ed9e..0000000 --- a/VAR.Focus.Web/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/VAR.Focus.Web/priv/keep.txt b/VAR.Focus.Web/priv/keep.txt deleted file mode 100644 index 5f28270..0000000 --- a/VAR.Focus.Web/priv/keep.txt +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/VAR.Focus.Web/web.Debug.config b/VAR.Focus.Web/web.Debug.config deleted file mode 100644 index fca8f9f..0000000 --- a/VAR.Focus.Web/web.Debug.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/VAR.Focus.Web/web.Release.config b/VAR.Focus.Web/web.Release.config deleted file mode 100644 index 618dbd2..0000000 --- a/VAR.Focus.Web/web.Release.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/VAR.Focus.Web/web.config b/VAR.Focus.Web/web.config deleted file mode 100644 index 9bccd4f..0000000 --- a/VAR.Focus.Web/web.config +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/VAR.WebForms.Common/Code/ExtensionMethods.cs b/VAR.WebForms.Common/Code/ExtensionMethods.cs deleted file mode 100644 index 9750638..0000000 --- a/VAR.WebForms.Common/Code/ExtensionMethods.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Web; -using VAR.Json; - -namespace VAR.WebForms.Common.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) - { - context.Response.ContentType = "text/json"; - string strObject = JsonWriter.WriteObject(obj); - context.Response.Write(strObject); - } - - public static void PrepareCacheableResponse(this HttpResponse response) - { - const int secondsInDay = 86400; - response.ExpiresAbsolute = DateTime.Now.AddSeconds(secondsInDay); - response.Expires = secondsInDay; - response.Cache.SetCacheability(HttpCacheability.Public); - response.Cache.SetMaxAge(new TimeSpan(0, 0, secondsInDay)); - } - - public static void PrepareUncacheableResponse(this HttpResponse response) - { - response.ExpiresAbsolute = DateTime.Now.AddDays(-2d); - response.Expires = -1500; - response.AddHeader("Cache-Control", "max-age=0, no-cache, no-store"); - response.BufferOutput = true; - } - - #endregion HttpContext - } -} \ No newline at end of file diff --git a/VAR.WebForms.Common/Code/MultiLang.cs b/VAR.WebForms.Common/Code/MultiLang.cs deleted file mode 100644 index 6aea3aa..0000000 --- a/VAR.WebForms.Common/Code/MultiLang.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Web; -using VAR.Json; - -namespace VAR.WebForms.Common.Code -{ - public class MultiLang - { - private static string GetLocalPath(string path) - { - string currentDir = Path.GetDirectoryName((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath); - return string.Format("{0}/{1}", Directory.GetParent(currentDir), path); - } - - private static Dictionary> _literals = null; - - private static void InitializeLiterals() - { - _literals = new Dictionary>(); - - JsonParser jsonParser = new JsonParser(); - foreach (string lang in new string[] { "en", "es" }) - { - string filePath = GetLocalPath(string.Format("Resources/Literals.{0}.json", lang)); - if (File.Exists(filePath) == false) { continue; } - - string strJsonLiteralsLanguage = File.ReadAllText(filePath); - object result = jsonParser.Parse(strJsonLiteralsLanguage); - _literals.Add(lang, result as Dictionary); - } - } - - private const string _defaultLanguage = "en"; - - private static string GetUserLanguage() - { - HttpContext ctx = HttpContext.Current; - if (ctx != null) - { - if (ctx.Items["UserLang"] != null) - { - return (string)ctx.Items["UserLang"]; - } - - IEnumerable userLanguages = ctx.Request.UserLanguages - .Select(lang => - { - if (lang.Contains(";")) - { - lang = lang.Split(';')[0]; - } - if (lang.Contains("-")) - { - lang = lang.Split('-')[0]; - } - return lang.ToLower(); - }) - .Where(lang => _literals.ContainsKey(lang)); - string userLang = userLanguages.FirstOrDefault() ?? _defaultLanguage; - - ctx.Items["UserLang"] = userLang; - return userLang; - } - return _defaultLanguage; - } - - public static string GetLiteral(string resource, string culture = null) - { - if (_literals == null) { InitializeLiterals(); } - if (culture == null) { culture = GetUserLanguage(); } - - if (_literals == null || _literals.ContainsKey(culture) == false) { return resource; } - Dictionary _literalCurrentCulture = _literals[culture]; - - if (_literalCurrentCulture == null || _literalCurrentCulture.ContainsKey(resource) == false) { return resource; } - return (_literalCurrentCulture[resource] as string) ?? resource; - } - } -} \ No newline at end of file diff --git a/VAR.WebForms.Common/Controls/CButton.cs b/VAR.WebForms.Common/Controls/CButton.cs deleted file mode 100644 index 6d4e873..0000000 --- a/VAR.WebForms.Common/Controls/CButton.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Web.UI.WebControls; - -namespace VAR.WebForms.Common.Controls -{ - public class CButton : Button - { - public CButton() - { - CssClass = "button"; - } - } -} \ No newline at end of file diff --git a/VAR.WebForms.Common/Controls/CLabel.cs b/VAR.WebForms.Common/Controls/CLabel.cs deleted file mode 100644 index f41b899..0000000 --- a/VAR.WebForms.Common/Controls/CLabel.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Web.UI; -using System.Web.UI.WebControls; - -namespace VAR.WebForms.Common.Controls -{ - public class CLabel : Label - { - #region Declarations - - private string _tagName = "span"; - - #endregion Declarations - - #region Properties - - public string Tag - { - get { return _tagName; } - set { _tagName = value; } - } - - #endregion Properties - - #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 Life cycle - } -} \ No newline at end of file diff --git a/VAR.WebForms.Common/GlobalModule.cs b/VAR.WebForms.Common/GlobalModule.cs deleted file mode 100644 index e4650c6..0000000 --- a/VAR.WebForms.Common/GlobalModule.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Web; - -namespace VAR.WebForms.Common -{ - public class GlobalModule : IHttpModule - { - public void Dispose() { } - - public void Init(HttpApplication context) - { - context.PreSendRequestHeaders += Context_PreSendRequestHeaders; - } - - private void Context_PreSendRequestHeaders(object sender, EventArgs e) - { - HttpContext ctx = HttpContext.Current; - if (ctx == null) { return; } - - ctx.Response.Headers.Remove("Server"); - ctx.Response.Headers.Remove("X-Powered-By"); - ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff"); - ctx.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); - ctx.Response.Headers.Add("X-XSS-Protection", "1; mode=block"); - } - } -} \ No newline at end of file diff --git a/VAR.WebForms.Common/Pages/FrmEcho.cs b/VAR.WebForms.Common/Pages/FrmEcho.cs deleted file mode 100644 index 6d589cc..0000000 --- a/VAR.WebForms.Common/Pages/FrmEcho.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Web; -using VAR.Json; - -namespace VAR.WebForms.Common.Pages -{ - public class FrmEcho : IHttpHandler - { - #region IHttpHandler - - public bool IsReusable - { - get { return false; } - } - - public void ProcessRequest(HttpContext context) - { - context.Response.Write("
");
-            context.Response.Write(JsonWriter.WriteObject(context.Request, indent: true));
-            context.Response.Write("
"); - } - - #endregion IHttpHandler - } -} \ No newline at end of file diff --git a/VAR.WebForms.Common/Properties/AssemblyInfo.cs b/VAR.WebForms.Common/Properties/AssemblyInfo.cs deleted file mode 100644 index a50379a..0000000 --- a/VAR.WebForms.Common/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("VAR.WebForms.Common")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("VAR.WebForms.Common")] -[assembly: AssemblyCopyright("Copyright © VAR 2015-2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("328bb4e2-58f2-4beb-a619-ce3fa842ef43")] -[assembly: AssemblyVersion("1.0.0")] diff --git a/VAR.WebForms.Common/VAR.WebForms.Common.csproj b/VAR.WebForms.Common/VAR.WebForms.Common.csproj deleted file mode 100644 index d6f8f2b..0000000 --- a/VAR.WebForms.Common/VAR.WebForms.Common.csproj +++ /dev/null @@ -1,85 +0,0 @@ - - - - - Debug - AnyCPU - {328BB4E2-58F2-4BEB-A619-CE3FA842EF43} - Library - Properties - VAR.WebForms.Common - VAR.WebForms.Common - v4.6.1 - 512 - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - ..\packages\VAR.Json.1.2.2\lib\netstandard2.0\VAR.Json.dll - - - - - - - - - - - - - - - - - - - - - - - ASPXCodeBehind - - - ASPXCodeBehind - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/VAR.WebForms.Common/packages.config b/VAR.WebForms.Common/packages.config deleted file mode 100644 index f74ed9e..0000000 --- a/VAR.WebForms.Common/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/VAR.WebForms.Common/Code/Bundler.cs b/VAR.WebFormsCore/Code/Bundler.cs similarity index 73% rename from VAR.WebForms.Common/Code/Bundler.cs rename to VAR.WebFormsCore/Code/Bundler.cs index bf18b1b..3b8a253 100644 --- a/VAR.WebForms.Common/Code/Bundler.cs +++ b/VAR.WebFormsCore/Code/Bundler.cs @@ -3,9 +3,9 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; -using System.Web; +using Microsoft.AspNetCore.Http; -namespace VAR.WebForms.Common.Code +namespace VAR.WebFormsCore.Code { public class Bundler { @@ -70,34 +70,27 @@ namespace VAR.WebForms.Common.Code #region Public methods - public void WriteResponse(HttpResponse response, string contentType) + private static Encoding _utf8Econding = new UTF8Encoding(); + + public async void WriteResponse(HttpResponse response, string contentType) { + StringWriter textWriter = new StringWriter(); response.ContentType = contentType; foreach (string fileName in AssemblyFiles) { Stream resourceStream = _assembly.GetManifestResourceStream(fileName); string fileContent = new StreamReader(resourceStream).ReadToEnd(); - byte[] byteArray = Encoding.UTF8.GetBytes(fileContent); - if (byteArray.Length > 0) - { - response.OutputStream.Write(byteArray, 0, byteArray.Length); - - byteArray = Encoding.UTF8.GetBytes("\n\n"); - response.OutputStream.Write(byteArray, 0, byteArray.Length); - } + textWriter.Write(fileContent); + textWriter.Write("\n\n"); } foreach (string fileName in AbsoluteFiles) { string fileContent = File.ReadAllText(fileName); - byte[] byteArray = Encoding.UTF8.GetBytes(fileContent); - if (byteArray.Length > 0) - { - response.OutputStream.Write(byteArray, 0, byteArray.Length); - - byteArray = Encoding.UTF8.GetBytes("\n\n"); - response.OutputStream.Write(byteArray, 0, byteArray.Length); - } + textWriter.Write(fileContent); + textWriter.Write("\n\n"); } + byte[] byteObject = _utf8Econding.GetBytes(textWriter.ToString()); + await response.Body.WriteAsync(byteObject); } #endregion Public methods diff --git a/VAR.WebFormsCore/Code/ExtensionMethods.cs b/VAR.WebFormsCore/Code/ExtensionMethods.cs new file mode 100644 index 0000000..e1327be --- /dev/null +++ b/VAR.WebFormsCore/Code/ExtensionMethods.cs @@ -0,0 +1,61 @@ +using System; +using System.Text; +using Microsoft.AspNetCore.Http; +using VAR.Json; + +namespace VAR.WebFormsCore.Code +{ + public static class ExtensionMethods + { + #region HttpContext + + public static string GetRequestParm(this HttpContext context, string parm) + { + if (context.Request.Method == "POST") + { + foreach (string key in context.Request.Form.Keys) + { + if (string.IsNullOrEmpty(key) == false && key == parm) + { + return context.Request.Form[key]; + } + } + } + foreach (string key in context.Request.Query.Keys) + { + if (string.IsNullOrEmpty(key) == false && key == parm) + { + return context.Request.Query[key]; + } + } + return string.Empty; + } + + private static Encoding _utf8Econding = new UTF8Encoding(); + + public static void ResponseObject(this HttpContext context, object obj) + { + context.Response.ContentType = "text/json"; + string strObject = JsonWriter.WriteObject(obj); + byte[] byteObject = _utf8Econding.GetBytes(strObject); + context.Response.Body.WriteAsync(byteObject); + } + + public static void PrepareCacheableResponse(this HttpResponse response) + { + const int secondsInDay = 86400; + response.Headers.Add("Cache-Control", string.Format("public, max-age={0}", secondsInDay)); + string ExpireDate = DateTime.UtcNow.AddSeconds(secondsInDay).ToString("ddd, dd MMM yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); + response.Headers.Add("Expires", ExpireDate + " GMT"); + } + + public static void PrepareUncacheableResponse(this HttpResponse response) + { + response.Headers.Add("Cache-Control", "max-age=0, no-cache, no-store"); + string ExpireDate = DateTime.UtcNow.AddSeconds(-1500).ToString("ddd, dd MMM yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); + response.Headers.Add("Expires", ExpireDate + " GMT"); + } + + #endregion HttpContext + } +} \ No newline at end of file diff --git a/VAR.WebForms.Common/Code/GlobalConfig.cs b/VAR.WebFormsCore/Code/GlobalConfig.cs similarity index 93% rename from VAR.WebForms.Common/Code/GlobalConfig.cs rename to VAR.WebFormsCore/Code/GlobalConfig.cs index c9335e3..14dbbec 100644 --- a/VAR.WebForms.Common/Code/GlobalConfig.cs +++ b/VAR.WebFormsCore/Code/GlobalConfig.cs @@ -1,7 +1,7 @@ using System; using System.Linq; -namespace VAR.WebForms.Common.Code +namespace VAR.WebFormsCore.Code { public static class GlobalConfig { diff --git a/VAR.WebForms.Common/Code/GlobalErrorHandler.cs b/VAR.WebFormsCore/Code/GlobalErrorHandler.cs similarity index 77% rename from VAR.WebForms.Common/Code/GlobalErrorHandler.cs rename to VAR.WebFormsCore/Code/GlobalErrorHandler.cs index 6d013a5..cf539b6 100644 --- a/VAR.WebForms.Common/Code/GlobalErrorHandler.cs +++ b/VAR.WebFormsCore/Code/GlobalErrorHandler.cs @@ -1,9 +1,9 @@ using System; using System.Text; -using System.Web; -using VAR.WebForms.Common.Pages; +using Microsoft.AspNetCore.Http; +using VAR.WebFormsCore.Pages; -namespace VAR.WebForms.Common.Code +namespace VAR.WebFormsCore.Code { public static class GlobalErrorHandler { @@ -12,12 +12,12 @@ namespace VAR.WebForms.Common.Code private static void ShowInternalError(HttpContext context, Exception ex) { context.Response.StatusCode = 500; - context.Response.Clear(); + //context.Response.Clear(); StringBuilder sbOutput = new StringBuilder(); sbOutput.Append("

Internal error

"); Exception exAux = ex; - if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; } + //if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; } while (exAux != null) { sbOutput.AppendFormat("

Message: {0}

", exAux.Message); @@ -37,7 +37,7 @@ namespace VAR.WebForms.Common.Code sbOutput.Append("-->"); } - context.Response.Write(sbOutput.ToString()); + context.Response.WriteAsync(sbOutput.ToString()); } #endregion Private methods @@ -49,8 +49,8 @@ namespace VAR.WebForms.Common.Code try { IHttpHandler frmError = new FrmError(ex); - context.Response.Clear(); - context.Handler = frmError; + //context.Response.Clear(); + //context.Handler = frmError; frmError.ProcessRequest(context); } catch diff --git a/VAR.WebForms.Common/GlobalRouter.cs b/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs similarity index 61% rename from VAR.WebForms.Common/GlobalRouter.cs rename to VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs index d4f7047..10c91fa 100644 --- a/VAR.WebForms.Common/GlobalRouter.cs +++ b/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs @@ -3,14 +3,88 @@ using System.Collections.Generic; using System.IO; using System.Reflection; using System.Threading; -using System.Web; -using VAR.WebForms.Common.Code; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; -namespace VAR.WebForms.Common +namespace VAR.WebFormsCore.Code { - public class GlobalRouter : IHttpHandler + public class GlobalRouterMiddleware { - #region Handlers + private readonly RequestDelegate _next; + private readonly IWebHostEnvironment _env; + + public GlobalRouterMiddleware(RequestDelegate next, IWebHostEnvironment env) + { + _next = next; + _env = env; + ServerHelpers.SetContentRoot(env.ContentRootPath); + } + + public async Task Invoke(HttpContext httpContext) + { + httpContext.Response.Headers.Remove("Server"); + httpContext.Response.Headers.Remove("X-Powered-By"); + httpContext.Response.Headers.Add("X-Content-Type-Options", "nosniff"); + httpContext.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); + httpContext.Response.Headers.Add("X-XSS-Protection", "1; mode=block"); + + try + { + RouteRequest(httpContext); + } + catch (Exception ex) + { + if (IsIgnoreException(ex) == false) + { + GlobalErrorHandler.HandleError(httpContext, ex); + } + } + + await httpContext.Response.Body.FlushAsync(); + } + + private static bool IsIgnoreException(Exception ex) + { + if (ex is ThreadAbortException) + { + return true; + } + return false; + } + + private void RouteRequest(HttpContext context) + { + string path = context.Request.Path; + string file = Path.GetFileName(path); + if (string.IsNullOrEmpty(file)) + { + file = GlobalConfig.Get().DefaultHandler; + } + + // Pass allowed extensions requests + string extension = Path.GetExtension(path).ToLower(); + if (GlobalConfig.Get().AllowedExtensions.Contains(extension)) + { + string filePath = ServerHelpers.MapContentPath(path); + if (File.Exists(filePath)) + { + StaticFileHelper.ResponseStaticFile(context, filePath); + return; + } + } + + IHttpHandler handler = GetHandler(file); + if (handler == null) + { + // TODO: FrmNotFound + throw new Exception("NotFound"); + } + + // Use handler + handler.ProcessRequest(context); + } private static Dictionary _handlers = new Dictionary(); @@ -77,68 +151,13 @@ namespace VAR.WebForms.Common return null; } - #endregion Handlers - - #region IHttpHandler - - public bool IsReusable - { - get { return false; } - } - - public void ProcessRequest(HttpContext context) - { - try - { - RouteRequest(context); - } - catch (Exception ex) - { - if (ex is ThreadAbortException) - { - return; - } - GlobalErrorHandler.HandleError(context, ex); - } - } - - #endregion IHttpHandler - - #region Private methods - - private void RouteRequest(HttpContext context) - { - string file = Path.GetFileName(context.Request.FilePath); - if (string.IsNullOrEmpty(file)) - { - file = GlobalConfig.Get().DefaultHandler; - } - - // Pass allowed extensions requests - string extension = Path.GetExtension(context.Request.FilePath).ToLower(); - if (GlobalConfig.Get().AllowedExtensions.Contains(extension)) - { - string filePath = context.Request.PhysicalPath; - if (File.Exists(filePath)) - { - StaticFileHelper.ResponseStaticFile(context, filePath); - return; - } - } - - IHttpHandler handler = GetHandler(file); - if (handler == null) - { - // TODO: FrmNotFound - throw new Exception("NotFound"); - } - - // Use handler - context.Response.Clear(); - context.Handler = handler; - handler.ProcessRequest(context); - } - - #endregion Private methods } -} \ No newline at end of file + + public static class GlobalRouterMiddlewareExtensions + { + public static IApplicationBuilder UseGlobalRouterMiddleware(this IApplicationBuilder builder, IWebHostEnvironment env) + { + return builder.UseMiddleware(env); + } + } +} diff --git a/VAR.WebForms.Common/Code/IGlobalConfig.cs b/VAR.WebFormsCore/Code/IGlobalConfig.cs similarity index 84% rename from VAR.WebForms.Common/Code/IGlobalConfig.cs rename to VAR.WebFormsCore/Code/IGlobalConfig.cs index 01803a4..6b46a2d 100644 --- a/VAR.WebForms.Common/Code/IGlobalConfig.cs +++ b/VAR.WebFormsCore/Code/IGlobalConfig.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; -using System.Web; +using Microsoft.AspNetCore.Http; -namespace VAR.WebForms.Common.Code +namespace VAR.WebFormsCore.Code { public interface IGlobalConfig { diff --git a/VAR.WebFormsCore/Code/IHttpHandler.cs b/VAR.WebFormsCore/Code/IHttpHandler.cs new file mode 100644 index 0000000..b5eabac --- /dev/null +++ b/VAR.WebFormsCore/Code/IHttpHandler.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Http; + +namespace VAR.WebFormsCore.Code +{ + public interface IHttpHandler + { + void ProcessRequest(HttpContext context); + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/MultiLang.cs b/VAR.WebFormsCore/Code/MultiLang.cs new file mode 100644 index 0000000..aefb084 --- /dev/null +++ b/VAR.WebFormsCore/Code/MultiLang.cs @@ -0,0 +1,89 @@ +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using VAR.Json; + +namespace VAR.WebFormsCore.Code +{ + public class MultiLang + { + private static string GetPrivatePath(string baseDir, string fileName) + { + string currentDir = Path.GetDirectoryName(new System.Uri(Assembly.GetExecutingAssembly().Location).AbsolutePath); + string privatePath = Path.Combine(currentDir, baseDir); + while (Directory.Exists(privatePath) == false) + { + DirectoryInfo dirInfo = Directory.GetParent(currentDir); + if (dirInfo == null) { break; } + currentDir = dirInfo.FullName; + privatePath = Path.Combine(currentDir, baseDir); + } + return Path.Combine(privatePath, fileName); + } + + private static Dictionary> _literals = null; + + private static void InitializeLiterals() + { + _literals = new Dictionary>(); + + JsonParser jsonParser = new JsonParser(); + foreach (string lang in new string[] { "en", "es" }) + { + string filePath = GetPrivatePath("Resources", string.Format("Literals.{0}.json", lang)); + if (File.Exists(filePath) == false) { continue; } + + string strJsonLiteralsLanguage = File.ReadAllText(filePath); + object result = jsonParser.Parse(strJsonLiteralsLanguage); + _literals.Add(lang, result as Dictionary); + } + } + + private const string _defaultLanguage = "en"; + + private static string GetUserLanguage() + { + // TODO: Needs replacement for ctx.Request.UserLanguages + //HttpContext ctx = HttpContext.Current; + //if (ctx != null) + //{ + // if (ctx.Items["UserLang"] != null) + // { + // return (string)ctx.Items["UserLang"]; + // } + + // IEnumerable userLanguages = ctx.Request.UserLanguages + // .Select(lang => + // { + // if (lang.Contains(";")) + // { + // lang = lang.Split(';')[0]; + // } + // if (lang.Contains("-")) + // { + // lang = lang.Split('-')[0]; + // } + // return lang.ToLower(); + // }) + // .Where(lang => _literals.ContainsKey(lang)); + // string userLang = userLanguages.FirstOrDefault() ?? _defaultLanguage; + + // ctx.Items["UserLang"] = userLang; + // return userLang; + //} + return _defaultLanguage; + } + + public static string GetLiteral(string resource, string culture = null) + { + if (_literals == null) { InitializeLiterals(); } + if (culture == null) { culture = GetUserLanguage(); } + + if (_literals == null || _literals.ContainsKey(culture) == false) { return resource; } + Dictionary _literalCurrentCulture = _literals[culture]; + + if (_literalCurrentCulture == null || _literalCurrentCulture.ContainsKey(resource) == false) { return resource; } + return (_literalCurrentCulture[resource] as string) ?? resource; + } + } +} \ No newline at end of file diff --git a/VAR.WebForms.Common/Code/ObjectActivator.cs b/VAR.WebFormsCore/Code/ObjectActivator.cs similarity index 93% rename from VAR.WebForms.Common/Code/ObjectActivator.cs rename to VAR.WebFormsCore/Code/ObjectActivator.cs index fe4889e..a4a81c7 100644 --- a/VAR.WebForms.Common/Code/ObjectActivator.cs +++ b/VAR.WebFormsCore/Code/ObjectActivator.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq.Expressions; -namespace VAR.WebForms.Common.Code +namespace VAR.WebFormsCore.Code { public class ObjectActivator { diff --git a/VAR.WebFormsCore/Code/Program.cs b/VAR.WebFormsCore/Code/Program.cs new file mode 100644 index 0000000..58a2ada --- /dev/null +++ b/VAR.WebFormsCore/Code/Program.cs @@ -0,0 +1,9 @@ +namespace VAR.WebFormsCore.Code +{ + public class Program + { + public static void Main() + { + } + } +} diff --git a/VAR.WebForms.Common/Code/ScriptsBundler.cs b/VAR.WebFormsCore/Code/ScriptsBundler.cs similarity index 71% rename from VAR.WebForms.Common/Code/ScriptsBundler.cs rename to VAR.WebFormsCore/Code/ScriptsBundler.cs index f99f79e..438db22 100644 --- a/VAR.WebForms.Common/Code/ScriptsBundler.cs +++ b/VAR.WebFormsCore/Code/ScriptsBundler.cs @@ -1,20 +1,18 @@ using System.Reflection; -using System.Web; +using Microsoft.AspNetCore.Http; -namespace VAR.WebForms.Common.Code +namespace VAR.WebFormsCore.Code { public class ScriptsBundler : IHttpHandler { #region IHttpHandler - public bool IsReusable { get { return false; } } - public void ProcessRequest(HttpContext context) { Bundler bundler = new Bundler( assembly: Assembly.GetExecutingAssembly(), assemblyNamespace: "Scripts", - absolutePath: context.Server.MapPath("~/Scripts/")); + absolutePath: ServerHelpers.MapContentPath("Scripts")); context.Response.PrepareCacheableResponse(); bundler.WriteResponse(context.Response, "text/javascript"); } diff --git a/VAR.WebFormsCore/Code/ServerHelpers.cs b/VAR.WebFormsCore/Code/ServerHelpers.cs new file mode 100644 index 0000000..de7ae19 --- /dev/null +++ b/VAR.WebFormsCore/Code/ServerHelpers.cs @@ -0,0 +1,113 @@ +using System.Globalization; +using System.Text; + +namespace VAR.WebFormsCore.Code +{ + public class ServerHelpers + { + private static string _contentRoot = null; + public static void SetContentRoot(string contentRoot) + { + _contentRoot = contentRoot; + } + + public static string MapContentPath(string path) + { + string mappedPath = string.Concat(_contentRoot, "/", path); + return mappedPath; + } + + public static string HtmlEncode(string text) + { + if (string.IsNullOrEmpty(text)) { return text; } + + StringBuilder sbResult = new(); + + for (int i = 0; i < text.Length; i++) + { + char ch = text[i]; + + if (ch == '<') + { + sbResult.Append("<"); + } + else if (ch == '>') + { + sbResult.Append(">"); + } + else if (ch == '"') + { + sbResult.Append("""); + } + else if (ch == '\'') + { + sbResult.Append("'"); + } + else if (ch == '&') + { + sbResult.Append("&"); + } + else if (ch > 127) + { + sbResult.Append("&#"); + sbResult.Append(((int)ch).ToString(NumberFormatInfo.InvariantInfo)); + sbResult.Append(';'); + } + else + { + sbResult.Append(ch); + } + } + + return sbResult.ToString(); + } + + public static string UrlEncode(string text) + { + if (string.IsNullOrEmpty(text)) { return text; } + + StringBuilder sbResult = new(); + + for (int i = 0; i < text.Length; i++) + { + char ch = text[i]; + + if (ch == ' ') + { + sbResult.Append('+'); + } + else if (IsUrlSafe(ch) == false) + { + sbResult.AppendFormat("%{0:X02}", ch); + } + else + { + sbResult.Append(ch); + } + } + + return sbResult.ToString(); + } + + public static bool IsUrlSafe(char ch) + { + if ( + (ch >= 'a' && ch <= 'z') || + (ch >= 'A' && ch <= 'Z') || + (ch >= '0' && ch <= '9') || + ch == '-' || + ch == '_' || + ch == '.' || + ch == '!' || + ch == '*' || + ch == '(' || + ch == ')' || + false) + { + return true; + } + + return false; + } + } +} diff --git a/VAR.WebForms.Common/Code/StaticFileHelper.cs b/VAR.WebFormsCore/Code/StaticFileHelper.cs similarity index 87% rename from VAR.WebForms.Common/Code/StaticFileHelper.cs rename to VAR.WebFormsCore/Code/StaticFileHelper.cs index 860f472..73c6ce4 100644 --- a/VAR.WebForms.Common/Code/StaticFileHelper.cs +++ b/VAR.WebFormsCore/Code/StaticFileHelper.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.IO; -using System.Web; +using Microsoft.AspNetCore.Http; -namespace VAR.WebForms.Common.Code +namespace VAR.WebFormsCore.Code { public class StaticFileHelper { @@ -66,7 +66,7 @@ namespace VAR.WebForms.Common.Code {".7z", "application/x-7z-compressed"}, }; - public static void ResponseStaticFile(HttpContext context, string filePath) + public static async void ResponseStaticFile(HttpContext context, string filePath) { string extension = Path.GetExtension(filePath).ToLower(); string contentType = null; @@ -75,19 +75,14 @@ namespace VAR.WebForms.Common.Code contentType = _mimeTypeByExtension[extension]; } - context.Response.Clear(); - if (string.IsNullOrEmpty(contentType) == false) { context.Response.ContentType = contentType; } context.Response.PrepareCacheableResponse(); - context.Response.Buffer = true; - context.Response.WriteFile(filePath); - context.Response.Flush(); - context.Response.Close(); - context.Response.End(); + byte[] fileData = File.ReadAllBytes(filePath); + await context.Response.Body.WriteAsync(fileData); } } diff --git a/VAR.WebForms.Common/Code/StylesBundler.cs b/VAR.WebFormsCore/Code/StylesBundler.cs similarity index 71% rename from VAR.WebForms.Common/Code/StylesBundler.cs rename to VAR.WebFormsCore/Code/StylesBundler.cs index 49452b6..d910598 100644 --- a/VAR.WebForms.Common/Code/StylesBundler.cs +++ b/VAR.WebFormsCore/Code/StylesBundler.cs @@ -1,20 +1,18 @@ using System.Reflection; -using System.Web; +using Microsoft.AspNetCore.Http; -namespace VAR.WebForms.Common.Code +namespace VAR.WebFormsCore.Code { public class StylesBundler : IHttpHandler { #region IHttpHandler - public bool IsReusable { get { return false; } } - public void ProcessRequest(HttpContext context) { Bundler bundler = new Bundler( assembly: Assembly.GetExecutingAssembly(), assemblyNamespace: "Styles", - absolutePath: context.Server.MapPath("~/Styles/")); + absolutePath: ServerHelpers.MapContentPath("Styles")); context.Response.PrepareCacheableResponse(); bundler.WriteResponse(context.Response, "text/css"); } diff --git a/VAR.WebFormsCore/Code/Unit.cs b/VAR.WebFormsCore/Code/Unit.cs new file mode 100644 index 0000000..3f9061f --- /dev/null +++ b/VAR.WebFormsCore/Code/Unit.cs @@ -0,0 +1,35 @@ +namespace VAR.WebFormsCore.Code +{ + public class Unit + { + private int _value; + private UnitType _unitType; + + public Unit(int value, UnitType type) + { + _value = value; + _unitType = type; + } + + public override string ToString() + { + if (_unitType == UnitType.Pixel) + { + return string.Format("{0}px", _value); + } + + if (_unitType == UnitType.Percentaje) + { + return string.Format("{0}%", _value); + } + + return string.Empty; + } + } + + public enum UnitType + { + Pixel, + Percentaje, + } +} diff --git a/VAR.WebFormsCore/Controls/Button.cs b/VAR.WebFormsCore/Controls/Button.cs new file mode 100644 index 0000000..99b76b0 --- /dev/null +++ b/VAR.WebFormsCore/Controls/Button.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; + +namespace VAR.WebFormsCore.Controls +{ + public class Button : Control, IReceivePostbackEvent + { + public Button() + { + CssClass = "button"; + } + + private string _text = string.Empty; + + public string Text { get { return _text; } set { _text = value; } } + + private string _commandArgument = string.Empty; + + public string CommandArgument { get { return _commandArgument; } set { _commandArgument = value; } } + + public event EventHandler Click; + + public override void Render(TextWriter textWriter) + { + textWriter.Write(""); + + base.Render(textWriter); + + textWriter.Write(""); + } + + public void ReceivePostBack() + { + Click?.Invoke(this, null); + } + } +} \ No newline at end of file diff --git a/VAR.WebForms.Common/Controls/CTextBox.cs b/VAR.WebFormsCore/Controls/CTextBox.cs similarity index 91% rename from VAR.WebForms.Common/Controls/CTextBox.cs rename to VAR.WebFormsCore/Controls/CTextBox.cs index aa1ee8f..8dd3117 100644 --- a/VAR.WebForms.Common/Controls/CTextBox.cs +++ b/VAR.WebFormsCore/Controls/CTextBox.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; using System.Text; -using System.Web.UI; -using System.Web.UI.WebControls; using VAR.Json; -namespace VAR.WebForms.Common.Controls +namespace VAR.WebFormsCore.Controls { public class CTextBox : Control, INamingContainer, IValidableControl { @@ -143,12 +141,6 @@ namespace VAR.WebForms.Common.Controls "if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}", _nextFocusOnEnter.ClientID)); } - - // FIX: The framework deletes textbox values on password mode - if (_txtContent.TextMode == TextBoxMode.Password) - { - _txtContent.Attributes["value"] = _txtContent.Text; - } } #endregion Control life cycle diff --git a/VAR.WebFormsCore/Controls/Control.cs b/VAR.WebFormsCore/Controls/Control.cs new file mode 100644 index 0000000..51a912a --- /dev/null +++ b/VAR.WebFormsCore/Controls/Control.cs @@ -0,0 +1,222 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using VAR.WebFormsCore.Code; +using VAR.WebFormsCore.Pages; + +namespace VAR.WebFormsCore.Controls +{ + public class Control + { + public event EventHandler PreInit; + + protected void OnPreInit() + { + PreInit?.Invoke(this, null); + foreach (Control control in Controls) + { + control.OnPreInit(); + } + } + + + public event EventHandler Init; + + protected void OnInit() + { + Init?.Invoke(this, null); + foreach (Control control in Controls) + { + control.OnInit(); + } + } + + + public event EventHandler Load; + + protected virtual void Process() { } + + protected void OnLoad() + { + Process(); + Load?.Invoke(this, null); + foreach (Control control in Controls) + { + control.OnLoad(); + } + } + + public event EventHandler PreRender; + + protected void OnPreRender() + { + PreRender?.Invoke(this, null); + foreach (Control control in Controls) + { + control.OnPreRender(); + } + } + + private string _id = null; + + public string ID { get { return _id; } set { _id = value; _clientID = null; } } + + private string _clientID = null; + + public string ClientID + { + get + { + if (_clientID == null) + { + _clientID = GenerateClientID(); + } + return _clientID; + } + } + + private Control _parent = null; + + public Control Parent { get { return _parent; } set { _parent = value; _clientID = null; } } + + private ControlCollection _controls = null; + + private string _cssClass = null; + + public string CssClass { get { return _cssClass; } set { _cssClass = value; } } + + public ControlCollection Controls + { + get + { + if (_controls == null) + { + _controls = new ControlCollection(this); + } + return _controls; + } + } + + private Page _page = null; + + public Page Page + { + get { return _page; } + set + { + _page = value; + foreach (Control control in Controls) + { + control.Page = value; + } + } + } + + private bool _visible = true; + + public bool Visible { get { return _visible; } set { _visible = value; } } + + private string GenerateClientID() + { + StringBuilder sbClientID = new(); + + if (string.IsNullOrEmpty(_id) == false) + { + sbClientID.Insert(0, _id); + } + else + { + string currentID = string.Format("ctl{0:00}", Index); + sbClientID.Insert(0, currentID); + } + + Control parent = Parent; + while (parent != null) + { + if (parent is INamingContainer) + { + sbClientID.Insert(0, "_"); + if (string.IsNullOrEmpty(parent.ID) == false) + { + sbClientID.Insert(0, parent.ID); + } + else + { + string parentID = string.Format("ctl{0:00}", parent.Index); + sbClientID.Insert(0, parentID); + } + } + + parent = parent.Parent; + } + + return sbClientID.ToString(); + } + + public Dictionary Style { get; } = new Dictionary(); + + public Dictionary Attributes { get; } = new Dictionary(); + + private int _index = 0; + + public int Index { get { return _index; } set { _index = value; } } + + public virtual void Render(TextWriter textWriter) + { + foreach (Control control in Controls) + { + if (control.Visible == false) { continue; } + control.Render(textWriter); + } + } + + public void RenderAttribute(TextWriter textWriter, string key, string value) + { + textWriter.Write(" {0}=\"{1}\"", key, ServerHelpers.HtmlEncode(value)); + } + + protected void RenderAttributes(TextWriter textWriter, bool forceId = false) + { + if (string.IsNullOrEmpty(_id) == false || forceId) + { + RenderAttribute(textWriter, "id", ClientID); + RenderAttribute(textWriter, "name", ClientID); + } + if (string.IsNullOrEmpty(_cssClass) == false) + { + RenderAttribute(textWriter, "class", _cssClass); + } + foreach (KeyValuePair attributePair in Attributes) + { + RenderAttribute(textWriter, attributePair.Key, attributePair.Value); + } + if (Style.Count > 0) + { + StringBuilder sbStyle = new(); + foreach (KeyValuePair stylePair in Style) + { + sbStyle.AppendFormat("{0}: {1};", stylePair.Key, stylePair.Value); + } + RenderAttribute(textWriter, "style", sbStyle.ToString()); + } + } + + public List ChildsOfType(List controls = null) + { + if (controls == null) + { + controls = new List(); + } + + if (this is T) { controls.Add(this); } + + foreach (Control child in _controls) + { + child.ChildsOfType(controls); + } + return controls; + } + + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/ControlCollection.cs b/VAR.WebFormsCore/Controls/ControlCollection.cs new file mode 100644 index 0000000..6442131 --- /dev/null +++ b/VAR.WebFormsCore/Controls/ControlCollection.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; + +namespace VAR.WebFormsCore.Controls +{ + public class ControlCollection : List + { + private Control _parent = null; + private int _index = 0; + + public ControlCollection(Control parent) + { + _parent = parent; + } + + public new void Add(Control control) + { + control.Page = _parent.Page; + control.Parent = _parent; + control.Index = _index; + _index++; + base.Add(control); + } + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/HiddenField.cs b/VAR.WebFormsCore/Controls/HiddenField.cs new file mode 100644 index 0000000..42db602 --- /dev/null +++ b/VAR.WebFormsCore/Controls/HiddenField.cs @@ -0,0 +1,31 @@ +using System.IO; + +namespace VAR.WebFormsCore.Controls +{ + public class HiddenField : Control + { + private string _value = string.Empty; + + public string Value { get { return _value; } set { _value = value; } } + + protected override void Process() + { + if (Page.IsPostBack && Page.Context.Request.Form.ContainsKey(ClientID)) + { + Value = Page.Context.Request.Form[ClientID]; + } + } + + public override void Render(TextWriter textWriter) + { + textWriter.Write(""); + textWriter.Write(""); + } + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/HtmlBody.cs b/VAR.WebFormsCore/Controls/HtmlBody.cs new file mode 100644 index 0000000..620c16e --- /dev/null +++ b/VAR.WebFormsCore/Controls/HtmlBody.cs @@ -0,0 +1,7 @@ +namespace VAR.WebFormsCore.Controls +{ + public class HtmlBody : HtmlGenericControl + { + public HtmlBody() : base("body") { } + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/HtmlForm.cs b/VAR.WebFormsCore/Controls/HtmlForm.cs new file mode 100644 index 0000000..0e4e111 --- /dev/null +++ b/VAR.WebFormsCore/Controls/HtmlForm.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using System.IO; +using System.Text; +using Microsoft.Extensions.Primitives; +using VAR.WebFormsCore.Code; + +namespace VAR.WebFormsCore.Controls +{ + public class HtmlForm : Control + { + private string _method = "post"; + + public HtmlForm() { } + + public override void Render(TextWriter textWriter) + { + textWriter.Write("
"); + + base.Render(textWriter); + + textWriter.Write("
"); + } + private string GetAction() + { + StringBuilder sbAction = new(); + sbAction.Append(Page.GetType().Name); + + if (Page.Context.Request.Query.Count > 0) + { + sbAction.Append('?'); + + foreach (KeyValuePair queryParam in Page.Context.Request.Query) + { + sbAction.AppendFormat("&{0}={1}", ServerHelpers.UrlEncode(queryParam.Key), ServerHelpers.UrlEncode(queryParam.Value[0])); + } + } + + return sbAction.ToString(); + } + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/HtmlGenericControl.cs b/VAR.WebFormsCore/Controls/HtmlGenericControl.cs new file mode 100644 index 0000000..6e5991a --- /dev/null +++ b/VAR.WebFormsCore/Controls/HtmlGenericControl.cs @@ -0,0 +1,25 @@ +using System.IO; + +namespace VAR.WebFormsCore.Controls +{ + public class HtmlGenericControl : Control + { + private string _tagName; + + public HtmlGenericControl(string tag) + { + _tagName = tag; + } + + public override void Render(TextWriter textWriter) + { + textWriter.Write("<{0} ", _tagName); + RenderAttributes(textWriter); + textWriter.Write(">"); + + base.Render(textWriter); + + textWriter.Write("", _tagName); + } + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/HtmlHead.cs b/VAR.WebFormsCore/Controls/HtmlHead.cs new file mode 100644 index 0000000..709c07e --- /dev/null +++ b/VAR.WebFormsCore/Controls/HtmlHead.cs @@ -0,0 +1,25 @@ +using System.IO; + +namespace VAR.WebFormsCore.Controls +{ + public class HtmlHead : Control + { + public string Title { get; set; } + + public override void Render(TextWriter textWriter) + { + textWriter.Write(""); + + if (string.IsNullOrEmpty(Title) == false) + { + textWriter.Write("{0}", Title); + } + + base.Render(textWriter); + + textWriter.Write(""); + } + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/HtmlMeta.cs b/VAR.WebFormsCore/Controls/HtmlMeta.cs new file mode 100644 index 0000000..335308c --- /dev/null +++ b/VAR.WebFormsCore/Controls/HtmlMeta.cs @@ -0,0 +1,29 @@ +using System.IO; + +namespace VAR.WebFormsCore.Controls +{ + public class HtmlMeta : Control + { + public string Name { get; set; } + public string Content { get; set; } + public string HttpEquiv { get; internal set; } + public override void Render(TextWriter textWriter) + { + textWriter.Write(""); + } + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/HyperLink.cs b/VAR.WebFormsCore/Controls/HyperLink.cs new file mode 100644 index 0000000..4bbabcb --- /dev/null +++ b/VAR.WebFormsCore/Controls/HyperLink.cs @@ -0,0 +1,32 @@ +using System.IO; + +namespace VAR.WebFormsCore.Controls +{ + public class HyperLink : Control + { + + public string NavigateUrl { get; set; } + public string Text { get; set; } + + public override void Render(TextWriter textWriter) + { + textWriter.Write(""); + + if (string.IsNullOrEmpty(Text) == false) + { + textWriter.Write(Text); + } + + base.Render(textWriter); + + textWriter.Write(""); + } + + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/INamingContainer.cs b/VAR.WebFormsCore/Controls/INamingContainer.cs new file mode 100644 index 0000000..84d9673 --- /dev/null +++ b/VAR.WebFormsCore/Controls/INamingContainer.cs @@ -0,0 +1,6 @@ +namespace VAR.WebFormsCore.Controls +{ + public interface INamingContainer + { + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/IReceivePostbackEvent.cs b/VAR.WebFormsCore/Controls/IReceivePostbackEvent.cs new file mode 100644 index 0000000..f66cf70 --- /dev/null +++ b/VAR.WebFormsCore/Controls/IReceivePostbackEvent.cs @@ -0,0 +1,7 @@ +namespace VAR.WebFormsCore.Controls +{ + public interface IReceivePostbackEvent + { + void ReceivePostBack(); + } +} \ No newline at end of file diff --git a/VAR.WebForms.Common/Controls/IValidableControl.cs b/VAR.WebFormsCore/Controls/IValidableControl.cs similarity index 61% rename from VAR.WebForms.Common/Controls/IValidableControl.cs rename to VAR.WebFormsCore/Controls/IValidableControl.cs index 111ced7..be6ff62 100644 --- a/VAR.WebForms.Common/Controls/IValidableControl.cs +++ b/VAR.WebFormsCore/Controls/IValidableControl.cs @@ -1,4 +1,4 @@ -namespace VAR.WebForms.Common.Controls +namespace VAR.WebFormsCore.Controls { public interface IValidableControl { diff --git a/VAR.WebFormsCore/Controls/Label.cs b/VAR.WebFormsCore/Controls/Label.cs new file mode 100644 index 0000000..6de15ff --- /dev/null +++ b/VAR.WebFormsCore/Controls/Label.cs @@ -0,0 +1,41 @@ +using System.IO; +using VAR.WebFormsCore.Code; + +namespace VAR.WebFormsCore.Controls +{ + public class Label : Control + { + #region Properties + + private string _tagName = "span"; + + public string Tag + { + get { return _tagName; } + set { _tagName = value; } + } + + private string _text = string.Empty; + + public string Text { get { return _text; } set { _text = value; } } + + #endregion Properties + + #region Life cycle + + public override void Render(TextWriter textWriter) + { + textWriter.Write("<{0} ", _tagName); + RenderAttributes(textWriter); + textWriter.Write(">"); + + textWriter.Write(ServerHelpers.HtmlEncode(_text)); + + base.Render(textWriter); + + textWriter.Write("", _tagName); + } + + #endregion Life cycle + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/LiteralControl.cs b/VAR.WebFormsCore/Controls/LiteralControl.cs new file mode 100644 index 0000000..87eb013 --- /dev/null +++ b/VAR.WebFormsCore/Controls/LiteralControl.cs @@ -0,0 +1,18 @@ +using System.IO; + +namespace VAR.WebFormsCore.Controls +{ + public class LiteralControl : Control + { + public string Content { get; set; } + + public LiteralControl() { } + public LiteralControl(string content) { Content = content; } + + public override void Render(TextWriter textWriter) + { + textWriter.Write(Content); + } + + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/Panel.cs b/VAR.WebFormsCore/Controls/Panel.cs new file mode 100644 index 0000000..19f7536 --- /dev/null +++ b/VAR.WebFormsCore/Controls/Panel.cs @@ -0,0 +1,7 @@ +namespace VAR.WebFormsCore.Controls +{ + public class Panel : HtmlGenericControl, INamingContainer + { + public Panel() : base("div") { } + } +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/TextBox.cs b/VAR.WebFormsCore/Controls/TextBox.cs new file mode 100644 index 0000000..99e4ab5 --- /dev/null +++ b/VAR.WebFormsCore/Controls/TextBox.cs @@ -0,0 +1,63 @@ +using System.IO; +using VAR.WebFormsCore.Code; + +namespace VAR.WebFormsCore.Controls +{ + public class TextBox : Control + { + private string _text = string.Empty; + + public string Text { get { return _text; } set { _text = value; } } + + public TextBoxMode TextMode { get; set; } = TextBoxMode.Normal; + + protected override void Process() + { + if (Page.IsPostBack && Page.Context.Request.Form.ContainsKey(ClientID)) + { + _text = Page.Context.Request.Form[ClientID]; + } + } + + public override void Render(TextWriter textWriter) + { + if (TextMode == TextBoxMode.MultiLine) + { + textWriter.Write(""); + } + else if (TextMode == TextBoxMode.Normal) + { + textWriter.Write(""); + textWriter.Write(""); + } + else if (TextMode == TextBoxMode.Password) + { + textWriter.Write(""); + textWriter.Write(""); + } + } + } + + public enum TextBoxMode + { + Normal, + Password, + MultiLine, + } +} \ No newline at end of file diff --git a/VAR.WebForms.Common/Pages/FormUtils.cs b/VAR.WebFormsCore/Pages/FormUtils.cs similarity index 89% rename from VAR.WebForms.Common/Pages/FormUtils.cs rename to VAR.WebFormsCore/Pages/FormUtils.cs index 5e197e1..2d5ec7f 100644 --- a/VAR.WebForms.Common/Pages/FormUtils.cs +++ b/VAR.WebFormsCore/Pages/FormUtils.cs @@ -1,8 +1,6 @@ -using System.Web.UI; -using System.Web.UI.WebControls; -using VAR.WebForms.Common.Controls; +using VAR.WebFormsCore.Controls; -namespace VAR.WebForms.Common.Pages +namespace VAR.WebFormsCore.Pages { public class FormUtils { @@ -36,7 +34,7 @@ namespace VAR.WebForms.Common.Pages if (string.IsNullOrEmpty(label) == false) { - CLabel lblField = new CLabel(); + Label lblField = new Label(); lblField.Text = label; pnlLabelContainer.Controls.Add(lblField); } diff --git a/VAR.WebFormsCore/Pages/FrmEcho.cs b/VAR.WebFormsCore/Pages/FrmEcho.cs new file mode 100644 index 0000000..7ea1ccc --- /dev/null +++ b/VAR.WebFormsCore/Pages/FrmEcho.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Http; +using VAR.Json; +using VAR.WebFormsCore.Code; + +namespace VAR.WebFormsCore.Pages +{ + public class FrmEcho : IHttpHandler + { + #region IHttpHandler + + public void ProcessRequest(HttpContext context) + { + context.Response.WriteAsync("
");
+            context.Response.WriteAsync(JsonWriter.WriteObject(context.Request, indent: true));
+            context.Response.WriteAsync("
"); + } + + #endregion IHttpHandler + } +} \ No newline at end of file diff --git a/VAR.WebForms.Common/Pages/FrmError.cs b/VAR.WebFormsCore/Pages/FrmError.cs similarity index 74% rename from VAR.WebForms.Common/Pages/FrmError.cs rename to VAR.WebFormsCore/Pages/FrmError.cs index 9b53149..44f5af9 100644 --- a/VAR.WebForms.Common/Pages/FrmError.cs +++ b/VAR.WebFormsCore/Pages/FrmError.cs @@ -1,10 +1,8 @@ using System; using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; -using VAR.WebForms.Common.Controls; +using VAR.WebFormsCore.Controls; -namespace VAR.WebForms.Common.Pages +namespace VAR.WebFormsCore.Pages { public class FrmError : PageCommon { @@ -18,6 +16,7 @@ namespace VAR.WebForms.Common.Pages public FrmError(Exception ex) { + MustBeAutenticated = false; _ex = ex; Init += FrmError_Init; } @@ -35,18 +34,18 @@ namespace VAR.WebForms.Common.Pages { Title = "Application Error"; - CLabel lblErrorTitle = new CLabel { Text = Title, Tag = "h2" }; + Label lblErrorTitle = new Label { Text = Title, Tag = "h2" }; Controls.Add(lblErrorTitle); Exception exAux = _ex; - if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; } + //if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; } while (exAux != null) { - CLabel lblMessage = new CLabel { Tag = "P" }; + Label lblMessage = new Label { Tag = "P" }; lblMessage.Text = string.Format("{0}: {1}", "Message", HttpUtility.HtmlEncode(exAux.Message)); Controls.Add(lblMessage); - CLabel lblStacktraceTitle = new CLabel { Tag = "p" }; + Label lblStacktraceTitle = new Label { Tag = "p" }; lblStacktraceTitle.Text = string.Format("{0}:", "Stacktrace"); Controls.Add(lblStacktraceTitle); Panel pnlStacktrace = new Panel(); diff --git a/VAR.WebFormsCore/Pages/Page.cs b/VAR.WebFormsCore/Pages/Page.cs new file mode 100644 index 0000000..87938cd --- /dev/null +++ b/VAR.WebFormsCore/Pages/Page.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.IO; +using System.Text; +using Microsoft.AspNetCore.Http; +using VAR.WebFormsCore.Code; +using VAR.WebFormsCore.Controls; + +namespace VAR.WebFormsCore.Pages +{ + public class Page : Control, IHttpHandler + { + public string Title { get; set; } + + public HttpContext Context { get; set; } + + private static Encoding _utf8Econding = new UTF8Encoding(); + + public async void ProcessRequest(HttpContext context) + { + StringWriter stringWriter = new(); + + Context = context; + Page = this; + + if (context.Request.Method == "POST") + { + _isPostBack = true; + } + + OnPreInit(); + if (context.Response.HasStarted) { return; } + + OnInit(); + if (context.Response.HasStarted) { return; } + + OnLoad(); + if (context.Response.HasStarted) { return; } + + if (_isPostBack) + { + List controls = ChildsOfType(); + foreach (Control control in controls) + { + string clientID = control.ClientID; + if (context.Request.Form.ContainsKey(clientID)) + { + (control as IReceivePostbackEvent).ReceivePostBack(); + if (context.Response.HasStarted) { return; } + } + } + } + + OnPreRender(); + if (context.Response.HasStarted) { return; } + + Render(stringWriter); + if (context.Response.HasStarted) { return; } + + context.Response.Headers.Add("Content-Type", "text/html"); + byte[] byteObject = _utf8Econding.GetBytes(stringWriter.ToString()); + await context.Response.Body.WriteAsync(byteObject); + } + + private bool _isPostBack = false; + + public bool IsPostBack { get { return _isPostBack; } } + } +} \ No newline at end of file diff --git a/VAR.WebForms.Common/Pages/PageCommon.cs b/VAR.WebFormsCore/Pages/PageCommon.cs similarity index 84% rename from VAR.WebForms.Common/Pages/PageCommon.cs rename to VAR.WebFormsCore/Pages/PageCommon.cs index ce3945f..2335c84 100644 --- a/VAR.WebForms.Common/Pages/PageCommon.cs +++ b/VAR.WebFormsCore/Pages/PageCommon.cs @@ -1,24 +1,20 @@ using System; using System.Reflection; -using System.Text; -using System.Web.UI; -using System.Web.UI.HtmlControls; -using System.Web.UI.WebControls; -using VAR.WebForms.Common.Code; -using VAR.WebForms.Common.Controls; +using VAR.WebFormsCore.Code; +using VAR.WebFormsCore.Controls; -namespace VAR.WebForms.Common.Pages +namespace VAR.WebFormsCore.Pages { public class PageCommon : Page { #region Declarations private HtmlHead _head; - private HtmlGenericControl _body; + private HtmlBody _body; private HtmlForm _form; private Panel _pnlContainer = new Panel(); - private CButton _btnPostback = new CButton(); - private CButton _btnLogout = new CButton(); + private Button _btnPostback = new Button(); + private Button _btnLogout = new Button(); private bool _mustBeAutenticated = true; private bool _isAuthenticated = false; @@ -56,7 +52,7 @@ namespace VAR.WebForms.Common.Pages _isAuthenticated = GlobalConfig.Get().IsUserAuthenticated(Context); if (_mustBeAutenticated && _isAuthenticated == false) { - Response.Redirect(GlobalConfig.Get().LoginHandler); + Context.Response.Redirect(GlobalConfig.Get().LoginHandler); } } @@ -80,7 +76,7 @@ namespace VAR.WebForms.Common.Pages GlobalConfig.Get().UserUnauthenticate(Context); if (_mustBeAutenticated) { - Response.Redirect(GlobalConfig.Get().LoginHandler); + Context.Response.Redirect(GlobalConfig.Get().LoginHandler); } } @@ -90,7 +86,7 @@ namespace VAR.WebForms.Common.Pages private void CreateControls() { - Context.Response.Charset = Encoding.UTF8.WebName; + //Context.Response.Charset = Encoding.UTF8.WebName; var doctype = new LiteralControl("\n"); base.Controls.Add(doctype); @@ -111,7 +107,7 @@ namespace VAR.WebForms.Common.Pages _head.Controls.Add(new LiteralControl(string.Format("\n", version))); _head.Controls.Add(new LiteralControl(string.Format("\n", version))); - _body = new HtmlGenericControl("body"); + _body = new HtmlBody(); html.Controls.Add(_body); _form = new HtmlForm { ID = "formMain" }; _body.Controls.Add(_form); @@ -123,7 +119,7 @@ namespace VAR.WebForms.Common.Pages lnkTitle.NavigateUrl = "."; pnlHeader.Controls.Add(lnkTitle); - var lblTitle = new CLabel { Text = GlobalConfig.Get().Title, Tag = "h1" }; + var lblTitle = new Label { Text = GlobalConfig.Get().Title, Tag = "h1" }; lnkTitle.Controls.Add(lblTitle); _btnPostback.ID = "btnPostback"; diff --git a/VAR.WebFormsCore/Properties/launchSettings.json b/VAR.WebFormsCore/Properties/launchSettings.json new file mode 100644 index 0000000..1fa47cd --- /dev/null +++ b/VAR.WebFormsCore/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:58454/", + "sslPort": 44386 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "VAR.WebFormsCore": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + } + } +} \ No newline at end of file diff --git a/VAR.WebForms.Common/Scripts/01. Base.js b/VAR.WebFormsCore/Scripts/01. Base.js similarity index 100% rename from VAR.WebForms.Common/Scripts/01. Base.js rename to VAR.WebFormsCore/Scripts/01. Base.js diff --git a/VAR.WebForms.Common/Scripts/02. Ajax.js b/VAR.WebFormsCore/Scripts/02. Ajax.js similarity index 100% rename from VAR.WebForms.Common/Scripts/02. Ajax.js rename to VAR.WebFormsCore/Scripts/02. Ajax.js diff --git a/VAR.WebForms.Common/Scripts/03. Controls.js b/VAR.WebFormsCore/Scripts/03. Controls.js similarity index 100% rename from VAR.WebForms.Common/Scripts/03. Controls.js rename to VAR.WebFormsCore/Scripts/03. Controls.js diff --git a/VAR.WebForms.Common/Styles/00. Reset.css b/VAR.WebFormsCore/Styles/00. Reset.css similarity index 100% rename from VAR.WebForms.Common/Styles/00. Reset.css rename to VAR.WebFormsCore/Styles/00. Reset.css diff --git a/VAR.WebForms.Common/Styles/01. base.css b/VAR.WebFormsCore/Styles/01. base.css similarity index 100% rename from VAR.WebForms.Common/Styles/01. base.css rename to VAR.WebFormsCore/Styles/01. base.css diff --git a/VAR.WebFormsCore/VAR.WebFormsCore.csproj b/VAR.WebFormsCore/VAR.WebFormsCore.csproj new file mode 100644 index 0000000..aeb7393 --- /dev/null +++ b/VAR.WebFormsCore/VAR.WebFormsCore.csproj @@ -0,0 +1,28 @@ + + + + net5.0 + + + + + + + + + + + + + + + + + + + + + + + +