Skip to content

Commit c6b0f02

Browse files
NestedResource bug fix.
1 parent eb69566 commit c6b0f02

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

src/ResourceManager/Common/Commands.Common.Strategies/IState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public interface IState
88
TModel Get<TModel>(ResourceConfig<TModel> config)
99
where TModel : class;
1010

11-
bool Contains(IEntityConfig config);
11+
bool Contains(IResourceConfig config);
1212
}
1313
}

src/ResourceManager/Common/Commands.Common.Strategies/State.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public TModel GetOrAdd<TModel>(ResourceConfig<TModel> config, Func<TModel> f)
1616
where TModel : class
1717
=> _Map.GetOrAddWithCast(config.DefaultIdStr(), f);
1818

19-
public bool Contains(IEntityConfig config)
19+
public bool Contains(IResourceConfig config)
2020
=> _Map.ContainsKey(config.DefaultIdStr());
2121
}
2222
}

src/ResourceManager/Common/Commands.Common.Strategies/StateExtensions.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Microsoft.Azure.Commands.Common.Strategies
1+
using System;
2+
3+
namespace Microsoft.Azure.Commands.Common.Strategies
24
{
35
public static class StateExtensions
46
{
@@ -28,6 +30,15 @@ public static TModel GetDispatch<TModel>(
2830
where TModel : class
2931
=> config.Accept(new GetVisitor<TModel>(), state);
3032

33+
public static bool Contains<TModel, TParentModel>(
34+
this IState state, NestedResourceConfig<TModel, TParentModel> config)
35+
where TModel : class
36+
where TParentModel : class
37+
=> state.Get(config) != null;
38+
39+
public static bool ContainsDispatch(this IState state, IEntityConfig config)
40+
=> config.Accept(new ContainsDispatchVisitor(), state);
41+
3142
sealed class GetVisitor<TModel> : IEntityConfigVisitor<TModel, IState, TModel>
3243
where TModel : class
3344
{
@@ -39,5 +50,18 @@ public TModel Visit<TParentModel>(
3950
where TParentModel : class
4051
=> state.Get(config);
4152
}
53+
54+
sealed class ContainsDispatchVisitor : IEntityConfigVisitor<IState, bool>
55+
{
56+
public bool Visit<TModel>(ResourceConfig<TModel> config, IState context)
57+
where TModel : class
58+
=> context.Contains(config);
59+
60+
public bool Visit<TModel, TParentModel>(
61+
NestedResourceConfig<TModel, TParentModel> config, IState context)
62+
where TModel : class
63+
where TParentModel : class
64+
=> context.Contains(config);
65+
}
4266
}
4367
}

src/ResourceManager/Common/Commands.Common.Strategies/TargetState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public Context(IState current, string subscription, string location)
3333

3434
public void AddIfRequired(IEntityConfig config)
3535
{
36-
if (!Current.Contains(config))
36+
if (!Current.ContainsDispatch(config))
3737
{
3838
config.Accept(new AddVisitor(), this);
3939
}

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ public void StrategyExecuteCmdlet()
223223
adminPassword: new NetworkCredential(string.Empty, Credential.Password).Password,
224224
image: image.Image);
225225

226-
//
227226
var client = new Client(DefaultProfile.DefaultContext);
228227
var current = virtualMachine
229228
.GetStateAsync(client, new CancellationToken())
@@ -240,10 +239,15 @@ public void StrategyExecuteCmdlet()
240239
}
241240

242241
var target = virtualMachine.GetTargetState(current, client.SubscriptionId, Location);
243-
var result = virtualMachine
244-
.UpdateStateAsync(client, target, new CancellationToken())
245-
.GetAwaiter()
246-
.GetResult();
242+
243+
if (ShouldProcess(Name, VerbsCommon.New))
244+
{
245+
var result = virtualMachine
246+
.UpdateStateAsync(client, target, new CancellationToken())
247+
.GetAwaiter()
248+
.GetResult();
249+
WriteObject(result);
250+
}
247251
}
248252

249253
public void DefaultExecuteCmdlet()
@@ -310,7 +314,8 @@ public void DefaultExecuteCmdlet()
310314
AutoUpgradeMinorVersion = true,
311315
};
312316

313-
typeof(CM.Resource).GetRuntimeProperty("Name").SetValue(extensionParameters, VirtualMachineBGInfoExtensionContext.ExtensionDefaultName);
317+
typeof(CM.Resource).GetRuntimeProperty("Name")
318+
.SetValue(extensionParameters, VirtualMachineBGInfoExtensionContext.ExtensionDefaultName);
314319
typeof(CM.Resource).GetRuntimeProperty("Type")
315320
.SetValue(extensionParameters, VirtualMachineExtensionType);
316321

0 commit comments

Comments
 (0)