Split VAR.WebForms.Common to a class library.

This commit is contained in:
2020-03-01 11:54:12 +01:00
parent df927722ba
commit e414663d12
37 changed files with 333 additions and 116 deletions

View File

@@ -1,65 +0,0 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
namespace VAR.Focus.Web.Code
{
public class Bundler
{
#region Declarations
private string _path = null;
private List<string> _files = null;
#endregion Declarations
#region Properties
private List<string> Files
{
get
{
if (_files != null) { return _files; }
DirectoryInfo dir = new DirectoryInfo(_path);
FileInfo[] files = dir.GetFiles();
_files = files.OrderBy(file => file.FullName).Select(file2 => file2.FullName).ToList();
return _files;
}
}
#endregion Properties
#region Creator
public Bundler(string path)
{
_path = path;
}
#endregion Creator
#region Public methods
public void WriteResponse(HttpResponse response, string contentType)
{
response.ContentType = contentType;
foreach (string fileName in Files)
{
string fileContent = File.ReadAllText(fileName);
byte[] byteArray = Encoding.UTF8.GetBytes(fileContent);
if (byteArray.Length > 0)
{
response.OutputStream.Write(byteArray, 0, byteArray.Length);
byteArray = Encoding.UTF8.GetBytes("\n\n");
response.OutputStream.Write(byteArray, 0, byteArray.Length);
}
}
}
#endregion Public methods
}
}

View File

@@ -1,50 +0,0 @@
using System;
using System.Web;
using VAR.Json;
namespace VAR.Focus.Web.Code
{
public static class ExtensionMethods
{
#region HttpContext
public static string GetRequestParm(this HttpContext context, string parm)
{
foreach (string key in context.Request.Params.AllKeys)
{
if (string.IsNullOrEmpty(key) == false && key.EndsWith(parm))
{
return context.Request.Params[key];
}
}
return string.Empty;
}
public static void ResponseObject(this HttpContext context, object obj)
{
var jsonWritter = new JsonWriter(true);
context.Response.ContentType = "text/json";
string strObject = jsonWritter.Write(obj);
context.Response.Write(strObject);
}
public static void PrepareCacheableResponse(this HttpResponse response)
{
const int secondsInDay = 86400;
response.ExpiresAbsolute = DateTime.Now.AddSeconds(secondsInDay);
response.Expires = secondsInDay;
response.Cache.SetCacheability(HttpCacheability.Public);
response.Cache.SetMaxAge(new TimeSpan(0, 0, secondsInDay));
}
public static void PrepareUncacheableResponse(this HttpResponse response)
{
response.ExpiresAbsolute = DateTime.Now.AddDays(-2d);
response.Expires = -1500;
response.AddHeader("Cache-Control", "max-age=0, no-cache, no-store");
response.BufferOutput = true;
}
#endregion HttpContext
}
}

View File

@@ -1,64 +0,0 @@
using System;
using System.Text;
using System.Web;
using VAR.Focus.Web.Pages;
namespace VAR.Focus.Web.Code
{
public static class GlobalErrorHandler
{
#region Private methods
private static void ShowInternalError(HttpContext context, Exception ex)
{
context.Response.StatusCode = 500;
context.Response.Clear();
StringBuilder sbOutput = new StringBuilder();
sbOutput.Append("<h2>Internal error</h2>");
Exception exAux = ex;
if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
while (exAux != null)
{
sbOutput.AppendFormat("<p><b>Message:</b> {0}</p>", exAux.Message);
sbOutput.AppendFormat("<p><b>StackTrace:</b></p> <pre><code>{0}</code></pre>", exAux.StackTrace);
exAux = exAux.InnerException;
}
// Fill response to 512 bytes to avoid browser "beauty" response of errors.
long fillResponse = 512 - sbOutput.Length;
if (fillResponse > 0)
{
sbOutput.Append("<!--");
for (int i = 0; i < fillResponse; i++)
{
sbOutput.Append("A");
}
sbOutput.Append("-->");
}
context.Response.Write(sbOutput.ToString());
}
#endregion Private methods
#region Public methods
public static void HandleError(HttpContext context, Exception ex)
{
try
{
IHttpHandler frmError = new FrmError(ex);
context.Response.Clear();
context.Handler = frmError;
frmError.ProcessRequest(context);
}
catch
{
ShowInternalError(context, ex);
}
}
#endregion Public methods
}
}

