mass update

This commit is contained in:
Michael Becker 2024-08-10 20:18:04 -04:00
parent c43eda9152
commit 94e3fcec40
14 changed files with 188 additions and 20 deletions

View File

@ -13,6 +13,7 @@ public abstract class Control : IWebHandler
}
public WebContext? Context { get; internal set; } = null;
public Dictionary<string, string> PathVariables { get; } = new Dictionary<string, string>();
public Dictionary<string, string> StyleProperties { get; } = new Dictionary<string, string>();
public bool Visible { get; set; } = true;
@ -33,6 +34,8 @@ public abstract class Control : IWebHandler
}
protected virtual string TagName { get; } = "div";
protected virtual bool ContentRequired { get; } = false;
public Dictionary<string, string> Attributes { get; } = new Dictionary<string, string>();
public CssClassList ClassList { get; } = new CssClassList();
@ -124,7 +127,14 @@ public abstract class Control : IWebHandler
protected virtual void RenderEndTag(XmlWriter writer)
{
writer.WriteEndElement();
if (ContentRequired)
{
writer.WriteFullEndElement();
}
else
{
writer.WriteEndElement();
}
}
public void Render(XmlWriter writer)
@ -144,6 +154,7 @@ public abstract class Control : IWebHandler
OnInit(new RenderEventArgs(context));
XmlWriter writer = XmlWriter.Create(context.Response.Stream);
Context = context;
Render(writer);
writer.Flush();

View File

@ -1,6 +1,8 @@
using System.ComponentModel;
namespace MBS.Web;
public class RenderEventArgs : EventArgs
public class RenderEventArgs : CancelEventArgs
{
public WebContext Context { get; }

View File

@ -0,0 +1,29 @@
using MBS.Core;
namespace MBS.Web.UI.HtmlControls;
public class HtmlAnchor : HtmlGenericControl
{
public string? TargetFrame { get; set; }
public string TargetUrl { get; set; }
public HtmlAnchor(string targetUrl, string? targetFrame = null) : base("a")
{
TargetUrl = targetUrl;
TargetFrame = targetFrame;
}
protected override IDictionary<string, string> GetControlAttributes()
{
IDictionary<string, string> list = base.GetControlAttributes();
list.Add("href", Context?.ExpandRelativePath(TargetUrl) ?? TargetUrl);
if (TargetFrame != null)
{
list.Add("target", TargetFrame);
}
return list;
}
}

View File

@ -35,13 +35,19 @@ public class HtmlGenericControl : Container
Content = content;
}
private string ReplaceContent(string content)
{
content = content.Replace("&nbsp;", "&#160;");
return content;
}
protected override void RenderContents(XmlWriter writer)
{
if (GetChildControls().Count == 0)
{
if (Content != null)
{
writer.WriteRaw(Content);
writer.WriteRaw(ReplaceContent(Content));
}
}
else

View File

@ -0,0 +1,20 @@
using MBS.Core;
using MBS.Core.Collections.Generic;
namespace MBS.Web.UI.HtmlControls;
public class HtmlParagraph : HtmlGenericControl
{
public HtmlParagraph() : base("p")
{
}
public HtmlParagraph(string content) : base("p")
{
Content = content;
}
public HtmlParagraph(IEnumerable<Control> controls) : base("p")
{
Controls.AddRange(controls);
}
}

View File

@ -0,0 +1,27 @@
namespace MBS.Web.UI.HtmlControls;
public class HtmlScript : Control
{
public string ContentType { get; set; }
public string TargetUrl { get; set; }
public HtmlScript(string contentType, string targetUrl)
{
ContentType = contentType;
TargetUrl = targetUrl;
}
protected override IDictionary<string, string> GetControlAttributes()
{
IDictionary<string, string> list = base.GetControlAttributes();
list.Add("type", ContentType);
list.Add("src", TargetUrl);
return list;
}
protected override string TagName => "script";
protected override bool ContentRequired => true;
}

View File

@ -16,6 +16,11 @@ public class AdditionalDetailWidget : Container
return base.GetChildControls();
}
protected virtual string GetActionURL()
{
return String.Empty;
}
// <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>

View File

@ -22,6 +22,7 @@ public abstract class ContainerBase : WebControl
}
foreach (Control control in _childControls)
{
control.Context = Context;
control.Render(writer);
}
}

View File

