mass update
This commit is contained in:
parent
c43eda9152
commit
94e3fcec40
@ -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> PathVariables { get; } = new Dictionary<string, string>();
|
||||||
public Dictionary<string, string> StyleProperties { get; } = new Dictionary<string, string>();
|
public Dictionary<string, string> StyleProperties { get; } = new Dictionary<string, string>();
|
||||||
public bool Visible { get; set; } = true;
|
public bool Visible { get; set; } = true;
|
||||||
@ -33,6 +34,8 @@ public abstract class Control : IWebHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual string TagName { get; } = "div";
|
protected virtual string TagName { get; } = "div";
|
||||||
|
protected virtual bool ContentRequired { get; } = false;
|
||||||
|
|
||||||
public Dictionary<string, string> Attributes { get; } = new Dictionary<string, string>();
|
public Dictionary<string, string> Attributes { get; } = new Dictionary<string, string>();
|
||||||
public CssClassList ClassList { get; } = new CssClassList();
|
public CssClassList ClassList { get; } = new CssClassList();
|
||||||
|
|
||||||
@ -124,7 +127,14 @@ public abstract class Control : IWebHandler
|
|||||||
|
|
||||||
protected virtual void RenderEndTag(XmlWriter writer)
|
protected virtual void RenderEndTag(XmlWriter writer)
|
||||||
{
|
{
|
||||||
writer.WriteEndElement();
|
if (ContentRequired)
|
||||||
|
{
|
||||||
|
writer.WriteFullEndElement();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
writer.WriteEndElement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(XmlWriter writer)
|
public void Render(XmlWriter writer)
|
||||||
@ -144,6 +154,7 @@ public abstract class Control : IWebHandler
|
|||||||
OnInit(new RenderEventArgs(context));
|
OnInit(new RenderEventArgs(context));
|
||||||
|
|
||||||
XmlWriter writer = XmlWriter.Create(context.Response.Stream);
|
XmlWriter writer = XmlWriter.Create(context.Response.Stream);
|
||||||
|
Context = context;
|
||||||
Render(writer);
|
Render(writer);
|
||||||
|
|
||||||
writer.Flush();
|
writer.Flush();
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace MBS.Web;
|
namespace MBS.Web;
|
||||||
|
|
||||||
public class RenderEventArgs : EventArgs
|
public class RenderEventArgs : CancelEventArgs
|
||||||
{
|
{
|
||||||
public WebContext Context { get; }
|
public WebContext Context { get; }
|
||||||
|
|
||||||
|
|||||||
29
src/lib/MBS.Web/UI/HtmlControls/HtmlAnchor.cs
Normal file
29
src/lib/MBS.Web/UI/HtmlControls/HtmlAnchor.cs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -35,13 +35,19 @@ public class HtmlGenericControl : Container
|
|||||||
Content = content;
|
Content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string ReplaceContent(string content)
|
||||||
|
{
|
||||||
|
content = content.Replace(" ", " ");
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void RenderContents(XmlWriter writer)
|
protected override void RenderContents(XmlWriter writer)
|
||||||
{
|
{
|
||||||
if (GetChildControls().Count == 0)
|
if (GetChildControls().Count == 0)
|
||||||
{
|
{
|
||||||
if (Content != null)
|
if (Content != null)
|
||||||
{
|
{
|
||||||
writer.WriteRaw(Content);
|
writer.WriteRaw(ReplaceContent(Content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
20
src/lib/MBS.Web/UI/HtmlControls/HtmlParagraph.cs
Normal file
20
src/lib/MBS.Web/UI/HtmlControls/HtmlParagraph.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/lib/MBS.Web/UI/HtmlControls/HtmlScript.cs
Normal file
27
src/lib/MBS.Web/UI/HtmlControls/HtmlScript.cs
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
@ -16,6 +16,11 @@ public class AdditionalDetailWidget : Container
|
|||||||
return base.GetChildControls();
|
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 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" />
|
// <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>
|
// <ul class="mcx-selected-items"><li>
|
||||||
|
|||||||
@ -22,6 +22,7 @@ public abstract class ContainerBase : WebControl
|
|||||||
}
|
}
|
||||||
foreach (Control control in _childControls)
|
foreach (Control control in _childControls)
|
||||||
{
|
{
|
||||||
|
control.Context = Context;
|
||||||
control.Render(writer);
|
control.Render(writer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -149,7 +149,14 @@ public class ListView : Container
|
|||||||
foreach (ListViewItemColumn col in lvi.Columns)
|
foreach (ListViewItemColumn col in lvi.Columns)
|
||||||
{
|
{
|
||||||
HtmlGenericControl td = new HtmlGenericControl("td");
|
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);
|
tr2.Controls.Add(td);
|
||||||
}
|
}
|
||||||
tbody.Controls.Add(tr2);
|
tbody.Controls.Add(tr2);
|
||||||
|
|||||||
11
src/lib/MBS.Web/UI/WebControls/Menu.cs
Normal file
11
src/lib/MBS.Web/UI/WebControls/Menu.cs
Normal 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" ];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -35,6 +35,11 @@ public class WebPage : Control
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual IEnumerable<Control> GetHeaderControls()
|
||||||
|
{
|
||||||
|
return [ ];
|
||||||
|
}
|
||||||
|
|
||||||
protected override string TagName => "html";
|
protected override string TagName => "html";
|
||||||
protected override void RenderBeginTag(XmlWriter writer)
|
protected override void RenderBeginTag(XmlWriter writer)
|
||||||
{
|
{
|
||||||
@ -56,7 +61,9 @@ public class WebPage : Control
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Control> ctls = new List<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)
|
foreach (WebStyleSheet ss in StyleSheets)
|
||||||
{
|
{
|
||||||
@ -72,6 +79,7 @@ public class WebPage : Control
|
|||||||
|
|
||||||
foreach (Control control in ctls)
|
foreach (Control control in ctls)
|
||||||
{
|
{
|
||||||
|
control.Context = Context;
|
||||||
control.Render(writer);
|
control.Render(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +91,7 @@ public class WebPage : Control
|
|||||||
writer.WriteAttributeString("method", "POST");
|
writer.WriteAttributeString("method", "POST");
|
||||||
foreach (Control control in Controls)
|
foreach (Control control in Controls)
|
||||||
{
|
{
|
||||||
|
control.Context = Context;
|
||||||
control.Render(writer);
|
control.Render(writer);
|
||||||
}
|
}
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
|
|||||||
@ -40,7 +40,7 @@ public abstract class WebApplication : Application
|
|||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
|
|
||||||
WebServer server = new WebServer(new IPEndPoint(IPAddress.Any, DefaultPort));
|
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));
|
OnServerCreated(new WebServerCreatedEventArgs(server));
|
||||||
server.ProcessRequest += server_OnProcessRequest;
|
server.ProcessRequest += server_OnProcessRequest;
|
||||||
@ -52,4 +52,8 @@ public abstract class WebApplication : Application
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string ExpandRelativePath(string path)
|
||||||
|
{
|
||||||
|
return path.Replace("~/", VirtualBasePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,24 @@
|
|||||||
|
|
||||||
namespace MBS.Web;
|
namespace MBS.Web;
|
||||||
|
|
||||||
public class WebContext
|
public class WebContext
|
||||||
{
|
{
|
||||||
public WebContext(WebApplication application, WebRequest request, WebResponse response, Dictionary<string, object> session)
|
public WebContext(WebApplication application, WebRequest request, WebResponse response, Dictionary<string, object> session)
|
||||||
{
|
{
|
||||||
Application = application;
|
Application = application;
|
||||||
Request = request;
|
Request = request;
|
||||||
Response = response;
|
Response = response;
|
||||||
Session = session;
|
Session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebApplication Application { get; }
|
public WebApplication Application { get; }
|
||||||
public WebRequest Request { get; }
|
public WebRequest Request { get; }
|
||||||
public WebResponse Response { get; }
|
public WebResponse Response { get; }
|
||||||
|
|
||||||
public Dictionary<string, object> Session { get; }
|
public Dictionary<string, object> Session { get; }
|
||||||
|
|
||||||
|
public string ExpandRelativePath(string path)
|
||||||
|
{
|
||||||
|
return Application.ExpandRelativePath(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,8 +57,33 @@ public class WebServer
|
|||||||
|
|
||||||
private void tServer_ThreadStart()
|
private void tServer_ThreadStart()
|
||||||
{
|
{
|
||||||
System.Net.Sockets.TcpListener listener = new System.Net.Sockets.TcpListener(EndPoint);
|
IPEndPoint ep = EndPoint;
|
||||||
listener.Start();
|
|
||||||
|
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)
|
while (!_Stopping)
|
||||||
{
|
{
|
||||||
@ -314,6 +339,11 @@ public class WebServer
|
|||||||
Console.Error.WriteLine("caught IOException; ignoring");
|
Console.Error.WriteLine("caught IOException; ignoring");
|
||||||
Console.Error.WriteLine(ex.Message);
|
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;
|
private bool _Stopping = false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user