From 577e8b4127312380fd0a8b7051b24df8ab932ae4 Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Tue, 13 Dec 2016 22:09:38 +0100 Subject: [PATCH] Split BusinessLogic from WebApp --- VAR.Focus.Web/Code/BusinessLogic/Boards.cs | 151 ----- VAR.Focus.Web/Code/BusinessLogic/CardBoard.cs | 286 -------- VAR.Focus.Web/Code/BusinessLogic/Groups.cs | 140 ---- .../Code/BusinessLogic/MessageBoard.cs | 89 --- .../Code/BusinessLogic/Persistence.cs | 74 -- VAR.Focus.Web/Code/BusinessLogic/Sessions.cs | 149 ---- VAR.Focus.Web/Code/BusinessLogic/Users.cs | 143 ---- VAR.Focus.Web/Code/CryptoUtils.cs | 40 -- VAR.Focus.Web/Code/Entities/Board.cs | 19 - VAR.Focus.Web/Code/Entities/Card.cs | 22 - VAR.Focus.Web/Code/Entities/CardEvents.cs | 81 --- VAR.Focus.Web/Code/Entities/Group.cs | 17 - VAR.Focus.Web/Code/Entities/GroupMember.cs | 17 - VAR.Focus.Web/Code/Entities/Message.cs | 12 - .../Code/Entities/OperationStatus.cs | 10 - VAR.Focus.Web/Code/Entities/Session.cs | 11 - VAR.Focus.Web/Code/Entities/User.cs | 11 - VAR.Focus.Web/Code/ExtensionMethods.cs | 2 +- VAR.Focus.Web/Code/JSON/JsonParser.cs | 637 ------------------ VAR.Focus.Web/Code/JSON/JsonWriter.cs | 337 --------- VAR.Focus.Web/Code/JSON/ParserContext.cs | 84 --- VAR.Focus.Web/Code/ObjectActivator.cs | 36 - VAR.Focus.Web/Code/WebSessions.cs | 92 +++ VAR.Focus.Web/Controls/CardBoardControl.cs | 2 +- VAR.Focus.Web/Controls/CardBoardHandler.cs | 6 +- VAR.Focus.Web/Controls/ChatControl.cs | 2 +- VAR.Focus.Web/Controls/ChatHandler.cs | 6 +- VAR.Focus.Web/GlobalRouter.cs | 1 + VAR.Focus.Web/Pages/FrmBoard.cs | 4 +- VAR.Focus.Web/Pages/FrmBoardEdit.cs | 4 +- VAR.Focus.Web/Pages/FrmEcho.cs | 2 +- VAR.Focus.Web/Pages/FrmLogin.cs | 5 +- VAR.Focus.Web/Pages/FrmRegister.cs | 4 +- VAR.Focus.Web/Pages/PageCommon.cs | 11 +- VAR.Focus.Web/VAR.Focus.Web.csproj | 28 +- 35 files changed, 125 insertions(+), 2410 deletions(-) delete mode 100644 VAR.Focus.Web/Code/BusinessLogic/Boards.cs delete mode 100644 VAR.Focus.Web/Code/BusinessLogic/CardBoard.cs delete mode 100644 VAR.Focus.Web/Code/BusinessLogic/Groups.cs delete mode 100644 VAR.Focus.Web/Code/BusinessLogic/MessageBoard.cs delete mode 100644 VAR.Focus.Web/Code/BusinessLogic/Persistence.cs delete mode 100644 VAR.Focus.Web/Code/BusinessLogic/Sessions.cs delete mode 100644 VAR.Focus.Web/Code/BusinessLogic/Users.cs delete mode 100644 VAR.Focus.Web/Code/CryptoUtils.cs delete mode 100644 VAR.Focus.Web/Code/Entities/Board.cs delete mode 100644 VAR.Focus.Web/Code/Entities/Card.cs delete mode 100644 VAR.Focus.Web/Code/Entities/CardEvents.cs delete mode 100644 VAR.Focus.Web/Code/Entities/Group.cs delete mode 100644 VAR.Focus.Web/Code/Entities/GroupMember.cs delete mode 100644 VAR.Focus.Web/Code/Entities/Message.cs delete mode 100644 VAR.Focus.Web/Code/Entities/OperationStatus.cs delete mode 100644 VAR.Focus.Web/Code/Entities/Session.cs delete mode 100644 VAR.Focus.Web/Code/Entities/User.cs delete mode 100644 VAR.Focus.Web/Code/JSON/JsonParser.cs delete mode 100644 VAR.Focus.Web/Code/JSON/JsonWriter.cs delete mode 100644 VAR.Focus.Web/Code/JSON/ParserContext.cs delete mode 100644 VAR.Focus.Web/Code/ObjectActivator.cs create mode 100644 VAR.Focus.Web/Code/WebSessions.cs diff --git a/VAR.Focus.Web/Code/BusinessLogic/Boards.cs b/VAR.Focus.Web/Code/BusinessLogic/Boards.cs deleted file mode 100644 index 47f4593..0000000 --- a/VAR.Focus.Web/Code/BusinessLogic/Boards.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using VAR.Focus.Web.Code.Entities; - -namespace VAR.Focus.Web.Code.BusinessLogic -{ - public class Boards - { - #region Declarations - - private static Boards _currentInstance = null; - - private List _boards = new List(); - private int _lastIDBoard=0; - - #endregion - - #region Properties - - public static Boards Current - { - get - { - if (_currentInstance == null) - { - _currentInstance = new Boards(); - } - return _currentInstance; - } - set { _currentInstance = value; } - } - - #endregion - - #region Life cycle - - public Boards() - { - LoadData(); - } - - #endregion - - #region Public methods - - public List Boards_GetListForUser(string userName) - { - // FIXME: filter by permissions - return _boards.Where(board => board.Active).ToList(); - } - - public Board Board_GetByIDBoard(int idBoard) - { - foreach (Board board in _boards) - { - if (board.IDBoard == idBoard) - { - return board; - } - } - return null; - } - - public Board Boards_SetBoard(int idBoard, string title, string description, string userName) - { - DateTime currentDate = DateTime.UtcNow; - Board board; - if (idBoard == 0) - { - lock (this) - { - _lastIDBoard++; - board = new Board(); - board.IDBoard = _lastIDBoard; - board.CreatedBy = userName; - board.CreatedDate = currentDate; - _boards.Add(board); - } - } - else - { - board = Board_GetByIDBoard(idBoard); - } - - board.Title = title; - board.Description = description; - - board.Active = true; - board.ModifiedBy = userName; - board.ModifiedDate = currentDate; - - SaveData(); - - return board; - } - - public bool Boards_DelBoard(int idBoard, string userName) - { - DateTime currentDate = DateTime.UtcNow; - Board board; - if (idBoard == 0) - { - return false; - } - else - { - board = Board_GetByIDBoard(idBoard); - } - if (board == null) { return false; } - - board.Active = false; - board.ModifiedBy = userName; - board.ModifiedDate = currentDate; - - SaveData(); - - return true; - } - - #endregion - - #region Private methods - - #region Persistence - - private const string BoardsPersistenceFile = "boards"; - - private void LoadData() - { - _boards = Persistence.LoadList(BoardsPersistenceFile); - _lastIDBoard = 0; - foreach (Board board in _boards) - { - if (board.IDBoard > _lastIDBoard) - { - _lastIDBoard = board.IDBoard; - } - } - } - - private void SaveData() - { - Persistence.SaveList(BoardsPersistenceFile, _boards); - } - - #endregion - - #endregion - } -} diff --git a/VAR.Focus.Web/Code/BusinessLogic/CardBoard.cs b/VAR.Focus.Web/Code/BusinessLogic/CardBoard.cs deleted file mode 100644 index c905109..0000000 --- a/VAR.Focus.Web/Code/BusinessLogic/CardBoard.cs +++ /dev/null @@ -1,286 +0,0 @@ -using System; -using System.Collections.Generic; -using VAR.Focus.Web.Code.Entities; - -namespace VAR.Focus.Web.Code.BusinessLogic -{ - public class CardBoard - { - #region Declarations - - private List _cards = new List(); - private int _lastIDCard = 0; - - private List _cardEvents = new List(); - private int _lastIDCardEvent = 0; - - private int _idBoard = 0; - - #endregion - - #region Life cycle - - public CardBoard(int idBoard) - { - _idBoard = idBoard; - LoadData(); - } - - #endregion - - #region Public methods - - public List Cards_Status() - { - List activeCards=new List(); - foreach (Card card in _cards) - { - if (card.Active) - { - activeCards.Add(card); - } - } - return activeCards; - } - - public List Cards_GetEventList(int idCardEvent) - { - List listEvents = new List(); - for (int i = 0, n = _cardEvents.Count; i < n; i++) - { - ICardEvent cardEvent = _cardEvents[i]; - if (cardEvent.IDCardEvent > idCardEvent) - { - listEvents.Insert(0, cardEvent); - } - else { break; } - } - return listEvents; - } - - public int GetLastIDCardEvent() - { - return _lastIDCardEvent; - } - - public int GetLastIDCard() - { - return _lastIDCard; - } - - public int Card_Create(string title, string body, int x, int y, string currentUserName) - { - DateTime currentDate = DateTime.UtcNow; - Card card; - lock (_cards) - { - // Create card - _lastIDCard++; - card = new Card() - { - IDCard = _lastIDCard, - Title = title, - Body = body, - X = x, - Y = y, - Active = true, - CreatedBy = currentUserName, - CreatedDate = currentDate, - ModifiedBy = currentUserName, - ModifiedDate = currentDate, - }; - _cards.Add(card); - - // Create event - _lastIDCardEvent++; - CardCreateEvent cardCreateEvent = new CardCreateEvent() - { - IDCardEvent = _lastIDCardEvent, - IDCard = card.IDCard, - UserName = currentUserName, - Date = currentDate, - Title = card.Title, - Body = card.Body, - X = card.X, - Y = card.Y, - }; - _cardEvents.Insert(0, cardCreateEvent); - - SaveData(); - } - return card.IDCard; - } - - public bool Card_Move(int idCard, int x, int y, string currentUserName) - { - DateTime currentDate = DateTime.UtcNow; - lock (_cards) - { - // Move card - Card card = GetByID(idCard); - if (card == null) { return false; } - card.X = x; - card.Y = y; - card.ModifiedBy = currentUserName; - card.ModifiedDate = currentDate; - _cards.Remove(card); - _cards.Add(card); - - // Create event - _lastIDCardEvent++; - CardMoveEvent cardMoveEvent = new CardMoveEvent() - { - IDCardEvent = _lastIDCardEvent, - IDCard = card.IDCard, - UserName = currentUserName, - Date = currentDate, - X = card.X, - Y = card.Y, - }; - _cardEvents.Insert(0, cardMoveEvent); - - SaveData(); - } - return true; - } - - public bool Card_Edit(int idCard, string title, string body, string currentUserName) - { - DateTime currentDate = DateTime.UtcNow; - lock (_cards) - { - // Edit card - Card card = GetByID(idCard); - if (card == null) { return false; } - card.Title = title; - card.Body = body; - card.ModifiedBy = currentUserName; - card.ModifiedDate = currentDate; - _cards.Remove(card); - _cards.Add(card); - - // Create event - _lastIDCardEvent++; - CardEditEvent cardEditEvent = new CardEditEvent() - { - IDCardEvent = _lastIDCardEvent, - IDCard = card.IDCard, - UserName = currentUserName, - Date = currentDate, - Title = card.Title, - Body = card.Body, - }; - _cardEvents.Insert(0, cardEditEvent); - - SaveData(); - } - return true; - } - - public bool Card_Delete(int idCard, string currentUserName) - { - DateTime currentDate = DateTime.UtcNow; - lock (_cards) - { - // Delete card - Card card = GetByID(idCard); - if (card == null) { return false; } - card.Active = false; - card.ModifiedBy = currentUserName; - - // Create event - _lastIDCardEvent++; - CardDeleteEvent cardDeleteEvent = new CardDeleteEvent() - { - IDCardEvent = _lastIDCardEvent, - IDCard = card.IDCard, - UserName = currentUserName, - Date = currentDate, - }; - _cardEvents.Insert(0, cardDeleteEvent); - - SaveData(); - } - return true; - } - - public static List ConvertCardsToEvents(List listCards, int lastIDCardEvent) - { - List listEvents = new List(); - foreach (Card card in listCards) - { - var evt = new CardCreateEvent() - { - IDCardEvent = lastIDCardEvent, - IDCard = card.IDCard, - UserName = card.ModifiedBy, - Date = card.ModifiedDate, - Title = card.Title, - Body = card.Body, - X = card.X, - Y = card.Y, - }; - listEvents.Add(evt); - } - return listEvents; - } - - #endregion - - #region Private methods - - private Card GetByID(int idCard) - { - foreach (Card card in _cards) - { - if (card.IDCard == idCard) - { - return card; - } - } - return null; - } - - #region Persistence - - private const string CardsPersistenceFile = "cardBoard.{0}"; - private const string EventsPersistenceFile = "cardEvents.{0}"; - - private void LoadData() - { - _cards = Persistence.LoadList(String.Format(CardsPersistenceFile, _idBoard)); - _lastIDCard = 0; - foreach (Card card in _cards) - { - if (card.IDCard > _lastIDCard) - { - _lastIDCard = card.IDCard; - } - } - - _cardEvents = Persistence.LoadList(String.Format(EventsPersistenceFile, _idBoard), - new List { - typeof(CardCreateEvent), - typeof(CardMoveEvent), - typeof(CardEditEvent), - typeof(CardDeleteEvent), - }); - _lastIDCardEvent = 0; - if (_cardEvents.Count > 0) - { - _lastIDCardEvent = _cardEvents[0].IDCardEvent; - } - } - - private void SaveData() - { - Persistence.SaveList(String.Format(CardsPersistenceFile, _idBoard), _cards); - Persistence.SaveList(String.Format(EventsPersistenceFile, _idBoard), _cardEvents); - } - - #endregion - - #endregion - - } -} diff --git a/VAR.Focus.Web/Code/BusinessLogic/Groups.cs b/VAR.Focus.Web/Code/BusinessLogic/Groups.cs deleted file mode 100644 index 32ec4d3..0000000 --- a/VAR.Focus.Web/Code/BusinessLogic/Groups.cs +++ /dev/null @@ -1,140 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using VAR.Focus.Web.Code.Entities; - -namespace VAR.Focus.Web.Code.BusinessLogic -{ - public class Groups - { - #region declarations - - private static Groups _currentInstance = null; - - private List _groups = new List(); - - private List _groupMembers = new List(); - - #endregion - - #region Properties - - public static Groups Current - { - get - { - if (_currentInstance == null) - { - _currentInstance = new Groups(); - } - return _currentInstance; - } - set { _currentInstance = value; } - } - - #endregion - - #region Public methods - - public Group Group_GetByName(string name) - { - name = name.ToLower(); - foreach (Group groupAux in _groups) - { - if (name.CompareTo(groupAux.Name.ToLower()) == 0) - { - return groupAux; - } - } - return null; - } - - public Group Group_Set(string name, string description) - { - Group group = null; - bool isNew = false; - lock (_groups) - { - group = Group_GetByName(name); - if (group == null) { group = new Group(); isNew = true; } - - group.Name = name; - group.Description = description; - - if (isNew) { _groups.Add(group); } - - SaveData(); - } - return group; - } - - public List GroupMember_GetGroupNamesByUser(string userName) - { - List groupNames = _groupMembers.Select(groupMember => groupMember.GroupName).ToList(); - return groupNames; - } - - public List GroupMember_GetUserNamesByGroup(string groupName) - { - List userNames = _groupMembers.Select(groupMember => groupMember.UserName).ToList(); - return userNames; - } - - public GroupMember GroupMember_Set(string groupName, string userName) - { - string groupNameLower = groupName.ToLower(); - string userNameLower = userName.ToLower(); - GroupMember groupMember = null; - bool isNew = false; - lock (_groups) - { - groupMember = _groupMembers.FirstOrDefault(x => ( - x.GroupName.ToLower() == groupNameLower && - x.UserName.ToLower() == userNameLower)); - - if (groupMember == null) { groupMember = new GroupMember(); isNew = true; } - - groupMember.GroupName = groupName; - groupMember.UserName = userName; - - if (isNew) { _groupMembers.Add(groupMember); } - - SaveData(); - } - return groupMember; - } - - #endregion - - #region Life cycle - - public Groups() - { - LoadData(); - } - - #endregion - - #region Private methods - - #region Persistence - - private const string GroupsPersistenceFile = "groups"; - private const string GroupMembersPersistenceFile = "groupMembers"; - - private void LoadData() - { - _groups = Persistence.LoadList(GroupsPersistenceFile); - _groupMembers = Persistence.LoadList(GroupMembersPersistenceFile); - } - - private void SaveData() - { - Persistence.SaveList(GroupsPersistenceFile, _groups); - Persistence.SaveList(GroupMembersPersistenceFile, _groupMembers); - } - - #endregion - - #endregion - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/BusinessLogic/MessageBoard.cs b/VAR.Focus.Web/Code/BusinessLogic/MessageBoard.cs deleted file mode 100644 index 25264ac..0000000 --- a/VAR.Focus.Web/Code/BusinessLogic/MessageBoard.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using VAR.Focus.Web.Code.Entities; - -namespace VAR.Focus.Web.Code.BusinessLogic -{ - public class MessageBoard - { - #region Declarations - - private List _messages = new List(); - private int _lastIDMessage = 0; - - private string _idMessageBoard = null; - - #endregion - - #region Life cycle - - public MessageBoard(string idMessageBoard) - { - _idMessageBoard = idMessageBoard; - LoadData(); - } - - #endregion - - #region Public methods - - public List Messages_GetList(int idMessage) - { - List listMessages = new List(); - for (int i = 0, n = _messages.Count; i < n; i++) - { - Message msg = _messages[i]; - if (msg.IDMessage > idMessage) - { - listMessages.Insert(0, msg); - } - else { break; } - } - return listMessages; - } - - public void Message_Add(string userName, string text) - { - lock (_messages) - { - _lastIDMessage++; - Message msg = new Message(); - msg.IDMessage = _lastIDMessage; - msg.UserName = userName; - msg.Text = text; - msg.Date = DateTime.UtcNow; - _messages.Insert(0, msg); - SaveData(); - } - } - - #endregion - - #region Private methods - - #region Persistence - - private const string PersistenceFile = "messageBoard.{0}"; - - private void LoadData() - { - _messages = Persistence.LoadList(String.Format(PersistenceFile, _idMessageBoard)); - _lastIDMessage = 0; - if (_messages.Count > 0) - { - _lastIDMessage = _messages[0].IDMessage; - } - } - - private void SaveData() - { - Persistence.SaveList(String.Format(PersistenceFile, _idMessageBoard), _messages); - } - - #endregion - - #endregion - - } - -} diff --git a/VAR.Focus.Web/Code/BusinessLogic/Persistence.cs b/VAR.Focus.Web/Code/BusinessLogic/Persistence.cs deleted file mode 100644 index 7158ddd..0000000 --- a/VAR.Focus.Web/Code/BusinessLogic/Persistence.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using VAR.Focus.Web.Code.JSON; - -namespace VAR.Focus.Web.Code.BusinessLogic -{ - public class Persistence - { - #region Private methods - - 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); - } - - #endregion - - #region public methods - - public static List LoadList(string file) - { - return LoadList(file, null); - } - - public static List LoadList(string file, List types) - { - List listResult = new List(); - JsonParser parser = new JsonParser(); - Type typeResult = typeof(T); - if (typeResult.IsInterface == false) - { - parser.KnownTypes.Add(typeof(T)); - } - if (types != null) - { - foreach (Type type in types) - { - parser.KnownTypes.Add(type); - } - } - string filePath = GetLocalPath(string.Format("priv/{0}.json", file)); - if (File.Exists(filePath) == false) { return listResult; } - - string strJsonUsers = File.ReadAllText(filePath); - object result = parser.Parse(strJsonUsers); - - if (result is IEnumerable) - { - foreach (object item in (IEnumerable)result) - { - if (item is T) - { - listResult.Add((T)item); - } - } - } - return listResult; - } - - public static bool SaveList(string file, object data) - { - JsonWriter writter = new JsonWriter(true); - string strJsonUsers = writter.Write(data); - string filePath = GetLocalPath(string.Format("priv/{0}.json", file)); - File.WriteAllText(filePath, strJsonUsers); - return true; - } - - #endregion - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/BusinessLogic/Sessions.cs b/VAR.Focus.Web/Code/BusinessLogic/Sessions.cs deleted file mode 100644 index c4711a2..0000000 --- a/VAR.Focus.Web/Code/BusinessLogic/Sessions.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Web; -using VAR.Focus.Web.Code.Entities; - -namespace VAR.Focus.Web.Code.BusinessLogic -{ - public class Sessions - { - #region declarations - - private static Sessions _currentInstance = null; - - private List _sessions = new List(); - - private string _cookieName = "FocusSID"; - private int _cookieExpirationDays = 30; - - #endregion - - #region Properties - - public static Sessions Current - { - get - { - if (_currentInstance == null) - { - _currentInstance = new Sessions(); - } - return _currentInstance; - } - set { _currentInstance = value; } - } - - public string CookieName - { - get { return _cookieName; } - set { _cookieName = value; } - } - - public int CookieExpirationDays - { - get { return _cookieExpirationDays; } - set { _cookieExpirationDays = value; } - } - - #endregion - - #region Life cycle - - public Sessions() - { - LoadData(); - } - - #endregion - - #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 bool Session_Init(HttpContext context, string userName) - { - lock (_sessions) - { - var session = new Session(); - session.UserName = userName; - session.SessionToken = CryptoUtils.GetCryptoToken(); - session.StartDate = DateTime.UtcNow; - _sessions.Add(session); - - Session_SetCookie(context, session); - - SaveData(); - } - return true; - } - - 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 = Session_GetByToken(sessionToken); - return session; - } - - public bool Session_FinalizeCurrent(HttpContext context) - { - lock (_sessions) - { - Session session = Session_GetCurrent(context); - if (session == null) { return false; } - - if (_sessions.Remove(session) == false) { return false; } - - HttpCookie cookie = new HttpCookie(_cookieName); - cookie.Expires = DateTime.Now.AddDays(-1d); - context.Response.Cookies.Add(cookie); - - SaveData(); - } - return true; - } - - #endregion - - #region Private methods - - private Session Session_GetByToken(string sessionToken) - { - foreach (Session session in _sessions) - { - if (session.SessionToken == sessionToken) - { - return session; - } - } - return null; - } - - #region Persistence - - private const string PersistenceFile = "sessions"; - - private void LoadData() - { - _sessions = Persistence.LoadList(PersistenceFile); - } - - private void SaveData() - { - Persistence.SaveList(PersistenceFile, _sessions); - } - - #endregion - - #endregion - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/BusinessLogic/Users.cs b/VAR.Focus.Web/Code/BusinessLogic/Users.cs deleted file mode 100644 index 0166598..0000000 --- a/VAR.Focus.Web/Code/BusinessLogic/Users.cs +++ /dev/null @@ -1,143 +0,0 @@ -using System.Collections.Generic; -using VAR.Focus.Web.Code.Entities; - -namespace VAR.Focus.Web.Code.BusinessLogic -{ - public class Users - { - #region declarations - - private static Users _currentInstance = null; - - private List _users = new List(); - - #endregion - - #region Properties - - public static Users Current - { - get - { - if (_currentInstance == null) - { - _currentInstance = new Users(); - } - return _currentInstance; - } - set { _currentInstance = value; } - } - - #endregion - - #region Life cycle - - public Users() - { - LoadData(); - } - - #endregion - - #region Public methods - - public User User_GetByName(string name) - { - name=name.ToLower(); - foreach (User userAux in _users) - { - if (name.CompareTo(userAux.Name.ToLower()) == 0) - { - return userAux; - } - } - return null; - } - - public User User_GetByEmail(string email) - { - email = email.ToLower(); - foreach (User userAux in _users) - { - if (email.CompareTo(userAux.Email.ToLower()) == 0) - { - return userAux; - } - } - return null; - } - - public User User_GetByNameOrEmail(string name, string email) - { - name = name.ToLower(); - email = email.ToLower(); - foreach (User userAux in _users) - { - if (name.CompareTo(userAux.Name.ToLower()) == 0 || - email.CompareTo(userAux.Email.ToLower()) == 0) - { - return userAux; - } - } - return null; - } - - public User User_Set(string name, string email, string password) - { - User user = null; - bool isNew = false; - lock (_users) - { - user = User_GetByName(name); - if (user == null) { user = User_GetByEmail(name); } - if (user == null) { user = new User(); isNew = true; } - - user.Name = name; - user.Email = email; - if (string.IsNullOrEmpty(password) == false) - { - user.PasswordSalt = CryptoUtils.GetCryptoToken(); - user.PasswordHash = CryptoUtils.GetHashedPassword(password, user.PasswordSalt); - } - - if (isNew) { _users.Add(user); } - - SaveData(); - } - return user; - } - - public bool User_Authenticate(string nameOrMail, string password) - { - User user = User_GetByNameOrEmail(nameOrMail, nameOrMail); - if (user == null) { return false; } - - string passwordHash = CryptoUtils.GetHashedPassword(password, user.PasswordSalt); - if (passwordHash != user.PasswordHash) { return false; } - - return true; - } - - #endregion - - #region Private methods - - #region Persistence - - private const string PersistenceFile = "users"; - - private void LoadData() - { - _users = Persistence.LoadList(PersistenceFile); - } - - private void SaveData() - { - Persistence.SaveList(PersistenceFile, _users); - } - - #endregion - - #endregion - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/CryptoUtils.cs b/VAR.Focus.Web/Code/CryptoUtils.cs deleted file mode 100644 index 74ec509..0000000 --- a/VAR.Focus.Web/Code/CryptoUtils.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Security.Cryptography; -using System.Text; - -namespace VAR.Focus.Web.Code -{ - public class CryptoUtils - { - public static string GetSHA1(string str) - { - SHA1 sha1 = SHA1.Create(); - UTF8Encoding encoding = new UTF8Encoding(); - byte[] stream = null; - StringBuilder sb = new StringBuilder(); - stream = sha1.ComputeHash(encoding.GetBytes(str)); - for (int i = 0; i < stream.Length; i++) sb.AppendFormat("{0:x2}", stream[i]); - return sb.ToString(); - } - - public static string GetRandString(int len) - { - byte[] bytes = new byte[len]; - var cryptoRandom = new RNGCryptoServiceProvider(); - cryptoRandom.GetBytes(bytes); - - UTF8Encoding encoding = new UTF8Encoding(); - return encoding.GetString(bytes); - } - - public static string GetCryptoToken() - { - return GetSHA1(GetRandString(10)); - } - - public static string GetHashedPassword(string password, string passwordSalt) - { - return GetSHA1(string.Format("{1}{0}{1}", password, passwordSalt)); - } - - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/Entities/Board.cs b/VAR.Focus.Web/Code/Entities/Board.cs deleted file mode 100644 index 96ef1bb..0000000 --- a/VAR.Focus.Web/Code/Entities/Board.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace VAR.Focus.Web.Code.Entities -{ - public class Board - { - public int IDBoard { get; set; } - - public string Title { get; set; } - public string Description { get; set; } - - private bool _active = true; - public bool Active { get { return _active; } set { _active = value; } } - public string CreatedBy { get; set; } - public DateTime CreatedDate { get; set; } - public string ModifiedBy { get; set; } - public DateTime ModifiedDate { get; set; } - } -} diff --git a/VAR.Focus.Web/Code/Entities/Card.cs b/VAR.Focus.Web/Code/Entities/Card.cs deleted file mode 100644 index c0968db..0000000 --- a/VAR.Focus.Web/Code/Entities/Card.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace VAR.Focus.Web.Code.Entities -{ - public class Card - { - public int IDCard { get; set; } - - public string Title { get; set; } - public string Body { get; set; } - - public int X { get; set; } - public int Y { get; set; } - - private bool _active = true; - public bool Active { get { return _active; } set { _active = value; } } - public string CreatedBy { get; set; } - public DateTime CreatedDate { get; set; } - public string ModifiedBy { get; set; } - public DateTime ModifiedDate { get; set; } - } -} diff --git a/VAR.Focus.Web/Code/Entities/CardEvents.cs b/VAR.Focus.Web/Code/Entities/CardEvents.cs deleted file mode 100644 index 4a03167..0000000 --- a/VAR.Focus.Web/Code/Entities/CardEvents.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; - -namespace VAR.Focus.Web.Code.Entities -{ - public interface ICardEvent - { - int IDCardEvent { get; set; } - string EventType { get; set; } - int IDCard { get; set; } - string UserName { get; set; } - DateTime Date { get; set; } - } - - public class CardCreateEvent : ICardEvent - { - #region ICardEvent - - public int IDCardEvent { get; set; } - private string _eventType="CardCreate"; - public string EventType { get { return _eventType; } set { _eventType = value; } } - public int IDCard { get; set; } - public string UserName { get; set; } - public DateTime Date { get; set; } - - #endregion - - public string Title { get; set; } - public string Body { get; set; } - - public int X { get; set; } - public int Y { get; set; } - } - - public class CardMoveEvent : ICardEvent - { - #region ICardEvent - - public int IDCardEvent { get; set; } - private string _eventType = "CardMove"; - public string EventType { get { return _eventType; } set { _eventType = value; } } - public int IDCard { get; set; } - public string UserName { get; set; } - public DateTime Date { get; set; } - - #endregion - - public int X { get; set; } - public int Y { get; set; } - } - - public class CardEditEvent : ICardEvent - { - #region ICardEvent - - public int IDCardEvent { get; set; } - private string _eventType = "CardEdit"; - public string EventType { get { return _eventType; } set { _eventType = value; } } - public int IDCard { get; set; } - public string UserName { get; set; } - public DateTime Date { get; set; } - - #endregion - - public string Title { get; set; } - public string Body { get; set; } - } - - public class CardDeleteEvent : ICardEvent - { - #region ICardEvent - - public int IDCardEvent { get; set; } - private string _eventType = "CardDelete"; - public string EventType { get { return _eventType; } set { _eventType = value; } } - public int IDCard { get; set; } - public string UserName { get; set; } - public DateTime Date { get; set; } - - #endregion - } -} diff --git a/VAR.Focus.Web/Code/Entities/Group.cs b/VAR.Focus.Web/Code/Entities/Group.cs deleted file mode 100644 index 10a8ca0..0000000 --- a/VAR.Focus.Web/Code/Entities/Group.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace VAR.Focus.Web.Code.Entities -{ - public class Group - { - public string Name { get; set; } - public string Description { get; set; } - - private bool _active = true; - public bool Active { get { return _active; } set { _active = value; } } - public string CreatedBy { get; set; } - public DateTime CreatedDate { get; set; } - public string ModifiedBy { get; set; } - public DateTime ModifiedDate { get; set; } - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/Entities/GroupMember.cs b/VAR.Focus.Web/Code/Entities/GroupMember.cs deleted file mode 100644 index ac7eed2..0000000 --- a/VAR.Focus.Web/Code/Entities/GroupMember.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace VAR.Focus.Web.Code.Entities -{ - public class GroupMember - { - public string UserName { get; set; } - public string GroupName { get; set; } - - private bool _active = true; - public bool Active { get { return _active; } set { _active = value; } } - public string CreatedBy { get; set; } - public DateTime CreatedDate { get; set; } - public string ModifiedBy { get; set; } - public DateTime ModifiedDate { get; set; } - } -} diff --git a/VAR.Focus.Web/Code/Entities/Message.cs b/VAR.Focus.Web/Code/Entities/Message.cs deleted file mode 100644 index 164b6ba..0000000 --- a/VAR.Focus.Web/Code/Entities/Message.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace VAR.Focus.Web.Code.Entities -{ - public class Message - { - public int IDMessage { get; set; } - public string UserName { get; set; } - public string Text { get; set; } - public DateTime Date { get; set; } - }; -} diff --git a/VAR.Focus.Web/Code/Entities/OperationStatus.cs b/VAR.Focus.Web/Code/Entities/OperationStatus.cs deleted file mode 100644 index 4bed1f5..0000000 --- a/VAR.Focus.Web/Code/Entities/OperationStatus.cs +++ /dev/null @@ -1,10 +0,0 @@ - -namespace VAR.Focus.Web.Code.Entities -{ - public class OperationStatus - { - public bool IsOK { get; set; } - public string Message { get; set; } - public string ReturnValue { get; set; } - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/Entities/Session.cs b/VAR.Focus.Web/Code/Entities/Session.cs deleted file mode 100644 index 1d7dbfa..0000000 --- a/VAR.Focus.Web/Code/Entities/Session.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace VAR.Focus.Web.Code.Entities -{ - public class Session - { - public string UserName { get; set; } - public string SessionToken { get; set; } - public DateTime StartDate { get; set; } - } -} diff --git a/VAR.Focus.Web/Code/Entities/User.cs b/VAR.Focus.Web/Code/Entities/User.cs deleted file mode 100644 index ec06c94..0000000 --- a/VAR.Focus.Web/Code/Entities/User.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace VAR.Focus.Web.Code.Entities -{ - public class User - { - public string Name { get; set; } - public string Email { get; set; } - public string PasswordHash { get; set; } - public string PasswordSalt { get; set; } - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/ExtensionMethods.cs b/VAR.Focus.Web/Code/ExtensionMethods.cs index ae236f6..551b8b2 100644 --- a/VAR.Focus.Web/Code/ExtensionMethods.cs +++ b/VAR.Focus.Web/Code/ExtensionMethods.cs @@ -1,5 +1,5 @@ using System.Web; -using VAR.Focus.Web.Code.JSON; +using VAR.Focus.BusinessLogic.JSON; namespace VAR.Focus.Web.Code { diff --git a/VAR.Focus.Web/Code/JSON/JsonParser.cs b/VAR.Focus.Web/Code/JSON/JsonParser.cs deleted file mode 100644 index 733d38c..0000000 --- a/VAR.Focus.Web/Code/JSON/JsonParser.cs +++ /dev/null @@ -1,637 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Reflection; -using System.Text; - -namespace VAR.Focus.Web.Code.JSON -{ - public class JsonParser - { - #region Declarations - - private const int MaxRecursiveCount = 20; - - private ParserContext _ctx; - private bool _tainted = false; - - private List _knownTypes = new List(); - - #endregion Declarations - - #region Properties - - public bool Tainted - { - get { return _tainted; } - } - - public List KnownTypes - { - get { return _knownTypes; } - } - - #endregion Properties - - #region Private methods - - private static Dictionary _dictProperties = new Dictionary(); - - private PropertyInfo[] Type_GetProperties(Type type) - { - PropertyInfo[] typeProperties = null; - if (_dictProperties.ContainsKey(type)) { typeProperties = _dictProperties[type]; } - else - { - lock (_dictProperties) - { - if (_dictProperties.ContainsKey(type)) { typeProperties = _dictProperties[type]; } - else - { - typeProperties = type.GetProperties(BindingFlags.Public | BindingFlags.OptionalParamBinding | BindingFlags.Instance); - _dictProperties.Add(type, typeProperties); - } - } - } - return typeProperties; - } - - private float CompareToType(Dictionary obj, Type type) - { - PropertyInfo[] typeProperties = Type_GetProperties(type); - int count = 0; - foreach (PropertyInfo prop in typeProperties) - { - if (obj.ContainsKey(prop.Name)) - { - count++; - } - } - return ((float)count / (float)typeProperties.Length); - } - - private object ConvertToType(Dictionary obj, Type type) - { - PropertyInfo[] typeProperties = Type_GetProperties(type); - object newObj = ObjectActivator.CreateInstance(type); - foreach (PropertyInfo prop in typeProperties) - { - if (obj.ContainsKey(prop.Name)) - { - prop.SetValue(newObj, Convert.ChangeType(obj[prop.Name], prop.PropertyType), null); - } - } - return newObj; - } - - private object TryConvertToTypes(Dictionary obj) - { - Type bestMatch = null; - float bestMatchFactor = 0.0f; - foreach (Type type in _knownTypes) - { - float matchFactor = CompareToType(obj, type); - if (matchFactor > bestMatchFactor) - { - bestMatch = type; - bestMatchFactor = matchFactor; - } - } - if (bestMatch != null) - { - return ConvertToType(obj, bestMatch); - } - return obj; - } - - private int ParseHexShort() - { - int value = 0; - for (int i = 0; i < 4; i++) - { - char c = _ctx.Next(); - if (char.IsDigit(c)) - { - value = (value << 4) | (c - '0'); - } - else - { - c = char.ToLower(c); - if (c >= 'a' && c <= 'f') - { - value = (value << 4) | ((c - 'a') + 10); - } - } - } - return value; - } - - private string ParseQuotedString() - { - StringBuilder scratch = new StringBuilder(); - char c = _ctx.SkipWhite(); - if (c == '"') - { - c = _ctx.Next(); - } - do - { - if (c == '\\') - { - c = _ctx.Next(); - if (c == '"') - { - scratch.Append('"'); - } - else if (c == '\\') - { - scratch.Append('\\'); - } - else if (c == '/') - { - scratch.Append('/'); - } - else if (c == 'b') - { - scratch.Append('\b'); - } - else if (c == 'f') - { - scratch.Append('\f'); - } - else if (c == 'n') - { - scratch.Append('\n'); - } - else if (c == 'r') - { - scratch.Append('\r'); - } - else if (c == 't') - { - scratch.Append('\t'); - } - else if (c == 'u') - { - scratch.Append((char)ParseHexShort()); - } - else - { - // StrictRules: Mark as tainted on unknown escaped character - _tainted = true; - } - c = _ctx.Next(); - } - else if (c == '"') - { - _ctx.Next(); - break; - } - else - { - // StrictRules: Mark as tainted on ilegal characters - if (c == '\t' || c == '\n') { _tainted = true; } - - scratch.Append(c); - c = _ctx.Next(); - } - } while (!_ctx.AtEnd()); - return scratch.ToString(); - } - - private string ParseSingleQuotedString() - { - StringBuilder scratch = new StringBuilder(); - char c = _ctx.SkipWhite(); - if (c == '\'') - { - c = _ctx.Next(); - } - do - { - if (c == '\\') - { - c = _ctx.Next(); - if (c == '\'') - { - scratch.Append('\''); - } - else if (c == '\\') - { - scratch.Append('\\'); - } - else if (c == '/') - { - scratch.Append('/'); - } - else if (c == 'b') - { - scratch.Append('\b'); - } - else if (c == 'f') - { - scratch.Append('\f'); - } - else if (c == 'n') - { - scratch.Append('\n'); - } - else if (c == 'r') - { - scratch.Append('\r'); - } - else if (c == 't') - { - scratch.Append('\t'); - } - else if (c == 'u') - { - scratch.Append((char)ParseHexShort()); - } - else - { - // StrictRules: Mark as tainted on unknown escaped character - _tainted = true; - } - c = _ctx.Next(); - } - else if (c == '\'') - { - _ctx.Next(); - break; - } - else - { - // StrictRules: Mark as tainted on ilegal characters - if (c == '\t' || c == '\n') { _tainted = true; } - - scratch.Append(c); - c = _ctx.Next(); - } - } while (!_ctx.AtEnd()); - return scratch.ToString(); - } - - private string ParseString(bool mustBeQuoted = false) - { - char c = _ctx.SkipWhite(); - if (c == '"') - { - return ParseQuotedString(); - } - if (c == '\'') - { - _tainted = true; - return ParseSingleQuotedString(); - } - if (mustBeQuoted) { _tainted = true; } - StringBuilder scratch = new StringBuilder(); - - while (!_ctx.AtEnd() - && (char.IsLetter(c) || char.IsDigit(c) || c == '_')) - { - scratch.Append(c); - c = _ctx.Next(); - } - - return scratch.ToString(); - } - - private object ParseNumber() - { - StringBuilder scratch = new StringBuilder(); - bool isFloat = false; - bool isExp = false; - int numberLenght = 0; - int expLenght = 0; - char c; - c = _ctx.SkipWhite(); - - // Sign - if (c == '-') - { - scratch.Append('-'); - c = _ctx.Next(); - } - - // Integer part - bool leadingZeroes = true; - int leadingZeroesLenght = 0; - while (char.IsDigit(c)) - { - // Count leading zeroes - if (leadingZeroes && c == '0') { leadingZeroesLenght++; } - else { leadingZeroes = false; } - - scratch.Append(c); - c = _ctx.Next(); - numberLenght++; - } - - // StrictRules: Mark as tainted with leading zeroes - if ((leadingZeroesLenght > 0 && leadingZeroesLenght != numberLenght) || leadingZeroesLenght > 1) - { - _tainted = true; - } - - // Decimal part - if (c == '.') - { - isFloat = true; - scratch.Append("."); - c = _ctx.Next(); - while (char.IsDigit(c)) - { - scratch.Append(c); - c = _ctx.Next(); - numberLenght++; - } - } - - if (numberLenght == 0) - { - _tainted = true; - return null; - } - - // Exponential part - if (c == 'e' || c == 'E') - { - isFloat = true; - isExp = true; - scratch.Append('E'); - c = _ctx.Next(); - if (c == '+' || c == '-') - { - scratch.Append(c); - c = _ctx.Next(); - } - while (char.IsDigit(c)) - { - scratch.Append(c); - c = _ctx.Next(); - numberLenght++; - expLenght++; - } - } - - if (isExp && expLenght == 0) - { - _tainted = true; - return null; - } - - // Build number from the parsed string - string s = scratch.ToString(); - if (isFloat) - { - if (numberLenght < 17) - { - return Convert.ToDouble(s, CultureInfo.InvariantCulture); - } - else - { - return Convert.ToDecimal(s, CultureInfo.InvariantCulture); - } - } - else - { - return Convert.ToInt32(s); - } - } - - private List ParseArray(int recursiveCount = 1) - { - // StrictRules: Mark as tainted when MaxRecursiveCount is exceeded - if (recursiveCount >= MaxRecursiveCount) { _tainted = true; } - - bool correct = false; - char c = _ctx.SkipWhite(); - List array = new List(); - if (c == '[') - { - _ctx.Next(); - } - bool? expectValue = null; - do - { - c = _ctx.SkipWhite(); - if (c == ']') - { - // StrictRules: Mark as tainted when unexpected end of array - if (expectValue == true) { _tainted = true; } - correct = true; - _ctx.Next(); - break; - } - else if (c == ',') - { - // StrictRules: Mark as tainted when unexpected comma on array - if (expectValue == true || array.Count == 0) { _tainted = true; } - - _ctx.Next(); - expectValue = true; - } - else - { - // StrictRules: Mark as tainted when unexpected value on array - if (expectValue == false) { _tainted = true; } - - array.Add(ParseValue(recursiveCount + 1)); - expectValue = false; - } - } while (!_ctx.AtEnd()); - if (correct == false) - { - _tainted = true; - } - return array; - } - - private Dictionary ParseObject(int recursiveCount = 1) - { - // StrictRules: Mark as tainted when MaxRecursiveCount is exceeded - if (recursiveCount >= MaxRecursiveCount) { _tainted = true; } - - bool correct = false; - char c = _ctx.SkipWhite(); - Dictionary obj = new Dictionary(); - if (c == '{') - { - _ctx.Next(); - } - string attributeName = null; - object attributeValue; - bool? expectedKey = null; - bool? expectedValue = null; - do - { - c = _ctx.SkipWhite(); - if (c == ':') - { - _ctx.Next(); - if (expectedValue == true) - { - attributeValue = ParseValue(recursiveCount + 1); - obj.Add(attributeName, attributeValue); - expectedKey = null; - expectedValue = false; - } - } - else if (c == ',') - { - _ctx.Next(); - c = _ctx.SkipWhite(); - expectedKey = true; - expectedValue = false; - } - else if (c == '}') - { - // StrictRules: Mark as tainted on unexpected end of object - if (expectedValue == true || expectedKey == true) - { - _tainted = true; - } - correct = true; - _ctx.Next(); - break; - } - else - { - if (expectedKey != false) - { - attributeName = ParseString(true); - c = _ctx.SkipWhite(); - expectedKey = false; - expectedValue = true; - } - else - { - // Unexpected character - _tainted = true; - break; - } - } - } while (!_ctx.AtEnd()); - if (correct == false) - { - _tainted = true; - } - return obj; - } - - private object ParseValue(int recusiveCount = 1) - { - object token = null; - char c = _ctx.SkipWhite(); - switch (c) - { - case '"': - token = ParseQuotedString(); - break; - - case '\'': - // StrictRules: Mark as tainted when parsing single quoted strings - _tainted = true; - token = ParseSingleQuotedString(); - break; - - case '{': - Dictionary obj = ParseObject(recusiveCount); - token = TryConvertToTypes(obj); - break; - - case '[': - token = ParseArray(recusiveCount); - break; - - default: - if (char.IsDigit(c) || c == '-') - { - token = ParseNumber(); - } - else - { - string aux = ParseString(); - if (aux.CompareTo("true") == 0) - { - token = true; - } - else if (aux.CompareTo("false") == 0) - { - token = false; - } - else if (aux.CompareTo("null") == 0) - { - token = null; - } - else - { - // Unexpected string - if (aux.Length == 0) - { - _ctx.Next(); - } - _tainted = true; - token = null; - } - } - break; - } - return token; - } - - private string CleanIdentifier(string input) - { - int i; - char c; - i = input.Length - 1; - if (i < 0) - { - return input; - } - c = input[i]; - while (char.IsLetter(c) || char.IsDigit(c) || c == '_') - { - i--; - if (i < 0) - { - break; - } - c = input[i]; - } - return input.Substring(i + 1); - } - - #endregion Private methods - - #region Public methods - - public object Parse(string text) - { - // Get the first object - _ctx = new ParserContext(text); - _tainted = false; - _ctx.Mark(); - object obj = ParseValue(); - _ctx.SkipWhite(); - if (_ctx.AtEnd()) - { - // StrictRules: Mark as tainted when top level is not object or array - if (obj is string || obj is decimal || obj is int || obj is double || obj is float) - { - _tainted = true; - } - - return obj; - } - - // StrictRules: Mark as tainted when there is more content - _tainted = true; - - return obj; - } - - #endregion Public methods - } -} diff --git a/VAR.Focus.Web/Code/JSON/JsonWriter.cs b/VAR.Focus.Web/Code/JSON/JsonWriter.cs deleted file mode 100644 index da83782..0000000 --- a/VAR.Focus.Web/Code/JSON/JsonWriter.cs +++ /dev/null @@ -1,337 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using System.Text; - -namespace VAR.Focus.Web.Code.JSON -{ - public class JsonWriter - { - #region Declarations - - private bool _indent = false; - private bool _useTabForIndent = false; - private int _indentChars = 4; - private int _indentThresold = 3; - - #endregion Declarations - - #region Creator - - public JsonWriter() - { - } - - public JsonWriter(int indentChars) - { - this._indent = true; - this._indentChars = indentChars; - this._useTabForIndent = false; - } - - public JsonWriter(bool useTabForIndent) - { - this._indent = true; - this._useTabForIndent = useTabForIndent; - } - - #endregion Creator - - #region Private methods - - private bool IsValue(Object obj) - { - if (obj == null) - { - return true; - } - if ((obj is float) || (obj is double) || - (obj is System.Int16) || (obj is System.Int32) || (obj is System.Int64) - || (obj is String) || (obj is Boolean)) - { - return true; - } - return false; - } - - private void WriteIndent(StringBuilder sbOutput, int level) - { - if (!_indent) - { - return; - } - sbOutput.Append('\n'); - if (_useTabForIndent) - { - for (int i = 0; i < level; i++) { sbOutput.Append('\t'); } - } - else - { - int n = level * _indentChars; - for (int i = 0; i < n; i++) { sbOutput.Append(' '); } - } - } - - private void WriteString(StringBuilder sbOutput, string str) - { - sbOutput.Append('"'); - char c; - int n = str.Length; - for (int i = 0; i < n; i++) - { - c = str[i]; - if (c == '"') { sbOutput.Append("\\\""); } - else if (c == '\\') { sbOutput.Append("\\\\"); } - else if (c == '/') { sbOutput.Append("\\/"); } - else if (c == '\b') { sbOutput.Append("\\b"); } - else if (c == '\f') { sbOutput.Append("\\f"); } - else if (c == '\n') { sbOutput.Append("\\n"); } - else if (c == '\r') { sbOutput.Append("\\r"); } - else if (c == '\t') { sbOutput.Append("\\t"); } - else if (c < 32 || c >= 127) { sbOutput.AppendFormat("\\u{0:X04}", (int)c); } - else { sbOutput.Append(c); } - } - sbOutput.Append('"'); - } - - private void WriteValue(StringBuilder sbOutput, Object obj, int level, bool useReflection) - { - if (obj == null || obj is DBNull) - { - // NULL - sbOutput.Append("null"); - } - else if ((obj is float) || (obj is double) || - (obj is System.Int16) || (obj is System.Int32) || (obj is System.Int64)) - { - // Numbers - sbOutput.Append(obj.ToString()); - } - else if (obj is String) - { - // Strings - WriteString(sbOutput, (String)obj); - } - else if (obj is Boolean) - { - // Booleans - sbOutput.Append(((Boolean)obj) ? "true" : "false"); - } - else if (obj is DateTime) - { - // DateTime - sbOutput.Append('"'); - sbOutput.Append(((DateTime)obj).ToString("yyyy-MM-ddTHH:mm:ssZ")); - sbOutput.Append('"'); - } - else if (obj is IDictionary) - { - // Objects - WriteObject(sbOutput, obj, level); - } - else if (obj is IEnumerable) - { - // Array/List - WriteList(sbOutput, obj, level); - } - else - { - if (useReflection) - { - // Reflected object - WriteReflectedObject(sbOutput, obj, level); - } - else - { - WriteString(sbOutput, Convert.ToString(obj)); - } - } - } - - private void WriteList(StringBuilder sbOutput, Object obj, int level) - { - IEnumerable list = (IEnumerable)obj; - int n = 0; - - // Check if it is a leaf object - bool isLeaf = true; - foreach (object childObj in list) - { - if (!IsValue(childObj)) - { - isLeaf = false; - } - n++; - } - - // Empty - if (n == 0) - { - sbOutput.Append("[ ]"); - return; - } - - // Write array - bool first = true; - sbOutput.Append("[ "); - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level + 1); - } - foreach (object childObj in list) - { - if (!first) - { - sbOutput.Append(", "); - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level + 1); - } - } - first = false; - WriteValue(sbOutput, childObj, level + 1, true); - } - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level); - } - sbOutput.Append(" ]"); - } - - private void WriteObject(StringBuilder sbOutput, Object obj, int level) - { - IDictionary map = (IDictionary)obj; - int n = map.Count; - - // Empty - if (map.Count == 0) - { - sbOutput.Append("{ }"); - return; - } - - // Check if it is a leaf object - bool isLeaf = true; - foreach (object value in map.Values) - { - if (!IsValue(value)) - { - isLeaf = false; - break; - } - } - - // Write object - bool first = true; - sbOutput.Append("{ "); - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level + 1); - } - foreach (object key in map.Keys) - { - object value = map[key]; - if (!first) - { - sbOutput.Append(", "); - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level + 1); - } - } - first = false; - WriteString(sbOutput, Convert.ToString(key)); - sbOutput.Append(": "); - WriteValue(sbOutput, value, level + 1, true); - } - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level); - } - sbOutput.Append(" }"); - } - - private void WriteReflectedObject(StringBuilder sbOutput, Object obj, int level) - { - Type type = obj.GetType(); - PropertyInfo[] rawProperties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); - List properties = new List(); - foreach (PropertyInfo property in rawProperties) - { - if (property.CanRead) - { - properties.Add(property); - } - } - int n = properties.Count; - - // Empty - if (n == 0) - { - sbOutput.Append("{ }"); - return; - } - - // Check if it is a leaf object - bool isLeaf = true; - foreach (PropertyInfo property in properties) - { - object value = property.GetValue(obj, null); - if (!IsValue(value)) - { - isLeaf = false; - break; - } - } - - // Write object - bool first = true; - sbOutput.Append("{ "); - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level + 1); - } - foreach (PropertyInfo property in properties) - { - object value = null; - MethodInfo getMethod = property.GetGetMethod(); - ParameterInfo[] parameters = getMethod.GetParameters(); - if (parameters.Length == 0) - { - value = property.GetValue(obj, null); - } - if (!first) - { - sbOutput.Append(", "); - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level + 1); - } - } - first = false; - WriteString(sbOutput, property.Name); - sbOutput.Append(": "); - WriteValue(sbOutput, value, level + 1, false); - } - if (!isLeaf || n > _indentThresold) - { - WriteIndent(sbOutput, level); - } - sbOutput.Append(" }"); - } - - #endregion Private methods - - #region Public methods - - public String Write(Object obj) - { - StringBuilder sbOutput = new StringBuilder(); - WriteValue(sbOutput, obj, 0, true); - return sbOutput.ToString(); - } - - #endregion Public methods - } -} diff --git a/VAR.Focus.Web/Code/JSON/ParserContext.cs b/VAR.Focus.Web/Code/JSON/ParserContext.cs deleted file mode 100644 index e2fd8b8..0000000 --- a/VAR.Focus.Web/Code/JSON/ParserContext.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; - -namespace VAR.Focus.Web.Code.JSON -{ - public class ParserContext - { - #region Declarations - - private string _text; - private int _length; - private int _i; - private int _markStart; - - #endregion Declarations - - #region Creator - - public ParserContext(string text) - { - _text = text; - _length = text.Length; - _i = 0; - _markStart = 0; - } - - #endregion Creator - - #region Public methods - - public char SkipWhite() - { - while (_i < _length && char.IsWhiteSpace(_text[_i])) - { - _i++; - } - if (AtEnd()) - { - return (char)0; - } - return _text[_i]; - } - - public char Next() - { - _i++; - if (AtEnd()) - { - return (char)0; - } - return _text[_i]; - } - - public bool AtEnd() - { - return _i >= _length; - } - - public void Mark() - { - _markStart = _i; - } - - public string GetMarked() - { - if (_i < _length && _markStart < _length) - { - return _text.Substring(_markStart, _i - _markStart); - } - else - { - if (_markStart < _length) - { - return _text.Substring(_markStart, _length - _markStart); - } - else - { - return string.Empty; - } - } - } - - #endregion Public methods - } -} diff --git a/VAR.Focus.Web/Code/ObjectActivator.cs b/VAR.Focus.Web/Code/ObjectActivator.cs deleted file mode 100644 index c3fe4c9..0000000 --- a/VAR.Focus.Web/Code/ObjectActivator.cs +++ /dev/null @@ -1,36 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Linq.Expressions; - -namespace VAR.Focus.Web.Code -{ - public class ObjectActivator - { - private static Dictionary> _creators = new Dictionary>(); - - public static Func GetLambdaNew(Type type) - { - if (_creators.ContainsKey(type)) - { - return _creators[type]; - } - - lock (_creators) - { - NewExpression newExp = Expression.New(type); - LambdaExpression lambda = Expression.Lambda(typeof(Func), newExp); - Func compiledLambdaNew = (Func)lambda.Compile(); - - _creators.Add(type, compiledLambdaNew); - } - return _creators[type]; - } - - public static object CreateInstance(Type type) - { - Func creator = GetLambdaNew(type); - return creator(); - } - } -} diff --git a/VAR.Focus.Web/Code/WebSessions.cs b/VAR.Focus.Web/Code/WebSessions.cs new file mode 100644 index 0000000..f8c77d0 --- /dev/null +++ b/VAR.Focus.Web/Code/WebSessions.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +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 + + #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 + + #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; + } + + #endregion + + } +} \ No newline at end of file diff --git a/VAR.Focus.Web/Controls/CardBoardControl.cs b/VAR.Focus.Web/Controls/CardBoardControl.cs index abcf69f..4257bfb 100644 --- a/VAR.Focus.Web/Controls/CardBoardControl.cs +++ b/VAR.Focus.Web/Controls/CardBoardControl.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; -using VAR.Focus.Web.Code.JSON; +using VAR.Focus.BusinessLogic.JSON; namespace VAR.Focus.Web.Controls { diff --git a/VAR.Focus.Web/Controls/CardBoardHandler.cs b/VAR.Focus.Web/Controls/CardBoardHandler.cs index cf6d008..256a0bd 100644 --- a/VAR.Focus.Web/Controls/CardBoardHandler.cs +++ b/VAR.Focus.Web/Controls/CardBoardHandler.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Threading; using System.Web; +using VAR.Focus.BusinessLogic; +using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.Web.Code; -using VAR.Focus.Web.Code.BusinessLogic; -using VAR.Focus.Web.Code.Entities; namespace VAR.Focus.Web.Controls { @@ -136,7 +136,7 @@ namespace VAR.Focus.Web.Controls private void ProcessEventSender(HttpContext context) { - Session session = Sessions.Current.Session_GetCurrent(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); diff --git a/VAR.Focus.Web/Controls/ChatControl.cs b/VAR.Focus.Web/Controls/ChatControl.cs index fad1763..6caadb2 100644 --- a/VAR.Focus.Web/Controls/ChatControl.cs +++ b/VAR.Focus.Web/Controls/ChatControl.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; -using VAR.Focus.Web.Code.JSON; +using VAR.Focus.BusinessLogic.JSON; namespace VAR.Focus.Web.Controls { diff --git a/VAR.Focus.Web/Controls/ChatHandler.cs b/VAR.Focus.Web/Controls/ChatHandler.cs index f2117e4..f19152f 100644 --- a/VAR.Focus.Web/Controls/ChatHandler.cs +++ b/VAR.Focus.Web/Controls/ChatHandler.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Threading; using System.Web; +using VAR.Focus.BusinessLogic; +using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.Web.Code; -using VAR.Focus.Web.Code.BusinessLogic; -using VAR.Focus.Web.Code.Entities; namespace VAR.Focus.Web.Controls { @@ -95,7 +95,7 @@ namespace VAR.Focus.Web.Controls string idMessageBoard = context.GetRequestParm("IDMessageBoard"); if (string.IsNullOrEmpty(idMessageBoard)) { idMessageBoard = "root"; } string userName = Convert.ToString(context.GetRequestParm("UserName")); - Session session = Sessions.Current.Session_GetCurrent(context); + Session session = WebSessions.Current.Session_GetCurrent(context); if (session.UserName.ToLower() != userName.ToLower()) { context.ResponseObject(new OperationStatus { IsOK = false, Message = "User mismatch" }); diff --git a/VAR.Focus.Web/GlobalRouter.cs b/VAR.Focus.Web/GlobalRouter.cs index 9d105c8..4e19d41 100644 --- a/VAR.Focus.Web/GlobalRouter.cs +++ b/VAR.Focus.Web/GlobalRouter.cs @@ -4,6 +4,7 @@ using System.IO; using System.Reflection; using System.Threading; using System.Web; +using VAR.Focus.BusinessLogic.Utils; using VAR.Focus.Web.Code; namespace VAR.Focus.Web diff --git a/VAR.Focus.Web/Pages/FrmBoard.cs b/VAR.Focus.Web/Pages/FrmBoard.cs index 9cea58b..8f72f65 100644 --- a/VAR.Focus.Web/Pages/FrmBoard.cs +++ b/VAR.Focus.Web/Pages/FrmBoard.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Web.UI.WebControls; +using VAR.Focus.BusinessLogic; +using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.Web.Code; -using VAR.Focus.Web.Code.BusinessLogic; -using VAR.Focus.Web.Code.Entities; using VAR.Focus.Web.Controls; namespace VAR.Focus.Web.Pages diff --git a/VAR.Focus.Web/Pages/FrmBoardEdit.cs b/VAR.Focus.Web/Pages/FrmBoardEdit.cs index c4d7f6b..8d4ed14 100644 --- a/VAR.Focus.Web/Pages/FrmBoardEdit.cs +++ b/VAR.Focus.Web/Pages/FrmBoardEdit.cs @@ -1,8 +1,8 @@ using System; using System.Web.UI.WebControls; +using VAR.Focus.BusinessLogic; +using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.Web.Code; -using VAR.Focus.Web.Code.BusinessLogic; -using VAR.Focus.Web.Code.Entities; using VAR.Focus.Web.Controls; namespace VAR.Focus.Web.Pages diff --git a/VAR.Focus.Web/Pages/FrmEcho.cs b/VAR.Focus.Web/Pages/FrmEcho.cs index 13c1ac8..bd9c0d2 100644 --- a/VAR.Focus.Web/Pages/FrmEcho.cs +++ b/VAR.Focus.Web/Pages/FrmEcho.cs @@ -1,5 +1,5 @@ using System.Web; -using VAR.Focus.Web.Code.JSON; +using VAR.Focus.BusinessLogic.JSON; namespace VAR.Focus.Web.Pages { diff --git a/VAR.Focus.Web/Pages/FrmLogin.cs b/VAR.Focus.Web/Pages/FrmLogin.cs index 818ebc0..3f6c18e 100644 --- a/VAR.Focus.Web/Pages/FrmLogin.cs +++ b/VAR.Focus.Web/Pages/FrmLogin.cs @@ -1,6 +1,7 @@ using System; using System.Web.UI.WebControls; -using VAR.Focus.Web.Code.BusinessLogic; +using VAR.Focus.BusinessLogic; +using VAR.Focus.Web.Code; using VAR.Focus.Web.Controls; namespace VAR.Focus.Web.Pages @@ -42,7 +43,7 @@ namespace VAR.Focus.Web.Pages return; } - Sessions.Current.Session_Init(Context, _txtNameEmail.Text); + WebSessions.Current.Session_Init(Context, _txtNameEmail.Text); Response.Redirect(Globals.DefaultHandler); } diff --git a/VAR.Focus.Web/Pages/FrmRegister.cs b/VAR.Focus.Web/Pages/FrmRegister.cs index 3d5ee3a..4c44ab8 100644 --- a/VAR.Focus.Web/Pages/FrmRegister.cs +++ b/VAR.Focus.Web/Pages/FrmRegister.cs @@ -1,7 +1,7 @@ using System; using System.Web.UI.WebControls; -using VAR.Focus.Web.Code.BusinessLogic; -using VAR.Focus.Web.Code.Entities; +using VAR.Focus.BusinessLogic; +using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.Web.Controls; namespace VAR.Focus.Web.Pages diff --git a/VAR.Focus.Web/Pages/PageCommon.cs b/VAR.Focus.Web/Pages/PageCommon.cs index 63caa1a..5610b31 100644 --- a/VAR.Focus.Web/Pages/PageCommon.cs +++ b/VAR.Focus.Web/Pages/PageCommon.cs @@ -4,8 +4,9 @@ using System.Text; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; -using VAR.Focus.Web.Code.BusinessLogic; -using VAR.Focus.Web.Code.Entities; +using VAR.Focus.BusinessLogic; +using VAR.Focus.BusinessLogic.Entities; +using VAR.Focus.Web.Code; using VAR.Focus.Web.Controls; namespace VAR.Focus.Web.Pages @@ -57,13 +58,13 @@ namespace VAR.Focus.Web.Pages void PageCommon_PreInit(object sender, EventArgs e) { - Session session = Sessions.Current.Session_GetCurrent(Context); + Session session = WebSessions.Current.Session_GetCurrent(Context); if (session != null) { _currentUser = Users.Current.User_GetByName(session.UserName); if (_mustBeAutenticated) { - Sessions.Current.Session_SetCookie(Context, session); + WebSessions.Current.Session_SetCookie(Context, session); } } if (_currentUser == null && _mustBeAutenticated) @@ -89,7 +90,7 @@ namespace VAR.Focus.Web.Pages void btnLogout_Click(object sender, EventArgs e) { - Sessions.Current.Session_FinalizeCurrent(Context); + WebSessions.Current.Session_FinalizeCurrent(Context); _currentUser = null; if (_mustBeAutenticated) { diff --git a/VAR.Focus.Web/VAR.Focus.Web.csproj b/VAR.Focus.Web/VAR.Focus.Web.csproj index 8bb140f..81d6742 100644 --- a/VAR.Focus.Web/VAR.Focus.Web.csproj +++ b/VAR.Focus.Web/VAR.Focus.Web.csproj @@ -72,20 +72,8 @@ - - - - - - - - - - - - - + @@ -94,13 +82,7 @@ - - - - - - ASPXCodeBehind @@ -121,8 +103,6 @@ - - ASPXCodeBehind @@ -132,6 +112,12 @@ + + + {d88af21d-1c60-4b27-abff-a133d6afc51c} + VAR.Focus.BusinessLogic + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)