@ -149,7 +149,14 @@ public class ListView : Container
foreach (ListViewItemColumn col in lvi.Columns)
{
HtmlGenericControl td = new HtmlGenericControl("td");
td.Content = col.Value?.ToString();
if (col.Value is Control)
{
td.Controls.Add((Control)col.Value);
}
else
{
td.Content = col.Value?.ToString();
}
tr2.Controls.Add(td);
}
tbody.Controls.Add(tr2);

View File

@ -0,0 +1,11 @@
namespace MBS.Web.UI.WebControls;
public class Menu : WebControl
{
protected override string TagName => "ul";
protected override IEnumerable<string> GetStyleClasses()
{
return [ "uwt-menu" ];
}
}

View File

@ -35,6 +35,11 @@ public class WebPage : Control
*/
}
protected virtual IEnumerable<Control> GetHeaderControls()
{
return [ ];
}
protected override string TagName => "html";
protected override void RenderBeginTag(XmlWriter writer)
{
@ -56,7 +61,9 @@ public class WebPage : Control
}
List<Control> ctls = new List<Control>();
ctls.Add(new HtmlLink("stylesheet", "text/css", "/madi/asset/ui-html/2024.27.5/css/mochaApp.css?plate=BMT216A&sha256-XjJJ2%2BcFxZXtxY579nwOKBNYdP1KUySxNDbxR4QGxvQ%3D"));
IEnumerable<Control> headerCtls = GetHeaderControls();
ctls.AddRange(headerCtls);
foreach (WebStyleSheet ss in StyleSheets)
{
@ -72,6 +79,7 @@ public class WebPage : Control
foreach (Control control in ctls)
{
control.Context = Context;
control.Render(writer);
}
@ -83,6 +91,7 @@ public class WebPage : Control
writer.WriteAttributeString("method", "POST");
foreach (Control control in Controls)
{
control.Context = Context;
control.Render(writer);
}
writer.WriteEndElement();

View File

@ -40,7 +40,7 @@ public abstract class WebApplication : Application
base.OnStartup(e);
WebServer server = new WebServer(new IPEndPoint(IPAddress.Any, DefaultPort));
Console.WriteLine("server listening on port {0}", DefaultPort);
Console.WriteLine("attempting to start server listening on port {0}", DefaultPort);
OnServerCreated(new WebServerCreatedEventArgs(server));
server.ProcessRequest += server_OnProcessRequest;
@ -52,4 +52,8 @@ public abstract class WebApplication : Application
}
}
public virtual string ExpandRelativePath(string path)
{
return path.Replace("~/", VirtualBasePath);
}
}

View File

@ -1,18 +1,24 @@
namespace MBS.Web;
public class WebContext
{
public WebContext(WebApplication application, WebRequest request, WebResponse response, Dictionary<string, object> session)
{
Application = application;
Request = request;
Response = response;
Session = session;
}
public WebContext(WebApplication application, WebRequest request, WebResponse response, Dictionary<string, object> session)
{
Application = application;
Request = request;
Response = response;
Session = session;
}
public WebApplication Application { get; }
public WebRequest Request { get; }
public WebResponse Response { get; }
public Dictionary<string, object> Session { get; }
public WebApplication Application { get; }
public WebRequest Request { get; }
public WebResponse Response { get; }
public Dictionary<string, object> Session { get; }
public string ExpandRelativePath(string path)
{
return Application.ExpandRelativePath(path);
}
}

View File

@ -57,8 +57,33 @@ public class WebServer
private void tServer_ThreadStart()
{
System.Net.Sockets.TcpListener listener = new System.Net.Sockets.TcpListener(EndPoint);
listener.Start();
IPEndPoint ep = EndPoint;
TcpListener? listener = null;
while (true)
{
listener = new TcpListener(ep);
try
{
listener.Start();
break;
}
catch (SocketException ex)
{
if (ex.ErrorCode == 98)
{
Console.Error.WriteLine("port {0} is busy, trying the next available one", ep.Port);
ep = new IPEndPoint(ep.Address, ep.Port + 1);
}
else
{
Console.Error.WriteLine("unknown SocketException {0} - {1}", ex.ErrorCode, ex.Message);
}
continue;
}
}
Console.WriteLine("server started on port {0}", ep.Port);
while (!_Stopping)
{
@ -314,6 +339,11 @@ public class WebServer
Console.Error.WriteLine("caught IOException; ignoring");
Console.Error.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.Error.WriteLine("caught exception of type {0}", ex.GetType().FullName);
Console.Error.WriteLine(ex.Message);
}
}
private bool _Stopping = false;