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