Compare commits

..

No commits in common. "35ea6c3cd70932911eb427892fc4dcd382dfe417" and "0750456c5fd2d4aaaa2d8478357c8e76d118430d" have entirely different histories.

9 changed files with 39 additions and 159 deletions

View File

@ -13,7 +13,6 @@ public abstract class Control : IWebHandler
}
public Dictionary<string, string> PathVariables { get; } = new Dictionary<string, string>();
public Control(Dictionary<string, string>? pathVariables = null)
{
if (pathVariables == null)
@ -33,11 +32,6 @@ public abstract class Control : IWebHandler
public Dictionary<string, string> Attributes { get; } = new Dictionary<string, string>();
public CssClassList ClassList { get; } = new CssClassList();
protected virtual IEnumerable<string> GetStyleClasses()
{
return new string[0];
}
private bool _initted = false;
protected void EnsureInitialized()
{
@ -63,17 +57,15 @@ public abstract class Control : IWebHandler
if (kvp.Key == "class")
{
IEnumerable<string> classList = ClassList.Union(kvp.Value.Split(new char[] { ' ' }));
value = String.Join(' ', classList);
classListWritten = true;
}
writer.WriteAttributeString(kvp.Key, value);
}
IEnumerable<string> actualClassList = ClassList.Union(GetStyleClasses());
if (!classListWritten && actualClassList.Count() > 0)
if (!classListWritten && ClassList.Count > 0)
{
writer.WriteAttributeString("class", String.Join(' ', actualClassList));
writer.WriteAttributeString("class", String.Join(' ', ClassList));
}
}
protected virtual void RenderEndTag(XmlWriter writer)
@ -92,7 +84,7 @@ public abstract class Control : IWebHandler
{
context.Response.ContentType = "application/xhtml+xml";
OnInit(new RenderEventArgs(context));
OnInit(new RenderEventArgs(context.Request, context.Response));
XmlWriter writer = XmlWriter.Create(context.Response.Stream);
Render(writer);

View File

@ -2,11 +2,14 @@ namespace MBS.Web;
public class RenderEventArgs : EventArgs
{
public WebContext Context { get; }
public RenderEventArgs(WebContext context)
public WebRequest Request { get; }
public WebResponse Response { get; }
public RenderEventArgs(WebRequest request, WebResponse response)
{
Context = context;
Request = request;
Response = response;
}
}

View File

@ -1,9 +0,0 @@
namespace MBS.Web.UI;
public enum ThemeColorPreset
{
Unspecified = 0,
Primary,
Warning,
Danger
}

View File

@ -18,19 +18,6 @@ public abstract class WebControl : Control
}
}
public string ClientId { get { return String.Format("UWT{0}", NanoIdString); } }
public ThemeColorPreset ThemeColorPreset { get; set;} = ThemeColorPreset.Unspecified;
protected override IEnumerable<string> GetStyleClasses()
{
List<string> styleClasses = new List<string>();
switch (ThemeColorPreset)
{
case ThemeColorPreset.Primary: styleClasses.Add("uwt-color-primary"); break;
case ThemeColorPreset.Warning: styleClasses.Add("uwt-color-warning"); break;
case ThemeColorPreset.Danger: styleClasses.Add("uwt-color-danger"); break;
}
return styleClasses;
}
protected override IDictionary<string, string> GetControlAttributes()
{

View File

@ -1,23 +0,0 @@
namespace MBS.Web.UI.WebControls;
public class AdditionalDetailWidget : Container
{
protected override string TagName => "div";
protected override IEnumerable<string> GetStyleClasses()
{
return new string[] { "uwt-actionpreviewbutton apb-show-text apb-style-ellipsis" };
}
protected override IList<Control> GetChildControls()
{
return base.GetChildControls();
}
// <div data-ecid="56$279" data-instance-ids="22002$1" data-valid-class-ids="1$22002" data-autocomplete-url="~/prompt/c0/3$37643" class="mcx-instancebrowser mcx-editable mcx-editing">
// <div class="uwt-title">Manufacturer</div><input type="hidden" name="ec_56$276:56$279" value="22002$1"><input type="text" />
// <ul class="mcx-selected-items"><li>
// <div data-instance-id="22002$1" class="mcx-moniker uwt-actionpreviewbutton apb-show-text apb-style-ellipsis"><a class="apb-text" href="/super/d/inst/1$22002/22002$1.htmld">Paper Mate</a><a class="apb-button" href="/super/d/inst/22002$1/rel-tasks.htmld" tabindex="-1">&nbsp;</a><div class="apb-preview uwt-popup"><div class="apb-actions uwt-empty"><h2>Available Actions</h2><ul class="uwt-menu"></ul></div><div class="apb-preview-content"><div class="apb-header"><h2><span class="apb-class-title">Manufacturer</span><a class="apb-text" href="/super/d/inst/1$22002/22002$1.htmld">Paper Mate</a></h2></div><div class="apb-content"></div></div><div class="uwt-spinner">&nbsp;</div></div></div><a class="uwt-delete-button"></a></li></ul><div class="uwt-popup mcx-search-results uwt-loading mcx-placeholder-visible"><ul class="uwt-menu uwt-multiselect"></ul><div class="uwt-spinner"></div><div class="uwt-placeholder">type to search the list</div></div></div>
}

View File

@ -2,17 +2,14 @@ namespace MBS.Web;
public class WebContext
{
public WebContext(WebApplication application, WebRequest request, WebResponse response, Dictionary<string, string> session)
public WebContext(WebApplication application, WebRequest request, WebResponse response)
{
Application = application;
Request = request;
Response = response;
Session = session;
}
public WebApplication Application { get; }
public WebRequest Request { get; }
public WebResponse Response { get; }
public Dictionary<string, string> Session { get; }
}

View File

@ -3,8 +3,9 @@ using MBS.Core;
namespace MBS.Web;
public class WebHeaderCollection : Dictionary<string, List<string>>
public class WebHeaderCollection : List<KeyValuePair<string, string>>
{
private Dictionary<string, List<string>> _list = new Dictionary<string, List<string>>();
public string? this[System.Net.HttpRequestHeader key]
{
get
@ -34,50 +35,51 @@ public class WebHeaderCollection : Dictionary<string, List<string>>
}
}
public new string this[string key]
public string? this[string key]
{
get
{
if (base.ContainsKey(key))
if (_list.ContainsKey(key))
{
if (base[key].Count > 0)
if (_list[key].Count > 0)
{
return base[key][base[key].Count - 1];
return _list[key][_list[key].Count - 1];
}
}
return String.Empty;
return null;
}
set
{
if (!base.ContainsKey(key))
if (!_list.ContainsKey(key))
{
base[key] = new List<string>();
_list[key] = new List<string>();
}
if (!base[key].Contains(value))
if (!_list[key].Contains(value))
{
base[key].Add(value);
_list[key].Add(value);
}
}
}
public IReadOnlyList<string> GetValues(string key)
{
return base[key];
return _list[key];
}
public void Add(string key, string value)
{
Add(new KeyValuePair<string, string>(key, value));
}
public void Add(KeyValuePair<string, string> value)
public new void Add(KeyValuePair<string, string> value)
{
if (!base.ContainsKey(value.Key))
if (!_list.ContainsKey(value.Key))
{
base[value.Key] = new List<string>();
_list[value.Key] = new List<string>();
}
if (!base[value.Key].Contains(value.Value))
if (!_list[value.Key].Contains(value.Value))
{
base[value.Key].Add(value.Value);
_list[value.Key].Add(value.Value);
}
base.Add(value);
}
}

