Skip to content

Commit f0dde96

Browse files
committed
Merge pull request #3 from AsrOneSdk/sriramvu-dev
Enabled StyleCop and fixed related errors
2 parents 1c98d6c + 526a44a commit f0dde96

35 files changed

+372
-227
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Commands.RecoveryServices.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<TargetFrameworkProfile />
1515
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
1616
<RestorePackages>true</RestorePackages>
17+
<StyleCopOverrideSettingsFile>Settings.StyleCop</StyleCopOverrideSettingsFile>
18+
<BuildToolsStyleCopVersion>4.7.44.0</BuildToolsStyleCopVersion>
1719
</PropertyGroup>
1820
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1921
<DebugSymbols>true</DebugSymbols>
@@ -28,10 +30,12 @@
2830
<CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode>
2931
<RunCodeAnalysis>true</RunCodeAnalysis>
3032
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
33+
<StyleCopEnabled>True</StyleCopEnabled>
34+
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
3135
</PropertyGroup>
3236
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3337
<OutputPath>..\..\..\Package\Release\ServiceManagement\Azure\RecoveryServices</OutputPath>
34-
<DefineConstants>TRACE;SIGN</DefineConstants>
38+
<DefineConstants>TRACE;SIGN;CODE_ANALYSIS</DefineConstants>
3539
<Optimize>true</Optimize>
3640
<DebugType>pdbonly</DebugType>
3741
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -189,6 +193,10 @@
189193
<Error Condition="!Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
190194
<Error Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
191195
</Target>
196+
<Import Project="..\..\..\packages\BuildTools.StyleCop.4.7.49.0\tools\StyleCop.targets" Condition="Exists('..\..\..\packages\BuildTools.StyleCop.4.7.49.0\tools\StyleCop.targets')" />
197+
<Target Name="_________packages_BuildTools_StyleCop_4_7_49_0_tools_StyleCop_targets" Condition="$(StyleCopOutputFile)==''" BeforeTargets="BeforeBuild">
198+
<Error Text="BuildTools_StyleCop - the BuildTools_StyleCop package has not been restored.&#xD;&#xA;If you are running this from an IDE, make sure NuGet Package Restore has been enabled, then reload the solution and re-run the build.&#xD;&#xA;If you are running this from the command line, run the build again.&#xD;&#xA;If this is a CI server, you may want to make sure NuGet Package Restore runs before your build with:&#xD;&#xA; msbuild solution.sln /t:restorepackages" />
199+
</Target>
192200
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
193201
Other similar extension points exist, see Microsoft.Common.targets.
194202
<Target Name="BeforeBuild">

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesNetworkMappingClient.cs

Lines changed: 155 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Collections.Generic;
17+
using System.Diagnostics.CodeAnalysis;
1618
using System.IO;
1719
using System.Runtime.Serialization;
1820
using System.Xml;
1921
using Microsoft.WindowsAzure;
22+
using Microsoft.WindowsAzure.Commands.Common;
23+
using Microsoft.WindowsAzure.Commands.Common.Models;
2024
using Microsoft.WindowsAzure.Management.SiteRecovery;
21-
// using Microsoft.WindowsAzure.Management.
2225
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
23-
using Microsoft.WindowsAzure.Commands.Common.Models;
24-
using Microsoft.WindowsAzure.Commands.Common;
25-
using System.Collections.Generic;
2626

