From e414663d12c3dc7b4eddb0cff01c6eb910b294ef Mon Sep 17 00:00:00 2001 From: "Valeriano A.R" Date: Sun, 1 Mar 2020 11:54:12 +0100 Subject: [PATCH] Split VAR.WebForms.Common to a class library. --- VAR.Focus.Web/Code/WebSessions.cs | 20 +++++ VAR.Focus.Web/Controls/CtrCardBoard.cs | 4 +- VAR.Focus.Web/Controls/CtrChat.cs | 3 +- VAR.Focus.Web/Controls/HndCardBoard.cs | 1 + VAR.Focus.Web/Controls/HndChat.cs | 1 + VAR.Focus.Web/FocusGlobalConfig.cs | 29 +++++++ VAR.Focus.Web/Globals.cs | 14 ---- VAR.Focus.Web/Pages/FrmBoard.cs | 17 ++-- VAR.Focus.Web/Pages/FrmBoardEdit.cs | 7 +- VAR.Focus.Web/Pages/FrmLogin.cs | 6 +- VAR.Focus.Web/Pages/FrmRegister.cs | 7 +- VAR.Focus.Web/VAR.Focus.Web.csproj | 32 ++------ VAR.Focus.Web/packages.config | 2 +- VAR.Focus.Web/web.config | 8 +- .../Code/Bundler.cs | 2 +- .../Code/ExtensionMethods.cs | 4 +- VAR.WebForms.Common/Code/GlobalConfig.cs | 29 +++++++ .../Code/GlobalErrorHandler.cs | 4 +- VAR.WebForms.Common/Code/IGlobalConfig.cs | 19 +++++ .../Code/MultiLang.cs | 6 +- VAR.WebForms.Common/Code/ObjectActivator.cs | 35 +++++++++ .../Code/ScriptsBundler.cs | 2 +- .../Code/StaticFileHelper.cs | 2 +- .../Code/StylesBundler.cs | 2 +- .../Controls/CButton.cs | 2 +- .../Controls/CLabel.cs | 2 +- .../Controls/CTextBox.cs | 2 +- .../Controls/IValidableControl.cs | 2 +- .../GlobalModule.cs | 2 +- .../GlobalRouter.cs | 9 +-- .../Pages/FormUtils.cs | 4 +- .../Pages/FrmEcho.cs | 4 +- .../Pages/FrmError.cs | 4 +- .../Pages/PageCommon.cs | 44 ++++------- .../Properties/AssemblyInfo.cs | 36 +++++++++ .../VAR.WebForms.Common.csproj | 78 +++++++++++++++++++ VAR.WebForms.Common/packages.config | 4 + 37 files changed, 333 insertions(+), 116 deletions(-) create mode 100644 VAR.Focus.Web/FocusGlobalConfig.cs delete mode 100644 VAR.Focus.Web/Globals.cs rename {VAR.Focus.Web => VAR.WebForms.Common}/Code/Bundler.cs (94%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Code/ExtensionMethods.cs (92%) create mode 100644 VAR.WebForms.Common/Code/GlobalConfig.cs rename {VAR.Focus.Web => VAR.WebForms.Common}/Code/GlobalErrorHandler.cs (93%) create mode 100644 VAR.WebForms.Common/Code/IGlobalConfig.cs rename {VAR.Focus.Web => VAR.WebForms.Common}/Code/MultiLang.cs (93%) create mode 100644 VAR.WebForms.Common/Code/ObjectActivator.cs rename {VAR.Focus.Web => VAR.WebForms.Common}/Code/ScriptsBundler.cs (90%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Code/StaticFileHelper.cs (96%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Code/StylesBundler.cs (89%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Controls/CButton.cs (76%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Controls/CLabel.cs (91%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Controls/CTextBox.cs (96%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Controls/IValidableControl.cs (61%) rename {VAR.Focus.Web => VAR.WebForms.Common}/GlobalModule.cs (93%) rename {VAR.Focus.Web => VAR.WebForms.Common}/GlobalRouter.cs (92%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Pages/FormUtils.cs (93%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Pages/FrmEcho.cs (76%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Pages/FrmError.cs (93%) rename {VAR.Focus.Web => VAR.WebForms.Common}/Pages/PageCommon.cs (75%) create mode 100644 VAR.WebForms.Common/Properties/AssemblyInfo.cs create mode 100644 VAR.WebForms.Common/VAR.WebForms.Common.csproj create mode 100644 VAR.WebForms.Common/packages.config diff --git a/VAR.Focus.Web/Code/WebSessions.cs b/VAR.Focus.Web/Code/WebSessions.cs index 14cdd1a..c876a57 100644 --- a/VAR.Focus.Web/Code/WebSessions.cs +++ b/VAR.Focus.Web/Code/WebSessions.cs @@ -84,6 +84,26 @@ namespace VAR.Focus.Web.Code return true; } + public bool Session_IsUserAuthenticated(HttpContext context) + { + Session session = Session_GetCurrent(context); + if (session == null) { return false; } + User user = Users.Current.User_GetByName(session.UserName); + if (user == null) { return false; } + return true; + } + + public User Session_GetCurrentUser(HttpContext context) + { + Session session = Session_GetCurrent(context); + if (session == null) + { + return null; + } + User user = Users.Current.User_GetByName(session.UserName); + return user; + } + #endregion Public methods } } \ No newline at end of file diff --git a/VAR.Focus.Web/Controls/CtrCardBoard.cs b/VAR.Focus.Web/Controls/CtrCardBoard.cs index 9eb48de..ffa855a 100644 --- a/VAR.Focus.Web/Controls/CtrCardBoard.cs +++ b/VAR.Focus.Web/Controls/CtrCardBoard.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; -using VAR.Focus.Web.Code; using VAR.Focus.Web.Pages; using VAR.Json; +using VAR.WebForms.Common.Code; namespace VAR.Focus.Web.Controls { @@ -146,7 +146,7 @@ namespace VAR.Focus.Web.Controls {"DefaultRegionWidth", _defaultRegionWidth}, {"DefaultRegionHeight", _defaultRegionHeight}, {"Texts", new Dictionary { - {"Toolbox",MultiLang.GetLiteral( "Toolbox")}, + {"Toolbox", MultiLang.GetLiteral( "Toolbox")}, {"AddCard", MultiLang.GetLiteral("AddCard")}, {"AddRegion", MultiLang.GetLiteral("AddRegion")}, {"EditBoard", MultiLang.GetLiteral("Config")}, diff --git a/VAR.Focus.Web/Controls/CtrChat.cs b/VAR.Focus.Web/Controls/CtrChat.cs index 7bdc49c..99a2dcc 100644 --- a/VAR.Focus.Web/Controls/CtrChat.cs +++ b/VAR.Focus.Web/Controls/CtrChat.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; -using VAR.Focus.Web.Code; using VAR.Json; +using VAR.WebForms.Common.Code; +using VAR.WebForms.Common.Controls; namespace VAR.Focus.Web.Controls { diff --git a/VAR.Focus.Web/Controls/HndCardBoard.cs b/VAR.Focus.Web/Controls/HndCardBoard.cs index e55a30a..9fd4787 100644 --- a/VAR.Focus.Web/Controls/HndCardBoard.cs +++ b/VAR.Focus.Web/Controls/HndCardBoard.cs @@ -6,6 +6,7 @@ using VAR.Focus.BusinessLogic; using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.BusinessLogic.Persistence; using VAR.Focus.Web.Code; +using VAR.WebForms.Common.Code; namespace VAR.Focus.Web.Controls { diff --git a/VAR.Focus.Web/Controls/HndChat.cs b/VAR.Focus.Web/Controls/HndChat.cs index ed078f4..5f2d1d9 100644 --- a/VAR.Focus.Web/Controls/HndChat.cs +++ b/VAR.Focus.Web/Controls/HndChat.cs @@ -6,6 +6,7 @@ using VAR.Focus.BusinessLogic; using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.BusinessLogic.Persistence; using VAR.Focus.Web.Code; +using VAR.WebForms.Common.Code; namespace VAR.Focus.Web.Controls { diff --git a/VAR.Focus.Web/FocusGlobalConfig.cs b/VAR.Focus.Web/FocusGlobalConfig.cs new file mode 100644 index 0000000..4537fd4 --- /dev/null +++ b/VAR.Focus.Web/FocusGlobalConfig.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Web; +using VAR.Focus.Web.Code; +using VAR.Focus.Web.Pages; +using VAR.WebForms.Common.Code; + +namespace VAR.Focus.Web +{ + public class FocusGlobalConfig : IGlobalConfig + { + public string Title { get; } = "Focus"; + public string TitleSeparator { get; } = " :: "; + public string Author { get; } = "Valeriano Alfonso Rodriguez"; + public string Copyright { get; } = "Copyright (c) 2015-2018 by Valeriano Alfonso, All Right Reserved"; + public string DefaultHandler { get; } = nameof(FrmBoard); + public string LoginHandler { get; } = nameof(FrmLogin); + public List AllowedExtensions { get; } = new List { ".png", ".jpg", ".jpeg", ".gif", ".ico", ".wav", ".mp3", ".ogg", ".mp4", ".webm", ".webp", ".mkv", ".avi" }; + + public bool IsUserAuthenticated(HttpContext context) + { + return WebSessions.Current.Session_IsUserAuthenticated(context); + } + + public void UserUnauthenticate(HttpContext context) + { + WebSessions.Current.Session_FinalizeCurrent(context); + } + } +} \ No newline at end of file diff --git a/VAR.Focus.Web/Globals.cs b/VAR.Focus.Web/Globals.cs deleted file mode 100644 index a874624..0000000 --- a/VAR.Focus.Web/Globals.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; - -namespace VAR.Focus.Web -{ - public static class Globals - { - public const string Title = "Focus"; - public const string TitleSeparator = " :: "; - public const string Author = "Valeriano Alfonso Rodriguez"; - public const string Copyright = "Copyright (c) 2015-2018 by Valeriano Alfonso, All Right Reserved"; - public const string DefaultHandler = "FrmBoard"; - public static List AllowedExtensions = new List { ".png", ".jpg", ".jpeg", ".gif", ".ico", ".wav", ".mp3", ".ogg", ".mp4", ".webm", ".webp", ".mkv", ".avi" }; - } -} \ No newline at end of file diff --git a/VAR.Focus.Web/Pages/FrmBoard.cs b/VAR.Focus.Web/Pages/FrmBoard.cs index f8988ed..1be4267 100644 --- a/VAR.Focus.Web/Pages/FrmBoard.cs +++ b/VAR.Focus.Web/Pages/FrmBoard.cs @@ -6,6 +6,9 @@ using VAR.Focus.BusinessLogic; using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.Web.Code; using VAR.Focus.Web.Controls; +using VAR.WebForms.Common.Code; +using VAR.WebForms.Common.Controls; +using VAR.WebForms.Common.Pages; namespace VAR.Focus.Web.Pages { @@ -52,7 +55,8 @@ namespace VAR.Focus.Web.Pages { if (FormUtils.Controls_AreValid(Controls) == false) { return; } - Board board = Boards.Current.Boards_SetBoard(0, _txtTitle.Text, _txtDescription.Text, null, CurrentUser.Name); + User user = WebSessions.Current.Session_GetCurrentUser(Context); + Board board = Boards.Current.Boards_SetBoard(0, _txtTitle.Text, _txtDescription.Text, null, user.Name); _idBoard = board.IDBoard; Response.Redirect(GetUrl(_idBoard)); @@ -77,7 +81,8 @@ namespace VAR.Focus.Web.Pages CButton btnEdit = (CButton)sender; int idBoard = Convert.ToInt32(btnEdit.CommandArgument); - if (Boards.Current.Boards_DelBoard(idBoard, CurrentUser.Name)) + User user = WebSessions.Current.Session_GetCurrentUser(Context); + if (Boards.Current.Boards_DelBoard(idBoard, user.Name)) { Controls.Clear(); FrmBoard_InitIndex(); @@ -146,7 +151,8 @@ namespace VAR.Focus.Web.Pages { Title = "Boards"; - List boards = Boards.Current.Boards_GetListForUser(CurrentUser.Name); + User user = WebSessions.Current.Session_GetCurrentUser(Context); + List boards = Boards.Current.Boards_GetListForUser(user?.Name); foreach (Board board in boards) { Panel pnlBoardSelector = BoardSelector_Create(board); @@ -167,6 +173,7 @@ namespace VAR.Focus.Web.Pages private void FrmBoard_InitBoard() { + User user = WebSessions.Current.Session_GetCurrentUser(Context); Board board = Boards.Current.Board_GetByIDBoard(_idBoard); Title = board.Title; @@ -175,7 +182,7 @@ namespace VAR.Focus.Web.Pages { ID = "ctrCardBoard", IDBoard = board.IDBoard, - UserName = CurrentUser.Name, + UserName = user.Name, }; Controls.Add(cardBoardControl); @@ -183,7 +190,7 @@ namespace VAR.Focus.Web.Pages { ID = "ctrChat", IDMessageBoard = string.Format("CardBoard_{0}", board.IDBoard), - UserName = CurrentUser.Name, + UserName = user.Name, }; Controls.Add(chatControl); } diff --git a/VAR.Focus.Web/Pages/FrmBoardEdit.cs b/VAR.Focus.Web/Pages/FrmBoardEdit.cs index 0d22871..d502722 100644 --- a/VAR.Focus.Web/Pages/FrmBoardEdit.cs +++ b/VAR.Focus.Web/Pages/FrmBoardEdit.cs @@ -4,7 +4,9 @@ using System.Web.UI.WebControls; using VAR.Focus.BusinessLogic; using VAR.Focus.BusinessLogic.Entities; using VAR.Focus.Web.Code; -using VAR.Focus.Web.Controls; +using VAR.WebForms.Common.Code; +using VAR.WebForms.Common.Controls; +using VAR.WebForms.Common.Pages; namespace VAR.Focus.Web.Pages { @@ -59,12 +61,13 @@ namespace VAR.Focus.Web.Pages { if (FormUtils.Controls_AreValid(Controls) == false) { return; } + User user = WebSessions.Current.Session_GetCurrentUser(Context); Board board = Boards.Current.Boards_SetBoard( _idBoard, _txtTitle.Text, _txtDescription.Text, _txtDescription.GetClientsideHeight(), - CurrentUser.Name); + user.Name); // FIXME: Notify User of "Save Succesfully" } diff --git a/VAR.Focus.Web/Pages/FrmLogin.cs b/VAR.Focus.Web/Pages/FrmLogin.cs index 4213c6d..d4801e5 100644 --- a/VAR.Focus.Web/Pages/FrmLogin.cs +++ b/VAR.Focus.Web/Pages/FrmLogin.cs @@ -2,7 +2,9 @@ using System.Web.UI.WebControls; using VAR.Focus.BusinessLogic; using VAR.Focus.Web.Code; -using VAR.Focus.Web.Controls; +using VAR.WebForms.Common.Code; +using VAR.WebForms.Common.Controls; +using VAR.WebForms.Common.Pages; namespace VAR.Focus.Web.Pages { @@ -44,7 +46,7 @@ namespace VAR.Focus.Web.Pages } WebSessions.Current.Session_Init(Context, _txtNameEmail.Text); - Response.Redirect(Globals.DefaultHandler); + Response.Redirect(GlobalConfig.Get().DefaultHandler); } #endregion UI Events diff --git a/VAR.Focus.Web/Pages/FrmRegister.cs b/VAR.Focus.Web/Pages/FrmRegister.cs index 85540e7..52338d2 100644 --- a/VAR.Focus.Web/Pages/FrmRegister.cs +++ b/VAR.Focus.Web/Pages/FrmRegister.cs @@ -2,8 +2,9 @@ using System.Web.UI.WebControls; using VAR.Focus.BusinessLogic; using VAR.Focus.BusinessLogic.Entities; -using VAR.Focus.Web.Code; -using VAR.Focus.Web.Controls; +using VAR.WebForms.Common.Code; +using VAR.WebForms.Common.Controls; +using VAR.WebForms.Common.Pages; namespace VAR.Focus.Web.Pages { @@ -66,7 +67,7 @@ namespace VAR.Focus.Web.Pages private void btnExit_Click(object sender, EventArgs e) { - Response.Redirect(Globals.DefaultHandler); + Response.Redirect(GlobalConfig.Get().DefaultHandler); } #endregion UI Events diff --git a/VAR.Focus.Web/VAR.Focus.Web.csproj b/VAR.Focus.Web/VAR.Focus.Web.csproj index 3358efb..2bd831f 100644 --- a/VAR.Focus.Web/VAR.Focus.Web.csproj +++ b/VAR.Focus.Web/VAR.Focus.Web.csproj @@ -45,9 +45,8 @@ - - ..\packages\VAR.Json.1.0.6252.27492\lib\net461\VAR.Json.dll - True + + ..\packages\VAR.Json.1.1.1.36534\lib\net461\VAR.Json.dll @@ -82,45 +81,24 @@ - - - - - - - - - - - ASPXCodeBehind ASPXCodeBehind - ASPXCodeBehind ASPXCodeBehind - - ASPXCodeBehind - - - - - - ASPXCodeBehind - - + @@ -128,6 +106,10 @@ {d88af21d-1c60-4b27-abff-a133d6afc51c} VAR.Focus.BusinessLogic + + {328bb4e2-58f2-4beb-a619-ce3fa842ef43} + VAR.WebForms.Common + 10.0 diff --git a/VAR.Focus.Web/packages.config b/VAR.Focus.Web/packages.config index 76f48f9..4953ba8 100644 --- a/VAR.Focus.Web/packages.config +++ b/VAR.Focus.Web/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/VAR.Focus.Web/web.config b/VAR.Focus.Web/web.config index a8e6fdf..9bccd4f 100644 --- a/VAR.Focus.Web/web.config +++ b/VAR.Focus.Web/web.config @@ -4,11 +4,11 @@ - + - + @@ -16,11 +16,11 @@ - + - + diff --git a/VAR.Focus.Web/Code/Bundler.cs b/VAR.WebForms.Common/Code/Bundler.cs similarity index 94% rename from VAR.Focus.Web/Code/Bundler.cs rename to VAR.WebForms.Common/Code/Bundler.cs index b6c2409..9ef558b 100644 --- a/VAR.Focus.Web/Code/Bundler.cs +++ b/VAR.WebForms.Common/Code/Bundler.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Web; -namespace VAR.Focus.Web.Code +namespace VAR.WebForms.Common.Code { public class Bundler { diff --git a/VAR.Focus.Web/Code/ExtensionMethods.cs b/VAR.WebForms.Common/Code/ExtensionMethods.cs similarity index 92% rename from VAR.Focus.Web/Code/ExtensionMethods.cs rename to VAR.WebForms.Common/Code/ExtensionMethods.cs index 7a16763..fe66ed3 100644 --- a/VAR.Focus.Web/Code/ExtensionMethods.cs +++ b/VAR.WebForms.Common/Code/ExtensionMethods.cs @@ -2,7 +2,7 @@ using System.Web; using VAR.Json; -namespace VAR.Focus.Web.Code +namespace VAR.WebForms.Common.Code { public static class ExtensionMethods { @@ -22,7 +22,7 @@ namespace VAR.Focus.Web.Code public static void ResponseObject(this HttpContext context, object obj) { - var jsonWritter = new JsonWriter(true); + var jsonWritter = new JsonWriter(); context.Response.ContentType = "text/json"; string strObject = jsonWritter.Write(obj); context.Response.Write(strObject); diff --git a/VAR.WebForms.Common/Code/GlobalConfig.cs b/VAR.WebForms.Common/Code/GlobalConfig.cs new file mode 100644 index 0000000..c9335e3 --- /dev/null +++ b/VAR.WebForms.Common/Code/GlobalConfig.cs @@ -0,0 +1,29 @@ +using System; +using System.Linq; + +namespace VAR.WebForms.Common.Code +{ + public static class GlobalConfig + { + private static IGlobalConfig _globalConfig = null; + + public static IGlobalConfig Get() + { + if (_globalConfig == null) + { + Type iGlobalConfig = typeof(IGlobalConfig); + Type foundGlobalConfig = AppDomain.CurrentDomain + .GetAssemblies() + .SelectMany(x => x.GetTypes()) + .Where(x => + x.IsAbstract == false && + x.IsInterface == false && + iGlobalConfig.IsAssignableFrom(x) && + true) + .FirstOrDefault(); + _globalConfig = ObjectActivator.CreateInstance(foundGlobalConfig) as IGlobalConfig; + } + return _globalConfig; + } + } +} diff --git a/VAR.Focus.Web/Code/GlobalErrorHandler.cs b/VAR.WebForms.Common/Code/GlobalErrorHandler.cs similarity index 93% rename from VAR.Focus.Web/Code/GlobalErrorHandler.cs rename to VAR.WebForms.Common/Code/GlobalErrorHandler.cs index fcaaa8e..6d013a5 100644 --- a/VAR.Focus.Web/Code/GlobalErrorHandler.cs +++ b/VAR.WebForms.Common/Code/GlobalErrorHandler.cs @@ -1,9 +1,9 @@ using System; using System.Text; using System.Web; -using VAR.Focus.Web.Pages; +using VAR.WebForms.Common.Pages; -namespace VAR.Focus.Web.Code +namespace VAR.WebForms.Common.Code { public static class GlobalErrorHandler { diff --git a/VAR.WebForms.Common/Code/IGlobalConfig.cs b/VAR.WebForms.Common/Code/IGlobalConfig.cs new file mode 100644 index 0000000..01803a4 --- /dev/null +++ b/VAR.WebForms.Common/Code/IGlobalConfig.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Web; + +namespace VAR.WebForms.Common.Code +{ + public interface IGlobalConfig + { + string Title { get; } + string TitleSeparator { get; } + string Author { get; } + string Copyright { get; } + string DefaultHandler { get; } + string LoginHandler { get; } + List AllowedExtensions { get; } + + bool IsUserAuthenticated(HttpContext context); + void UserUnauthenticate(HttpContext context); + } +} diff --git a/VAR.Focus.Web/Code/MultiLang.cs b/VAR.WebForms.Common/Code/MultiLang.cs similarity index 93% rename from VAR.Focus.Web/Code/MultiLang.cs rename to VAR.WebForms.Common/Code/MultiLang.cs index a09bd86..6aea3aa 100644 --- a/VAR.Focus.Web/Code/MultiLang.cs +++ b/VAR.WebForms.Common/Code/MultiLang.cs @@ -5,7 +5,7 @@ using System.Reflection; using System.Web; using VAR.Json; -namespace VAR.Focus.Web.Code +namespace VAR.WebForms.Common.Code { public class MultiLang { @@ -38,9 +38,9 @@ namespace VAR.Focus.Web.Code private static string GetUserLanguage() { HttpContext ctx = HttpContext.Current; - if(ctx != null) + if (ctx != null) { - if(ctx.Items["UserLang"] != null) + if (ctx.Items["UserLang"] != null) { return (string)ctx.Items["UserLang"]; } diff --git a/VAR.WebForms.Common/Code/ObjectActivator.cs b/VAR.WebForms.Common/Code/ObjectActivator.cs new file mode 100644 index 0000000..fe4889e --- /dev/null +++ b/VAR.WebForms.Common/Code/ObjectActivator.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; + +namespace VAR.WebForms.Common.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(); + } + } +} \ No newline at end of file diff --git a/VAR.Focus.Web/Code/ScriptsBundler.cs b/VAR.WebForms.Common/Code/ScriptsBundler.cs similarity index 90% rename from VAR.Focus.Web/Code/ScriptsBundler.cs rename to VAR.WebForms.Common/Code/ScriptsBundler.cs index 3b0730b..ef59d73 100644 --- a/VAR.Focus.Web/Code/ScriptsBundler.cs +++ b/VAR.WebForms.Common/Code/ScriptsBundler.cs @@ -1,6 +1,6 @@ using System.Web; -namespace VAR.Focus.Web.Code +namespace VAR.WebForms.Common.Code { public class ScriptsBundler : IHttpHandler { diff --git a/VAR.Focus.Web/Code/StaticFileHelper.cs b/VAR.WebForms.Common/Code/StaticFileHelper.cs similarity index 96% rename from VAR.Focus.Web/Code/StaticFileHelper.cs rename to VAR.WebForms.Common/Code/StaticFileHelper.cs index 465829e..860f472 100644 --- a/VAR.Focus.Web/Code/StaticFileHelper.cs +++ b/VAR.WebForms.Common/Code/StaticFileHelper.cs @@ -2,7 +2,7 @@ using System.IO; using System.Web; -namespace VAR.Focus.Web.Code +namespace VAR.WebForms.Common.Code { public class StaticFileHelper { diff --git a/VAR.Focus.Web/Code/StylesBundler.cs b/VAR.WebForms.Common/Code/StylesBundler.cs similarity index 89% rename from VAR.Focus.Web/Code/StylesBundler.cs rename to VAR.WebForms.Common/Code/StylesBundler.cs index d2794bd..a11aad8 100644 --- a/VAR.Focus.Web/Code/StylesBundler.cs +++ b/VAR.WebForms.Common/Code/StylesBundler.cs @@ -1,6 +1,6 @@ using System.Web; -namespace VAR.Focus.Web.Code +namespace VAR.WebForms.Common.Code { public class StylesBundler : IHttpHandler { diff --git a/VAR.Focus.Web/Controls/CButton.cs b/VAR.WebForms.Common/Controls/CButton.cs similarity index 76% rename from VAR.Focus.Web/Controls/CButton.cs rename to VAR.WebForms.Common/Controls/CButton.cs index 19d3ebb..6d4e873 100644 --- a/VAR.Focus.Web/Controls/CButton.cs +++ b/VAR.WebForms.Common/Controls/CButton.cs @@ -1,6 +1,6 @@ using System.Web.UI.WebControls; -namespace VAR.Focus.Web.Controls +namespace VAR.WebForms.Common.Controls { public class CButton : Button { diff --git a/VAR.Focus.Web/Controls/CLabel.cs b/VAR.WebForms.Common/Controls/CLabel.cs similarity index 91% rename from VAR.Focus.Web/Controls/CLabel.cs rename to VAR.WebForms.Common/Controls/CLabel.cs index 7194899..f41b899 100644 --- a/VAR.Focus.Web/Controls/CLabel.cs +++ b/VAR.WebForms.Common/Controls/CLabel.cs @@ -1,7 +1,7 @@ using System.Web.UI; using System.Web.UI.WebControls; -namespace VAR.Focus.Web.Controls +namespace VAR.WebForms.Common.Controls { public class CLabel : Label { diff --git a/VAR.Focus.Web/Controls/CTextBox.cs b/VAR.WebForms.Common/Controls/CTextBox.cs similarity index 96% rename from VAR.Focus.Web/Controls/CTextBox.cs rename to VAR.WebForms.Common/Controls/CTextBox.cs index 8f27e7d..a5bdd01 100644 --- a/VAR.Focus.Web/Controls/CTextBox.cs +++ b/VAR.WebForms.Common/Controls/CTextBox.cs @@ -5,7 +5,7 @@ using System.Web.UI; using System.Web.UI.WebControls; using VAR.Json; -namespace VAR.Focus.Web.Controls +namespace VAR.WebForms.Common.Controls { public class CTextBox : Control, INamingContainer, IValidableControl { diff --git a/VAR.Focus.Web/Controls/IValidableControl.cs b/VAR.WebForms.Common/Controls/IValidableControl.cs similarity index 61% rename from VAR.Focus.Web/Controls/IValidableControl.cs rename to VAR.WebForms.Common/Controls/IValidableControl.cs index e49fc6a..111ced7 100644 --- a/VAR.Focus.Web/Controls/IValidableControl.cs +++ b/VAR.WebForms.Common/Controls/IValidableControl.cs @@ -1,4 +1,4 @@ -namespace VAR.Focus.Web.Controls +namespace VAR.WebForms.Common.Controls { public interface IValidableControl { diff --git a/VAR.Focus.Web/GlobalModule.cs b/VAR.WebForms.Common/GlobalModule.cs similarity index 93% rename from VAR.Focus.Web/GlobalModule.cs rename to VAR.WebForms.Common/GlobalModule.cs index 760b277..e4650c6 100644 --- a/VAR.Focus.Web/GlobalModule.cs +++ b/VAR.WebForms.Common/GlobalModule.cs @@ -1,7 +1,7 @@ using System; using System.Web; -namespace VAR.Focus.Web +namespace VAR.WebForms.Common { public class GlobalModule : IHttpModule { diff --git a/VAR.Focus.Web/GlobalRouter.cs b/VAR.WebForms.Common/GlobalRouter.cs similarity index 92% rename from VAR.Focus.Web/GlobalRouter.cs rename to VAR.WebForms.Common/GlobalRouter.cs index 18bcf79..d4f7047 100644 --- a/VAR.Focus.Web/GlobalRouter.cs +++ b/VAR.WebForms.Common/GlobalRouter.cs @@ -4,10 +4,9 @@ using System.IO; using System.Reflection; using System.Threading; using System.Web; -using VAR.Focus.BusinessLogic.Utils; -using VAR.Focus.Web.Code; +using VAR.WebForms.Common.Code; -namespace VAR.Focus.Web +namespace VAR.WebForms.Common { public class GlobalRouter : IHttpHandler { @@ -112,12 +111,12 @@ namespace VAR.Focus.Web string file = Path.GetFileName(context.Request.FilePath); if (string.IsNullOrEmpty(file)) { - file = Globals.DefaultHandler; + file = GlobalConfig.Get().DefaultHandler; } // Pass allowed extensions requests string extension = Path.GetExtension(context.Request.FilePath).ToLower(); - if (Globals.AllowedExtensions.Contains(extension)) + if (GlobalConfig.Get().AllowedExtensions.Contains(extension)) { string filePath = context.Request.PhysicalPath; if (File.Exists(filePath)) diff --git a/VAR.Focus.Web/Pages/FormUtils.cs b/VAR.WebForms.Common/Pages/FormUtils.cs similarity index 93% rename from VAR.Focus.Web/Pages/FormUtils.cs rename to VAR.WebForms.Common/Pages/FormUtils.cs index 60246a3..5e197e1 100644 --- a/VAR.Focus.Web/Pages/FormUtils.cs +++ b/VAR.WebForms.Common/Pages/FormUtils.cs @@ -1,8 +1,8 @@ using System.Web.UI; using System.Web.UI.WebControls; -using VAR.Focus.Web.Controls; +using VAR.WebForms.Common.Controls; -namespace VAR.Focus.Web.Pages +namespace VAR.WebForms.Common.Pages { public class FormUtils { diff --git a/VAR.Focus.Web/Pages/FrmEcho.cs b/VAR.WebForms.Common/Pages/FrmEcho.cs similarity index 76% rename from VAR.Focus.Web/Pages/FrmEcho.cs rename to VAR.WebForms.Common/Pages/FrmEcho.cs index b5bc5f6..16f4ad9 100644 --- a/VAR.Focus.Web/Pages/FrmEcho.cs +++ b/VAR.WebForms.Common/Pages/FrmEcho.cs @@ -1,7 +1,7 @@ using System.Web; using VAR.Json; -namespace VAR.Focus.Web.Pages +namespace VAR.WebForms.Common.Pages { public class FrmEcho : IHttpHandler { @@ -14,7 +14,7 @@ namespace VAR.Focus.Web.Pages public void ProcessRequest(HttpContext context) { - var jsonWritter = new JsonWriter(true); + var jsonWritter = new JsonWriter(new JsonWriterConfiguration(indent: true)); context.Response.Write("
");
             context.Response.Write(jsonWritter.Write(context.Request));
             context.Response.Write("
"); diff --git a/VAR.Focus.Web/Pages/FrmError.cs b/VAR.WebForms.Common/Pages/FrmError.cs similarity index 93% rename from VAR.Focus.Web/Pages/FrmError.cs rename to VAR.WebForms.Common/Pages/FrmError.cs index ea35e72..9b53149 100644 --- a/VAR.Focus.Web/Pages/FrmError.cs +++ b/VAR.WebForms.Common/Pages/FrmError.cs @@ -2,9 +2,9 @@ using System.Web; using System.Web.UI; using System.Web.UI.WebControls; -using VAR.Focus.Web.Controls; +using VAR.WebForms.Common.Controls; -namespace VAR.Focus.Web.Pages +namespace VAR.WebForms.Common.Pages { public class FrmError : PageCommon { diff --git a/VAR.Focus.Web/Pages/PageCommon.cs b/VAR.WebForms.Common/Pages/PageCommon.cs similarity index 75% rename from VAR.Focus.Web/Pages/PageCommon.cs rename to VAR.WebForms.Common/Pages/PageCommon.cs index 6e57d78..ce3945f 100644 --- a/VAR.Focus.Web/Pages/PageCommon.cs +++ b/VAR.WebForms.Common/Pages/PageCommon.cs @@ -4,12 +4,10 @@ using System.Text; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; -using VAR.Focus.BusinessLogic; -using VAR.Focus.BusinessLogic.Entities; -using VAR.Focus.Web.Code; -using VAR.Focus.Web.Controls; +using VAR.WebForms.Common.Code; +using VAR.WebForms.Common.Controls; -namespace VAR.Focus.Web.Pages +namespace VAR.WebForms.Common.Pages { public class PageCommon : Page { @@ -23,7 +21,7 @@ namespace VAR.Focus.Web.Pages private CButton _btnLogout = new CButton(); private bool _mustBeAutenticated = true; - private User _currentUser = null; + private bool _isAuthenticated = false; #endregion Declarations @@ -40,11 +38,6 @@ namespace VAR.Focus.Web.Pages set { _mustBeAutenticated = value; } } - public User CurrentUser - { - get { return _currentUser; } - } - #endregion Properties #region Life cycle @@ -60,18 +53,10 @@ namespace VAR.Focus.Web.Pages { Context.Response.PrepareUncacheableResponse(); - Session session = WebSessions.Current.Session_GetCurrent(Context); - if (session != null) + _isAuthenticated = GlobalConfig.Get().IsUserAuthenticated(Context); + if (_mustBeAutenticated && _isAuthenticated == false) { - _currentUser = Users.Current.User_GetByName(session.UserName); - if (_mustBeAutenticated) - { - WebSessions.Current.Session_SetCookie(Context, session); - } - } - if (_currentUser == null && _mustBeAutenticated) - { - Response.Redirect(nameof(FrmLogin)); + Response.Redirect(GlobalConfig.Get().LoginHandler); } } @@ -82,8 +67,8 @@ namespace VAR.Focus.Web.Pages private void PageCommon_PreRender(object sender, EventArgs e) { - _head.Title = string.IsNullOrEmpty(Title) ? Globals.Title : string.Format("{0}{1}{2}", Title, Globals.TitleSeparator, Globals.Title); - _btnLogout.Visible = (_currentUser != null); + _head.Title = string.IsNullOrEmpty(Title) ? GlobalConfig.Get().Title : string.Concat(Title, GlobalConfig.Get().TitleSeparator, GlobalConfig.Get().Title); + _btnLogout.Visible = _isAuthenticated; } #endregion Life cycle @@ -92,11 +77,10 @@ namespace VAR.Focus.Web.Pages private void btnLogout_Click(object sender, EventArgs e) { - WebSessions.Current.Session_FinalizeCurrent(Context); - _currentUser = null; + GlobalConfig.Get().UserUnauthenticate(Context); if (_mustBeAutenticated) { - Response.Redirect(nameof(FrmLogin)); + Response.Redirect(GlobalConfig.Get().LoginHandler); } } @@ -119,8 +103,8 @@ namespace VAR.Focus.Web.Pages _head.Controls.Add(new HtmlMeta { HttpEquiv = "X-UA-Compatible", Content = "IE=Edge" }); _head.Controls.Add(new HtmlMeta { HttpEquiv = "content-type", Content = "text/html; charset=utf-8" }); - _head.Controls.Add(new HtmlMeta { Name = "author", Content = Globals.Author }); - _head.Controls.Add(new HtmlMeta { Name = "Copyright", Content = Globals.Copyright }); + _head.Controls.Add(new HtmlMeta { Name = "author", Content = GlobalConfig.Get().Author }); + _head.Controls.Add(new HtmlMeta { Name = "Copyright", Content = GlobalConfig.Get().Copyright }); _head.Controls.Add(new HtmlMeta { Name = "viewport", Content = "width=device-width, initial-scale=1, maximum-scale=4, user-scalable=1" }); string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); @@ -139,7 +123,7 @@ namespace VAR.Focus.Web.Pages lnkTitle.NavigateUrl = "."; pnlHeader.Controls.Add(lnkTitle); - var lblTitle = new CLabel { Text = Globals.Title, Tag = "h1" }; + var lblTitle = new CLabel { Text = GlobalConfig.Get().Title, Tag = "h1" }; lnkTitle.Controls.Add(lblTitle); _btnPostback.ID = "btnPostback"; diff --git a/VAR.WebForms.Common/Properties/AssemblyInfo.cs b/VAR.WebForms.Common/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fd22e1f --- /dev/null +++ b/VAR.WebForms.Common/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("VAR.WebForms.Common")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("VAR.WebForms.Common")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("328bb4e2-58f2-4beb-a619-ce3fa842ef43")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/VAR.WebForms.Common/VAR.WebForms.Common.csproj b/VAR.WebForms.Common/VAR.WebForms.Common.csproj new file mode 100644 index 0000000..d0d799d --- /dev/null +++ b/VAR.WebForms.Common/VAR.WebForms.Common.csproj @@ -0,0 +1,78 @@ + + + + + Debug + AnyCPU + {328BB4E2-58F2-4BEB-A619-CE3FA842EF43} + Library + Properties + VAR.WebForms.Common + VAR.WebForms.Common + v4.6.1 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + ..\packages\VAR.Json.1.1.1.36534\lib\net461\VAR.Json.dll + + + + + + + + + + + + + + + + + + + + + + + ASPXCodeBehind + + + ASPXCodeBehind + + + + + + + + \ No newline at end of file diff --git a/VAR.WebForms.Common/packages.config b/VAR.WebForms.Common/packages.config new file mode 100644 index 0000000..4953ba8 --- /dev/null +++ b/VAR.WebForms.Common/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file