fix some stuff

This commit is contained in:
Michael Becker 2024-08-05 09:05:20 -04:00
parent 35ea6c3cd7
commit 3569914d3f
4 changed files with 39 additions and 13 deletions

View File

@ -13,6 +13,7 @@ public abstract class Control : IWebHandler
} }
public Dictionary<string, string> PathVariables { get; } = new Dictionary<string, string>(); public Dictionary<string, string> PathVariables { get; } = new Dictionary<string, string>();
public bool Visible { get; set; } = true;
public Control(Dictionary<string, string>? pathVariables = null) public Control(Dictionary<string, string>? pathVariables = null)
{ {
@ -41,18 +42,26 @@ public abstract class Control : IWebHandler
private bool _initted = false; private bool _initted = false;
protected void EnsureInitialized() protected void EnsureInitialized()
{ {
if (_initted) return; if (!_initted)
{
InitializeInternal(); InitializeInternal();
_initted = true; _initted = true;
} }
PersistentInitializeInternal();
}
protected virtual void InitializeInternal() protected virtual void InitializeInternal()
{ {
} }
protected virtual void PersistentInitializeInternal()
{
}
protected virtual void RenderBeginTag(XmlWriter writer) protected virtual void RenderBeginTag(XmlWriter writer)
{ {
EnsureInitialized(); EnsureInitialized();
writer.WriteStartElement(TagName); writer.WriteStartElement(TagName);
bool classListWritten = false; bool classListWritten = false;
@ -83,6 +92,8 @@ public abstract class Control : IWebHandler
public void Render(XmlWriter writer) public void Render(XmlWriter writer)
{ {
if (!Visible) return;
RenderBeginTag(writer); RenderBeginTag(writer);
RenderContents(writer); RenderContents(writer);
RenderEndTag(writer); RenderEndTag(writer);
@ -92,6 +103,7 @@ public abstract class Control : IWebHandler
{ {
context.Response.ContentType = "application/xhtml+xml"; context.Response.ContentType = "application/xhtml+xml";
EnsureInitialized();
OnInit(new RenderEventArgs(context)); OnInit(new RenderEventArgs(context));
XmlWriter writer = XmlWriter.Create(context.Response.Stream); XmlWriter writer = XmlWriter.Create(context.Response.Stream);

View File

@ -19,15 +19,10 @@ public class WebPage : Control
{ {
} }
protected override string TagName => "html"; protected override void PersistentInitializeInternal()
protected override void RenderBeginTag(XmlWriter writer)
{ {
EnsureInitialized(); base.PersistentInitializeInternal();
writer.WriteStartElement(TagName, "http://www.w3.org/1999/xhtml");
}
protected override void RenderContents(XmlWriter writer)
{
Controls.Clear(); Controls.Clear();
CreateChildControls(); CreateChildControls();
@ -38,7 +33,17 @@ public class WebPage : Control
ChildControlsCreated = true; ChildControlsCreated = true;
} }
*/ */
}
protected override string TagName => "html";
protected override void RenderBeginTag(XmlWriter writer)
{
EnsureInitialized();
writer.WriteStartElement(TagName, "http://www.w3.org/1999/xhtml");
}
protected override void RenderContents(XmlWriter writer)
{
writer.WriteStartElement("head"); writer.WriteStartElement("head");
writer.WriteElementString("title", "Mocha Application"); writer.WriteElementString("title", "Mocha Application");

View File

@ -168,6 +168,14 @@ public class WebServer
string requestMethod = lineParts[0]; string requestMethod = lineParts[0];
string path = lineParts[1]; string path = lineParts[1];
if (path.Length > 1)
{
if (path.EndsWith("/"))
{
path = path.Substring(0, path.Length - 1);
}
}
string version = lineParts[2]; string version = lineParts[2];
WebHeaderCollection headers = new WebHeaderCollection(); WebHeaderCollection headers = new WebHeaderCollection();
@ -235,7 +243,8 @@ public class WebServer
if (cookieValue == "") if (cookieValue == "")
{ {
cookieValue = "0068F5AD24A89AB4AFCC4057F619EADF.authgwy-prod-mzzygbiy.prod-ui-auth.pr502.cust.pdx.wd"; // 0068F5AD24A89AB4AFCC4057F619EADF
cookieValue = (Guid.NewGuid()).ToString("N").ToUpper() + ".authgwy-prod-mzzygbiy.prod-ui-auth.pr502.cust.pdx.wd";
} }
bool found = false; bool found = false;