Split BusinessLogic from WebApp

This commit is contained in:
2016-12-13 22:09:38 +01:00
parent 4e0304d9a4
commit 577e8b4127
35 changed files with 125 additions and 2410 deletions

View File

@@ -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<Board> _boards = new List<Board>();
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<Board> 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<Board>(BoardsPersistenceFile);
_lastIDBoard = 0;
foreach (Board board in _boards)
{
if (board.IDBoard > _lastIDBoard)
{
_lastIDBoard = board.IDBoard;
}
}
}
private void SaveData()
{
Persistence.SaveList(BoardsPersistenceFile, _boards);
}
#endregion
#endregion
}
}

View File

@@ -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<Card> _cards = new List<Card>();
private int _lastIDCard = 0;
private List<ICardEvent> _cardEvents = new List<ICardEvent>();
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<Card> Cards_Status()
{
List<Card> activeCards=new List<Card>();
foreach (Card card in _cards)
{
if (card.Active)
{
activeCards.Add(card);
}
}
return activeCards;
}
public List<ICardEvent> Cards_GetEventList(int idCardEvent)
{
List<ICardEvent> listEvents = new List<ICardEvent>();
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<ICardEvent> ConvertCardsToEvents(List<Card> listCards, int lastIDCardEvent)
{
List<ICardEvent> listEvents = new List<ICardEvent>();
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<Card>(String.Format(CardsPersistenceFile, _idBoard));
_lastIDCard = 0;
foreach (Card card in _cards)
{
if (card.IDCard > _lastIDCard)
{
_lastIDCard = card.IDCard;
}
}
_cardEvents = Persistence.LoadList<ICardEvent>(String.Format(EventsPersistenceFile, _idBoard),
new List<Type> {
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
}
}

View File

@@ -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<Group> _groups = new List<Group>();
private List<GroupMember> _groupMembers = new List<GroupMember>();
#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<string> GroupMember_GetGroupNamesByUser(string userName)
{
List<string> groupNames = _groupMembers.Select(groupMember => groupMember.GroupName).ToList();
return groupNames;
}
public List<string> GroupMember_GetUserNamesByGroup(string groupName)
{
List<string> 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<Group>(GroupsPersistenceFile);
_groupMembers = Persistence.LoadList<GroupMember>(GroupMembersPersistenceFile);
}
private void SaveData()
{
Persistence.SaveList(GroupsPersistenceFile, _groups);
Persistence.SaveList(GroupMembersPersistenceFile, _groupMembers);
}
#endregion
#endregion
}
}

View File

@@ -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<Message> _messages = new List<Message>();
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<Message> Messages_GetList(int idMessage)
{
List<Message> listMessages = new List<Message>();
for (int i = 0, n = _messages.Count; i < n; i++)
{
Message msg = _messages[i];
if (msg.IDMessage > idMessage)
{
listMessages.Insert(0, msg);
}
else { break; }
}
return listMessages;
}
public void Message_Add(string userName, string text)
{
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<Message>(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
}
}

View File

@@ -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<T> LoadList<T>(string file)
{
return LoadList<T>(file, null);
}
public static List<T> LoadList<T>(string file, List<Type> types)
{
List<T> listResult = new List<T>();
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<object>)
{
foreach (object item in (IEnumerable<object>)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
}
}

View File

@@ -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<Session> _sessions = new List<Session>();
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<Session>(PersistenceFile);
}
private void SaveData()
{
Persistence.SaveList(PersistenceFile, _sessions);
}
#endregion
#endregion
}
}

View File

@@ -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<User> _users = new List<User>();
#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<User>(PersistenceFile);
}
private void SaveData()
{
Persistence.SaveList(PersistenceFile, _users);
}
#endregion
#endregion
}
}

View File

@@ -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));
}
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
};
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -1,5 +1,5 @@
using System.Web; using System.Web;
using VAR.Focus.Web.Code.JSON; using VAR.Focus.BusinessLogic.JSON;
namespace VAR.Focus.Web.Code namespace VAR.Focus.Web.Code
{ {

View File

@@ -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<Type> _knownTypes = new List<Type>();
#endregion Declarations
#region Properties
public bool Tainted
{
get { return _tainted; }
}
public List<Type> KnownTypes
{
get { return _knownTypes; }
}
#endregion Properties
#region Private methods
private static Dictionary<Type, PropertyInfo[]> _dictProperties = new Dictionary<Type, PropertyInfo[]>();
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<string, object> 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<string, object> 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<string, object> 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<object> 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<object> array = new List<object>();
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<string, object> 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<string, object> obj = new Dictionary<string, object>();
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<string, object> 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
}
}

