diff --git a/VAR.Focus.sln.DotSettings b/VAR.Focus.sln.DotSettings new file mode 100644 index 0000000..5394c59 --- /dev/null +++ b/VAR.Focus.sln.DotSettings @@ -0,0 +1,33 @@ + + False + False + False + False + False + False + True + True + True + IF_OWNER_IS_SINGLE_LINE + True + True + CHOP_IF_LONG + False + True + True + True + CHOP_IF_LONG + CHOP_IF_LONG + CHOP_IF_LONG + CHOP_IF_LONG + ID + OK + SHA + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="AaBb_AaBb" /></Policy> + True + True + True + True + True + True + True \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/Bundler.cs b/VAR.WebFormsCore/Code/Bundler.cs index 3b8a253..9cec531 100644 --- a/VAR.WebFormsCore/Code/Bundler.cs +++ b/VAR.WebFormsCore/Code/Bundler.cs @@ -11,11 +11,11 @@ namespace VAR.WebFormsCore.Code { #region Declarations - private Assembly _assembly = null; - private string _assemblyNamespace = null; - private List _assemblyFiles = null; - private string _absolutePath = null; - private List _absoluteFiles = null; + private readonly Assembly _assembly; + private readonly string _assemblyNamespace; + private List _assemblyFiles; + private readonly string _absolutePath; + private List _absoluteFiles; #endregion Declarations @@ -26,11 +26,13 @@ namespace VAR.WebFormsCore.Code get { if (_assemblyFiles != null) { return _assemblyFiles; } + if (_assembly == null || string.IsNullOrEmpty(_assemblyNamespace)) { _assemblyFiles = new List(); return _assemblyFiles; } + string assemblyPath = string.Concat(_assembly.GetName().Name, ".", _assemblyNamespace, "."); _assemblyFiles = _assembly.GetManifestResourceNames().Where(r => r.StartsWith(assemblyPath)).ToList(); return _assemblyFiles; @@ -48,6 +50,7 @@ namespace VAR.WebFormsCore.Code _absoluteFiles = new List(); return _absoluteFiles; } + DirectoryInfo dir = new DirectoryInfo(_absolutePath); FileInfo[] files = dir.GetFiles(); _absoluteFiles = files.OrderBy(file => file.FullName).Select(file2 => file2.FullName).ToList(); @@ -70,7 +73,7 @@ namespace VAR.WebFormsCore.Code #region Public methods - private static Encoding _utf8Econding = new UTF8Encoding(); + private static readonly Encoding Utf8Encoding = new UTF8Encoding(); public async void WriteResponse(HttpResponse response, string contentType) { @@ -79,17 +82,23 @@ namespace VAR.WebFormsCore.Code foreach (string fileName in AssemblyFiles) { Stream resourceStream = _assembly.GetManifestResourceStream(fileName); - string fileContent = new StreamReader(resourceStream).ReadToEnd(); - textWriter.Write(fileContent); + if (resourceStream != null) + { + string fileContent = new StreamReader(resourceStream).ReadToEnd(); + textWriter.Write(fileContent); + } + textWriter.Write("\n\n"); } + foreach (string fileName in AbsoluteFiles) { string fileContent = File.ReadAllText(fileName); textWriter.Write(fileContent); textWriter.Write("\n\n"); } - byte[] byteObject = _utf8Econding.GetBytes(textWriter.ToString()); + + byte[] byteObject = Utf8Encoding.GetBytes(textWriter.ToString()); await response.Body.WriteAsync(byteObject); } diff --git a/VAR.WebFormsCore/Code/ExtensionMethods.cs b/VAR.WebFormsCore/Code/ExtensionMethods.cs index 8b3d1b2..f451a61 100644 --- a/VAR.WebFormsCore/Code/ExtensionMethods.cs +++ b/VAR.WebFormsCore/Code/ExtensionMethods.cs @@ -15,65 +15,54 @@ namespace VAR.WebFormsCore.Code { foreach (string key in context.Request.Form.Keys) { - if (string.IsNullOrEmpty(key) == false && key == parm) - { - return context.Request.Form[key]; - } + if (string.IsNullOrEmpty(key) == false && key == parm) { return context.Request.Form[key]; } } } + foreach (string key in context.Request.Query.Keys) { - if (string.IsNullOrEmpty(key) == false && key == parm) - { - return context.Request.Query[key]; - } + if (string.IsNullOrEmpty(key) == false && key == parm) { return context.Request.Query[key]; } } + return string.Empty; } - private static Encoding _utf8Econding = new UTF8Encoding(); + private static readonly Encoding Utf8Encoding = new UTF8Encoding(); public static void ResponseObject(this HttpContext context, object obj) { context.Response.ContentType = "text/json"; string strObject = JsonWriter.WriteObject(obj); - byte[] byteObject = _utf8Econding.GetBytes(strObject); + byte[] byteObject = Utf8Encoding.GetBytes(strObject); context.Response.Body.WriteAsync(byteObject); } public static void SafeSet(this IHeaderDictionary header, string key, string value) { - if (header.ContainsKey(key)) - { - header[key] = value; - } - else - { - header.Add(key, value); - } + if (header.ContainsKey(key)) { header[key] = value; } + else { header.Add(key, value); } } public static void SafeDel(this IHeaderDictionary header, string key) { - if (header.ContainsKey(key)) - { - header.Remove(key); - } + if (header.ContainsKey(key)) { header.Remove(key); } } public static void PrepareCacheableResponse(this HttpResponse response) { const int secondsInDay = 86400; - response.Headers.SafeSet("Cache-Control", string.Format("public, max-age={0}", secondsInDay)); - string ExpireDate = DateTime.UtcNow.AddSeconds(secondsInDay).ToString("ddd, dd MMM yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); - response.Headers.SafeSet("Expires", ExpireDate + " GMT"); + response.Headers.SafeSet("Cache-Control", $"public, max-age={secondsInDay}"); + string expireDate = DateTime.UtcNow.AddSeconds(secondsInDay) + .ToString("ddd, dd MMM yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); + response.Headers.SafeSet("Expires", expireDate + " GMT"); } public static void PrepareUncacheableResponse(this HttpResponse response) { response.Headers.SafeSet("Cache-Control", "max-age=0, no-cache, no-store"); - string ExpireDate = DateTime.UtcNow.AddSeconds(-1500).ToString("ddd, dd MMM yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); - response.Headers.SafeSet("Expires", ExpireDate + " GMT"); + string expireDate = DateTime.UtcNow.AddSeconds(-1500) + .ToString("ddd, dd MMM yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); + response.Headers.SafeSet("Expires", expireDate + " GMT"); } #endregion HttpContext diff --git a/VAR.WebFormsCore/Code/GlobalConfig.cs b/VAR.WebFormsCore/Code/GlobalConfig.cs index 14dbbec..7f6056a 100644 --- a/VAR.WebFormsCore/Code/GlobalConfig.cs +++ b/VAR.WebFormsCore/Code/GlobalConfig.cs @@ -5,25 +5,29 @@ namespace VAR.WebFormsCore.Code { public static class GlobalConfig { - private static IGlobalConfig _globalConfig = null; + private static IGlobalConfig _globalConfig; public static IGlobalConfig Get() { - if (_globalConfig == null) - { - Type iGlobalConfig = typeof(IGlobalConfig); - Type foundGlobalConfig = AppDomain.CurrentDomain - .GetAssemblies() - .SelectMany(x => x.GetTypes()) - .Where(x => + if (_globalConfig != null) { return _globalConfig; } + + Type iGlobalConfig = typeof(IGlobalConfig); + Type foundGlobalConfig = AppDomain.CurrentDomain + .GetAssemblies() + .SelectMany( + x => + x.GetTypes() + ) + .FirstOrDefault( + x => x.IsAbstract == false && x.IsInterface == false && iGlobalConfig.IsAssignableFrom(x) && - true) - .FirstOrDefault(); - _globalConfig = ObjectActivator.CreateInstance(foundGlobalConfig) as IGlobalConfig; - } + true + ); + _globalConfig = ObjectActivator.CreateInstance(foundGlobalConfig) as IGlobalConfig; + return _globalConfig; } } -} +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/GlobalErrorHandler.cs b/VAR.WebFormsCore/Code/GlobalErrorHandler.cs index 33bc5be..e7107b6 100644 --- a/VAR.WebFormsCore/Code/GlobalErrorHandler.cs +++ b/VAR.WebFormsCore/Code/GlobalErrorHandler.cs @@ -31,17 +31,18 @@ namespace VAR.WebFormsCore.Code if (fillResponse > 0) { sbOutput.Append(""); } await context.Response.WriteAsync(sbOutput.ToString()); await context.Response.Body.FlushAsync(); } - catch { /* Nom nom nom */ } + catch + { + /* Nom nom nom */ + } } #endregion Private methods @@ -58,10 +59,7 @@ namespace VAR.WebFormsCore.Code frmError.ProcessRequest(context); await context.Response.Body.FlushAsync(); } - catch - { - await ShowInternalErrorAsync(context, ex); - } + catch { await ShowInternalErrorAsync(context, ex); } } #endregion Public methods diff --git a/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs b/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs index b715aa0..802510a 100644 --- a/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs +++ b/VAR.WebFormsCore/Code/GlobalRouterMiddleware.cs @@ -12,13 +12,8 @@ namespace VAR.WebFormsCore.Code { public class GlobalRouterMiddleware { - private readonly RequestDelegate _next; - private readonly IWebHostEnvironment _env; - public GlobalRouterMiddleware(RequestDelegate next, IWebHostEnvironment env) { - _next = next; - _env = env; ServerHelpers.SetContentRoot(env.ContentRootPath); } @@ -46,26 +41,15 @@ namespace VAR.WebFormsCore.Code await GlobalErrorHandler.HandleErrorAsync(httpContext, ex); } } - } - private static bool IsIgnoreException(Exception ex) - { - if (ex is ThreadAbortException) - { - return true; - } - return false; - } + private static bool IsIgnoreException(Exception ex) { return ex is ThreadAbortException; } private void RouteRequest(HttpContext context) { string path = context.Request.Path; string file = Path.GetFileName(path); - if (string.IsNullOrEmpty(file)) - { - file = GlobalConfig.Get().DefaultHandler; - } + if (string.IsNullOrEmpty(file)) { file = GlobalConfig.Get().DefaultHandler; } // Pass allowed extensions requests string extension = Path.GetExtension(path).ToLower(); @@ -80,7 +64,7 @@ namespace VAR.WebFormsCore.Code else { // TODO: FrmNotFound - throw new Exception("NotFound"); + throw new Exception($"NotFound: {path}"); } } @@ -88,33 +72,36 @@ namespace VAR.WebFormsCore.Code if (handler == null) { // TODO: FrmNotFound - throw new Exception("NotFound"); + throw new Exception($"NotFound: {path}"); } // Use handler handler.ProcessRequest(context); } - private static Dictionary _handlers = new Dictionary(); + private static readonly Dictionary Handlers = new Dictionary(); private static IHttpHandler GetHandler(string typeName) { if (string.IsNullOrEmpty(typeName)) { return null; } + Type type = null; - if (_handlers.ContainsKey(typeName)) + lock (Handlers) { - type = _handlers[typeName]; - IHttpHandler handler = ObjectActivator.CreateInstance(type) as IHttpHandler; - return handler; + 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(); + Type[] types = asm.GetTypes(); foreach (Type typeAux in types) { - if (typeAux.FullName.EndsWith(typeName)) + if (typeAux.FullName?.EndsWith(typeName) == true) { type = typeAux; break; @@ -124,18 +111,18 @@ namespace VAR.WebFormsCore.Code // Search type on all loaded assemblies if (type == null) { - Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies(); - foreach (Assembly asmAux in asms) + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + foreach (Assembly asmAux in assemblies) { types = asmAux.GetTypes(); foreach (Type typeAux in types) { - if (typeAux.FullName.EndsWith(typeName)) - { - type = typeAux; - break; - } + if (typeAux.FullName?.EndsWith(typeName) != true) { continue; } + + type = typeAux; + break; } + if (type != null) { break; } } } @@ -146,27 +133,27 @@ namespace VAR.WebFormsCore.Code IHttpHandler handler = ObjectActivator.CreateInstance(type) as IHttpHandler; if (handler != null) { - lock (_handlers) + lock (Handlers) { - if (_handlers.ContainsKey(typeName) == false) - { - _handlers.Add(typeName, type); - } + if (Handlers.ContainsKey(typeName) == false) { Handlers.Add(typeName, type); } } } + return handler; } return null; } - } public static class GlobalRouterMiddlewareExtensions { - public static IApplicationBuilder UseGlobalRouterMiddleware(this IApplicationBuilder builder, IWebHostEnvironment env) + public static IApplicationBuilder UseGlobalRouterMiddleware( + this IApplicationBuilder builder, + IWebHostEnvironment env + ) { return builder.UseMiddleware(env); } } -} +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/IGlobalConfig.cs b/VAR.WebFormsCore/Code/IGlobalConfig.cs index 6b46a2d..c93fe32 100644 --- a/VAR.WebFormsCore/Code/IGlobalConfig.cs +++ b/VAR.WebFormsCore/Code/IGlobalConfig.cs @@ -16,4 +16,4 @@ namespace VAR.WebFormsCore.Code bool IsUserAuthenticated(HttpContext context); void UserUnauthenticate(HttpContext context); } -} +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/MultiLang.cs b/VAR.WebFormsCore/Code/MultiLang.cs index 030a91c..4e4de1d 100644 --- a/VAR.WebFormsCore/Code/MultiLang.cs +++ b/VAR.WebFormsCore/Code/MultiLang.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using VAR.Json; namespace VAR.WebFormsCore.Code { - public class MultiLang + public static class MultiLang { private static string GetPrivatePath(string baseDir, string fileName) { @@ -15,22 +14,24 @@ namespace VAR.WebFormsCore.Code { DirectoryInfo dirInfo = Directory.GetParent(currentDir); if (dirInfo == null) { break; } + currentDir = dirInfo.FullName; privatePath = Path.Combine(currentDir, baseDir); } + return Path.Combine(privatePath, fileName); } - private static Dictionary> _literals = null; + private static Dictionary> _literals; private static void InitializeLiterals() { _literals = new Dictionary>(); JsonParser jsonParser = new JsonParser(); - foreach (string lang in new string[] { "en", "es" }) + foreach (string lang in new[] {"en", "es"}) { - string filePath = GetPrivatePath("Resources", string.Format("Literals.{0}.json", lang)); + string filePath = GetPrivatePath("Resources", $"Literals.{lang}.json"); if (File.Exists(filePath) == false) { continue; } string strJsonLiteralsLanguage = File.ReadAllText(filePath); @@ -39,7 +40,7 @@ namespace VAR.WebFormsCore.Code } } - private const string _defaultLanguage = "en"; + private const string DefaultLanguage = "en"; private static string GetUserLanguage() { @@ -71,19 +72,25 @@ namespace VAR.WebFormsCore.Code // ctx.Items["UserLang"] = userLang; // return userLang; //} - return _defaultLanguage; + return DefaultLanguage; } public static string GetLiteral(string resource, string culture = null) { if (_literals == null) { InitializeLiterals(); } - if (culture == null) { culture = GetUserLanguage(); } + + culture ??= GetUserLanguage(); if (_literals == null || _literals.ContainsKey(culture) == false) { return resource; } - Dictionary _literalCurrentCulture = _literals[culture]; - if (_literalCurrentCulture == null || _literalCurrentCulture.ContainsKey(resource) == false) { return resource; } - return (_literalCurrentCulture[resource] as string) ?? resource; + Dictionary literalCurrentCulture = _literals[culture]; + + if (literalCurrentCulture == null || literalCurrentCulture.ContainsKey(resource) == false) + { + return resource; + } + + return (literalCurrentCulture[resource] as string) ?? resource; } } } \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/ObjectActivator.cs b/VAR.WebFormsCore/Code/ObjectActivator.cs index a4a81c7..ed3e3c1 100644 --- a/VAR.WebFormsCore/Code/ObjectActivator.cs +++ b/VAR.WebFormsCore/Code/ObjectActivator.cs @@ -4,26 +4,24 @@ using System.Linq.Expressions; namespace VAR.WebFormsCore.Code { - public class ObjectActivator + public static class ObjectActivator { - private static Dictionary> _creators = new Dictionary>(); + private static readonly Dictionary> Creators = new Dictionary>(); - public static Func GetLambdaNew(Type type) + private static Func GetLambdaNew(Type type) { - if (_creators.ContainsKey(type)) + lock (Creators) { - return _creators[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(); + Func compiledLambdaNew = (Func) lambda.Compile(); - _creators.Add(type, compiledLambdaNew); + Creators.Add(type, compiledLambdaNew); + + return Creators[type]; } - return _creators[type]; } public static object CreateInstance(Type type) diff --git a/VAR.WebFormsCore/Code/Program.cs b/VAR.WebFormsCore/Code/Program.cs index 58a2ada..bfe917b 100644 --- a/VAR.WebFormsCore/Code/Program.cs +++ b/VAR.WebFormsCore/Code/Program.cs @@ -2,8 +2,6 @@ { public class Program { - public static void Main() - { - } + public static void Main() { } } -} +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/ScriptsBundler.cs b/VAR.WebFormsCore/Code/ScriptsBundler.cs index 438db22..6a5e704 100644 --- a/VAR.WebFormsCore/Code/ScriptsBundler.cs +++ b/VAR.WebFormsCore/Code/ScriptsBundler.cs @@ -12,7 +12,8 @@ namespace VAR.WebFormsCore.Code Bundler bundler = new Bundler( assembly: Assembly.GetExecutingAssembly(), assemblyNamespace: "Scripts", - absolutePath: ServerHelpers.MapContentPath("Scripts")); + absolutePath: ServerHelpers.MapContentPath("Scripts") + ); context.Response.PrepareCacheableResponse(); bundler.WriteResponse(context.Response, "text/javascript"); } diff --git a/VAR.WebFormsCore/Code/ServerHelpers.cs b/VAR.WebFormsCore/Code/ServerHelpers.cs index de7ae19..ad139e7 100644 --- a/VAR.WebFormsCore/Code/ServerHelpers.cs +++ b/VAR.WebFormsCore/Code/ServerHelpers.cs @@ -3,13 +3,10 @@ using System.Text; namespace VAR.WebFormsCore.Code { - public class ServerHelpers + public static class ServerHelpers { - private static string _contentRoot = null; - public static void SetContentRoot(string contentRoot) - { - _contentRoot = contentRoot; - } + private static string _contentRoot; + public static void SetContentRoot(string contentRoot) { _contentRoot = contentRoot; } public static string MapContentPath(string path) { @@ -27,36 +24,18 @@ namespace VAR.WebFormsCore.Code { char ch = text[i]; - if (ch == '<') - { - sbResult.Append("<"); - } - else if (ch == '>') - { - sbResult.Append(">"); - } - else if (ch == '"') - { - sbResult.Append("""); - } - else if (ch == '\'') - { - sbResult.Append("'"); - } - else if (ch == '&') - { - sbResult.Append("&"); - } + if (ch == '<') { sbResult.Append("<"); } + else if (ch == '>') { sbResult.Append(">"); } + else if (ch == '"') { sbResult.Append("""); } + else if (ch == '\'') { sbResult.Append("'"); } + else if (ch == '&') { sbResult.Append("&"); } else if (ch > 127) { sbResult.Append("&#"); - sbResult.Append(((int)ch).ToString(NumberFormatInfo.InvariantInfo)); + sbResult.Append(((int) ch).ToString(NumberFormatInfo.InvariantInfo)); sbResult.Append(';'); } - else - { - sbResult.Append(ch); - } + else { sbResult.Append(ch); } } return sbResult.ToString(); @@ -72,18 +51,9 @@ namespace VAR.WebFormsCore.Code { char ch = text[i]; - if (ch == ' ') - { - sbResult.Append('+'); - } - else if (IsUrlSafe(ch) == false) - { - sbResult.AppendFormat("%{0:X02}", ch); - } - else - { - sbResult.Append(ch); - } + if (ch == ' ') { sbResult.Append('+'); } + else if (IsUrlSafe(ch) == false) { sbResult.AppendFormat("%{0:X02}", ch); } + else { sbResult.Append(ch); } } return sbResult.ToString(); @@ -102,12 +72,9 @@ namespace VAR.WebFormsCore.Code ch == '*' || ch == '(' || ch == ')' || - false) - { - return true; - } + false) { return true; } return false; } } -} +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/StaticFileHelper.cs b/VAR.WebFormsCore/Code/StaticFileHelper.cs index 73c6ce4..84c8943 100644 --- a/VAR.WebFormsCore/Code/StaticFileHelper.cs +++ b/VAR.WebFormsCore/Code/StaticFileHelper.cs @@ -4,9 +4,11 @@ using Microsoft.AspNetCore.Http; namespace VAR.WebFormsCore.Code { - public class StaticFileHelper + public static class StaticFileHelper { - private static Dictionary _mimeTypeByExtension = new Dictionary { {".aac", "audio/aac"}, + private static readonly Dictionary MimeTypeByExtension = new Dictionary + { + {".aac", "audio/aac"}, {".abw", "application/x-abiword"}, {".arc", "application/octet-stream"}, {".avi", "video/x-msvideo"}, @@ -70,20 +72,14 @@ namespace VAR.WebFormsCore.Code { string extension = Path.GetExtension(filePath).ToLower(); string contentType = null; - if (_mimeTypeByExtension.ContainsKey(extension)) - { - contentType = _mimeTypeByExtension[extension]; - } + if (MimeTypeByExtension.ContainsKey(extension)) { contentType = MimeTypeByExtension[extension]; } + + if (string.IsNullOrEmpty(contentType) == false) { context.Response.ContentType = contentType; } - if (string.IsNullOrEmpty(contentType) == false) - { - context.Response.ContentType = contentType; - } context.Response.PrepareCacheableResponse(); byte[] fileData = File.ReadAllBytes(filePath); await context.Response.Body.WriteAsync(fileData); } - } } \ No newline at end of file diff --git a/VAR.WebFormsCore/Code/StylesBundler.cs b/VAR.WebFormsCore/Code/StylesBundler.cs index d910598..fd48e7a 100644 --- a/VAR.WebFormsCore/Code/StylesBundler.cs +++ b/VAR.WebFormsCore/Code/StylesBundler.cs @@ -12,7 +12,8 @@ namespace VAR.WebFormsCore.Code Bundler bundler = new Bundler( assembly: Assembly.GetExecutingAssembly(), assemblyNamespace: "Styles", - absolutePath: ServerHelpers.MapContentPath("Styles")); + absolutePath: ServerHelpers.MapContentPath("Styles") + ); context.Response.PrepareCacheableResponse(); bundler.WriteResponse(context.Response, "text/css"); } diff --git a/VAR.WebFormsCore/Code/Unit.cs b/VAR.WebFormsCore/Code/Unit.cs index 3f9061f..52706ed 100644 --- a/VAR.WebFormsCore/Code/Unit.cs +++ b/VAR.WebFormsCore/Code/Unit.cs @@ -2,8 +2,8 @@ { public class Unit { - private int _value; - private UnitType _unitType; + private readonly int _value; + private readonly UnitType _unitType; public Unit(int value, UnitType type) { @@ -13,15 +13,9 @@ public override string ToString() { - if (_unitType == UnitType.Pixel) - { - return string.Format("{0}px", _value); - } + if (_unitType == UnitType.Pixel) { return $"{_value}px"; } - if (_unitType == UnitType.Percentaje) - { - return string.Format("{0}%", _value); - } + if (_unitType == UnitType.Percentage) { return $"{_value}%"; } return string.Empty; } @@ -29,7 +23,6 @@ public enum UnitType { - Pixel, - Percentaje, + Pixel, Percentage, } -} +} \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/Button.cs b/VAR.WebFormsCore/Controls/Button.cs index 99b76b0..2507001 100644 --- a/VAR.WebFormsCore/Controls/Button.cs +++ b/VAR.WebFormsCore/Controls/Button.cs @@ -5,18 +5,17 @@ namespace VAR.WebFormsCore.Controls { public class Button : Control, IReceivePostbackEvent { - public Button() - { - CssClass = "button"; - } + public Button() { CssClass = "button"; } private string _text = string.Empty; - public string Text { get { return _text; } set { _text = value; } } + public string Text + { + get => _text; + set => _text = value; + } - private string _commandArgument = string.Empty; - - public string CommandArgument { get { return _commandArgument; } set { _commandArgument = value; } } + public string CommandArgument { get; set; } = string.Empty; public event EventHandler Click; @@ -32,9 +31,6 @@ namespace VAR.WebFormsCore.Controls textWriter.Write(""); } - public void ReceivePostBack() - { - Click?.Invoke(this, null); - } + public void ReceivePostBack() { Click?.Invoke(this, EventArgs.Empty); } } } \ No newline at end of file diff --git a/VAR.WebFormsCore/Controls/CTextBox.cs b/VAR.WebFormsCore/Controls/CTextBox.cs index 8dd3117..caefacb 100644 --- a/VAR.WebFormsCore/Controls/CTextBox.cs +++ b/VAR.WebFormsCore/Controls/CTextBox.cs @@ -9,9 +9,9 @@ namespace VAR.WebFormsCore.Controls { #region Declarations - private TextBox _txtContent = new TextBox(); + private readonly TextBox _txtContent = new TextBox(); - private HiddenField _hidSize = null; + private HiddenField _hidSize; private const string CssClassBase = "textbox"; private string _cssClassExtra = ""; @@ -20,11 +20,11 @@ namespace VAR.WebFormsCore.Controls private string _placeHolder = string.Empty; - private bool _markedInvalid = false; + private bool _markedInvalid; - private Control _nextFocusOnEnter = null; + private Control _nextFocusOnEnter; - private bool _keepSize = false; + private bool _keepSize; #endregion Declarations @@ -32,50 +32,50 @@ namespace VAR.WebFormsCore.Controls public string CssClassExtra { - get { return _cssClassExtra; } - set { _cssClassExtra = value; } + get => _cssClassExtra; + set => _cssClassExtra = value; } public bool AllowEmpty { - get { return _allowEmpty; } - set { _allowEmpty = value; } + get => _allowEmpty; + set => _allowEmpty = value; } public string PlaceHolder { - get { return _placeHolder; } - set { _placeHolder = value; } + get => _placeHolder; + set => _placeHolder = value; } public bool MarkedInvalid { - get { return _markedInvalid; } - set { _markedInvalid = value; } + get => _markedInvalid; + set => _markedInvalid = value; } public Control NextFocusOnEnter { - get { return _nextFocusOnEnter; } - set { _nextFocusOnEnter = value; } + get => _nextFocusOnEnter; + set => _nextFocusOnEnter = value; } public bool KeepSize { - get { return _keepSize; } - set { _keepSize = value; } + get => _keepSize; + set => _keepSize = value; } public string Text { - get { return _txtContent.Text; } - set { _txtContent.Text = value; } + get => _txtContent.Text; + set => _txtContent.Text = value; } public TextBoxMode TextMode { - get { return _txtContent.TextMode; } - set { _txtContent.TextMode = value; } + get => _txtContent.TextMode; + init => _txtContent.TextMode = value; } #endregion Properties @@ -100,12 +100,10 @@ namespace VAR.WebFormsCore.Controls Controls.Add(_hidSize); } - string strCfgName = string.Format("{0}_cfg", this.ClientID); + string strCfgName = $"{this.ClientID}_cfg"; Dictionary cfg = new Dictionary { - {"txtContent", _txtContent.ClientID}, - {"hidSize", _hidSize.ClientID}, - {"keepSize", _keepSize }, + {"txtContent", _txtContent.ClientID}, {"hidSize", _hidSize.ClientID}, {"keepSize", _keepSize}, }; StringBuilder sbCfg = new StringBuilder(); sbCfg.AppendFormat("\n", version))); - _head.Controls.Add(new LiteralControl(string.Format("\n", version))); + string version = Assembly.GetExecutingAssembly().GetName().Version?.ToString(); + _head.Controls.Add( + new LiteralControl($"\n") + ); + _head.Controls.Add( + new LiteralControl($"\n") + ); _body = new HtmlBody(); html.Controls.Add(_body); - _form = new HtmlForm { ID = "formMain" }; + _form = new HtmlForm {ID = "formMain"}; _body.Controls.Add(_form); - var pnlHeader = new Panel { CssClass = "divHeader" }; + var pnlHeader = new Panel {CssClass = "divHeader"}; _form.Controls.Add(pnlHeader); - HyperLink lnkTitle = new HyperLink(); - lnkTitle.NavigateUrl = "."; + HyperLink lnkTitle = new HyperLink {NavigateUrl = "."}; pnlHeader.Controls.Add(lnkTitle); - var lblTitle = new Label { Text = GlobalConfig.Get().Title, Tag = "h1" }; + var lblTitle = new Label {Text = GlobalConfig.Get().Title, Tag = "h1"}; lnkTitle.Controls.Add(lblTitle); _btnPostback.ID = "btnPostback"; @@ -127,13 +124,16 @@ namespace VAR.WebFormsCore.Pages pnlHeader.Controls.Add(_btnPostback); _btnPostback.Style.Add("display", "none"); - var pnlUserInfo = new Panel { CssClass = "divUserInfo" }; + 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"))); + _btnLogout.Attributes.Add( + "onclick", + $"return confirm('{MultiLang.GetLiteral("ConfirmExit")}');" + ); pnlUserInfo.Controls.Add(_btnLogout); _pnlContainer.CssClass = "divContent"; diff --git a/VAR.WebFormsCore/Scripts/03. Controls.js b/VAR.WebFormsCore/Scripts/03. Controls.js index 4c0ec17..2177487 100644 --- a/VAR.WebFormsCore/Scripts/03. Controls.js +++ b/VAR.WebFormsCore/Scripts/03. Controls.js @@ -1,6 +1,5 @@ - -//////////////////////// -// CTextBox_Multilin_SetText +//////////////////////// +// CTextBox_SetText // var CTextBox_SetText = function (id, text) { var element = document.getElementById(id); diff --git a/VAR.WebFormsCore/Styles/01. base.css b/VAR.WebFormsCore/Styles/01. base.css index 7426fa9..8fb2126 100644 --- a/VAR.WebFormsCore/Styles/01. base.css +++ b/VAR.WebFormsCore/Styles/01. base.css @@ -16,7 +16,7 @@ form { p { margin-bottom: 0.5em; - text-shadow: 0 1px 1px rgba(255,255,255,0.5); + text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5); } h1 { @@ -24,7 +24,7 @@ h1 { text-align: center; margin-top: 1.0em; margin-bottom: 0.5em; - text-shadow: 0 1px 1px rgba(255,255,255,0.5); + text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5); } h2 { @@ -32,7 +32,7 @@ h2 { text-align: center; margin-top: 1.0em; margin-bottom: 0.5em; - text-shadow: 0 1px 1px rgba(255,255,255,0.5); + text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5); } h3 { @@ -40,7 +40,7 @@ h3 { text-align: left; margin-top: 1.0em; margin-bottom: 0.5em; - text-shadow: 0 1px 1px rgba(255,255,255,0.5); + text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5); } .divHeader { @@ -80,7 +80,7 @@ h3 { overflow: auto; margin: 5px; padding: 2px; - box-shadow: 0 0 10px rgb(0,0,0); + box-shadow: 0 0 10px rgb(0, 0, 0); } .formColumn { @@ -98,7 +98,7 @@ h3 { display: inline-block; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 12px; - text-shadow: 0 1px 1px rgba(255,255,255,0.5); + text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5); text-align: right; padding-right: 20px; vertical-align: top; @@ -122,12 +122,12 @@ h3 { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 11px; padding: 3px; - box-shadow: inset 0 -2px 5px rgba(255,255,255,1), inset 0 2px 5px rgba(128,128,128,1); + box-shadow: inset 0 -2px 5px rgba(255, 255, 255, 1), inset 0 2px 5px rgba(128, 128, 128, 1); } .textbox:focus { border: solid 1px black; - box-shadow: 0 0 10px rgba(255,255,255,0.5), inset 0 -2px 5px rgba(255,255,255,1), inset 0 2px 5px rgba(0,0,0,0.5); + box-shadow: 0 0 10px rgba(255, 255, 255, 0.5), inset 0 -2px 5px rgba(255, 255, 255, 1), inset 0 2px 5px rgba(0, 0, 0, 0.5); } textarea.textbox { @@ -137,26 +137,26 @@ textarea.textbox { } .textboxInvalid { - box-shadow: 0 0 10px rgba(255,0,0,1), inset 0 -2px 5px rgba(255,255,255,1), inset 0 2px 5px rgba(0,0,0,0.5); - border: solid 1px rgb(255,0,0); + box-shadow: 0 0 10px rgba(255, 0, 0, 1), inset 0 -2px 5px rgba(255, 255, 255, 1), inset 0 2px 5px rgba(0, 0, 0, 0.5); + border: solid 1px rgb(255, 0, 0); } .textboxInvalid:focus { - box-shadow: 0 0 10px rgba(255,0,0,1), inset 0 -2px 5px rgba(255,255,255,1), inset 0 2px 5px rgba(0,0,0,0.5); + box-shadow: 0 0 10px rgba(255, 0, 0, 1), inset 0 -2px 5px rgba(255, 255, 255, 1), inset 0 2px 5px rgba(0, 0, 0, 0.5); border: solid 1px black; } .button { - box-shadow: 0 2px 10px rgba(0,0,0,0.5), inset 0 2px 5px rgba(255,255,255,1), inset 0 -2px 5px rgba(128,128,128,1); + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), inset 0 2px 5px rgba(255, 255, 255, 1), inset 0 -2px 5px rgba(128, 128, 128, 1); vertical-align: top; border-radius: 5px; border: solid 1px rgba(0, 0, 0, 0.5); font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; font-size: 11px; - text-shadow: 0 1px 1px rgba(255,255,255,0.5); + text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5); text-align: center; cursor: pointer; - background-color: rgb(192,192,192); + background-color: rgb(192, 192, 192); margin-left: 5px; padding-bottom: 2px; padding-top: 2px; @@ -169,15 +169,15 @@ textarea.textbox { } .button:hover { - background-color: rgb(220,220,220); + background-color: rgb(220, 220, 220); } .button:focus { border: solid 1px black; } .button:active { - background-color: rgb(220,220,220); - box-shadow: inset 0 2px 5px rgba(255,255,255,1), inset 0 -2px 5px rgba(128,128,128,1); + background-color: rgb(220, 220, 220); + box-shadow: inset 0 2px 5px rgba(255, 255, 255, 1), inset 0 -2px 5px rgba(128, 128, 128, 1); } .width25pc {