View File

@@ -1,82 +0,0 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
using VAR.Json;
namespace VAR.Focus.Web.Code
{
public class MultiLang
{
private static string GetLocalPath(string path)
{
string currentDir = Path.GetDirectoryName((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath);
return string.Format("{0}/{1}", Directory.GetParent(currentDir), path);
}
private static Dictionary<string, Dictionary<string, object>> _literals = null;
private static void InitializeLiterals()
{
_literals = new Dictionary<string, Dictionary<string, object>>();
JsonParser jsonParser = new JsonParser();
foreach (string lang in new string[] { "en", "es" })
{
string filePath = GetLocalPath(string.Format("Resources/Literals.{0}.json", lang));
if (File.Exists(filePath) == false) { continue; }
string strJsonLiteralsLanguage = File.ReadAllText(filePath);
object result = jsonParser.Parse(strJsonLiteralsLanguage);
_literals.Add(lang, result as Dictionary<string, object>);
}
}
private const string _defaultLanguage = "en";
private static string GetUserLanguage()
{
HttpContext ctx = HttpContext.Current;
if(ctx != null)
{
if(ctx.Items["UserLang"] != null)
{
return (string)ctx.Items["UserLang"];
}
IEnumerable<string> userLanguages = ctx.Request.UserLanguages
.Select(lang =>
{
if (lang.Contains(";"))
{
lang = lang.Split(';')[0];
}
if (lang.Contains("-"))
{
lang = lang.Split('-')[0];
}
return lang.ToLower();
})
.Where(lang => _literals.ContainsKey(lang));
string userLang = userLanguages.FirstOrDefault() ?? _defaultLanguage;
ctx.Items["UserLang"] = userLang;
return userLang;
}
return _defaultLanguage;
}
public static string GetLiteral(string resource, string culture = null)
{
if (_literals == null) { InitializeLiterals(); }
if (culture == null) { culture = GetUserLanguage(); }
if (_literals == null || _literals.ContainsKey(culture) == false) { return resource; }
Dictionary<string, object> _literalCurrentCulture = _literals[culture];
if (_literalCurrentCulture == null || _literalCurrentCulture.ContainsKey(resource) == false) { return resource; }
return (_literalCurrentCulture[resource] as string) ?? resource;
}
}
}

View File

@@ -1,20 +0,0 @@
using System.Web;
namespace VAR.Focus.Web.Code
{
public class ScriptsBundler : IHttpHandler
{
#region IHttpHandler
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
Bundler bundler = new Bundler(context.Server.MapPath("~/Scripts/"));
context.Response.PrepareCacheableResponse();
bundler.WriteResponse(context.Response, "text/javascript");
}
#endregion IHttpHandler
}
}

View File