2727
namespace Microsoft.Azure.Commands.RecoveryServices
2828
{
@@ -32,51 +32,190 @@ namespace Microsoft.Azure.Commands.RecoveryServices
3232
public enum TargetNetworkType
3333
{
3434
/// <summary>
35-
/// Server.
35+
/// Target type of the network is Server.
3636
/// </summary>
3737
Server = 0,
3838

3939
/// <summary>
40-
/// Azure.
40+
/// Target type of the network is Azure.
4141
/// </summary>
4242
Azure,
4343
}
4444

45+
/// <summary>
46+
/// Helper around serialization/deserialization of objects. This one is a thin wrapper around
47+
/// DataContractUtils template class which is the one doing the heavy lifting.
48+
/// </summary>
49+
[SuppressMessage(
50+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
51+
"SA1402:FileMayOnlyContainASingleClass",
52+
Justification = "Keeping all contracts together.")]
53+
public static class DataContractUtils
54+
{
55+
/// <summary>
56+
/// Serializes the supplied object to the string.
57+
/// </summary>
58+
/// <typeparam name="T">The object type.</typeparam>
59+
/// <param name="obj">Object to serialize</param>
60+
/// <returns>Serialized string.</returns>
61+
public static string Serialize<T>(T obj)
62+
{
63+
return DataContractUtils<T>.Serialize(obj);
64+
}
65+
66+
/// <summary>
67+
/// Deserialize the string to the expected object type.
68+
/// </summary>
69+
/// <typeparam name="T">The object type</typeparam>
70+
/// <param name="xmlString">Serialized string</param>
71+
/// <param name="result">Deserialized object</param>
72+
public static void Deserialize<T>(string xmlString, out T result)
73+
{
74+
result = DataContractUtils<T>.Deserialize(xmlString);
75+
}
76+
}
77+
78+
/// <summary>
79+
/// Template class for DataContractUtils.
80+
/// </summary>
81+
/// <typeparam name="T">The object type</typeparam>
82+
[SuppressMessage(
83+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
84+
"SA1402:FileMayOnlyContainASingleClass",
85+
Justification = "Keeping all contracts together.")]
86+
public static class DataContractUtils<T>
87+
{
88+
/// <summary>
89+
/// Serializes the propertyBagContainer to the string.
90+
/// </summary>
91+
/// <param name="propertyBagContainer">Property bag</param>
92+
/// <returns>Serialized string </returns>
93+
public static string Serialize(T propertyBagContainer)
94+
{
95+
var serializer = new DataContractSerializer(typeof(T));
96+
string xmlString;
97+
StringWriter sw = null;
98+
try
99+
{
100+
sw = new StringWriter();
101+
using (var writer = new XmlTextWriter(sw))
102+
{
103+
// Indent the XML so it's human readable.
104+
writer.Formatting = Formatting.Indented;
105+
serializer.WriteObject(writer, propertyBagContainer);
106+
writer.Flush();
107+
xmlString = sw.ToString();
108+
}
109+
}
110+
finally
111+
{
112+
if (sw != null)
113+
{
114+
sw.Close();
115+
}
116+
}
117+
118+
return xmlString;
119+
}
120+
121+
/// <summary>
122+
/// Deserialize the string to the propertyBagContainer.
123+
/// </summary>
124+
/// <param name="xmlString">Serialized string</param>
125+
/// <returns>Deserialized object</returns>
126+
public static T Deserialize(string xmlString)
127+
{
128+
T propertyBagContainer;
129+
using (Stream stream = new MemoryStream())
130+
{
131+
byte[] data = System.Text.Encoding.UTF8.GetBytes(xmlString);
132+
stream.Write(data, 0, data.Length);
133+
stream.Position = 0;
134+
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
135+
propertyBagContainer = (T)deserializer.ReadObject(stream);
136+
}
137+
138+
return propertyBagContainer;
139+
}
140+
}
141+
142+
/// <summary>
143+
/// Create network mapping input.
144+
/// </summary>
145+
[SuppressMessage(
146+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
147+
"SA1402:FileMayOnlyContainASingleClass",
148+
Justification = "Keeping all contracts together.")]
45149
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
46150
public class CreateNetworkMappingInput
47151
{
152+
/// <summary>
153+
/// Gets or sets Primary Server Id.
154+
/// </summary>
48155
[DataMember(Order = 1)]
49156
public string PrimaryServerId { get; set; }
50157

158+
/// <summary>
159+
/// Gets or sets Primary Network Id.
160+
/// </summary>
51161
[DataMember(Order = 2)]
52162
public string PrimaryNetworkId { get; set; }
53163

164+
/// <summary>
165+
/// Gets or sets Recovery Server Id.
166+
/// </summary>
54167
[DataMember(Order = 3)]
55168
public string RecoveryServerId { get; set; }
56169

170+
/// <summary>
171+
/// Gets or sets Recovery Network Id.
172+
/// </summary>
57173
[DataMember(Order = 4)]
58174
public string RecoveryNetworkId { get; set; }
59175
}
60176

177+
/// <summary>
178+
/// Create Azure network mapping input.
179+
/// </summary>
180+
[SuppressMessage(
181+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
182+
"SA1402:FileMayOnlyContainASingleClass",
183+
Justification = "Keeping all contracts together.")]
61184
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
62185
public class CreateAzureNetworkMappingInput
63186
{
187+
/// <summary>
188+
/// Gets or sets Primary Server Id.
189+
/// </summary>
64190
[DataMember(Order = 1)]
65191
public string PrimaryServerId { get; set; }
66192

193+
/// <summary>
194+
/// Gets or sets Primary Network Id.
195+
/// </summary>
67196
[DataMember(Order = 2)]
68197
public string PrimaryNetworkId { get; set; }
69198

199+
/// <summary>
200+
/// Gets or sets Azure VM Network Id.
201+
/// </summary>
70202
[DataMember(Order = 3)]
71203
public string AzureVMNetworkId { get; set; }
72204

205+
/// <summary>
206+
/// Gets or sets Azure VM Network name.
207+
/// </summary>
73208
[DataMember(Order = 4)]
74209
public string AzureVMNetworkName { get; set; }
75210
}
76211

77212
/// <summary>
78213
/// Recovery services convenience client.
79214
/// </summary>
215+
[SuppressMessage(
216+
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
217+
"SA1402:FileMayOnlyContainASingleClass",
218+
Justification = "Keeping all contracts together.")]
80219
public partial class PSRecoveryServicesClient
81220
{
82221
/// <summary>
@@ -154,6 +293,10 @@ public JobResponse NewAzureSiteRecoveryAzureNetworkMapping(
154293
.Create(networkMappingInput, this.GetRequestHeaders());
155294
}
156295

296+
/// <summary>
297+
/// Validates whether the subscription belongs to the currently logged account or not.
298+
/// </summary>
299+
/// <param name="azureSubscriptionId">Azure Subscription ID</param>
157300
public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
158301
{
159302
bool associatedSubscription = false;
@@ -179,6 +322,11 @@ public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
179322
}
180323
}
181324

325+
/// <summary>
326+
/// Validates whether the Azure VM Network is associated with the subscription or not.
327+
/// </summary>
328+
/// <param name="subscriptionId">Subscription Id</param>
329+
/// <param name="azureNetworkId">Azure Network Id</param>
182330
public void ValidateVMNetworkSubscriptionAssociation(string subscriptionId, string azureNetworkId)
183331
{
184332
/*
@@ -188,6 +336,7 @@ public void ValidateVMNetworkSubscriptionAssociation(string subscriptionId, stri
188336
var sites = response.VirtualNetworkSites;
189337
*/
190338
}
339+
191340
/// <summary>
192341
/// Delete Azure Site Recovery Network Mapping.
193342
/// </summary>
@@ -210,86 +359,4 @@ public JobResponse RemoveAzureSiteRecoveryNetworkMapping(
210359
.Delete(networkUnMappingInput, this.GetRequestHeaders());
211360
}
212361
}
213-
214-
/// <summary>
215-
/// Helper around serialization/deserialization of objects. This one is a thin wrapper around
216-
/// DataContractUtils<T> which is the one doing the heavy lifting.
217-
/// </summary>
218-
public static class DataContractUtils
219-
{
220-
/// <summary>
221-
/// Serializes the supplied object to the string.
222-
/// </summary>
223-
/// <typeparam name="T">The object type.</typeparam>
224-
/// <param name="The object to serialize."></param>
225-
/// <returns>Serialized string.</returns>
226-
public static string Serialize<T>(T obj)
227-
{
228-
return DataContractUtils<T>.Serialize(obj);
229-
}
230-
231-
/// <summary>
232-
/// Deserialize the string to the expected object type.
233-
/// </summary>
234-
/// <param name="xmlString">Serialized string.</param>
235-
/// <param name="result">Deserialized object.</param>
236-
public static void Deserialize<T>(string xmlString, out T result)
237-
{
238-
result = DataContractUtils<T>.Deserialize(xmlString);
239-
}
240-
}
241-
242-
public static class DataContractUtils<T>
243-
{
244-
/// <summary>
245-
/// Serializes the propertyBagContainer to the string.
246-
/// </summary>
247-
/// <param name="propertyBagContainer"></param>
248-
/// <returns></returns>
249-
public static string Serialize(T propertyBagContainer)
250-
{
251-
var serializer = new DataContractSerializer(typeof(T));
252-
string xmlString;
253-
StringWriter sw = null;
254-
try
255-
{
256-
sw = new StringWriter();
257-
using (var writer = new XmlTextWriter(sw))
258-
{
259-
// Indent the XML so it's human readable.
260-
writer.Formatting = Formatting.Indented;
261-
serializer.WriteObject(writer, propertyBagContainer);
262-
writer.Flush();
263-
xmlString = sw.ToString();
264-
}
265-
}
266-
finally
267-
{
268-
if (sw != null)
269-
sw.Close();
270-
}
271-
272-
return xmlString;
273-
}
274-
275-
/// <summary>
276-
/// Deserialize the string to the propertyBagContainer.
277-
/// </summary>
278-
/// <param name="xmlString"></param>
279-
/// <returns></returns>
280-
public static T Deserialize(string xmlString)
281-
{
282-
T propertyBagContainer;
283-
using (Stream stream = new MemoryStream())
284-
{
285-
byte[] data = System.Text.Encoding.UTF8.GetBytes(xmlString);
286-
stream.Write(data, 0, data.Length);
287-
stream.Position = 0;
288-
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
289-
propertyBagContainer = (T)deserializer.ReadObject(stream);
290-
}
291-
292-
return propertyBagContainer;
293-
}
294-
}
295362
}

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/CreateAzureSiteRecoveryRecoveryPlan.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
using System.Threading;
1919
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
2020
using Microsoft.WindowsAzure;
21-
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2221
using Microsoft.WindowsAzure.Commands.Utilities.Common;
22+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
2323

2424
namespace Microsoft.Azure.Commands.RecoveryServices
2525
{
@@ -41,7 +41,7 @@ public class CreateAzureSiteRecoveryRecoveryPlan : RecoveryServicesCmdletBase
4141
/// </summary>
4242
[Parameter(Mandatory = true)]
4343
[ValidateNotNullOrEmpty]
44-
public string File {get; set;}
44+
public string File { get; set; }
4545

4646
/// <summary>
4747
/// Gets or sets switch parameter. This is required to wait for job completion.

0 commit comments

Comments
 (0)