Skip to content

Commit 2eaa48f

Browse files
Merge pull request #7 from shipram/dev
cmdlet bugs
2 parents 76ae1e1 + b86f77c commit 2eaa48f

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

src/ResourceManager/Automation/Commands.Automation/Cmdlet/NewAzureAutomationWebhook.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using Microsoft.Azure.Commands.Automation.Properties;
1717
using Microsoft.WindowsAzure.Commands.Common;
1818
using System;
19-
using System.Collections.Generic;
19+
using System.Collections;
2020
using System.Management.Automation;
2121
using System.Security.Permissions;
2222

@@ -66,7 +66,7 @@ public class NewAzureAutomationWebhook : AzureAutomationBaseCmdlet
6666
/// </summary>
6767
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
6868
HelpMessage = "The Runbook parameters name/value.")]
69-
public IDictionary<string, string> Parameters { get; set; }
69+
public IDictionary Parameters { get; set; }
7070

7171
[Parameter(Mandatory = false, HelpMessage = "Skip warning message about one-time viewable webhook URL")]
7272
public SwitchParameter Force { get; set; }
@@ -91,7 +91,7 @@ protected override void AutomationExecuteCmdlet()
9191
this.RunbookName,
9292
this.IsEnabled,
9393
this.ExpiryTime,
94-
this.Parameters.ToHashtable())));
94+
this.Parameters)));
9595

9696
}
9797
}

src/ResourceManager/Automation/Commands.Automation/Cmdlet/SetAzureAutomationWebhook.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System.Collections;
1516
using Microsoft.Azure.Commands.Automation.Model;
1617
using Microsoft.WindowsAzure.Commands.Common;
17-
using System.Collections.Generic;
1818
using System.Management.Automation;
1919
using System.Security.Permissions;
2020

@@ -48,7 +48,7 @@ public class SetAzureAutomationWebhook : AzureAutomationBaseCmdlet
4848
/// </summary>
4949
[Parameter(Position = 4, Mandatory = false, ValueFromPipelineByPropertyName = true,
5050
HelpMessage = "The Runbook parameters name/value.")]
51-
public IDictionary<string, string> Parameters { get; set; }
51+
public IDictionary Parameters { get; set; }
5252

5353
/// <summary>
5454
/// Execute this cmdlet.
@@ -60,7 +60,7 @@ protected override void AutomationExecuteCmdlet()
6060
this.ResourceGroupName,
6161
this.AutomationAccountName,
6262
this.Name,
63-
this.Parameters.ToHashtable(),
63+
this.Parameters,
6464
this.IsEnabled);
6565
this.WriteObject(updatedWebhook);
6666
}

src/ResourceManager/Automation/Commands.Automation/Common/AutomationClientWebhook.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Model.Webhook CreateWebhook(
3737
string runbookName,
3838
bool isEnabled,
3939
DateTimeOffset expiryTime,
40-
Hashtable runbookParameters)
40+
IDictionary runbookParameters)
4141
{
4242
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
4343
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
@@ -57,9 +57,7 @@ public Model.Webhook CreateWebhook(
5757
};
5858
if (runbookParameters != null)
5959
{
60-
createOrUpdateProperties.Parameters =
61-
runbookParameters.Cast<DictionaryEntry>()
62-
.ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
60+
createOrUpdateProperties.Parameters = this.ProcessRunbookParameters(resourceGroupName, automationAccountName, runbookName, runbookParameters);
6361
}
6462

6563
var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters(
@@ -154,7 +152,7 @@ public Model.Webhook UpdateWebhook(
154152
string resourceGroupName,
155153
string automationAccountName,
156154
string name,
157-
Hashtable parameters,
155+
IDictionary parameters,
158156
bool? isEnabled)
159157
{
160158
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
@@ -173,8 +171,7 @@ public Model.Webhook UpdateWebhook(
173171
if (parameters != null)
174172
{
175173
webhookPatchProperties.Parameters =
176-
parameters.Cast<DictionaryEntry>()
177-
.ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
174+
this.ProcessRunbookParameters(resourceGroupName, automationAccountName, webhookModel.Properties.Runbook.Name, parameters);
178175
}
179176
}
180177

src/ResourceManager/Automation/Commands.Automation/Common/IAutomationClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.IO;
1717
using System.Collections;
1818
using System.Collections.Generic;
19+
using System.Runtime.CompilerServices;
1920
using System.Security;
2021
using Microsoft.Azure.Commands.Automation.Model;
2122
using Microsoft.Azure.Common.Authentication.Models;
@@ -141,13 +142,13 @@ Model.Webhook CreateWebhook(
141142
string runbookName,
142143
bool isEnabled,
143144
DateTimeOffset expiryTime,
144-
Hashtable parameters);
145+
IDictionary parameters);
145146

146147
Model.Webhook GetWebhook(string resourceGroupName, string automationAccountName, string name);
147148

148149
IEnumerable<Model.Webhook> ListWebhooks(string resourceGroupName, string automationAccountName, string runbooName, ref string nextLink);
149150

150-
Model.Webhook UpdateWebhook(string resourceGroupName, string automationAccountName, string name, Hashtable parameters, bool? isEnabled);
151+
Model.Webhook UpdateWebhook(string resourceGroupName, string automationAccountName, string name, IDictionary parameters, bool? isEnabled);
151152

152153
void DeleteWebhook(string resourceGroupName, string automationAccountName, string name);
153154

src/ResourceManager/Automation/Commands.Automation/Model/Job.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Linq;
19+
using System.Linq.Expressions;
20+
using System.Management.Automation;
1921

2022
namespace Microsoft.Azure.Commands.Automation.Model
2123
{
@@ -65,7 +67,20 @@ public Job(string resourceGroupName, string accountName, Azure.Management.Automa
6567
if (0 != String.Compare(kvp.Key, Constants.JobStartedByParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase) &&
6668
0 != String.Compare(kvp.Key, Constants.JobRunOnParameterName, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase))
6769
{
68-
this.JobParameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value));
70+
object paramValue;
71+
try
72+
{
73+
paramValue = ((object) PowerShellJsonConverter.Deserialize(kvp.Value));
74+
}
75+
catch (CmdletInvocationException exception)
76+
{
77+
if (!exception.Message.Contains("Invalid JSON primitive"))
78+
throw;
79+
80+
paramValue = kvp.Value;
81+
}
82+
this.JobParameters.Add(kvp.Key, paramValue);
83+
6984
}
7085
}
7186
}

src/ResourceManager/Automation/Commands.Automation/Model/Webhook.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ public Webhook(
6565
}
6666

6767
this.LastModifiedTime = webhook.Properties.LastModifiedTime.ToLocalTime();
68-
this.Parameters = new Hashtable(webhook.Properties.Parameters.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
68+
this.Parameters = new Hashtable(StringComparer.InvariantCultureIgnoreCase);
69+
foreach (var kvp in webhook.Properties.Parameters)
70+
{
71+
this.Parameters.Add(kvp.Key, (object)PowerShellJsonConverter.Deserialize(kvp.Value));
72+
}
73+
6974
this.RunbookName = webhook.Properties.Runbook.Name;
7075
this.WebhookURI = webhookUri;
7176
}

0 commit comments

Comments
 (0)