Skip to content

Commit 8e7ab32

Browse files
Update WebForms.cs
1 parent 45c577c commit 8e7ab32

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

class/WebForms.cs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace CodeBehind
44
{
55
public class WebForms
66
{
7-
private NameValueCollection WebFormsData = new NameValueCollection();
7+
private NameAndValueCollection WebFormsData = new NameAndValueCollection();
88

99
// For Extension
1010
public void AddLine(string Name, string Value) => WebFormsData.Add(Name, Value);
@@ -21,7 +21,7 @@ public class WebForms
2121
public void AddTitle(string InputPlace, string Title) => WebFormsData.Add("al" + InputPlace, Title);
2222
public void AddText(string InputPlace, string Text) => WebFormsData.Add("at" + InputPlace, Text.Replace('\n'.ToString(), "$[ln];"));
2323
public void AddTextToUp(string InputPlace, string Text) => WebFormsData.Add("pt" + InputPlace, Text.Replace('\n'.ToString(), "$[ln];"));
24-
public void AddAttribute(string InputPlace, string Attribute, string Value = "") => WebFormsData.Add("aa" + InputPlace, Attribute + '|' + Value);
24+
public void AddAttribute(string InputPlace, string Attribute, string Value = "") => WebFormsData.Add("aa" + InputPlace, Attribute + (!string.IsNullOrEmpty(Value) ? '|' + Value : ""));
2525
public void AddTag(string InputPlace, string TagName, string Id = "") => WebFormsData.Add("nt" + InputPlace, TagName + (!string.IsNullOrEmpty(Id) ? '|' + Id : ""));
2626
public void AddTagToUp(string InputPlace, string TagName, string Id = "") => WebFormsData.Add("ut" + InputPlace, TagName + (!string.IsNullOrEmpty(Id) ? '|' + Id : ""));
2727
public void AddTagBefore(string InputPlace, string TagName, string Id = "") => WebFormsData.Add("bt" + InputPlace, TagName + (!string.IsNullOrEmpty(Id) ? '|' + Id : ""));
@@ -74,7 +74,6 @@ public class WebForms
7474
public void Delete(string InputPlace) => WebFormsData.Add("de" + InputPlace, "1");
7575
public void DeleteParent(string InputPlace) => WebFormsData.Add("dp" + InputPlace, "1");
7676

77-
7877
// Other
7978
public void SetBackgroundColor(string InputPlace, string Color) => WebFormsData.Add("bc" + InputPlace, Color);
8079
public void SetTextColor(string InputPlace, string Color) => WebFormsData.Add("tc" + InputPlace, Color);
@@ -137,12 +136,16 @@ public class WebForms
137136
public void SetGetEventInFormListener(string InputPlace, string HtmlEventListener, string OutputPlace) => WebFormsData.Add("EG" + InputPlace, HtmlEventListener + "|" + OutputPlace);
138137
public void SetTagEvent(string InputPlace, string HtmlEvent, string OutputPlace) => WebFormsData.Add("Et" + InputPlace, HtmlEvent + "|" + OutputPlace);
139138
public void SetTagEventListener(string InputPlace, string HtmlEvent, string OutputPlace) => WebFormsData.Add("ET" + InputPlace, HtmlEvent + "|" + OutputPlace);
139+
public void SetWebSocketEvent(string InputPlace, string HtmlEvent, string Path) => WebFormsData.Add("Ew" + InputPlace, HtmlEvent + "|" + Path);
140+
public void SetWebSocketEventListener(string InputPlace, string HtmlEvent, string Path) => WebFormsData.Add("EW" + InputPlace, HtmlEvent + "|" + Path);
140141
public void RemovePostEvent(string InputPlace, string HtmlEvent) => WebFormsData.Add("Rp" + InputPlace, HtmlEvent);
141142
public void RemoveGetEvent(string InputPlace, string HtmlEvent) => WebFormsData.Add("Rg" + InputPlace, HtmlEvent);
142143
public void RemoveTagEvent(string InputPlace, string HtmlEvent) => WebFormsData.Add("Rt" + InputPlace, HtmlEvent);
144+
public void RemoveWebSocketEvent(string InputPlace, string HtmlEvent) => WebFormsData.Add("Rw" + InputPlace, HtmlEvent);
143145
public void RemovePostEventListener(string InputPlace, string HtmlEventListener) => WebFormsData.Add("RP" + InputPlace, HtmlEventListener);
144146
public void RemoveGetEventListener(string InputPlace, string HtmlEventListener) => WebFormsData.Add("RG" + InputPlace, HtmlEventListener);
145147
public void RemoveTagEventListener(string InputPlace, string HtmlEventListener) => WebFormsData.Add("RT" + InputPlace, HtmlEventListener);
148+
public void RemoveWebSocketEventListener(string InputPlace, string HtmlEventListener) => WebFormsData.Add("RW" + InputPlace, HtmlEventListener);
146149

147150
// Save
148151
public void SaveId(string InputPlace, string Key = ".") => WebFormsData.Add("@gi" + InputPlace, Key);
@@ -212,12 +215,19 @@ public void AssignIntervalChange(float Second, int Index = -1)
212215
public void StartIndex(string Name) => WebFormsData.Add("#", Name);
213216
public void StartIndex() => StartIndex("");
214217

218+
// Enable
219+
public void EnableWebSocket(bool Enable = true) => WebFormsData.Add("ew", Enable ? "1" : "0");
220+
public void EnableWebSocketOnce(bool Enable = true) => WebFormsData.Add("ew", "@");
221+
222+
// Use
223+
public void UseWebSocket(string Path) => WebFormsData.Add("uw", Path);
224+
215225
// Get
216226
public string GetFormsActionData()
217227
{
218228
string ReturnValue = "";
219229

220-
foreach (NameValue nv in WebFormsData.GetList())
230+
foreach (NameAndValue nv in WebFormsData.GetList())
221231
{
222232
ReturnValue += Environment.NewLine + nv.Name;
223233

@@ -244,10 +254,10 @@ public string GetFormsActionDataLineBreak()
244254
{
245255
string ReturnValue = "";
246256

247-
List<NameValue> WebFormsDataList = WebFormsData.GetList();
257+
List<NameAndValue> WebFormsDataList = WebFormsData.GetList();
248258

249259
int i = WebFormsDataList.Count;
250-
foreach (NameValue nv in WebFormsData.GetList())
260+
foreach (NameAndValue nv in WebFormsData.GetList())
251261
{
252262
ReturnValue += nv.Name;
253263

@@ -285,7 +295,7 @@ public string DoneToWebFormsTag(string Id = null)
285295
return "<web-forms ac=\"" + GetFormsActionDataLineBreak() + "\"" + (!string.IsNullOrEmpty(Id) ? " id=\"" + Id + "\" done=\"true\"" : "") + "></web-forms>";
286296
}
287297

288-
public NameValueCollection ExportToNameValue()
298+
public NameAndValueCollection ExportToNameValue()
289299
{
290300
return WebFormsData;
291301
}
@@ -302,7 +312,7 @@ public void SetHeaders(HttpContext context)
302312

303313
public void Clean()
304314
{
305-
WebFormsData = new NameValueCollection();
315+
WebFormsData = new NameAndValueCollection();
306316
}
307317
}
308318

@@ -559,29 +569,29 @@ public static string RemoveOuter(this string Text, string StartString, string En
559569
}
560570
}
561571

562-
public class NameValue
572+
public class NameAndValue
563573
{
564574
public string Name { get; set; }
565575
public string Value { get; set; }
566576

567-
public NameValue()
577+
public NameAndValue()
568578
{
569579

570580
}
571581

572-
public NameValue(string Name, string Value)
582+
public NameAndValue(string Name, string Value)
573583
{
574584
this.Name = Name;
575585
this.Value = Value;
576586
}
577587
}
578-
public class NameValueCollection
588+
public class NameAndValueCollection
579589
{
580-
private List<NameValue> NameValueList = new List<NameValue>();
590+
private List<NameAndValue> NameValueList = new List<NameAndValue>();
581591

582592
public void Add(string Name, string Value)
583593
{
584-
NameValueList.Add(new NameValue(Name, Value));
594+
NameValueList.Add(new NameAndValue(Name, Value));
585595
}
586596

587597
public void Set(string Name, string Value)
@@ -594,9 +604,9 @@ public void Set(string Name, string Value)
594604

595605
public void Delete(string Name)
596606
{
597-
List<NameValue> TmpNameValueList = new List<NameValue>();
607+
List<NameAndValue> TmpNameValueList = new List<NameAndValue>();
598608

599-
foreach (NameValue nv in NameValueList)
609+
foreach (NameAndValue nv in NameValueList)
600610
{
601611
if (nv.Name != Name)
602612
TmpNameValueList.Add(nv);
@@ -613,12 +623,12 @@ public void DeleteByIndex(int Index)
613623

614624
public void Empty()
615625
{
616-
NameValueList = new List<NameValue>();
626+
NameValueList = new List<NameAndValue>();
617627
}
618628

619629
public bool Exist(string Name)
620630
{
621-
foreach (NameValue nv in NameValueList)
631+
foreach (NameAndValue nv in NameValueList)
622632
{
623633
if (nv.Name == Name)
624634
return true;
@@ -629,7 +639,7 @@ public bool Exist(string Name)
629639

630640
public void ChangeValue(string Name, string Value)
631641
{
632-
foreach (NameValue nv in NameValueList)
642+
foreach (NameAndValue nv in NameValueList)
633643
{
634644
if (nv.Name == Name)
635645
{
@@ -641,7 +651,7 @@ public void ChangeValue(string Name, string Value)
641651

642652
public void ChangeName(string Name, string NewName)
643653
{
644-
foreach (NameValue nv in NameValueList)
654+
foreach (NameAndValue nv in NameValueList)
645655
{
646656
if (nv.Name == Name)
647657
{
@@ -654,7 +664,7 @@ public void ChangeName(string Name, string NewName)
654664
// Overload
655665
public void ChangeValue(string Name, string NewName, string Value)
656666
{
657-
foreach (NameValue nv in NameValueList)
667+
foreach (NameAndValue nv in NameValueList)
658668
{
659669
if (nv.Name == Name)
660670
{
@@ -695,15 +705,15 @@ public void ChangeNameValueByIndex(int Index, string Name, string Value)
695705
}
696706
}
697707

698-
public void AddList(List<NameValue> NameValueList)
708+
public void AddList(List<NameAndValue> NameValueList)
699709
{
700-
foreach (NameValue nv in NameValueList)
710+
foreach (NameAndValue nv in NameValueList)
701711
this.NameValueList.Add(nv);
702712
}
703713

704714
public string GetValue(string Name)
705715
{
706-
foreach (NameValue nv in NameValueList)
716+
foreach (NameAndValue nv in NameValueList)
707717
{
708718
if (nv.Name == Name)
709719
return nv.Value;
@@ -724,7 +734,7 @@ public string GetValueByIndex(int Index)
724734
return NameValueList[TmpIndex].Value; ;
725735
}
726736

727-
public List<NameValue> GetList()
737+
public List<NameAndValue> GetList()
728738
{
729739
return NameValueList;
730740
}

0 commit comments

Comments
 (0)