Skip to content

Commit 28e8804

Browse files
committed
report model update2
1 parent 802904b commit 28e8804

File tree

5 files changed

+47
-29
lines changed

5 files changed

+47
-29
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public class ImportAzureAutomationDscNodeConfiguration : AzureAutomationBaseCmdl
4646
/// <summary>
4747
/// Gets or sets the configuration name for the node configuration.
4848
/// </summary>
49-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the DSC Configuration to import the node configuration under. All Node Configurations in Azure Automation must exist under a Configuration. The name of the Configuration will become the namespace of the imported Node Configuration, in the form of 'ConfigurationName.MofFileName'")]
49+
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the DSC Configuration to import the Node Configuration under. All Node Configurations in Azure Automation must exist under a Configuration. The name of the Configuration will become the namespace of the imported Node Configuration, in the form of 'ConfigurationName.MofFileName'")]
5050
[Alias("NodeConfigurationName")]
51-
public string ConfigurationName { get; set; }
51+
public string Name { get; set; }
5252

5353

5454
/// <summary>
5555
/// Gets or sets switch parameter to confirm overwriting of existing configurations.
5656
/// </summary>
57-
[Parameter(Mandatory = false, HelpMessage = "Forces the command to overwrite an existing configuration.")]
57+
[Parameter(Mandatory = false, HelpMessage = "Forces the command to overwrite an existing Node Configuration.")]
5858
public SwitchParameter Force
5959
{
6060
get { return this.overwriteExistingConfiguration; }
@@ -71,7 +71,7 @@ public override void ExecuteCmdlet()
7171
this.ResourceGroupName,
7272
this.AutomationAccountName,
7373
this.SourcePath,
74-
this.ConfigurationName,
74+
this.Name,
7575
this.Force);
7676

7777
this.WriteObject(nodeConfiguration);

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,25 +1169,22 @@ public Model.NodeConfiguration CreateNodeConfiguration(
11691169
{
11701170
using (var request = new RequestSettings(this.automationManagementClient))
11711171
{
1172-
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
1173-
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
1174-
Requires.Argument("SourcePath", sourcePath).NotNull();
1175-
Requires.Argument("nodeConfigurationName", nodeConfigurationName).NotNull();
1172+
Requires.Argument("ResourceGroupName", resourceGroupName).NotNullOrEmpty();
1173+
Requires.Argument("AutomationAccountName", automationAccountName).NotNullOrEmpty();
1174+
Requires.Argument("SourcePath", sourcePath).NotNullOrEmpty();
1175+
Requires.Argument("nodeConfigurationName", nodeConfigurationName).NotNullOrEmpty();
11761176

11771177
string fileContent = null;
11781178
string configurationName = null;
11791179
string nodeName = null;
11801180

1181-
try
1181+
if (File.Exists(Path.GetFullPath(sourcePath)))
11821182
{
1183-
if (File.Exists(Path.GetFullPath(sourcePath)))
1184-
{
1185-
fileContent = System.IO.File.ReadAllText(sourcePath);
1186-
}
1183+
fileContent = System.IO.File.ReadAllText(sourcePath);
11871184
}
1188-
catch (Exception)
1185+
else
11891186
{
1190-
// exception in accessing the file path
1187+
// file path not valid.
11911188
throw new FileNotFoundException(
11921189
string.Format(
11931190
CultureInfo.CurrentCulture,
@@ -1196,21 +1193,25 @@ public Model.NodeConfiguration CreateNodeConfiguration(
11961193

11971194
try
11981195
{
1199-
var configuration = nodeConfigurationName.Split('.');
1200-
if(configuration.Length == 2)
1196+
int index = nodeConfigurationName.IndexOf(".");
1197+
if (index > 0)
12011198
{
1202-
configurationName = configuration[0];
1203-
nodeName = configuration[1];
1199+
nodeName = nodeConfigurationName.Substring(0, index);
1200+
int configNameStartIndex = index + 1;
1201+
int configNameLenght = nodeConfigurationName.Length - index -1;
1202+
configurationName = nodeConfigurationName.Substring(configNameStartIndex, configNameLenght);
12041203
}
12051204
else
12061205
{
1207-
throw new Exception();
1206+
throw new ArgumentException(string.Format(
1207+
CultureInfo.CurrentCulture,
1208+
Resources.NodeConfigurationNameInvalid));
12081209
}
12091210
}
12101211
catch (Exception)
12111212
{
1212-
// exception in getting the config name from NodeConfigName
1213-
throw new FileNotFoundException(
1213+
// exception in getting the config name from configurationName
1214+
throw new ArgumentException(
12141215
string.Format(
12151216
CultureInfo.CurrentCulture,
12161217
Resources.NodeConfigurationNameInvalid));
@@ -1490,17 +1491,16 @@ private IDictionary<string, string> ProcessConfigurationParameters(string resour
14901491
{
14911492
parameters = parameters ?? new Dictionary<string, string>();
14921493
var filteredParameters = new Dictionary<string,string>();
1493-
foreach (var configParameter in parameters.Keys)
1494+
foreach (var key in parameters.Keys)
14941495
{
14951496
try
14961497
{
1497-
filteredParameters.Add(configParameter.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(parameters[configParameter]));
1498+
filteredParameters.Add(key.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(parameters[key]));
14981499
}
14991500
catch (JsonSerializationException)
15001501
{
1501-
throw new ArgumentException(
1502-
string.Format(
1503-
CultureInfo.CurrentCulture, Resources.ConfigurationParameterCannotBeSerializedToJson, configParameter.ToString()));
1502+
throw new ArgumentException(string.Format(
1503+
CultureInfo.CurrentCulture, Resources.ConfigurationParameterCannotBeSerializedToJson, key.ToString()));
15041504
}
15051505
}
15061506
return filteredParameters;

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ public ArgumentRequirements<T> NotNull()
7373

7474
return this;
7575
}
76+
77+
/// <summary>
78+
/// Checks argument value for not null or empty
79+
/// </summary>
80+
/// <returns>The not null requirement</returns>
81+
public ArgumentRequirements<T> NotNullOrEmpty()
82+
{
83+
if (this.Value == null)
84+
{
85+
throw new ArgumentNullException(this.Name);
86+
}
87+
else if (string.IsNullOrEmpty(this.Value.ToString()))
88+
{
89+
throw new ArgumentNullException(this.Name);
90+
}
91+
92+
return this;
93+
}
7694
}
7795
}
7896
}

src/ResourceManager/Automation/Commands.Automation/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Automation/Commands.Automation/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@
415415
<comment>Automation</comment>
416416
</data>
417417
<data name="NodeConfigurationNameInvalid" xml:space="preserve">
418-
<value>Invalid node configuration name. Please specify in the format &lt;node name&gt;.&lt;config name&gt;</value>
418+
<value>Invalid node configuration name. Please specify in the format &lt;config name&gt;.&lt;node name&gt;</value>
419419
<comment>Automation</comment>
420420
</data>
421421
</root>

0 commit comments

Comments
 (0)