Skip to content

Commit cd65d22

Browse files
ReFormatting RecoveryServices.SiteRecovery project
1 parent 13346e2 commit cd65d22

File tree

73 files changed

+6463
-4903
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+6463
-4903
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ----------------------------------------------------------------------------------
2-
//
2+
//
33
// Copyright Microsoft Corporation
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -13,60 +13,63 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Management.Automation;
1617
using System.Runtime.Serialization;
1718
using System.Text;
1819
using System.Threading;
1920
using System.Xml;
20-
using Microsoft.Azure.Commands.Common.Authentication;
21+
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.Properties;
2122
using Microsoft.Azure.Commands.ResourceManager.Common;
22-
using Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models;
2323
using Microsoft.Rest.Azure;
24+
using Microsoft.Rest.Serialization;
2425
using Newtonsoft.Json;
26+
using Job = Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models.Job;
2527

2628
namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery
2729
{
2830
/// <summary>
29-
/// The base class for all Windows Azure Recovery Services commands
31+
/// The base class for all Windows Azure Recovery Services commands
3032
/// </summary>
3133
public abstract class SiteRecoveryCmdletBase : AzureRMCmdlet
3234
{
3335
/// <summary>
34-
/// Recovery Services client.
35-
/// </summary>
36-
private PSRecoveryServicesClient recoveryServicesClient;
37-
38-
/// <summary>
39-
/// Gets or sets a value indicating whether stop processing has been triggered.
36+
/// Gets or sets a value indicating whether stop processing has been triggered.
4037
/// </summary>
4138
internal bool StopProcessingFlag { get; set; }
4239

4340
/// <summary>
44-
/// Gets Recovery Services client.
41+
/// Gets Recovery Services client.
4542
/// </summary>
4643
internal PSRecoveryServicesClient RecoveryServicesClient
4744
{
4845
get
4946
{
50-
if (this.recoveryServicesClient == null)
47+
if (recoveryServicesClient == null)
5148
{
52-
this.recoveryServicesClient = new PSRecoveryServicesClient(DefaultProfile);
49+
recoveryServicesClient = new PSRecoveryServicesClient(DefaultProfile);
5350
}
5451

55-
return this.recoveryServicesClient;
52+
return recoveryServicesClient;
5653
}
5754
}
5855

5956
/// <summary>
60-
/// Virtual method to be implemented by Site Recovery cmdlets.
57+
/// Recovery Services client.
58+
/// </summary>
59+
private PSRecoveryServicesClient recoveryServicesClient;
60+
61+
/// <summary>
62+
/// Virtual method to be implemented by Site Recovery cmdlets.
6163
/// </summary>
6264
public virtual void ExecuteSiteRecoveryCmdlet()
6365
{
6466
SiteRecoveryAutoMapperProfile.Initialize();
67+
6568
// Do Nothing
6669
}
6770

6871
/// <summary>
69-
/// Overriding base implementation go execute cmdlet.
72+
/// Overriding base implementation go execute cmdlet.
7073
/// </summary>
7174
public override void ExecuteCmdlet()
7275
{
@@ -77,47 +80,57 @@ public override void ExecuteCmdlet()
7780
}
7881
catch (Exception ex)
7982
{
80-
this.HandleException(ex);
83+
HandleException(ex);
8184
}
8285
}
8386

8487
/// <summary>
85-
/// Exception handler.
88+
/// Exception handler.
8689
/// </summary>
8790
/// <param name="ex">Exception to handle.</param>
8891
public void HandleException(Exception ex)
8992
{
90-
string clientRequestIdMsg = string.Empty;
91-
if (this.recoveryServicesClient != null)
93+
var clientRequestIdMsg = string.Empty;
94+
if (recoveryServicesClient != null)
9295
{
93-
clientRequestIdMsg = "ClientRequestId: " + this.recoveryServicesClient.ClientRequestId + "\n";
96+
clientRequestIdMsg = "ClientRequestId: " +
97+
recoveryServicesClient.ClientRequestId +
98+
"\n";
9499
}
95100

96-
CloudException cloudException = ex as CloudException;
97-
if (cloudException != null && cloudException.Body != null && cloudException.Response != null)
98-
{
101+
var cloudException = ex as CloudException;
102+
if (cloudException != null &&
103+
cloudException.Body != null &&
104+
cloudException.Response != null)
105+
{
99106
try
100107
{
101108
if (cloudException.Message != null)
102109
{
103-
ARMError error = Rest.Serialization.SafeJsonConvert.DeserializeObject<ARMError>(cloudException.Response.Content); ;
104-
StringBuilder exceptionMessage = new StringBuilder();
105-
exceptionMessage.Append(Properties.Resources.CloudExceptionDetails);
110+
var error =
111+
SafeJsonConvert.DeserializeObject<ARMError>(cloudException.Response
112+
.Content);
113+
;
114+
var exceptionMessage = new StringBuilder();
115+
exceptionMessage.Append(Resources.CloudExceptionDetails);
106116

107117
if (error.Error.Details != null)
108118
{
109-
foreach (ARMExceptionDetails detail in error.Error.Details)
119+
foreach (var detail in error.Error.Details)
110120
{
111121
if (!string.IsNullOrEmpty(detail.ErrorCode))
112122
exceptionMessage.AppendLine("ErrorCode: " + detail.ErrorCode);
113123
if (!string.IsNullOrEmpty(detail.Message))
114124
exceptionMessage.AppendLine("Message: " + detail.Message);
115125
if (!string.IsNullOrEmpty(detail.PossibleCauses))
116-
exceptionMessage.AppendLine("Possible Causes: " + detail.PossibleCauses);
126+
exceptionMessage.AppendLine(
127+
"Possible Causes: " + detail.PossibleCauses);
117128
if (!string.IsNullOrEmpty(detail.RecommendedAction))
118-
exceptionMessage.AppendLine("Recommended Action: " + detail.RecommendedAction);
129+
exceptionMessage.AppendLine(
130+
"Recommended Action: " + detail.RecommendedAction);
119131
if (!string.IsNullOrEmpty(detail.ClientRequestId))
120-
exceptionMessage.AppendLine("ClientRequestId: " + detail.ClientRequestId);
132+
exceptionMessage.AppendLine(
133+
"ClientRequestId: " + detail.ClientRequestId);
121134
if (!string.IsNullOrEmpty(detail.ActivityId))
122135
exceptionMessage.AppendLine("ActivityId: " + detail.ActivityId);
123136

@@ -134,52 +147,44 @@ public void HandleException(Exception ex)
134147

135148
throw new InvalidOperationException(exceptionMessage.ToString());
136149
}
137-
else
138-
{
139-
throw new Exception(
140-
string.Format(
141-
Properties.Resources.InvalidCloudExceptionErrorMessage,
150+
151+
throw new Exception(string.Format(Resources.InvalidCloudExceptionErrorMessage,
142152
clientRequestIdMsg + ex.Message),
143-
ex);
144-
}
153+
ex);
145154
}
146155
catch (XmlException)
147156
{
148157
throw new XmlException(
149-
string.Format(
150-
Properties.Resources.InvalidCloudExceptionErrorMessage,
151-
cloudException.Message),
158+
string.Format(Resources.InvalidCloudExceptionErrorMessage,
159+
cloudException.Message),
152160
cloudException);
153161
}
154162
catch (SerializationException)
155163
{
156-
throw new SerializationException(
157-
string.Format(
158-
Properties.Resources.InvalidCloudExceptionErrorMessage,
159-
clientRequestIdMsg + cloudException.Message),
164+
throw new SerializationException(string.Format(
165+
Resources.InvalidCloudExceptionErrorMessage,
166+
clientRequestIdMsg + cloudException.Message),
160167
cloudException);
161168
}
162169
catch (JsonReaderException)
163170
{
164171
throw new JsonReaderException(
165-
string.Format(
166-
Properties.Resources.InvalidCloudExceptionErrorMessage,
167-
clientRequestIdMsg + cloudException.Message),
172+
string.Format(Resources.InvalidCloudExceptionErrorMessage,
173+
clientRequestIdMsg + cloudException.Message),
168174
cloudException);
169175
}
170176
}
171-
else if (ex.Message != null)
177+
178+
if (ex.Message != null)
172179
{
173-
throw new Exception(
174-
string.Format(
175-
Properties.Resources.InvalidCloudExceptionErrorMessage,
176-
clientRequestIdMsg + ex.Message),
180+
throw new Exception(string.Format(Resources.InvalidCloudExceptionErrorMessage,
181+
clientRequestIdMsg + ex.Message),
177182
ex);
178183
}
179184
}
180185

181186
/// <summary>
182-
/// Waits for the job to complete.
187+
/// Waits for the job to complete.
183188
/// </summary>
184189
/// <param name="jobId">Id of the job to wait for.</param>
185190
/// <returns>Final job response</returns>
@@ -189,53 +194,47 @@ public Job WaitForJobCompletion(string jobId)
189194
do
190195
{
191196
Thread.Sleep(PSRecoveryServicesClient.TimeToSleepBeforeFetchingJobDetailsAgain);
192-
job = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(jobId);
193-
this.WriteProgress(
194-
new System.Management.Automation.ProgressRecord(
195-
0,
196-
Properties.Resources.WaitingForCompletion,
197-
job.Properties.State));
198-
}
199-
while (!(job.Properties.State == JobStatus.Cancelled ||
200-
job.Properties.State == JobStatus.Failed ||
201-
job.Properties.State == JobStatus.Suspended ||
202-
job.Properties.State == JobStatus.Succeeded ||
203-
this.StopProcessingFlag));
197+
job = RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(jobId);
198+
WriteProgress(new ProgressRecord(0,
199+
Resources.WaitingForCompletion,
200+
job.Properties.State));
201+
} while (!(job.Properties.State == TaskStatus.Cancelled ||
202+
job.Properties.State == TaskStatus.Failed ||
203+
job.Properties.State == TaskStatus.Suspended ||
204+
job.Properties.State == TaskStatus.Succeeded ||
205+
StopProcessingFlag));
206+
204207
return job;
205208
}
206209

207-
208210
/// <summary>
209-
/// Handles interrupts.
211+
/// Handles interrupts.
210212
/// </summary>
211213
protected override void StopProcessing()
212214
{
213215
// Ctrl + C and etc
214216
base.StopProcessing();
215-
this.StopProcessingFlag = true;
217+
StopProcessingFlag = true;
216218
}
217219

218220
/// <summary>
219-
/// Validates if the usage by ID is allowed or not.
221+
/// Validates if the usage by ID is allowed or not.
220222
/// </summary>
221223
/// <param name="replicationProvider">Replication provider.</param>
222224
/// <param name="paramName">Parameter name.</param>
223-
protected void ValidateUsageById(string replicationProvider, string paramName)
225+
protected void ValidateUsageById(string replicationProvider,
226+
string paramName)
224227
{
225228
if (replicationProvider != Constants.HyperVReplica2012)
226229
{
227-
throw new Exception(
228-
string.Format(
230+
throw new Exception(string.Format(
229231
"Call using ID based parameter {0} is not supported for this provider. Please use its corresponding full object parameter instead",
230232
paramName));
231233
}
232-
else
233-
{
234-
this.WriteWarningWithTimestamp(
235-
string.Format(
236-
Properties.Resources.IDBasedParamUsageNotSupportedFromNextRelease,
234+
235+
WriteWarningWithTimestamp(
236+
string.Format(Resources.IDBasedParamUsageNotSupportedFromNextRelease,
237237
paramName));
238-
}
239238
}
240239
}
241-
}
240+
}

0 commit comments

Comments
 (0)