Skip to content

Commit 29b6d96

Browse files
author
Samuel Anudeep
committed
Merge pull request AzureRT#186 from MabOneSdk/anudeeb-dev1
Using ExecutionBlock in cmdlets
2 parents aaae0fa + 2bc0e7e commit 29b6d96

File tree

13 files changed

+120
-19
lines changed

13 files changed

+120
-19
lines changed

src/ResourceManager/RecoveryServices.Backup/Cmdlets/Container/GetAzureRmRecoveryServicesContainer.cs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,35 @@ public class GetAzureRmRecoveryServicesContainer : RecoveryServicesBackupCmdletB
5353

5454
public override void ExecuteCmdlet()
5555
{
56-
base.ExecuteCmdlet();
56+
ExecutionBlock(() =>
57+
{
58+
base.ExecuteCmdlet();
5759

58-
ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
60+
ProtectionContainerListQueryParams queryParams = new ProtectionContainerListQueryParams();
5961

60-
// 1. Filter by Name
61-
queryParams.FriendlyName = Name;
62+
// 1. Filter by Name
63+
queryParams.FriendlyName = Name;
6264

63-
// 2. Filter by ContainerType
64-
queryParams.ProviderType = HydraHelpers.GetHydraProviderType(ContainerType);
65+
// 2. Filter by ContainerType
66+
queryParams.ProviderType = HydraHelpers.GetHydraProviderType(ContainerType);
6567

66-
// 3. Filter by Status
67-
queryParams.RegistrationStatus = Status.ToString();
68+
// 3. Filter by Status
69+
queryParams.RegistrationStatus = Status.ToString();
6870

69-
var listResponse = HydraAdapter.ListContainers(Vault.Name, Vault.ResouceGroupName, queryParams);
71+
var listResponse = HydraAdapter.ListContainers(Vault.Name, Vault.ResouceGroupName, queryParams);
7072

71-
List<AzureRmRecoveryServicesContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
73+
List<AzureRmRecoveryServicesContainerBase> containerModels = ConversionHelpers.GetContainerModelList(listResponse);
7274

73-
// 4. Filter by RG Name
74-
if (ContainerType == Models.ContainerType.AzureVM)
75-
{
76-
containerModels.RemoveAll(containerModel =>
77-
(containerModel as AzureRmRecoveryServicesIaasVmContainer).ResourceGroupName == ResourceGroupName);
78-
}
75+
// NOTE: Should move this to provider?
76+
// 4. Filter by RG Name
77+
if (ContainerType == Models.ContainerType.AzureVM)
78+
{
79+
containerModels = containerModels.Where(containerModel =>
80+
(containerModel as AzureRmRecoveryServicesIaasVmContainer).ResourceGroupName == ResourceGroupName).ToList();
81+
}
7982

80-
WriteObject(containerModels);
83+
WriteObject(containerModels);
84+
});
8185
}
8286
}
8387
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/GetAzureRMBackupRetentionPolicyObject.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public class GetAzureRMBackupRetentionPolicyObject : RecoveryServicesBackupCmdle
3939

4040
public override void ExecuteCmdlet()
4141
{
42-
base.ExecuteCmdlet();
42+
ExecutionBlock(() =>
43+
{
44+
base.ExecuteCmdlet();
45+
});
4346
}
4447
}
4548
}

src/ResourceManager/RecoveryServices.Backup/Cmdlets/ProtectionPolicy/GetAzureRMBackupSchedulePolicyObject.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ public class GetAzureRMBackupSchedulePolicyObject : RecoveryServicesBackupCmdlet
3939

