Cleanup
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
namespace VAR.WebFormsCore.TestWebApp
|
namespace VAR.WebFormsCore.TestWebApp
|
||||||
{
|
{
|
||||||
public class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
CreateHostBuilder(args).Build().Run();
|
CreateHostBuilder(args).Build().Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||||
Host.CreateDefaultBuilder(args)
|
Host.CreateDefaultBuilder(args)
|
||||||
.ConfigureWebHostDefaults(webBuilder =>
|
.ConfigureWebHostDefaults(webBuilder =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,15 +2,18 @@ using VAR.WebFormsCore.Code;
|
|||||||
|
|
||||||
namespace VAR.WebFormsCore.TestWebApp;
|
namespace VAR.WebFormsCore.TestWebApp;
|
||||||
|
|
||||||
public class TestWebAppGlobalConfig: IGlobalConfig
|
public class TestWebAppGlobalConfig : IGlobalConfig
|
||||||
{
|
{
|
||||||
public string Title { get; } = "TestWebApp";
|
public string Title => "TestWebApp";
|
||||||
public string TitleSeparator { get; } = " :: ";
|
public string TitleSeparator => " :: ";
|
||||||
public string Author { get; } = "XXX";
|
public string Author => "XXX";
|
||||||
public string Copyright { get; } = "Copyright (c) 2022 by XXX, All Right Reserved";
|
public string Copyright => "Copyright (c) 2022 by XXX, All Right Reserved";
|
||||||
public string DefaultHandler { get; } = nameof(FrmDefault);
|
public string DefaultHandler => nameof(FrmDefault);
|
||||||
public string LoginHandler { get; } = nameof(FrmDefault);
|
public string LoginHandler => nameof(FrmDefault);
|
||||||
public List<string> AllowedExtensions { get; } = new List<string> { ".png", ".jpg", ".jpeg", ".gif", ".ico", ".wav", ".mp3", ".ogg", ".mp4", ".webm", ".webp", ".mkv", ".avi" };
|
|
||||||
|
public List<string> AllowedExtensions { get; } = new()
|
||||||
|
{ ".png", ".jpg", ".jpeg", ".gif", ".ico", ".wav", ".mp3", ".ogg", ".mp4", ".webm", ".webp", ".mkv", ".avi" };
|
||||||
|
|
||||||
public bool IsUserAuthenticated(HttpContext context)
|
public bool IsUserAuthenticated(HttpContext context)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -28,25 +28,20 @@ namespace VAR.WebFormsCore.Code
|
|||||||
{
|
{
|
||||||
_globalConfig = ObjectActivator.CreateInstance(foundGlobalConfig) as IGlobalConfig;
|
_globalConfig = ObjectActivator.CreateInstance(foundGlobalConfig) as IGlobalConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_globalConfig == null)
|
|
||||||
{
|
|
||||||
_globalConfig = new DefaultGlobalConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
return _globalConfig;
|
return _globalConfig ??= new DefaultGlobalConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Better default global config
|
// TODO: Better default global config
|
||||||
private class DefaultGlobalConfig : IGlobalConfig
|
private class DefaultGlobalConfig : IGlobalConfig
|
||||||
{
|
{
|
||||||
public string Title { get; } = string.Empty;
|
public string Title => string.Empty;
|
||||||
public string TitleSeparator { get; } = string.Empty;
|
public string TitleSeparator => string.Empty;
|
||||||
public string Author { get; } = string.Empty;
|
public string Author => string.Empty;
|
||||||
public string Copyright { get; } = string.Empty;
|
public string Copyright => string.Empty;
|
||||||
public string DefaultHandler { get; } = string.Empty;
|
public string DefaultHandler => string.Empty;
|
||||||
public string LoginHandler { get; } = string.Empty;
|
public string LoginHandler => string.Empty;
|
||||||
public List<string> AllowedExtensions { get; } = new List<string>();
|
public List<string> AllowedExtensions { get; } = new();
|
||||||
|
|
||||||
public bool IsUserAuthenticated(HttpContext context)
|
public bool IsUserAuthenticated(HttpContext context)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace VAR.WebFormsCore.Code
|
|||||||
Exception? exAux = ex;
|
Exception? exAux = ex;
|
||||||
while (exAux != null)
|
while (exAux != null)
|
||||||
{
|
{
|
||||||
sbOutput.AppendFormat("<p><b>Message:</b> {0}</p>", exAux.Message);
|
sbOutput.Append($"<p><b>Message:</b> {exAux.Message}</p>");
|
||||||
sbOutput.AppendFormat("<p><b>StackTrace:</b></p> <pre><code>{0}</code></pre>", exAux.StackTrace);
|
sbOutput.Append($"<p><b>StackTrace:</b></p> <pre><code>{exAux.StackTrace}</code></pre>");
|
||||||
exAux = exAux.InnerException;
|
exAux = exAux.InnerException;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace VAR.WebFormsCore.Code
|
|||||||
handler.ProcessRequest(context);
|
handler.ProcessRequest(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Dictionary<string, Type> Handlers = new Dictionary<string, Type>();
|
private static readonly Dictionary<string, Type> Handlers = new();
|
||||||
|
|
||||||
private static IHttpHandler? GetHandler(string typeName)
|
private static IHttpHandler? GetHandler(string typeName)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace VAR.WebFormsCore.Code
|
|||||||
{
|
{
|
||||||
public static class ObjectActivator
|
public static class ObjectActivator
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<Type, Func<object>> Creators = new Dictionary<Type, Func<object>>();
|
private static readonly Dictionary<Type, Func<object>> Creators = new();
|
||||||
|
|
||||||
private static Func<object> GetLambdaNew(Type type)
|
private static Func<object> GetLambdaNew(Type type)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace VAR.WebFormsCore.Code
|
|
||||||
{
|
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
public static void Main() { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,11 @@ namespace VAR.WebFormsCore.Code
|
|||||||
public static class ServerHelpers
|
public static class ServerHelpers
|
||||||
{
|
{
|
||||||
private static string? _contentRoot;
|
private static string? _contentRoot;
|
||||||
public static void SetContentRoot(string contentRoot) { _contentRoot = contentRoot; }
|
|
||||||
|
public static void SetContentRoot(string contentRoot)
|
||||||
|
{
|
||||||
|
_contentRoot = contentRoot;
|
||||||
|
}
|
||||||
|
|
||||||
public static string MapContentPath(string path)
|
public static string MapContentPath(string path)
|
||||||
{
|
{
|
||||||
@@ -16,26 +20,48 @@ namespace VAR.WebFormsCore.Code
|
|||||||
|
|
||||||
public static string HtmlEncode(string text)
|
public static string HtmlEncode(string text)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(text)) { return text; }
|
if (string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder sbResult = new();
|
StringBuilder sbResult = new();
|
||||||
|
|
||||||
for (int i = 0; i < text.Length; i++)
|
foreach (var ch in text)
|
||||||
{
|
{
|
||||||
char ch = text[i];
|
switch (ch)
|
||||||
|
|
||||||
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("&#");
|
case '<':
|
||||||
sbResult.Append(((int) ch).ToString(NumberFormatInfo.InvariantInfo));
|
sbResult.Append("<");
|
||||||
sbResult.Append(';');
|
break;
|
||||||
|
case '>':
|
||||||
|
sbResult.Append(">");
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
sbResult.Append(""");
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
sbResult.Append("'");
|
||||||
|
break;
|
||||||
|
case '&':
|
||||||
|
sbResult.Append("&");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (ch > 127)
|
||||||
|
{
|
||||||
|
sbResult.Append("&#");
|
||||||
|
sbResult.Append(((int)ch).ToString(NumberFormatInfo.InvariantInfo));
|
||||||
|
sbResult.Append(';');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sbResult.Append(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else { sbResult.Append(ch); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sbResult.ToString();
|
return sbResult.ToString();
|
||||||
@@ -43,23 +69,33 @@ namespace VAR.WebFormsCore.Code
|
|||||||
|
|
||||||
public static string UrlEncode(string text)
|
public static string UrlEncode(string text)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(text)) { return text; }
|
if (string.IsNullOrEmpty(text))
|
||||||
|
{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder sbResult = new();
|
StringBuilder sbResult = new();
|
||||||
|
|
||||||
for (int i = 0; i < text.Length; i++)
|
foreach (var ch in text)
|
||||||
{
|
{
|
||||||
char ch = text[i];
|
if (ch == ' ')
|
||||||
|
{
|
||||||
if (ch == ' ') { sbResult.Append('+'); }
|
sbResult.Append('+');
|
||||||
else if (IsUrlSafe(ch) == false) { sbResult.AppendFormat("%{0:X02}", ch); }
|
}
|
||||||
else { sbResult.Append(ch); }
|
else if (IsUrlSafe(ch) == false)
|
||||||
|
{
|
||||||
|
sbResult.Append($"%{ch:X02}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sbResult.Append(ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sbResult.ToString();
|
return sbResult.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsUrlSafe(char ch)
|
private static bool IsUrlSafe(char ch)
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
(ch >= 'a' && ch <= 'z') ||
|
(ch >= 'a' && ch <= 'z') ||
|
||||||
@@ -71,7 +107,10 @@ namespace VAR.WebFormsCore.Code
|
|||||||
ch == '!' ||
|
ch == '!' ||
|
||||||
ch == '*' ||
|
ch == '*' ||
|
||||||
ch == '(' ||
|
ch == '(' ||
|
||||||
ch == ')') { return true; }
|
ch == ')')
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace VAR.WebFormsCore.Controls
|
|||||||
{
|
{
|
||||||
#region Declarations
|
#region Declarations
|
||||||
|
|
||||||
private readonly TextBox _txtContent = new TextBox();
|
private readonly TextBox _txtContent = new();
|
||||||
|
|
||||||
private HiddenField? _hidSize;
|
private HiddenField? _hidSize;
|
||||||
|
|
||||||
@@ -101,14 +101,14 @@ namespace VAR.WebFormsCore.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
string strCfgName = $"{this.ClientID}_cfg";
|
string strCfgName = $"{this.ClientID}_cfg";
|
||||||
Dictionary<string, object> cfg = new Dictionary<string, object>
|
Dictionary<string, object> cfg = new()
|
||||||
{
|
{
|
||||||
{"txtContent", _txtContent.ClientID}, {"hidSize", _hidSize?.ClientID ?? string.Empty}, {"keepSize", _keepSize},
|
{"txtContent", _txtContent.ClientID}, {"hidSize", _hidSize?.ClientID ?? string.Empty}, {"keepSize", _keepSize},
|
||||||
};
|
};
|
||||||
StringBuilder sbCfg = new StringBuilder();
|
StringBuilder sbCfg = new StringBuilder();
|
||||||
sbCfg.AppendFormat("<script>\n");
|
sbCfg.AppendFormat("<script>\n");
|
||||||
sbCfg.AppendFormat("var {0} = {1};\n", strCfgName, JsonWriter.WriteObject(cfg));
|
sbCfg.Append($"var {strCfgName} = {JsonWriter.WriteObject(cfg)};\n");
|
||||||
sbCfg.AppendFormat("CTextBox_Multiline_Init({0});\n", strCfgName);
|
sbCfg.Append($"CTextBox_Multiline_Init({strCfgName});\n");
|
||||||
sbCfg.AppendFormat("</script>\n");
|
sbCfg.AppendFormat("</script>\n");
|
||||||
LiteralControl liScript = new LiteralControl(sbCfg.ToString());
|
LiteralControl liScript = new LiteralControl(sbCfg.ToString());
|
||||||
Controls.Add(liScript);
|
Controls.Add(liScript);
|
||||||
@@ -182,10 +182,7 @@ namespace VAR.WebFormsCore.Controls
|
|||||||
JsonParser jsonParser = new JsonParser();
|
JsonParser jsonParser = new JsonParser();
|
||||||
sizeObj = jsonParser.Parse(_hidSize.Value) as Dictionary<string, object?>;
|
sizeObj = jsonParser.Parse(_hidSize.Value) as Dictionary<string, object?>;
|
||||||
}
|
}
|
||||||
if(sizeObj == null)
|
sizeObj ??= new Dictionary<string, object?> { { "height", height }, { "width", null }, { "scrollTop", null }, };
|
||||||
{
|
|
||||||
sizeObj = new Dictionary<string, object?> {{"height", height}, {"width", null}, {"scrollTop", null},};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_hidSize != null)
|
if (_hidSize != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace VAR.WebFormsCore.Controls
|
|||||||
{
|
{
|
||||||
public class HtmlForm : Control
|
public class HtmlForm : Control
|
||||||
{
|
{
|
||||||
private string _method = "post";
|
private readonly string _method = "post";
|
||||||
|
|
||||||
protected override void Render(TextWriter textWriter)
|
protected override void Render(TextWriter textWriter)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user