@@ -1,94 +0,0 @@
using System.Collections.Generic;
using System.IO;
using System.Web;
namespace VAR.Focus.Web.Code
{
public class StaticFileHelper
{
private static Dictionary<string, string> _mimeTypeByExtension = new Dictionary<string, string> { {".aac", "audio/aac"},
{".abw", "application/x-abiword"},
{".arc", "application/octet-stream"},
{".avi", "video/x-msvideo"},
{".azw", "application/vnd.amazon.ebook"},
{".bin", "application/octet-stream"},
{".bz", "application/x-bzip"},
{".bz2", "application/x-bzip2"},
{".csh", "application/x-csh"},
{".css", "text/css"},
{".csv", "text/csv"},
{".doc", "application/msword"},
{".epub", "application/epub+zip"},
{".gif", "image/gif"},
{".htm", "text/html"},
{".html", "text/html"},
{".ico", "image/x-icon"},
{".ics", "text/calendar"},
{".jar", "application/java-archive"},
{".jpg", "image/jpeg"},
{".jpeg", "image/jpeg"},
{".js", "application/javascript"},
{".json", "application/json"},
{".mid", "audio/midi"},
{".midi", "audio/midi"},
{".mpeg", "video/mpeg"},
{".mpkg", "application/vnd.apple.installer+xml"},
{".odp", "application/vnd.oasis.opendocument.presentation"},
{".ods", "application/vnd.oasis.opendocument.spreadsheet"},
{".odt", "application/vnd.oasis.opendocument.text"},
{".oga", "audio/ogg"},
{".ogv", "video/ogg"},
{".ogx", "application/ogg"},
{".png", "image/png"},
{".pdf", "application/pdf"},
{".ppt", "application/vnd.ms-powerpoint"},
{".rar", "application/x-rar-compressed"},
{".rtf", "application/rtf"},
{".sh", "application/x-sh"},
{".svg", "image/svg+xml"},
{".swf", "application/x-shockwave-flash"},
{".tar", "application/x-tar"},
{".tiff", "image/tiff"},
{".tif", "image/tiff"},
{".ttf", "font/ttf"},
{".vsd", "application/vnd.visio"},
{".wav", "audio/x-wav"},
{".weba", "audio/webm"},
{".webm", "video/webm"},
{".webp", "image/webp"},
{".woff", "font/woff"},
{".woff2", "font/woff2"},
{".xhtml", "application/xhtml+xml"},
{".xls", "application/vnd.ms-excel"},
{".xml", "application/xml"},
{".xul", "application/vnd.mozilla.xul+xml"},
{".zip", "application/zip"},
{".7z", "application/x-7z-compressed"},
};
public static void ResponseStaticFile(HttpContext context, string filePath)
{
string extension = Path.GetExtension(filePath).ToLower();
string contentType = null;
if (_mimeTypeByExtension.ContainsKey(extension))
{
contentType = _mimeTypeByExtension[extension];
}
context.Response.Clear();
if (string.IsNullOrEmpty(contentType) == false)
{
context.Response.ContentType = contentType;
}
context.Response.PrepareCacheableResponse();
context.Response.Buffer = true;
context.Response.WriteFile(filePath);
context.Response.Flush();
context.Response.Close();
context.Response.End();
}
}
}

View File

@@ -1,20 +0,0 @@
using System.Web;
namespace VAR.Focus.Web.Code
{
public class StylesBundler : IHttpHandler
{
#region IHttpHandler
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
Bundler bundler = new Bundler(context.Server.MapPath("~/Styles/"));
context.Response.PrepareCacheableResponse();
bundler.WriteResponse(context.Response, "text/css");
}
#endregion IHttpHandler
}
}

View File

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

View File

@@ -1,12 +0,0 @@
using System.Web.UI.WebControls;
namespace VAR.Focus.Web.Controls
{
public class CButton : Button
{
public CButton()
{
CssClass = "button";
}
}
}

View File

@@ -1,41 +0,0 @@
using System.Web.UI;
using System.Web.UI.WebControls;
namespace VAR.Focus.Web.Controls
{
public class CLabel : Label
{
#region Declarations
private string _tagName = "span";
#endregion Declarations
#region Properties
public string Tag
{
get { return _tagName; }
set { _tagName = value; }
}
#endregion Properties
#region Life cycle
public override void RenderBeginTag(HtmlTextWriter writer)
{
if (string.IsNullOrEmpty(_tagName) == false)
{
this.AddAttributesToRender(writer);
writer.RenderBeginTag(_tagName);
}
else
{
base.RenderBeginTag(writer);
}
}
#endregion Life cycle
}
}

View File