View File

@@ -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<PropertyInfo> properties = new List<PropertyInfo>();
foreach (PropertyInfo property in rawProperties)
{
if (property.CanRead)
{
properties.Add(property);
}
}
int n = properties.Count;
// Empty
if (n == 0)
{
sbOutput.Append("{ }");
return;
}
// Check if it is a leaf object
bool isLeaf = true;
foreach (PropertyInfo property in properties)
{
object value = property.GetValue(obj, null);
if (!IsValue(value))
{
isLeaf = false;
break;
}
}
// Write object
bool first = true;
sbOutput.Append("{ ");
if (!isLeaf || n > _indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
foreach (PropertyInfo property in properties)
{
object value = null;
MethodInfo getMethod = property.GetGetMethod();
ParameterInfo[] parameters = getMethod.GetParameters();
if (parameters.Length == 0)
{
value = property.GetValue(obj, null);
}
if (!first)
{
sbOutput.Append(", ");
if (!isLeaf || n > _indentThresold)
{
WriteIndent(sbOutput, level + 1);
}
}
first = false;
WriteString(sbOutput, property.Name);
sbOutput.Append(": ");
WriteValue(sbOutput, value, level + 1, false);
}
if (!isLeaf || n > _indentThresold)
{
WriteIndent(sbOutput, level);
}
sbOutput.Append(" }");
}
#endregion 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
}
}

View File

@@ -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
}
}

View File

@@ -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<Type, Func<object>> _creators = new Dictionary<Type, Func<object>>();
public static Func<object> GetLambdaNew(Type type)
{
if (_creators.ContainsKey(type))
{
return _creators[type];
}
lock (_creators)
{
NewExpression newExp = Expression.New(type);
LambdaExpression lambda = Expression.Lambda(typeof(Func<object>), newExp);
Func<object> compiledLambdaNew = (Func<object>)lambda.Compile();
_creators.Add(type, compiledLambdaNew);
}
return _creators[type];
}
public static object CreateInstance(Type type)
{
Func<object> creator = GetLambdaNew(type);
return creator();
}
}
}

View File

