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