@@ -1,210 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using VAR.Json;
namespace VAR.Focus.Web.Controls
{
public class CTextBox : Control, INamingContainer, IValidableControl
{
#region Declarations
private TextBox _txtContent = new TextBox();
private HiddenField _hidSize = null;
private const string CssClassBase = "textbox";
private string _cssClassExtra = "";
private bool _allowEmpty = true;
private string _placeHolder = string.Empty;
private bool _markedInvalid = false;
private Control _nextFocusOnEnter = null;
private bool _keepSize = false;
#endregion Declarations
#region Properties
public string CssClassExtra
{
get { return _cssClassExtra; }
set { _cssClassExtra = value; }
}
public bool AllowEmpty
{
get { return _allowEmpty; }
set { _allowEmpty = value; }
}
public string PlaceHolder
{
get { return _placeHolder; }
set { _placeHolder = value; }
}
public bool MarkedInvalid
{
get { return _markedInvalid; }
set { _markedInvalid = value; }
}
public Control NextFocusOnEnter
{
get { return _nextFocusOnEnter; }
set { _nextFocusOnEnter = value; }
}
public bool KeepSize
{
get { return _keepSize; }
set { _keepSize = value; }
}
public string Text
{
get { return _txtContent.Text; }
set { _txtContent.Text = value; }
}
public TextBoxMode TextMode
{
get { return _txtContent.TextMode; }
set { _txtContent.TextMode = value; }
}
#endregion Properties
#region Control life cycle
public CTextBox()
{
Init += CTextBox_Init;
PreRender += CTextbox_PreRender;
}
private void CTextBox_Init(object sender, EventArgs e)
{
Controls.Add(_txtContent);
if (TextMode == TextBoxMode.MultiLine)
{
if (_keepSize)
{
_hidSize = new HiddenField();
Controls.Add(_hidSize);
}
string strCfgName = string.Format("{0}_cfg", this.ClientID);
Dictionary<string, object> cfg = new Dictionary<string, object>
{
{"txtContent", _txtContent.ClientID},
{"hidSize", _hidSize.ClientID},
{"keepSize", _keepSize },
};
JsonWriter jsonWriter = new JsonWriter();
StringBuilder sbCfg = new StringBuilder();
sbCfg.AppendFormat("<script>\n");
sbCfg.AppendFormat("var {0} = {1};\n", strCfgName, jsonWriter.Write(cfg));
sbCfg.AppendFormat("CTextBox_Multiline_Init({0});\n", strCfgName);
sbCfg.AppendFormat("</script>\n");
LiteralControl liScript = new LiteralControl(sbCfg.ToString());
Controls.Add(liScript);
}
}
private void CTextbox_PreRender(object sender, EventArgs e)
{
_txtContent.CssClass = CssClassBase;
if (string.IsNullOrEmpty(_cssClassExtra) == false)
{
_txtContent.CssClass = string.Format("{0} {1}", CssClassBase, _cssClassExtra);
}
if (Page.IsPostBack && (_allowEmpty == false && IsEmpty()) || _markedInvalid)
{
_txtContent.CssClass += " textboxInvalid";
}
_txtContent.Attributes.Add("onchange", "ElementRemoveClass(this, 'textboxInvalid');");
if (string.IsNullOrEmpty(_placeHolder) == false)
{
_txtContent.Attributes.Add("placeholder", _placeHolder);
}
if (_nextFocusOnEnter != null)
{
_txtContent.Attributes.Add("onkeydown", string.Format(
"if(event.keyCode==13){{document.getElementById('{0}').focus(); return false;}}",
_nextFocusOnEnter.ClientID));
}
// FIX: The framework deletes textbox values on password mode
if (_txtContent.TextMode == TextBoxMode.Password)
{
_txtContent.Attributes["value"] = _txtContent.Text;
}
}
#endregion Control life cycle
#region Public methods
public bool IsEmpty()
{
return string.IsNullOrEmpty(_txtContent.Text);
}
public bool IsValid()
{
return _allowEmpty || (string.IsNullOrEmpty(_txtContent.Text) == false);
}
public int? GetClientsideHeight()
{
if (string.IsNullOrEmpty(_hidSize.Value))
{
return null;
}
JsonParser jsonParser = new JsonParser();
Dictionary<string, object> sizeObj = jsonParser.Parse(_hidSize.Value) as Dictionary<string, object>;
if (sizeObj == null) { return null; }
if (sizeObj.ContainsKey("height") == false) { return null; }
return (int)sizeObj["height"];
}
public void SetClientsideHeight(int? height)
{
if(height == null)
{
_hidSize.Value = string.Empty;
return;
}
Dictionary<string, object> sizeObj = null;
if (string.IsNullOrEmpty(_hidSize.Value) == false)
{
JsonParser jsonParser = new JsonParser();
sizeObj = jsonParser.Parse(_hidSize.Value) as Dictionary<string, object>;
}
else
{
sizeObj = new Dictionary<string, object> {
{ "height", height },
{ "width", null },
{ "scrollTop", null },
};
}
JsonWriter jsonWriter = new JsonWriter();
_hidSize.Value = jsonWriter.Write(sizeObj);
}
#endregion Public methods
}
}

