17
17
using System . Collections . Generic ;
18
18
using System . Xml ;
19
19
using Microsoft . WindowsAzure . Commands . Utilities . Common ;
20
- using Microsoft . WindowsAzure . Management . BackupServices ;
21
20
using Microsoft . Azure . Common . Authentication ;
22
21
using Microsoft . Azure . Common . Authentication . Models ;
23
22
using System . Threading ;
24
23
using Hyak . Common ;
25
24
using Microsoft . Azure . Commands . AzureBackup . Properties ;
26
25
using System . Net ;
26
+ using Microsoft . WindowsAzure . Management . Scheduler ;
27
+ using Microsoft . Azure . Management . BackupServices ;
28
+ using Microsoft . Azure . Management . BackupServices . Models ;
27
29
28
30
namespace Microsoft . Azure . Commands . AzureBackup . Cmdlets
29
31
{
@@ -32,17 +34,17 @@ public abstract class AzureBackupCmdletBase : AzurePSCmdlet
32
34
/// <summary>
33
35
/// ResourceGroup context for the operation
34
36
/// </summary>
35
- protected string ResourceGroupName { get ; set ; }
37
+ private string resourceGroupName { get ; set ; }
36
38
37
39
/// <summary>
38
40
/// Resource context for the operation
39
41
/// </summary>
40
- protected string ResourceName { get ; set ; }
42
+ private string resourceName { get ; set ; }
41
43
42
44
/// <summary>
43
45
/// Client request id.
44
46
/// </summary>
45
- protected string clientRequestId ;
47
+ private string clientRequestId ;
46
48
47
49
/// <summary>
48
50
/// Azure backup client.
@@ -64,24 +66,25 @@ protected BackupServicesManagementClient AzureBackupClient
64
66
{
65
67
if ( this . azureBackupClient == null )
66
68
{
67
- this . azureBackupClient = AzureSession . ClientFactory . CreateClient < BackupServicesManagementClient > ( Profile , Profile . Context . Subscription , AzureEnvironment . Endpoint . ResourceManager ) ;
68
- // this.azureBackupClient.ResourceGroupName = resourceGroupName;
69
- // this.azureBackupClient.ResourceName = resourceName;
69
+ // Temp code to be able to test internal env.
70
+ ServicePointManager . ServerCertificateValidationCallback = delegate { return true ; } ;
71
+
72
+ var cloudServicesClient = AzureSession . ClientFactory . CreateClient < CloudServiceManagementClient > ( Profile , Profile . Context . Subscription , AzureEnvironment . Endpoint . ResourceManager ) ;
73
+ this . azureBackupClient = AzureSession . ClientFactory . CreateCustomClient < BackupServicesManagementClient > ( resourceName , resourceGroupName , cloudServicesClient . Credentials , cloudServicesClient . BaseUri ) ;
70
74
}
71
75
72
76
return this . azureBackupClient ;
73
77
}
74
78
}
75
79
76
- public override void ExecuteCmdlet ( )
80
+ public void InitializeAzureBackupCmdlet ( string rgName , string rName )
77
81
{
78
- base . ExecuteCmdlet ( ) ;
79
-
80
- // Vaildate RGName, RName?
82
+ resourceGroupName = rgName ;
83
+ resourceName = rName ;
81
84
82
85
clientRequestId = Guid . NewGuid ( ) . ToString ( ) + "-" + DateTime . Now . ToUniversalTime ( ) . ToString ( "yyyy-MM-dd HH:mm:ssZ" ) + "-PS" ;
83
86
84
- WriteVerbose ( string . Format ( "ClientRequestId: {0}" , this . clientRequestId ) ) ;
87
+ WriteDebug ( string . Format ( "Initialized AzureBackup Cmdlet, ClientRequestId: {0}, ResourceGroupName: {1}, ResourceName : {2} " , this . clientRequestId , resourceGroupName , resourceName ) ) ;
85
88
86
89
CmdletCancellationToken = cancellationTokenSource . Token ;
87
90
}
@@ -155,6 +158,17 @@ private void HandleException(Exception exception)
155
158
WriteError ( errorRecord ) ;
156
159
}
157
160
}
161
+
162
+ protected CustomRequestHeaders GetCustomRequestHeaders ( )
163
+ {
164
+ var hdrs = new CustomRequestHeaders ( )
165
+ {
166
+ // ClientRequestId is a unique ID for every request to backend service.
167
+ ClientRequestId = this . clientRequestId ,
168
+ } ;
169
+
170
+ return hdrs ;
171
+ }
158
172
}
159
173
}
160
174
0 commit comments