View File

@ -1,4 +1,3 @@
using System.Collections.ObjectModel;
using System.Net;
namespace MBS.Web;
@ -14,9 +13,7 @@ public class WebRequest
public Dictionary<string, string> PathVariables { get; }
public WebHeaderCollection Headers { get; }
public ReadOnlyDictionary<string, string> Form { get; }
public WebRequest(string version, string method, string path, WebHeaderCollection headers, Dictionary<string, string> pathVariables, Dictionary<string, string> form)
public WebRequest(string version, string method, string path, WebHeaderCollection headers, Dictionary<string, string> pathVariables)
{
Version = version;
Method = method;
@ -27,6 +24,5 @@ public class WebRequest
}
Headers = headers;
PathVariables = pathVariables;
Form = new ReadOnlyDictionary<string, string>(form);
}
}

View File

@ -1,6 +1,4 @@
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using MBS.Core;
using MBS.Web.UI;
@ -88,12 +86,9 @@ public class WebServer
{
sw.WriteLine(String.Format("{0}: {1}", header.Key, header.Value));
}
foreach (KeyValuePair<string, List<string>> header in context.Response.Headers)
foreach (KeyValuePair<string, string> header in context.Response.Headers)
{
foreach (string val in header.Value)
{
sw.WriteLine(String.Format("{0}: {1}", header.Key, val));
}
sw.WriteLine(String.Format("{0}: {1}", header.Key, header.Value));
}
foreach (WebCookie cookie in context.Response.Cookies)
{
@ -133,8 +128,6 @@ public class WebServer
return sb.ToString();
}
private Dictionary<string, Dictionary<string, string>> _sessions = new Dictionary<string, Dictionary<string, string>>();
private void HandleClient(System.Net.Sockets.TcpClient client)
{
// WebServerProcessRequestEventArgs e = new WebServerProcessRequestEventArgs();
@ -146,11 +139,8 @@ public class WebServer
return;
}
*/
// client.ReceiveTimeout = 5000;
// client.SendTimeout = 5000;
NetworkStream st = client.GetStream();
StreamReader sr = new StreamReader(st);
StreamReader sr = new StreamReader(client.GetStream());
string line = sr.ReadLine();
if (line == null)
{
@ -174,7 +164,6 @@ public class WebServer
while (true)
{
string headerLine = sr.ReadLine();
if (String.IsNullOrEmpty(headerLine))
break;
@ -182,67 +171,18 @@ public class WebServer
if (headerParts.Length != 2)
continue;
headers[headerParts[0].Trim()] = headerParts[1].Trim();
headers[headerParts[0]] = headerParts[1];
}
Dictionary<string, string> form = new Dictionary<string, string>();
string contentLength = headers["Content-Length"];
if (contentLength != "")
{
int contentLengthInt = Int32.Parse(contentLength);
char[] buffer = new char[contentLengthInt];
sr.ReadBlock(buffer, 0, contentLengthInt);
string content = new string(buffer);
string[] kvps = content.Split(new char[] { '&' });
foreach (string kvp in kvps)
{
string[] pv = kvp.Split(new char[] { '=' });
form[pv[0]] = pv[1];
}
}
Dictionary<string, string> session;
string cookie = "", cookieKey = "", cookieValue = "";
if (headers[HttpRequestHeader.Cookie] != null)
{
cookie = headers[HttpRequestHeader.Cookie];
string[] cookieParts = cookie.Split(new char[] { ';' });
if (cookieParts.Length >= 1)
{
string[] cookieParts2 = cookieParts[0].Split(new char[] { '=' });
if (cookieParts2.Length >= 2)
{
cookieKey = cookieParts2[0];
cookieValue = cookieParts2[1]; //cookies[cookieKey] = cookieValue;
}
}
if (!_sessions.ContainsKey(cookieValue))
{
_sessions[cookieValue] = new Dictionary<string, string>();
}
session = _sessions[cookieValue];
}
else
{
session = new Dictionary<string, string>();
}
if (cookieValue == "")
{
cookieValue = "0068F5AD24A89AB4AFCC4057F619EADF.authgwy-prod-mzzygbiy.prod-ui-auth.pr502.cust.pdx.wd";
string cookie = headers[HttpRequestHeader.Cookie];
}
bool found = false;
Dictionary<string, string> pathVariables = new Dictionary<string, string>();
WebContext context = new WebContext((WebApplication)Application.Instance, new WebRequest(version, requestMethod, path, headers, pathVariables, form), new WebResponse(), session);
context.Response.Cookies.Add("JSESSIONID", cookieValue, WebCookieScope.FromPath("/"), WebCookieSecurity.Secure | WebCookieSecurity.HttpOnly, WebCookieSameSite.None);
WebContext context = new WebContext((WebApplication)Application.Instance, new WebRequest(version, requestMethod, path, headers, pathVariables), new WebResponse());
context.Response.Cookies.Add("JSESSIONID", "0068F5AD24A89AB4AFCC4057F619EADF.authgwy-prod-mzzygbiy.prod-ui-auth.pr502.cust.pdx.wd", WebCookieScope.FromPath("/"), WebCookieSecurity.Secure | WebCookieSecurity.HttpOnly, WebCookieSameSite.None);
WebServerProcessRequestEventArgs e = new WebServerProcessRequestEventArgs(client, context);
OnProcessRequest(e);
@ -263,13 +203,10 @@ public class WebServer
if (route.Matches(path, pathVariables))
{
lock (route.Handler)
{
route.Handler.ProcessRequest(context);
route.Handler.ProcessRequest(context);
WriteResponse(context, client.GetStream());
found = true;
}
WriteResponse(context, client.GetStream());
found = true;
break;
}
}
@ -295,12 +232,10 @@ public class WebServer
catch (System.Net.Sockets.SocketException ex)
{
Console.Error.WriteLine("caught SocketException; ignoring");
Console.Error.WriteLine(ex.Message);
}
catch (System.IO.IOException ex)
{
Console.Error.WriteLine("caught IOException; ignoring");
Console.Error.WriteLine(ex.Message);
}
}