View File

@@ -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<string, object> {
{"Toolbox",MultiLang.GetLiteral( "Toolbox")},
{"Toolbox", MultiLang.GetLiteral( "Toolbox")},
{"AddCard", MultiLang.GetLiteral("AddCard")},
{"AddRegion", MultiLang.GetLiteral("AddRegion")},
{"EditBoard", MultiLang.GetLiteral("Config")},

View File

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

View File

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

View File

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

View File

@@ -1,7 +0,0 @@
namespace VAR.Focus.Web.Controls
{
public interface IValidableControl
{
bool IsValid();
}
}

View File

@@ -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<string> AllowedExtensions { get; } = new List<string> { ".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);
}
}
}

View File

@@ -1,27 +0,0 @@
using System;
using System.Web;
namespace VAR.Focus.Web
{
public class GlobalModule : IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += Context_PreSendRequestHeaders;
}
private void Context_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext ctx = HttpContext.Current;
if (ctx == null) { return; }
ctx.Response.Headers.Remove("Server");
ctx.Response.Headers.Remove("X-Powered-By");
ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff");
ctx.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN");
ctx.Response.Headers.Add("X-XSS-Protection", "1; mode=block");
}
}
}

View File

@@ -1,145 +0,0 @@
using System;
using System.Collections.Generic;
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
{
public class GlobalRouter : IHttpHandler
{
#region Handlers
private static Dictionary<string, Type> _handlers = new Dictionary<string, Type>();
private static IHttpHandler GetHandler(string typeName)
{
if (string.IsNullOrEmpty(typeName)) { return null; }
Type type = null;
if (_handlers.ContainsKey(typeName))
{
type = _handlers[typeName];
IHttpHandler handler = ObjectActivator.CreateInstance(type) as IHttpHandler;
return handler;
}
// Search type on executing assembly
Type[] types;
Assembly asm = Assembly.GetExecutingAssembly();
types = asm.GetTypes();
foreach (Type typeAux in types)
{
if (typeAux.FullName.EndsWith(typeName))
{
type = typeAux;
break;
}
}
// Search type on all loaded assemblies
if (type == null)
{
Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly asmAux in asms)
{
types = asmAux.GetTypes();
foreach (Type typeAux in types)
{
if (typeAux.FullName.EndsWith(typeName))
{
type = typeAux;
break;
}
}
if (type != null) { break; }
}
}
// Use found type
if (type != null)
{
IHttpHandler handler = ObjectActivator.CreateInstance(type) as IHttpHandler;
if (handler != null)
{
lock (_handlers)
{
if (_handlers.ContainsKey(typeName) == false)
{
_handlers.Add(typeName, type);
}
}
}
return handler;
}
return null;
}
#endregion Handlers
#region IHttpHandler
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
try
{
RouteRequest(context);
}
catch (Exception ex)
{
if (ex is ThreadAbortException)
{
return;
}
GlobalErrorHandler.HandleError(context, ex);
}
}
#endregion IHttpHandler
#region Private methods
private void RouteRequest(HttpContext context)
{
string file = Path.GetFileName(context.Request.FilePath);
if (string.IsNullOrEmpty(file))
{
file = Globals.DefaultHandler;
}
// Pass allowed extensions requests
string extension = Path.GetExtension(context.Request.FilePath).ToLower();
if (Globals.AllowedExtensions.Contains(extension))
{
string filePath = context.Request.PhysicalPath;
if (File.Exists(filePath))
{
StaticFileHelper.ResponseStaticFile(context, filePath);
return;
}
}
IHttpHandler handler = GetHandler(file);
if (handler == null)
{
// TODO: FrmNotFound
throw new Exception("NotFound");
}
// Use handler
context.Response.Clear();
context.Handler = handler;
handler.ProcessRequest(context);
}
#endregion Private methods
}
}

