From cf74cde6d3127462fa65834388659193c623dadf Mon Sep 17 00:00:00 2001
From: CarloToso <105941898+CarloToso@users.noreply.github.com>
Date: Wed, 22 Mar 2023 12:58:03 +0100
Subject: [PATCH] Revert "Remove FormObject.cs and FormObjectCollection.cs
(#19383)"
This reverts commit 190c99a416b6f3c7e48066eadf3943d4ddccb2d8.
---
.../Common/WebRequestPSCmdlet.Common.cs | 3 +
.../commands/utility/WebCmdlet/FormObject.cs | 55 +++++++++++++++++++
.../utility/WebCmdlet/FormObjectCollection.cs | 37 +++++++++++++
3 files changed, 95 insertions(+)
create mode 100644 src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FormObject.cs
create mode 100644 src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FormObjectCollection.cs
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
index 597e7caa2bb..c078faaed5c 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
@@ -1157,6 +1157,9 @@ internal virtual void FillRequestStream(HttpRequestMessage request)
switch (content)
{
+ case FormObject form:
+ SetRequestContent(request, form.Fields);
+ break;
case IDictionary dictionary when request.Method != HttpMethod.Get:
SetRequestContent(request, dictionary);
break;
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FormObject.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FormObject.cs
new file mode 100644
index 00000000000..b496a120329
--- /dev/null
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FormObject.cs
@@ -0,0 +1,55 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+
+using System.Collections.Generic;
+
+namespace Microsoft.PowerShell.Commands
+{
+ ///
+ /// FormObject used in HtmlWebResponseObject.
+ ///
+ public class FormObject
+ {
+ ///
+ /// Gets the Id property.
+ ///
+ public string Id { get; }
+
+ ///
+ /// Gets the Method property.
+ ///
+ public string Method { get; }
+
+ ///
+ /// Gets the Action property.
+ ///
+ public string Action { get; }
+
+ ///
+ /// Gets the Fields property.
+ ///
+ public Dictionary Fields { get; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ ///
+ ///
+ public FormObject(string id, string method, string action)
+ {
+ Id = id;
+ Method = method;
+ Action = action;
+ Fields = new Dictionary();
+ }
+
+ internal void AddField(string key, string value)
+ {
+ if (key is not null && !Fields.TryGetValue(key, out string test))
+ {
+ Fields[key] = value;
+ }
+ }
+ }
+}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FormObjectCollection.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FormObjectCollection.cs
new file mode 100644
index 00000000000..f435b92e484
--- /dev/null
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/FormObjectCollection.cs
@@ -0,0 +1,37 @@
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
+
+using System;
+using System.Collections.ObjectModel;
+
+namespace Microsoft.PowerShell.Commands
+{
+ ///
+ /// FormObjectCollection used in HtmlWebResponseObject.
+ ///
+ public class FormObjectCollection : Collection
+ {
+ ///
+ /// Gets the FormObject from the key.
+ ///
+ ///
+ ///
+ public FormObject this[string key]
+ {
+ get
+ {
+ FormObject form = null;
+ foreach (FormObject f in this)
+ {
+ if (string.Equals(key, f.Id, StringComparison.OrdinalIgnoreCase))
+ {
+ form = f;
+ break;
+ }
+ }
+
+ return form;
+ }
+ }
+ }
+}