Compare commits
2 Commits
0750456c5f
...
35ea6c3cd7
| Author | SHA1 | Date | |
|---|---|---|---|
| 35ea6c3cd7 | |||
| e6cdfb8521 |
@ -13,6 +13,7 @@ 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)
|
||||
@ -32,6 +33,11 @@ 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()
|
||||
{
|
||||
@ -57,15 +63,17 @@ 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);
|
||||
}
|
||||
|
||||
if (!classListWritten && ClassList.Count > 0)
|
||||
IEnumerable<string> actualClassList = ClassList.Union(GetStyleClasses());
|
||||
if (!classListWritten && actualClassList.Count() > 0)
|
||||
{
|
||||
writer.WriteAttributeString("class", String.Join(' ', ClassList));
|
||||
writer.WriteAttributeString("class", String.Join(' ', actualClassList));
|
||||
}
|
||||
}
|
||||
protected virtual void RenderEndTag(XmlWriter writer)
|
||||
@ -84,7 +92,7 @@ public abstract class Control : IWebHandler
|
||||
{
|
||||
context.Response.ContentType = "application/xhtml+xml";
|
||||
|
||||
OnInit(new RenderEventArgs(context.Request, context.Response));
|
||||
OnInit(new RenderEventArgs(context));
|
||||
|
||||
XmlWriter writer = XmlWriter.Create(context.Response.Stream);
|
||||
Render(writer);
|
||||
|
||||
@ -2,14 +2,11 @@ namespace MBS.Web;
|
||||
|
||||
public class RenderEventArgs : EventArgs
|
||||
{
|
||||
public WebContext Context { get; }
|
||||
|
||||
public WebRequest Request { get; }
|
||||
public WebResponse Response { get; }
|
||||
|
||||
public RenderEventArgs(WebRequest request, WebResponse response)
|
||||
public RenderEventArgs(WebContext context)
|
||||
{
|
||||
Request = request;
|
||||
Response = response;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
}
|
||||
9
src/lib/MBS.Web/UI/ThemeColorPreset.cs
Normal file
9
src/lib/MBS.Web/UI/ThemeColorPreset.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace MBS.Web.UI;
|
||||
|
||||
public enum ThemeColorPreset
|
||||
{
|
||||
Unspecified = 0,
|
||||
Primary,
|
||||
Warning,
|
||||
Danger
|
||||
}
|
||||
@ -18,6 +18,19 @@ 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()
|
||||
{
|
||||
|
||||
23
src/lib/MBS.Web/UI/WebControls/AdditionalDetailWidget.cs
Normal file
23
src/lib/MBS.Web/UI/WebControls/AdditionalDetailWidget.cs
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
|
||||
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"> </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"> </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>
|
||||
}
|
||||
@ -2,14 +2,17 @@ namespace MBS.Web;
|
||||
|
||||
public class WebContext
|
||||
{
|
||||
public WebContext(WebApplication application, WebRequest request, WebResponse response)
|
||||
public WebContext(WebApplication application, WebRequest request, WebResponse response, Dictionary<string, string> session)
|
||||
{
|
||||
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; }
|
||||
}
|
||||
|
||||
@ -3,9 +3,8 @@ using MBS.Core;
|
||||
|
||||
namespace MBS.Web;
|
||||
|
||||
public class WebHeaderCollection : List<KeyValuePair<string, string>>
|
||||
public class WebHeaderCollection : Dictionary<string, List<string>>
|
||||
{
|
||||
private Dictionary<string, List<string>> _list = new Dictionary<string, List<string>>();
|
||||
public string? this[System.Net.HttpRequestHeader key]
|
||||
{
|
||||
get
|
||||
@ -35,51 +34,50 @@ public class WebHeaderCollection : List<KeyValuePair<string, string>>
|
||||
}
|
||||
}
|
||||
|
||||
public string? this[string key]
|
||||
public new string this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_list.ContainsKey(key))
|
||||
if (base.ContainsKey(key))
|
||||
{
|
||||
if (_list[key].Count > 0)
|
||||
if (base[key].Count > 0)
|
||||
{
|
||||
return _list[key][_list[key].Count - 1];
|
||||
return base[key][base[key].Count - 1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return String.Empty;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!_list.ContainsKey(key))
|
||||
if (!base.ContainsKey(key))
|
||||
{
|
||||
_list[key] = new List<string>();
|
||||
base[key] = new List<string>();
|
||||
}
|
||||
if (!_list[key].Contains(value))
|
||||
if (!base[key].Contains(value))
|
||||
{
|
||||
_list[key].Add(value);
|
||||
base[key].Add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<string> GetValues(string key)
|
||||
{
|
||||
return _list[key];
|
||||
return base[key];
|
||||
}
|
||||
|
||||
public void Add(string key, string value)
|
||||
{
|
||||
Add(new KeyValuePair<string, string>(key, value));
|
||||
}
|
||||
public new void Add(KeyValuePair<string, string> value)
|
||||
public void Add(KeyValuePair<string, string> value)
|
||||
{
|
||||
if (!_list.ContainsKey(value.Key))
|
||||
if (!base.ContainsKey(value.Key))
|
||||
{
|
||||
_list[value.Key] = new List<string>();
|
||||
base[value.Key] = new List<string>();
|
||||
}
|
||||
if (!_list[value.Key].Contains(value.Value))
|
||||
if (!base[value.Key].Contains(value.Value))
|
||||
{
|
||||
_list[value.Key].Add(value.Value);
|
||||
base[value.Key].Add(value.Value);
|
||||
}
|
||||
base.Add(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Net;
|
||||
|
||||
namespace MBS.Web;
|
||||
@ -13,7 +14,9 @@ public class WebRequest
|
||||
public Dictionary<string, string> PathVariables { get; }
|
||||
public WebHeaderCollection Headers { get; }
|
||||
|
||||
public WebRequest(string version, string method, string path, WebHeaderCollection headers, Dictionary<string, string> pathVariables)
|
||||
public ReadOnlyDictionary<string, string> Form { get; }
|
||||
|
||||
public WebRequest(string version, string method, string path, WebHeaderCollection headers, Dictionary<string, string> pathVariables, Dictionary<string, string> form)
|
||||
{
|
||||
Version = version;
|
||||
Method = method;
|
||||
@ -24,5 +27,6 @@ public class WebRequest
|
||||
}
|
||||
Headers = headers;
|
||||
PathVariables = pathVariables;
|
||||
Form = new ReadOnlyDictionary<string, string>(form);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using MBS.Core;
|
||||
using MBS.Web.UI;
|
||||
@ -86,9 +88,12 @@ public class WebServer
|
||||
{
|
||||
sw.WriteLine(String.Format("{0}: {1}", header.Key, header.Value));
|
||||
}
|
||||
foreach (KeyValuePair<string, string> header in context.Response.Headers)
|
||||
foreach (KeyValuePair<string, List<string>> header in context.Response.Headers)
|
||||
{
|
||||
sw.WriteLine(String.Format("{0}: {1}", header.Key, header.Value));
|
||||
foreach (string val in header.Value)
|
||||
{
|
||||
sw.WriteLine(String.Format("{0}: {1}", header.Key, val));
|
||||
}
|
||||
}
|
||||
foreach (WebCookie cookie in context.Response.Cookies)
|
||||
{
|
||||
@ -128,6 +133,8 @@ 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();
|
||||
@ -139,8 +146,11 @@ public class WebServer
|
||||
return;
|
||||
}
|
||||
*/
|
||||
// client.ReceiveTimeout = 5000;
|
||||
// client.SendTimeout = 5000;
|
||||
|
||||
StreamReader sr = new StreamReader(client.GetStream());
|
||||
NetworkStream st = client.GetStream();
|
||||
StreamReader sr = new StreamReader(st);
|
||||
string line = sr.ReadLine();
|
||||
if (line == null)
|
||||
{
|
||||
@ -164,6 +174,7 @@ public class WebServer
|
||||
while (true)
|
||||
{
|
||||
string headerLine = sr.ReadLine();
|
||||
|
||||
if (String.IsNullOrEmpty(headerLine))
|
||||
break;
|
||||
|
||||
@ -171,18 +182,67 @@ public class WebServer
|
||||
if (headerParts.Length != 2)
|
||||
continue;
|
||||
|
||||
headers[headerParts[0]] = headerParts[1];
|
||||
headers[headerParts[0].Trim()] = headerParts[1].Trim();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
string cookie = headers[HttpRequestHeader.Cookie];
|
||||
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";
|
||||
}
|
||||
|
||||
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), 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);
|
||||
|
||||
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);
|
||||
|
||||
WebServerProcessRequestEventArgs e = new WebServerProcessRequestEventArgs(client, context);
|
||||
OnProcessRequest(e);
|
||||
@ -203,10 +263,13 @@ public class WebServer
|
||||
|
||||
if (route.Matches(path, pathVariables))
|
||||
{
|
||||
route.Handler.ProcessRequest(context);
|
||||
lock (route.Handler)
|
||||
{
|
||||
route.Handler.ProcessRequest(context);
|
||||
|
||||
WriteResponse(context, client.GetStream());
|
||||
found = true;
|
||||
WriteResponse(context, client.GetStream());
|
||||
found = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -232,10 +295,12 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user