View File

@@ -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<string> AllowedExtensions = new List<string> { ".png", ".jpg", ".jpeg", ".gif", ".ico", ".wav", ".mp3", ".ogg", ".mp4", ".webm", ".webp", ".mkv", ".avi" };
}
}

View File

@@ -1,87 +0,0 @@
using System.Web.UI;
using System.Web.UI.WebControls;
using VAR.Focus.Web.Controls;
namespace VAR.Focus.Web.Pages
{
public class FormUtils
{
public static Control CreatePanel(string cssClass, Control ctrl)
{
Panel pnl = new Panel();
if (ctrl != null)
{
pnl.Controls.Add(ctrl);
}
if (string.IsNullOrEmpty(cssClass) == false)
{
pnl.CssClass = cssClass;
}
return pnl;
}
public static Control CreatePanel(string cssClass)
{
return CreatePanel(cssClass, null);
}
public static Control CreateField(string label, Control fieldControl)
{
Panel pnlRow = new Panel();
pnlRow.CssClass = "formRow";
Panel pnlLabelContainer = new Panel();
pnlLabelContainer.CssClass = "formLabel width25pc";
pnlRow.Controls.Add(pnlLabelContainer);
if (string.IsNullOrEmpty(label) == false)
{
CLabel lblField = new CLabel();
lblField.Text = label;
pnlLabelContainer.Controls.Add(lblField);
}
Panel pnlFieldContainer = new Panel();
pnlFieldContainer.CssClass = "formField width75pc";
pnlRow.Controls.Add(pnlFieldContainer);
pnlFieldContainer.Controls.Add(fieldControl);
return pnlRow;
}
public static bool Control_IsValid(Control control)
{
if (control is IValidableControl)
{
if (((IValidableControl)control).IsValid() == false)
{
return false;
}
}
return true;
}
public static bool Controls_AreValid(ControlCollection controls)
{
bool valid = true;
foreach (Control control in controls)
{
if (Control_IsValid(control))
{
if (Controls_AreValid(control.Controls) == false)
{
valid = false;
break;
}
}
else
{
valid = false;
break;
}
}
return valid;
}
}
}

View File

@@ -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<Board> boards = Boards.Current.Boards_GetListForUser(CurrentUser.Name);
User user = WebSessions.Current.Session_GetCurrentUser(Context);
List<Board> 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);
}

View File

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

View File

@@ -1,25 +0,0 @@
using System.Web;
using VAR.Json;
namespace VAR.Focus.Web.Pages
{
public class FrmEcho : IHttpHandler
{
#region IHttpHandler
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
var jsonWritter = new JsonWriter(true);
context.Response.Write("<pre><code>");
context.Response.Write(jsonWritter.Write(context.Request));
context.Response.Write("</code></pre>");
}
#endregion IHttpHandler
}
}

View File

@@ -1,65 +0,0 @@
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VAR.Focus.Web.Controls;
namespace VAR.Focus.Web.Pages
{
public class FrmError : PageCommon
{
#region Declarations
private Exception _ex = null;
#endregion Declarations
#region Page life cycle
public FrmError(Exception ex)
{
_ex = ex;
Init += FrmError_Init;
}
private void FrmError_Init(object sender, EventArgs e)
{
InitializeControls();
}
#endregion Page life cycle
#region Private methods
private void InitializeControls()
{
Title = "Application Error";
CLabel lblErrorTitle = new CLabel { Text = Title, Tag = "h2" };
Controls.Add(lblErrorTitle);
Exception exAux = _ex;
if (exAux is HttpUnhandledException && exAux.InnerException != null) { exAux = exAux.InnerException; }
while (exAux != null)
{
CLabel lblMessage = new CLabel { Tag = "P" };
lblMessage.Text = string.Format("<b>{0}:</b> {1}", "Message", HttpUtility.HtmlEncode(exAux.Message));
Controls.Add(lblMessage);
CLabel lblStacktraceTitle = new CLabel { Tag = "p" };
lblStacktraceTitle.Text = string.Format("<b>{0}:</b>", "Stacktrace");
Controls.Add(lblStacktraceTitle);
Panel pnlStacktrace = new Panel();
pnlStacktrace.CssClass = "divCode";
Controls.Add(pnlStacktrace);
LiteralControl litStackTrace = new LiteralControl(
string.Format("<pre><code>{0}</code></pre>", HttpUtility.HtmlEncode(exAux.StackTrace)));
pnlStacktrace.Controls.Add(litStackTrace);
exAux = exAux.InnerException;
}
}
#endregion Private methods
}
}