4040
public override void ExecuteCmdlet()
4141
{
42-
base.ExecuteCmdlet();
42+
ExecutionBlock(() =>
43+
{
44+
base.ExecuteCmdlet();
45+
});
4346
}
4447
}
4548
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/Commands.RecoveryServices.Backup.HydraAdapter.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
<ItemGroup>
7171
<Content Include="Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll" />
7272
</ItemGroup>
73+
<ItemGroup>
74+
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Models\Commands.RecoveryServices.Backup.Models.csproj">
75+
<Project>{30b92759-50b3-494e-b9f0-ec9a2ce9d57b}</Project>
76+
<Name>Commands.RecoveryServices.Backup.Models</Name>
77+
</ProjectReference>
78+
</ItemGroup>
7379
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7480
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7581
Other similar extension points exist, see Microsoft.Common.targets.

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Commands.RecoveryServices.Backup.Providers.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
<Compile Include="Providers\IaasVmPsBackupProvider.cs" />
6060
</ItemGroup>
6161
<ItemGroup>
62+
<ProjectReference Include="..\..\Common\Commands.ResourceManager.Common\Commands.ResourceManager.Common.csproj">
63+
<Project>{3819d8a7-c62c-4c47-8ddd-0332d9ce1252}</Project>
64+
<Name>Commands.ResourceManager.Common</Name>
65+
</ProjectReference>
6266
<ProjectReference Include="..\Commands.RecoveryServices.Backup.Helpers\Commands.RecoveryServices.Backup.Helpers.csproj">
6367
<Project>{0e1d3f36-e6c8-4764-8c7d-6f9ee537490c}</Project>
6468
<Name>Commands.RecoveryServices.Backup.Helpers</Name>

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Providers/Providers/AzureSqlPsBackupProvider.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,15 @@ public Management.RecoveryServices.Backup.Models.ProtectionPolicyResponse Modify
6666
{
6767
throw new NotImplementedException();
6868
}
69+
70+
public Management.RecoveryServices.Backup.Models.ProtectionPolicyResponse GetPolicy()
71+
{
72+
throw new NotImplementedException();
73+
}
74+
75+
public void DeletePolicy()
76+
{
77+
throw new NotImplementedException();
78+
}
6979
}
7080
}

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Test/Commands.RecoveryServices.Backup.Test.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@
6262
<Reference Include="Microsoft.CSharp" />
6363
<Reference Include="System.Data" />
6464
<Reference Include="System.Xml" />
65+
<Reference Include="xunit">
66+
<HintPath>..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
67+
</Reference>
6568
</ItemGroup>
6669
<ItemGroup>
6770
<Compile Include="Properties\AssemblyInfo.cs" />
71+
<None Include="ScenarioTests\AzureVm\ContainerTests.ps1" />
72+
<Compile Include="ScenarioTests\AzureVm\ContainerTests.cs" />
6873
<Compile Include="ScenarioTests\TestsBase.cs" />
6974
</ItemGroup>
7075
<ItemGroup>
@@ -79,6 +84,9 @@
7984
<ItemGroup>
8085
<WCFMetadata Include="Service References\" />
8186
</ItemGroup>
87+
<ItemGroup>
88+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
89+
</ItemGroup>
8290
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8391
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
8492
Other similar extension points exist, see Microsoft.Common.targets.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Text;
19+
using System.Threading.Tasks;
20+
using Xunit;
21+
22+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Test.ScenarioTests
23+
{
24+
public class ContainerTests : RecoveryServicesBackupTestsBase
25+
{
26+
[Fact]
27+
public void Test()
28+
{
29+
this.RunPowerShellTest("Test");
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+

src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.Test/ScenarioTests/TestsBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ protected void RunPowerShellTest(params string[] scripts)
6161
using (UndoContext context = UndoContext.Current)
6262
{
6363
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));
64+
65+
string baseDir = TestUtilities.GetMockBaseDirectory();
66+
string callingClass = TestUtilities.GetCallingClass(2);
67+
string currMethodName = TestUtilities.GetCurrentMethodName(2);
6468

6569
SetupManagementClients();
6670

src/ResourceManager/RecoveryServices.Backup/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/RecoveryServices.Backup/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="CloudExceptionCodeNotFound" xml:space="preserve">
130130
<value>Received CloudException, StatusCode: {0}.</value>
131131
</data>
132+
<data name="ExceptionInExecution" xml:space="preserve">
133+
<value>Caught exception, type: {0}.</value>
134+
</data>
132135
<data name="ResourceNotFoundMessage" xml:space="preserve">
133136
<value>The specified resource does not exist.</value>
134137
</data>

src/ResourceManager/RecoveryServices.Backup/RecoveryServicesBackupCmdletBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected void ExecutionBlock(Action action)
5050
}
5151
catch (Exception exception)
5252
{
53+
WriteDebug(String.Format(Resources.ExceptionInExecution, exception.GetType()));
5354
HandleException(exception);
5455
}
5556
}

0 commit comments

Comments
 (0)