Skip to content

Commit

Permalink
Merge pull request #3 from AsrOneSdk/sriramvu-dev
Browse files Browse the repository at this point in the history
Enabled StyleCop and fixed related errors
  • Loading branch information
sriramvu committed Dec 29, 2014
2 parents 1c98d6c + 526a44a commit f0dde96
Show file tree
Hide file tree
Showing 35 changed files with 372 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<StyleCopOverrideSettingsFile>Settings.StyleCop</StyleCopOverrideSettingsFile>
<BuildToolsStyleCopVersion>4.7.44.0</BuildToolsStyleCopVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -28,10 +30,12 @@
<CodeAnalysisIgnoreGeneratedCode>true</CodeAnalysisIgnoreGeneratedCode>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<StyleCopEnabled>True</StyleCopEnabled>
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>..\..\..\Package\Release\ServiceManagement\Azure\RecoveryServices</OutputPath>
<DefineConstants>TRACE;SIGN</DefineConstants>
<DefineConstants>TRACE;SIGN;CODE_ANALYSIS</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -189,6 +193,10 @@
<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" />
<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" />
</Target>
<Import Project="..\..\..\packages\BuildTools.StyleCop.4.7.49.0\tools\StyleCop.targets" Condition="Exists('..\..\..\packages\BuildTools.StyleCop.4.7.49.0\tools\StyleCop.targets')" />
<Target Name="_________packages_BuildTools_StyleCop_4_7_49_0_tools_StyleCop_targets" Condition="$(StyleCopOutputFile)==''" BeforeTargets="BeforeBuild">
<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" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Common.Models;
using Microsoft.WindowsAzure.Management.SiteRecovery;
// using Microsoft.WindowsAzure.Management.
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
using Microsoft.WindowsAzure.Commands.Common.Models;
using Microsoft.WindowsAzure.Commands.Common;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.RecoveryServices
{
Expand All @@ -32,51 +32,190 @@ namespace Microsoft.Azure.Commands.RecoveryServices
public enum TargetNetworkType
{
/// <summary>
/// Server.
/// Target type of the network is Server.
/// </summary>
Server = 0,

/// <summary>
/// Azure.
/// Target type of the network is Azure.
/// </summary>
Azure,
}

/// <summary>
/// Helper around serialization/deserialization of objects. This one is a thin wrapper around
/// DataContractUtils template class which is the one doing the heavy lifting.
/// </summary>
[SuppressMessage(
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
"SA1402:FileMayOnlyContainASingleClass",
Justification = "Keeping all contracts together.")]
public static class DataContractUtils
{
/// <summary>
/// Serializes the supplied object to the string.
/// </summary>
/// <typeparam name="T">The object type.</typeparam>
/// <param name="obj">Object to serialize</param>
/// <returns>Serialized string.</returns>
public static string Serialize<T>(T obj)
{
return DataContractUtils<T>.Serialize(obj);
}

/// <summary>
/// Deserialize the string to the expected object type.
/// </summary>
/// <typeparam name="T">The object type</typeparam>
/// <param name="xmlString">Serialized string</param>
/// <param name="result">Deserialized object</param>
public static void Deserialize<T>(string xmlString, out T result)
{
result = DataContractUtils<T>.Deserialize(xmlString);
}
}

/// <summary>
/// Template class for DataContractUtils.
/// </summary>
/// <typeparam name="T">The object type</typeparam>
[SuppressMessage(
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
"SA1402:FileMayOnlyContainASingleClass",
Justification = "Keeping all contracts together.")]
public static class DataContractUtils<T>
{
/// <summary>
/// Serializes the propertyBagContainer to the string.
/// </summary>
/// <param name="propertyBagContainer">Property bag</param>
/// <returns>Serialized string </returns>
public static string Serialize(T propertyBagContainer)
{
var serializer = new DataContractSerializer(typeof(T));
string xmlString;
StringWriter sw = null;
try
{
sw = new StringWriter();
using (var writer = new XmlTextWriter(sw))
{
// Indent the XML so it's human readable.
writer.Formatting = Formatting.Indented;
serializer.WriteObject(writer, propertyBagContainer);
writer.Flush();
xmlString = sw.ToString();
}
}
finally
{
if (sw != null)
{
sw.Close();
}
}

return xmlString;
}

/// <summary>
/// Deserialize the string to the propertyBagContainer.
/// </summary>
/// <param name="xmlString">Serialized string</param>
/// <returns>Deserialized object</returns>
public static T Deserialize(string xmlString)
{
T propertyBagContainer;
using (Stream stream = new MemoryStream())
{
byte[] data = System.Text.Encoding.UTF8.GetBytes(xmlString);
stream.Write(data, 0, data.Length);
stream.Position = 0;
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
propertyBagContainer = (T)deserializer.ReadObject(stream);
}

return propertyBagContainer;
}
}

/// <summary>
/// Create network mapping input.
/// </summary>
[SuppressMessage(
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
"SA1402:FileMayOnlyContainASingleClass",
Justification = "Keeping all contracts together.")]
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
public class CreateNetworkMappingInput
{
/// <summary>
/// Gets or sets Primary Server Id.
/// </summary>
[DataMember(Order = 1)]
public string PrimaryServerId { get; set; }

/// <summary>
/// Gets or sets Primary Network Id.
/// </summary>
[DataMember(Order = 2)]
public string PrimaryNetworkId { get; set; }

/// <summary>
/// Gets or sets Recovery Server Id.
/// </summary>
[DataMember(Order = 3)]
public string RecoveryServerId { get; set; }

/// <summary>
/// Gets or sets Recovery Network Id.
/// </summary>
[DataMember(Order = 4)]
public string RecoveryNetworkId { get; set; }
}

/// <summary>
/// Create Azure network mapping input.
/// </summary>
[SuppressMessage(
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
"SA1402:FileMayOnlyContainASingleClass",
Justification = "Keeping all contracts together.")]
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
public class CreateAzureNetworkMappingInput
{
/// <summary>
/// Gets or sets Primary Server Id.
/// </summary>
[DataMember(Order = 1)]
public string PrimaryServerId { get; set; }

/// <summary>
/// Gets or sets Primary Network Id.
/// </summary>
[DataMember(Order = 2)]
public string PrimaryNetworkId { get; set; }

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

/// <summary>
/// Gets or sets Azure VM Network name.
/// </summary>
[DataMember(Order = 4)]
public string AzureVMNetworkName { get; set; }
}

/// <summary>
/// Recovery services convenience client.
/// </summary>
[SuppressMessage(
"Microsoft.StyleCop.CSharp.MaintainabilityRules",
"SA1402:FileMayOnlyContainASingleClass",
Justification = "Keeping all contracts together.")]
public partial class PSRecoveryServicesClient
{
/// <summary>
Expand Down Expand Up @@ -154,6 +293,10 @@ public JobResponse NewAzureSiteRecoveryAzureNetworkMapping(
.Create(networkMappingInput, this.GetRequestHeaders());
}

/// <summary>
/// Validates whether the subscription belongs to the currently logged account or not.
/// </summary>
/// <param name="azureSubscriptionId">Azure Subscription ID</param>
public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
{
bool associatedSubscription = false;
Expand All @@ -179,6 +322,11 @@ public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
}
}

/// <summary>
/// Validates whether the Azure VM Network is associated with the subscription or not.
/// </summary>
/// <param name="subscriptionId">Subscription Id</param>
/// <param name="azureNetworkId">Azure Network Id</param>
public void ValidateVMNetworkSubscriptionAssociation(string subscriptionId, string azureNetworkId)
{
/*
Expand All @@ -188,6 +336,7 @@ public void ValidateVMNetworkSubscriptionAssociation(string subscriptionId, stri
var sites = response.VirtualNetworkSites;
*/
}

/// <summary>
/// Delete Azure Site Recovery Network Mapping.
/// </summary>
Expand All @@ -210,86 +359,4 @@ public JobResponse RemoveAzureSiteRecoveryNetworkMapping(
.Delete(networkUnMappingInput, this.GetRequestHeaders());
}
}