View File

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

View File

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

View File

@@ -1,165 +0,0 @@
using System;
using System.Reflection;
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;
namespace VAR.Focus.Web.Pages
{
public class PageCommon : Page
{
#region Declarations
private HtmlHead _head;
private HtmlGenericControl _body;
private HtmlForm _form;
private Panel _pnlContainer = new Panel();
private CButton _btnPostback = new CButton();
private CButton _btnLogout = new CButton();
private bool _mustBeAutenticated = true;
private User _currentUser = null;
#endregion Declarations
#region Properties
public new ControlCollection Controls
{
get { return _pnlContainer.Controls; }
}
public bool MustBeAutenticated
{
get { return _mustBeAutenticated; }
set { _mustBeAutenticated = value; }
}
public User CurrentUser
{
get { return _currentUser; }
}
#endregion Properties
#region Life cycle
public PageCommon()
{
PreInit += PageCommon_PreInit;
Init += PageCommon_Init;
PreRender += PageCommon_PreRender;
}
private void PageCommon_PreInit(object sender, EventArgs e)
{
Context.Response.PrepareUncacheableResponse();
Session session = WebSessions.Current.Session_GetCurrent(Context);
if (session != null)
{
_currentUser = Users.Current.User_GetByName(session.UserName);
if (_mustBeAutenticated)
{
WebSessions.Current.Session_SetCookie(Context, session);
}
}
if (_currentUser == null && _mustBeAutenticated)
{
Response.Redirect(nameof(FrmLogin));
}
}
private void PageCommon_Init(object sender, EventArgs e)
{
CreateControls();
}
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);
}
#endregion Life cycle
#region UI Events
private void btnLogout_Click(object sender, EventArgs e)
{
WebSessions.Current.Session_FinalizeCurrent(Context);
_currentUser = null;
if (_mustBeAutenticated)
{
Response.Redirect(nameof(FrmLogin));
}
}
#endregion UI Events
#region Private methods
private void CreateControls()
{
Context.Response.Charset = Encoding.UTF8.WebName;
var doctype = new LiteralControl("<!DOCTYPE html>\n");
base.Controls.Add(doctype);
var html = new HtmlGenericControl("html");
base.Controls.Add(html);
_head = new HtmlHead();
html.Controls.Add(_head);
_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 = "viewport", Content = "width=device-width, initial-scale=1, maximum-scale=4, user-scalable=1" });
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
_head.Controls.Add(new LiteralControl(string.Format("<script type=\"text/javascript\" src=\"ScriptsBundler?v={0}\"></script>\n", version)));
_head.Controls.Add(new LiteralControl(string.Format("<link href=\"StylesBundler?v={0}\" type=\"text/css\" rel=\"stylesheet\"/>\n", version)));
_body = new HtmlGenericControl("body");
html.Controls.Add(_body);
_form = new HtmlForm { ID = "formMain" };
_body.Controls.Add(_form);
var pnlHeader = new Panel { CssClass = "divHeader" };
_form.Controls.Add(pnlHeader);
HyperLink lnkTitle = new HyperLink();
lnkTitle.NavigateUrl = ".";
pnlHeader.Controls.Add(lnkTitle);
var lblTitle = new CLabel { Text = Globals.Title, Tag = "h1" };
lnkTitle.Controls.Add(lblTitle);
_btnPostback.ID = "btnPostback";
_btnPostback.Text = "Postback";
pnlHeader.Controls.Add(_btnPostback);
_btnPostback.Style.Add("display", "none");
var pnlUserInfo = new Panel { CssClass = "divUserInfo" };
pnlHeader.Controls.Add(pnlUserInfo);
_btnLogout.ID = "btnLogout";
_btnLogout.Text = MultiLang.GetLiteral("Logout");
_btnLogout.Click += btnLogout_Click;
_btnLogout.Attributes.Add("onclick", string.Format("return confirm('{0}');", MultiLang.GetLiteral("ConfirmExit")));
pnlUserInfo.Controls.Add(_btnLogout);
_pnlContainer.CssClass = "divContent";
_form.Controls.Add(_pnlContainer);
}
#endregion Private methods
}
}

