Skip to content

Commit

Permalink
Merge pull request Azure#8 from markcowl/fixparams
Browse files Browse the repository at this point in the history
Fix usage of parameter sets in jobs
  • Loading branch information
sergey-shandar committed Dec 6, 2017
2 parents 9c141ae + 2eedb8e commit 0146c16
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Common/Commands.Common/AzureLongRunningJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ public override string StatusMessage
returnValue.MyInvocation.BoundParameters.Add(parameter.Key, parameter.Value);
}

foreach (var field in returnType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly))

foreach (var field in returnType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
{
field.SafeCopyValue(source: cmdlet, target: returnValue);
}

cmdlet.SafeCopyParameterSet(returnValue);
return returnValue as U;
}

Expand Down Expand Up @@ -829,6 +831,9 @@ private bool InvokeShouldMethodAndWaitForResults(Func<Cmdlet, bool> shouldMethod
}
}

/// <summary>
/// Stop job execution
/// </summary>
public override void StopJob()
{
ShouldMethodStreamItem stream;
Expand Down
24 changes: 24 additions & 0 deletions src/Common/Commands.Common/Extensions/CmdletExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ public static void SafeCopyValue<T>(this FieldInfo field, T source, T target)
}
}

/// <summary>
/// Safely copy the selected parameter set from one cmdlet to another
/// </summary>
/// <typeparam name="T">The cmdlet type</typeparam>
/// <param name="source">The cmdlet to copy the parameter set name from</param>
/// <param name="target">The cmdlet to copy to</param>
public static void SafeCopyParameterSet<T>(this T source, T target) where T: AzurePSCmdlet
{
if (source != null && target != null)
{
if (!string.IsNullOrWhiteSpace(source.ParameterSetName))
{
try
{
target.SetParameterSet(source.ParameterSetName);
}
catch
{

}
}
}
}

public static string AsAbsoluteLocation(this string realtivePath)
{
return Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, realtivePath));
Expand Down

0 comments on commit 0146c16

Please sign in to comment.