Skip to content

Commit 642b5e4

Browse files
author
Samuel Anudeep
committed
Merge pull request AzureRT#171 from MabOneSdk/anudeeb-dev1
Added Cmdlet Base and Adapter
2 parents 1f246ec + 4f74881 commit 642b5e4

33 files changed

+904
-91
lines changed
Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="Hyak.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
34+
<SpecificVersion>False</SpecificVersion>
35+
<HintPath>..\..\packages\Hyak.Common.1.0.3\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
36+
</Reference>
3337
<Reference Include="System" />
3438
<Reference Include="System.Core" />
39+
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
40+
<SpecificVersion>False</SpecificVersion>
41+
<HintPath>C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35\System.Management.Automation.dll</HintPath>
42+
</Reference>
43+
<Reference Include="System.Net" />
3544
<Reference Include="System.Xml.Linq" />
3645
<Reference Include="System.Data.DataSetExtensions" />
3746
<Reference Include="Microsoft.CSharp" />
@@ -40,6 +49,12 @@
4049
</ItemGroup>
4150
<ItemGroup>
4251
<Compile Include="Properties\AssemblyInfo.cs" />
52+
<Compile Include="Properties\Resources.Designer.cs">
53+
<AutoGen>True</AutoGen>
54+
<DesignTime>True</DesignTime>
55+
<DependentUpon>Resources.resx</DependentUpon>
56+
</Compile>
57+
<Compile Include="RecoveryServicesBackupCmdletBase.cs" />
4358
</ItemGroup>
4459
<ItemGroup>
4560
<Folder Include="Cmdlets\Backup\" />
@@ -51,19 +66,21 @@
5166
<Folder Include="Cmdlets\Restore\" />
5267
</ItemGroup>
5368
<ItemGroup>
54-
<ProjectReference Include="..\Helpers\Helpers.csproj">
55-
<Project>{0e1d3f36-e6c8-4764-8c7d-6f9ee537490c}</Project>
56-
<Name>Helpers</Name>
69+
<ProjectReference Include="..\..\Common\Commands.Common\Commands.Common.csproj">
70+
<Project>{5ee72c53-1720-4309-b54b-5fb79703195f}</Project>
71+
<Name>Commands.Common</Name>
5772
</ProjectReference>
58-
<ProjectReference Include="..\Models\Models.csproj">
59-
<Project>{30b92759-50b3-494e-b9f0-ec9a2ce9d57b}</Project>
60-
<Name>Models</Name>
61-
</ProjectReference>
62-
<ProjectReference Include="..\ProviderModel\ProviderModel.csproj">
63-
<Project>{02234e90-bcde-4b20-b1f5-01b1005821db}</Project>
64-
<Name>ProviderModel</Name>
73+
<ProjectReference Include="..\Common\Commands.ResourceManager.Common\Commands.ResourceManager.Common.csproj">
74+
<Project>{3819d8a7-c62c-4c47-8ddd-0332d9ce1252}</Project>
75+
<Name>Commands.ResourceManager.Common</Name>
6576
</ProjectReference>
6677
</ItemGroup>
78+
<ItemGroup>
79+
<EmbeddedResource Include="Properties\Resources.resx">
80+
<Generator>ResXFileCodeGenerator</Generator>
81+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
82+
</EmbeddedResource>
83+
</ItemGroup>
6784
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6885
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6986
Other similar extension points exist, see Microsoft.Common.targets.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 Microsoft.Azure.Management.RecoveryServices.Backup.Models;
16+
using System;
17+
using System.Collections.Generic;
18+
using System.Linq;
19+
using System.Text;
20+
using System.Threading.Tasks;
21+
22+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
23+
{
24+
public partial class HydraAdapter
25+
{
26+
/// <summary>
27+
/// Fetches protection containers in the vault according to the query params
28+
/// </summary>
29+
/// <param name="parameters"></param>
30+
/// <returns></returns>
31+
public IEnumerable<ProtectionContainerResource> RecoveryServicesListContainers(string resourceGroupName, string resourceName, ProtectionContainerListQueryParams queryParams)
32+
{
33+
var listResponse = BmsAdapter.Client.Container.ListAsync(resourceGroupName, resourceName, queryParams,
34+
BmsAdapter.GetCustomRequestHeaders(), BmsAdapter.CmdletCancellationToken).Result;
35+
return listResponse.ItemList.ProtectionContainers;
36+
}
37+
38+
/// <summary>
39+
/// Triggers refresh of container catalog in service
40+
/// </summary>
41+
/// <returns></returns>
42+
public BaseRecoveryServicesJobResponse RecoveryServicesRefreshContainers(string resourceGroupName, string resourceName)
43+
{
44+
var response = BmsAdapter.Client.Container.RefreshAsync(
45+
resourceGroupName, resourceName,
46+
BmsAdapter.GetCustomRequestHeaders(), AzureFabricName, BmsAdapter.CmdletCancellationToken).Result;
47+
return response;
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
22+
{
23+
public partial class HydraAdapter
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
22+
{
23+
public partial class HydraAdapter
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
22+
{
23+
public partial class HydraAdapter
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
21+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
22+
{
23+
public partial class HydraAdapter
24+
{
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 Hyak.Common;
16+
using Microsoft.Azure.Common.Authentication;
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Text;
21+
using System.Threading.Tasks;
22+
23+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
24+
{
25+
public partial class ClientProxy<TClient, THeader> : ClientProxyBase
26+
where TClient : ServiceClient<TClient>
27+
{
28+
/// <summary>
29+
/// Client to talk to backend service
30+
/// </summary>
31+
private TClient client;
32+
33+
/// <summary>
34+
/// Delegate action to generate custom request headers
35+
/// </summary>
36+
private Func<string, THeader> CustomRequestHeaderGenerator;
37+
38+
/// <summary>
39+
/// Get Azure backup client.
40+
/// </summary>
41+
public TClient Client
42+
{
43+
get
44+
{
45+
if (this.client == null)
46+
{
47+
this.client = AzureSession.ClientFactory.CreateCustomClient<TClient>(Parameters);
48+
}
49+
50+
return this.client;
51+
}
52+
}
53+
54+
public ClientProxy(Func<string, THeader> headerGenerator, params object[] parameters)
55+
: base(parameters)
56+
{
57+
CustomRequestHeaderGenerator = headerGenerator;
58+
}
59+
60+
public THeader GetCustomRequestHeaders()
61+
{
62+
return CustomRequestHeaderGenerator(this.ClientRequestId);
63+
}
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.Net;
19+
using System.Text;
20+
using System.Threading;
21+
using System.Threading.Tasks;
22+
23+
namespace Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.HydraAdapter
24+
{
25+
public class ClientProxyBase
26+
{
27+
protected object[] Parameters;
28+
29+
/// <summary>
30+
/// Client request id.
31+
/// </summary>
32+
protected string ClientRequestId;
33+
34+
/// <summary>
35+
/// Cancellation Token Source
36+
/// </summary>
37+
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
38+
public CancellationToken CmdletCancellationToken;
39+
40+
public ClientProxyBase(params object[] parameters)
41+
{
42+
Parameters = parameters;
43+
44+
RefreshClientRequestId();
45+
46+
// Temp code to be able to test internal env.
47+
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
48+
}
49+
50+
public void RefreshClientRequestId()
51+
{
52+
ClientRequestId = Guid.NewGuid().ToString() + "-" + DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ssZ") + "-PS";
53+
}
54+
55+
public string GetClientRequestId()
56+
{
57+
return ClientRequestId;
58+
}
59+
}
60+
}

src/ResourceManager/RecoveryServices.Backup/RecoveryServices.Backup/Adapter/Adapter.csproj renamed to src/ResourceManager/RecoveryServices.Backup/Commands.RecoveryServices.Backup.HydraAdapter/Commands.RecoveryServices.Backup.HydraAdapter.csproj

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,46 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="Hyak.Common">
34+
<HintPath>..\..\..\packages\Hyak.Common.1.0.3\lib\portable-net403+win+wpa81\Hyak.Common.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Microsoft.Azure.Common">
37+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.2.1.0\lib\net45\Microsoft.Azure.Common.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Microsoft.Azure.Common.Authentication">
40+
<HintPath>..\..\..\packages\Microsoft.Azure.Common.Authentication.1.6.1-preview\lib\net45\Microsoft.Azure.Common.Authentication.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Microsoft.Azure.Management.RecoveryServicesBackupManagement, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
43+
<SpecificVersion>False</SpecificVersion>
44+
<HintPath>Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll</HintPath>
45+
</Reference>
46+
<Reference Include="Microsoft.Rest.ClientRuntime">
47+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.1.8.2\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
48+
</Reference>
3349
<Reference Include="System" />
50+
<Reference Include="System.Configuration" />
3451
<Reference Include="System.Core" />
52+
<Reference Include="System.Net.Http" />
3553
<Reference Include="System.Xml.Linq" />
3654
<Reference Include="System.Data.DataSetExtensions" />
3755
<Reference Include="Microsoft.CSharp" />
3856
<Reference Include="System.Data" />
3957
<Reference Include="System.Xml" />
4058
</ItemGroup>
4159
<ItemGroup>
60+
<Compile Include="BMSAPIs\PolicyAPIs.cs" />
61+
<Compile Include="BMSAPIs\OperationStatusAPIs.cs" />
62+
<Compile Include="BMSAPIs\JobAPIs.cs" />
63+
<Compile Include="BMSAPIs\ItemAPIs.cs" />
64+
<Compile Include="BMSAPIs\ContainerAPIs.cs" />
65+
<Compile Include="ClientProxy.cs" />
66+
<Compile Include="ClientProxyBase.cs" />
67+
<Compile Include="HydraAdapter.cs" />
4268
<Compile Include="Properties\AssemblyInfo.cs" />
4369
</ItemGroup>
70+
<ItemGroup>
71+
<Content Include="Resources\Microsoft.Azure.Management.RecoveryServicesBackupManagement.dll" />
72+
</ItemGroup>
4473
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
4574
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
4675
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)