View File

@@ -45,9 +45,8 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Web" />
<Reference Include="VAR.Json, Version=1.0.6252.27492, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VAR.Json.1.0.6252.27492\lib\net461\VAR.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="VAR.Json, Version=1.1.1.36534, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\VAR.Json.1.1.1.36534\lib\net461\VAR.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -82,45 +81,24 @@
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="Code\Bundler.cs" />
<Compile Include="Code\ExtensionMethods.cs" />
<Compile Include="Code\MultiLang.cs" />
<Compile Include="Code\StaticFileHelper.cs" />
<Compile Include="Code\WebSessions.cs" />
<Compile Include="Controls\CtrCardBoard.cs" />
<Compile Include="Controls\HndCardBoard.cs" />
<Compile Include="Controls\CButton.cs" />
<Compile Include="Controls\CtrChat.cs" />
<Compile Include="Controls\HndChat.cs" />
<Compile Include="Controls\CLabel.cs" />
<Compile Include="Controls\CTextBox.cs" />
<Compile Include="Controls\IValidableControl.cs" />
<Compile Include="Code\GlobalErrorHandler.cs" />
<Compile Include="GlobalModule.cs" />
<Compile Include="Pages\FormUtils.cs" />
<Compile Include="Pages\FrmBoard.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Pages\FrmBoardEdit.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Pages\FrmEcho.cs" />
<Compile Include="Pages\FrmLogin.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Pages\FrmRegister.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Pages\PageCommon.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Code\ScriptsBundler.cs" />
<Compile Include="Code\StylesBundler.cs" />
<Compile Include="GlobalRouter.cs" />
<Compile Include="Pages\FrmError.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Globals.cs" />
<Compile Include="FocusGlobalConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -128,6 +106,10 @@
<Project>{d88af21d-1c60-4b27-abff-a133d6afc51c}</Project>
<Name>VAR.Focus.BusinessLogic</Name>
</ProjectReference>
<ProjectReference Include="..\VAR.WebForms.Common\VAR.WebForms.Common.csproj">
<Project>{328bb4e2-58f2-4beb-a619-ce3fa842ef43}</Project>
<Name>VAR.WebForms.Common</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="VAR.Json" version="1.0.6252.27492" targetFramework="net461" />
<package id="VAR.Json" version="1.1.1.36534" targetFramework="net461" />
</packages>

View File

@@ -4,11 +4,11 @@
<compilation debug="true" targetFramework="4.6.1" />
<httpModules>
<remove name="GlobalModule" />
<add name="GlobalModule" type="VAR.Focus.Web.GlobalModule" />
<add name="GlobalModule" type="VAR.WebForms.Common.GlobalModule" />
</httpModules>
<httpHandlers>
<clear />
<add path="*" verb="*" type="VAR.Focus.Web.GlobalRouter" />
<add path="*" verb="*" type="VAR.WebForms.Common.GlobalRouter" />
</httpHandlers>
<pages clientIDMode="AutoID" enableViewState="false" enableSessionState="false" enableViewStateMac="false" />
<httpRuntime enableVersionHeader="false" />
@@ -16,11 +16,11 @@
<system.webServer>
<modules>
<remove name="GlobalModule" />
<add name="GlobalModule" type="VAR.Focus.Web.GlobalModule" />
<add name="GlobalModule" type="VAR.WebForms.Common.GlobalModule" />
</modules>
<handlers>
<clear />
<add name="GlobalRouter" path="*" verb="*" type="VAR.Focus.Web.GlobalRouter" />
<add name="GlobalRouter" path="*" verb="*" type="VAR.WebForms.Common.GlobalRouter" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<httpProtocol>