@@ -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
}
}

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Web.UI; using System.Web.UI;
using System.Web.UI.WebControls; using System.Web.UI.WebControls;
using VAR.Focus.Web.Code.JSON; using VAR.Focus.BusinessLogic.JSON;
namespace VAR.Focus.Web.Controls namespace VAR.Focus.Web.Controls
{ {

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Web; using System.Web;
using VAR.Focus.BusinessLogic;
using VAR.Focus.BusinessLogic.Entities;
using VAR.Focus.Web.Code; using VAR.Focus.Web.Code;
using VAR.Focus.Web.Code.BusinessLogic;
using VAR.Focus.Web.Code.Entities;
namespace VAR.Focus.Web.Controls namespace VAR.Focus.Web.Controls
{ {
@@ -136,7 +136,7 @@ namespace VAR.Focus.Web.Controls
private void ProcessEventSender(HttpContext context) private void ProcessEventSender(HttpContext context)
{ {
Session session = Sessions.Current.Session_GetCurrent(context); Session session = WebSessions.Current.Session_GetCurrent(context);
string currentUserName = session.UserName; string currentUserName = session.UserName;
string strIDBoard = context.GetRequestParm("IDBoard"); string strIDBoard = context.GetRequestParm("IDBoard");
int idBoard = Convert.ToInt32(string.IsNullOrEmpty(strIDBoard) ? "0" : strIDBoard); int idBoard = Convert.ToInt32(string.IsNullOrEmpty(strIDBoard) ? "0" : strIDBoard);

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Web.UI; using System.Web.UI;
using System.Web.UI.WebControls; using System.Web.UI.WebControls;
using VAR.Focus.Web.Code.JSON; using VAR.Focus.BusinessLogic.JSON;
namespace VAR.Focus.Web.Controls namespace VAR.Focus.Web.Controls
{ {

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Web; using System.Web;
using VAR.Focus.BusinessLogic;
using VAR.Focus.BusinessLogic.Entities;
using VAR.Focus.Web.Code; using VAR.Focus.Web.Code;
using VAR.Focus.Web.Code.BusinessLogic;
using VAR.Focus.Web.Code.Entities;
namespace VAR.Focus.Web.Controls namespace VAR.Focus.Web.Controls
{ {
@@ -95,7 +95,7 @@ namespace VAR.Focus.Web.Controls
string idMessageBoard = context.GetRequestParm("IDMessageBoard"); string idMessageBoard = context.GetRequestParm("IDMessageBoard");
if (string.IsNullOrEmpty(idMessageBoard)) { idMessageBoard = "root"; } if (string.IsNullOrEmpty(idMessageBoard)) { idMessageBoard = "root"; }
string userName = Convert.ToString(context.GetRequestParm("UserName")); 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()) if (session.UserName.ToLower() != userName.ToLower())
{ {
context.ResponseObject(new OperationStatus { IsOK = false, Message = "User mismatch" }); context.ResponseObject(new OperationStatus { IsOK = false, Message = "User mismatch" });

View File

@@ -4,6 +4,7 @@ using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Web; using System.Web;
using VAR.Focus.BusinessLogic.Utils;
using VAR.Focus.Web.Code; using VAR.Focus.Web.Code;
namespace VAR.Focus.Web namespace VAR.Focus.Web

View File

@@ -1,9 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Web.UI.WebControls; using System.Web.UI.WebControls;
using VAR.Focus.BusinessLogic;
using VAR.Focus.BusinessLogic.Entities;
using VAR.Focus.Web.Code; using VAR.Focus.Web.Code;
using VAR.Focus.Web.Code.BusinessLogic;
using VAR.Focus.Web.Code.Entities;
using VAR.Focus.Web.Controls; using VAR.Focus.Web.Controls;
namespace VAR.Focus.Web.Pages namespace VAR.Focus.Web.Pages

View File

@@ -1,8 +1,8 @@
using System; using System;
using System.Web.UI.WebControls; using System.Web.UI.WebControls;
using VAR.Focus.BusinessLogic;
using VAR.Focus.BusinessLogic.Entities;
using VAR.Focus.Web.Code; using VAR.Focus.Web.Code;
using VAR.Focus.Web.Code.BusinessLogic;
using VAR.Focus.Web.Code.Entities;
using VAR.Focus.Web.Controls; using VAR.Focus.Web.Controls;
namespace VAR.Focus.Web.Pages namespace VAR.Focus.Web.Pages

View File

@@ -1,5 +1,5 @@
using System.Web; using System.Web;
using VAR.Focus.Web.Code.JSON; using VAR.Focus.BusinessLogic.JSON;
namespace VAR.Focus.Web.Pages namespace VAR.Focus.Web.Pages
{ {

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Web.UI.WebControls; 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; using VAR.Focus.Web.Controls;
namespace VAR.Focus.Web.Pages namespace VAR.Focus.Web.Pages
@@ -42,7 +43,7 @@ namespace VAR.Focus.Web.Pages
return; return;
} }
Sessions.Current.Session_Init(Context, _txtNameEmail.Text); WebSessions.Current.Session_Init(Context, _txtNameEmail.Text);
Response.Redirect(Globals.DefaultHandler); Response.Redirect(Globals.DefaultHandler);
} }

View File

@@ -1,7 +1,7 @@
using System; using System;
using System.Web.UI.WebControls; using System.Web.UI.WebControls;
using VAR.Focus.Web.Code.BusinessLogic; using VAR.Focus.BusinessLogic;
using VAR.Focus.Web.Code.Entities; using VAR.Focus.BusinessLogic.Entities;
using VAR.Focus.Web.Controls; using VAR.Focus.Web.Controls;
namespace VAR.Focus.Web.Pages namespace VAR.Focus.Web.Pages

View File

@@ -4,8 +4,9 @@ using System.Text;
using System.Web.UI; using System.Web.UI;
using System.Web.UI.HtmlControls; using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls; using System.Web.UI.WebControls;
using VAR.Focus.Web.Code.BusinessLogic; using VAR.Focus.BusinessLogic;
using VAR.Focus.Web.Code.Entities; using VAR.Focus.BusinessLogic.Entities;
using VAR.Focus.Web.Code;
using VAR.Focus.Web.Controls; using VAR.Focus.Web.Controls;
namespace VAR.Focus.Web.Pages namespace VAR.Focus.Web.Pages
@@ -57,13 +58,13 @@ namespace VAR.Focus.Web.Pages
void PageCommon_PreInit(object sender, EventArgs e) void PageCommon_PreInit(object sender, EventArgs e)
{ {
Session session = Sessions.Current.Session_GetCurrent(Context); Session session = WebSessions.Current.Session_GetCurrent(Context);
if (session != null) if (session != null)
{ {
_currentUser = Users.Current.User_GetByName(session.UserName); _currentUser = Users.Current.User_GetByName(session.UserName);
if (_mustBeAutenticated) if (_mustBeAutenticated)
{ {
Sessions.Current.Session_SetCookie(Context, session); WebSessions.Current.Session_SetCookie(Context, session);
} }
} }
if (_currentUser == null && _mustBeAutenticated) if (_currentUser == null && _mustBeAutenticated)
@@ -89,7 +90,7 @@ namespace VAR.Focus.Web.Pages
void btnLogout_Click(object sender, EventArgs e) void btnLogout_Click(object sender, EventArgs e)
{ {
Sessions.Current.Session_FinalizeCurrent(Context); WebSessions.Current.Session_FinalizeCurrent(Context);
_currentUser = null; _currentUser = null;
if (_mustBeAutenticated) if (_mustBeAutenticated)
{ {

View File

@@ -72,20 +72,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Code\Bundler.cs" /> <Compile Include="Code\Bundler.cs" />
<Compile Include="Code\BusinessLogic\Boards.cs" />
<Compile Include="Code\BusinessLogic\CardBoard.cs" />
<Compile Include="Code\BusinessLogic\Groups.cs" />
<Compile Include="Code\BusinessLogic\MessageBoard.cs" />
<Compile Include="Code\BusinessLogic\Persistence.cs" />
<Compile Include="Code\BusinessLogic\Sessions.cs" />
<Compile Include="Code\BusinessLogic\Users.cs" />
<Compile Include="Code\Entities\Board.cs" />
<Compile Include="Code\Entities\Card.cs" />
<Compile Include="Code\Entities\CardEvents.cs" />
<Compile Include="Code\Entities\Group.cs" />
<Compile Include="Code\Entities\GroupMember.cs" />
<Compile Include="Code\ExtensionMethods.cs" /> <Compile Include="Code\ExtensionMethods.cs" />
<Compile Include="Code\ObjectActivator.cs" /> <Compile Include="Code\WebSessions.cs" />
<Compile Include="Controls\CardBoardControl.cs" /> <Compile Include="Controls\CardBoardControl.cs" />
<Compile Include="Controls\CardBoardHandler.cs" /> <Compile Include="Controls\CardBoardHandler.cs" />
<Compile Include="Controls\CButton.cs" /> <Compile Include="Controls\CButton.cs" />
@@ -94,13 +82,7 @@
<Compile Include="Controls\CLabel.cs" /> <Compile Include="Controls\CLabel.cs" />
<Compile Include="Controls\CTextBox.cs" /> <Compile Include="Controls\CTextBox.cs" />
<Compile Include="Controls\IValidableControl.cs" /> <Compile Include="Controls\IValidableControl.cs" />
<Compile Include="Code\CryptoUtils.cs" />
<Compile Include="Code\Entities\Message.cs" />
<Compile Include="Code\Entities\OperationStatus.cs" />
<Compile Include="Code\Entities\Session.cs" />
<Compile Include="Code\Entities\User.cs" />
<Compile Include="Code\GlobalErrorHandler.cs" /> <Compile Include="Code\GlobalErrorHandler.cs" />
<Compile Include="Code\JSON\ParserContext.cs" />
<Compile Include="Pages\FormUtils.cs" /> <Compile Include="Pages\FormUtils.cs" />
<Compile Include="Pages\FrmBoard.cs"> <Compile Include="Pages\FrmBoard.cs">
<SubType>ASPXCodeBehind</SubType> <SubType>ASPXCodeBehind</SubType>
@@ -121,8 +103,6 @@
<Compile Include="Code\ScriptsBundler.cs" /> <Compile Include="Code\ScriptsBundler.cs" />
<Compile Include="Code\StylesBundler.cs" /> <Compile Include="Code\StylesBundler.cs" />
<Compile Include="GlobalRouter.cs" /> <Compile Include="GlobalRouter.cs" />
<Compile Include="Code\JSON\JsonParser.cs" />
<Compile Include="Code\JSON\JsonWriter.cs" />
<Compile Include="Pages\FrmError.cs"> <Compile Include="Pages\FrmError.cs">
<SubType>ASPXCodeBehind</SubType> <SubType>ASPXCodeBehind</SubType>
</Compile> </Compile>
@@ -132,6 +112,12 @@
<ItemGroup> <ItemGroup>
<WCFMetadata Include="Service References\" /> <WCFMetadata Include="Service References\" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VAR.Focus.BusinessLogic\VAR.Focus.BusinessLogic.csproj">
<Project>{d88af21d-1c60-4b27-abff-a133d6afc51c}</Project>
<Name>VAR.Focus.BusinessLogic</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>