13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using System ;
16
+ using System . Collections . Generic ;
17
+ using System . Diagnostics . CodeAnalysis ;
16
18
using System . IO ;
17
19
using System . Runtime . Serialization ;
18
20
using System . Xml ;
19
21
using Microsoft . WindowsAzure ;
22
+ using Microsoft . WindowsAzure . Commands . Common ;
23
+ using Microsoft . WindowsAzure . Commands . Common . Models ;
20
24
using Microsoft . WindowsAzure . Management . SiteRecovery ;
21
- // using Microsoft.WindowsAzure.Management.
22
25
using Microsoft . WindowsAzure . Management . SiteRecovery . Models ;
23
- using Microsoft . WindowsAzure . Commands . Common . Models ;
24
- using Microsoft . WindowsAzure . Commands . Common ;
25
- using System . Collections . Generic ;
26
26
27
27
namespace Microsoft . Azure . Commands . RecoveryServices
28
28
{
@@ -32,51 +32,190 @@ namespace Microsoft.Azure.Commands.RecoveryServices
32
32
public enum TargetNetworkType
33
33
{
34
34
/// <summary>
35
- /// Server.
35
+ /// Target type of the network is Server.
36
36
/// </summary>
37
37
Server = 0 ,
38
38
39
39
/// <summary>
40
- /// Azure.
40
+ /// Target type of the network is Azure.
41
41
/// </summary>
42
42
Azure ,
43
43
}
44
44
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." ) ]
45
149
[ DataContract ( Namespace = "http://schemas.microsoft.com/windowsazure" ) ]
46
150
public class CreateNetworkMappingInput
47
151
{
152
+ /// <summary>
153
+ /// Gets or sets Primary Server Id.
154
+ /// </summary>
48
155
[ DataMember ( Order = 1 ) ]
49
156
public string PrimaryServerId { get ; set ; }
50
157
158
+ /// <summary>
159
+ /// Gets or sets Primary Network Id.
160
+ /// </summary>
51
161
[ DataMember ( Order = 2 ) ]
52
162
public string PrimaryNetworkId { get ; set ; }
53
163
164
+ /// <summary>
165
+ /// Gets or sets Recovery Server Id.
166
+ /// </summary>
54
167
[ DataMember ( Order = 3 ) ]
55
168
public string RecoveryServerId { get ; set ; }
56
169
170
+ /// <summary>
171
+ /// Gets or sets Recovery Network Id.
172
+ /// </summary>
57
173
[ DataMember ( Order = 4 ) ]
58
174
public string RecoveryNetworkId { get ; set ; }
59
175
}
60
176
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." ) ]
61
184
[ DataContract ( Namespace = "http://schemas.microsoft.com/windowsazure" ) ]
62
185
public class CreateAzureNetworkMappingInput
63
186
{
187
+ /// <summary>
188
+ /// Gets or sets Primary Server Id.
189
+ /// </summary>
64
190
[ DataMember ( Order = 1 ) ]
65
191
public string PrimaryServerId { get ; set ; }
66
192
193
+ /// <summary>
194
+ /// Gets or sets Primary Network Id.
195
+ /// </summary>
67
196
[ DataMember ( Order = 2 ) ]
68
197
public string PrimaryNetworkId { get ; set ; }
69
198
199
+ /// <summary>
200
+ /// Gets or sets Azure VM Network Id.
201
+ /// </summary>
70
202
[ DataMember ( Order = 3 ) ]
71
203
public string AzureVMNetworkId { get ; set ; }
72
204
205
+ /// <summary>
206
+ /// Gets or sets Azure VM Network name.
207
+ /// </summary>
73
208
[ DataMember ( Order = 4 ) ]
74
209
public string AzureVMNetworkName { get ; set ; }
75
210
}
76
211
77
212
/// <summary>
78
213
/// Recovery services convenience client.
79
214
/// </summary>
215
+ [ SuppressMessage (
216
+ "Microsoft.StyleCop.CSharp.MaintainabilityRules" ,
217
+ "SA1402:FileMayOnlyContainASingleClass" ,
218
+ Justification = "Keeping all contracts together." ) ]
80
219
public partial class PSRecoveryServicesClient
81
220
{
82
221
/// <summary>
@@ -154,6 +293,10 @@ public JobResponse NewAzureSiteRecoveryAzureNetworkMapping(
154
293
. Create ( networkMappingInput , this . GetRequestHeaders ( ) ) ;
155
294
}
156
295
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>
157
300
public void ValidateSubscriptionAccountAssociation ( string azureSubscriptionId )
158
301
{
159
302
bool associatedSubscription = false ;
@@ -179,6 +322,11 @@ public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
179
322
}
180
323
}
181
324
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>
182
330
public void ValidateVMNetworkSubscriptionAssociation ( string subscriptionId , string azureNetworkId )
183
331
{
184
332
/*
@@ -188,6 +336,7 @@ public void ValidateVMNetworkSubscriptionAssociation(string subscriptionId, stri
188
336
var sites = response.VirtualNetworkSites;
189
337
*/
190
338
}
339
+
191
340
/// <summary>
192
341
/// Delete Azure Site Recovery Network Mapping.
193
342
/// </summary>
@@ -210,86 +359,4 @@ public JobResponse RemoveAzureSiteRecoveryNetworkMapping(
210
359
. Delete ( networkUnMappingInput , this . GetRequestHeaders ( ) ) ;
211
360
}
212
361
}
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
- }
295
362
}
0 commit comments