/// <summary>
/// Helper around serialization/deserialization of objects. This one is a thin wrapper around
/// DataContractUtils<T> which is the one doing the heavy lifting.
/// </summary>
public static class DataContractUtils
{
/// <summary>
/// Serializes the supplied object to the string.
/// </summary>
/// <typeparam name="T">The object type.</typeparam>
/// <param name="The object to serialize."></param>
/// <returns>Serialized string.</returns>
public static string Serialize<T>(T obj)
{
return DataContractUtils<T>.Serialize(obj);
}

/// <summary>
/// Deserialize the string to the expected object type.
/// </summary>
/// <param name="xmlString">Serialized string.</param>
/// <param name="result">Deserialized object.</param>
public static void Deserialize<T>(string xmlString, out T result)
{
result = DataContractUtils<T>.Deserialize(xmlString);
}
}

public static class DataContractUtils<T>
{
/// <summary>
/// Serializes the propertyBagContainer to the string.
/// </summary>
/// <param name="propertyBagContainer"></param>
/// <returns></returns>
public static string Serialize(T propertyBagContainer)
{
var serializer = new DataContractSerializer(typeof(T));
string xmlString;
StringWriter sw = null;
try
{
sw = new StringWriter();
using (var writer = new XmlTextWriter(sw))
{
// Indent the XML so it's human readable.
writer.Formatting = Formatting.Indented;
serializer.WriteObject(writer, propertyBagContainer);
writer.Flush();
xmlString = sw.ToString();
}
}
finally
{
if (sw != null)
sw.Close();
}

return xmlString;
}

/// <summary>
/// Deserialize the string to the propertyBagContainer.
/// </summary>
/// <param name="xmlString"></param>
/// <returns></returns>
public static T Deserialize(string xmlString)
{
T propertyBagContainer;
using (Stream stream = new MemoryStream())
{
byte[] data = System.Text.Encoding.UTF8.GetBytes(xmlString);
stream.Write(data, 0, data.Length);
stream.Position = 0;
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
propertyBagContainer = (T)deserializer.ReadObject(stream);
}

return propertyBagContainer;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
using System.Threading;
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;

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

/// <summary>
/// Gets or sets switch parameter. This is required to wait for job completion.
Expand Down
Loading

0 comments on commit f0dde96

Please sign in to comment.