/// <summary> /// Gets network configuration from MS azure using management API call. /// Changed in v2.0 /// </summary> /// <param name="credentials">Source subscription credentials</param> /// <param name="serviceUrl">Subscription service Url</param> /// <returns>Network configuration for subscription</returns> private NetworkGetConfigurationResponse GetNetworkConfigurationFromMSAzure(SubscriptionCloudCredentials credentials, Uri serviceUrl) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureStarted, ResourceType.VirtualNetwork.ToString()); dcMigration.ReportProgress(ProgressResources.GetVirtualNetworkConfigFromMSAzureStarted); NetworkGetConfigurationResponse ventConfig = null; using (var vnetClient = new NetworkManagementClient(credentials, serviceUrl)) { try { ventConfig = vnetClient.Networks.GetConfiguration(); Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureCompleted, ResourceType.VirtualNetwork.ToString()); return(ventConfig); } catch (CloudException cex) { if (ventConfig == null) { return(ventConfig); } if (string.Compare(cex.Error.ToString(), Constants.ResourceNotFound, StringComparison.CurrentCultureIgnoreCase) == 0) { return(null); } else { Logger.Error(methodName, cex, ResourceType.VirtualNetwork.ToString()); throw; } } } }
/// <summary> /// Gets network configuration from MS azure using management API call. /// </summary> /// <param name="credentials">Subscription Cloud Credentials</param> /// <param name="serviceUrl">service url of subscription</param> /// <returns>Network configuration for subscription</returns> private NetworkGetConfigurationResponse GetNetworkConfigurationFromMSAzure(SubscriptionCloudCredentials credentials, Uri serviceUrl) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; Logger.Info(methodName, ProgressResources.ExecutionStarted, ResourceType.VirtualNetwork.ToString()); Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureStarted); using (var vnetClient = new NetworkManagementClient(credentials, serviceUrl)) { try { NetworkGetConfigurationResponse ventConfig = vnetClient.Networks.GetConfiguration(); Logger.Info(methodName, ProgressResources.GetVirtualNetworkConfigFromMSAzureCompleted, ResourceType.VirtualNetwork.ToString()); Logger.Info(methodName, ProgressResources.ExecutionCompleted, ResourceType.VirtualNetwork.ToString()); return(ventConfig); } catch (CloudException cex) { if (cex.ErrorCode == Constants.ResourceNotFound) { return(null); } else { Logger.Error(methodName, cex); throw cex; } } } }
internal async Task AddVirtualNetworkSiteAsync() { if (_virtualNetworkManagementClient != null && _managementClient != null) { try { // Get the existing netwirking configuration if (_networkConfig == null) { _networkConfig = await _virtualNetworkManagementClient.Networks.GetConfigurationAsync(); } // create affinity group await CreateAffinityGroupAsync(); // use the new affinity group for the virtual network string newVirtualNetworkElement = string.Format(_parameters.VirtualNetworkSite, _parameters.AffinityGroupName); // add the new virtual network element to the existing network configuration under VirtualNetworkSites string newNetworkConfig = AddXmlElement(_networkConfig.Configuration, "VirtualNetworkSites", newVirtualNetworkElement); await _virtualNetworkManagementClient.Networks.SetConfigurationAsync( new NetworkSetConfigurationParameters() { Configuration = newNetworkConfig }); } catch (Exception e) { Console.WriteLine("\n Error: \n {0}", e.ToString()); } } }
internal async Task GetVirtualNetworkConfigurationAsync() { if (_virtualNetworkManagementClient != null) { _networkConfig = await _virtualNetworkManagementClient.Networks.GetConfigurationAsync(); Console.Write(_networkConfig.Configuration); } }
internal void GetVirtualNetworkConfiguration() { if (_virtualNetworkManagementClient != null) { _networkConfig = _virtualNetworkManagementClient.Networks.GetConfiguration(); Console.Write(_networkConfig.Configuration); } }
public void SetWideVNetConfiguration() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { networkTestClient.Gateways.EnsureNoGatewayExists(); OperationStatusResponse response = networkTestClient.SetNetworkConfiguration(NetworkTestConstants.WideVNetNetworkConfigurationParameters); Assert.NotNull(response); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); NetworkGetConfigurationResponse getConfigurationResponse = networkTestClient.GetNetworkConfiguration(); Assert.NotNull(getConfigurationResponse); string responseConfiguration = getConfigurationResponse.Configuration; Assert.NotNull(responseConfiguration); Assert.NotEmpty(responseConfiguration); Assert.True(responseConfiguration.Contains(NetworkTestConstants.VirtualNetworkSiteName)); Assert.True(responseConfiguration.Contains(NetworkTestConstants.WideVNetLocation)); Assert.True(responseConfiguration.Contains(NetworkTestConstants.WideVNetSubnetName)); } }
public void SetSiteToSiteConfiguration() { using (NetworkTestClient networkTestClient = new NetworkTestClient()) { networkTestClient.Gateways.EnsureNoGatewayExists(); OperationStatusResponse response = networkTestClient.SetNetworkConfiguration(NetworkTestConstants.SiteToSiteNetworkConfigurationParameters); Assert.NotNull(response); Assert.Equal(HttpStatusCode.OK, response.HttpStatusCode); NetworkGetConfigurationResponse getConfigurationResponse = networkTestClient.GetNetworkConfiguration(); Assert.NotNull(getConfigurationResponse); string responseConfiguration = getConfigurationResponse.Configuration; Assert.NotNull(responseConfiguration); Assert.NotEmpty(responseConfiguration); Assert.True(responseConfiguration.Contains("localNetworkSiteName")); Assert.True(responseConfiguration.Contains("virtualNetworkSiteName")); Assert.True(responseConfiguration.Contains("affinityGroupName")); Assert.True(responseConfiguration.Contains("192.168.0.0/24")); } }
/// <summary> /// The Get Network Configuration operation retrieves the network /// configuration file for the given subscription. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx /// for more information) /// </summary> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The Get Network Configuration operation response. /// </returns> public async Task <NetworkGetConfigurationResponse> GetConfigurationAsync(CancellationToken cancellationToken) { // Validate // Tracing bool shouldTrace = CloudContext.Configuration.Tracing.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = Tracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); Tracing.Enter(invocationId, this, "GetConfigurationAsync", tracingParameters); } // Construct URL string url = new Uri(this.Client.BaseUri, "/").ToString() + this.Client.Credentials.SubscriptionId + "/services/networking/media"; // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2013-11-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { Tracing.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { Tracing.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false), CloudExceptionType.Xml); if (shouldTrace) { Tracing.Error(invocationId, ex); } throw ex; } // Create Result NetworkGetConfigurationResponse result = null; // Deserialize Response cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new NetworkGetConfigurationResponse(); result.Configuration = responseContent; result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { Tracing.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// The Get Network Configuration operation retrieves the network /// configuration file for the given subscription. (see /// http://msdn.microsoft.com/en-us/library/windowsazure/jj157196.aspx /// for more information) /// </summary> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// The Get Network Configuration operation response. /// </returns> public async Task <NetworkGetConfigurationResponse> GetConfigurationAsync(CancellationToken cancellationToken) { // Validate // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); TracingAdapter.Enter(invocationId, this, "GetConfigurationAsync", tracingParameters); } // Construct URL string url = ""; url = url + "/"; if (this.Client.Credentials.SubscriptionId != null) { url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId); } url = url + "/services/networking/media"; string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2015-02-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result NetworkGetConfigurationResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new NetworkGetConfigurationResponse(); result.Configuration = responseContent; } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
/// <summary> /// Exports Subscription metadata. /// </summary> /// <returns>Subscription details/></returns> internal Subscription ExportSubscriptionMetadata() { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; Logger.Info(methodName, ProgressResources.ExecutionStarted); Subscription subscription = new Subscription() { Name = exportParameters.SourceSubscriptionSettings.Name }; Logger.Info(methodName, string.Format(ProgressResources.ExportDataCenterStarted, exportParameters.SourceDCName), ResourceType.DataCenter.ToString(), exportParameters.SourceDCName); dcMigration.ReportProgress(string.Format(ProgressResources.ExportDataCenterStarted, exportParameters.SourceDCName)); AffinityGroupListResponse affinityGroupResponse = GetAffinityGroupListResponseFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials); HostedServiceListResponse cloudserviceResponse = GetCloudServiceListResponseFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials, exportParameters.SourceSubscriptionSettings.ServiceUrl); NetworkGetConfigurationResponse networkResponse = GetNetworkConfigurationFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials, exportParameters.SourceSubscriptionSettings.ServiceUrl); StorageAccountListResponse storageAccountResponse = GetStorageAccountListResponseFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials); // Create an instance of data center. var dataCenter = new DataCenter { LocationName = exportParameters.SourceDCName, }; // Get all affinity groups. Logger.Info(methodName, ProgressResources.ExportAffinityGroupStarted, ResourceType.AffinityGroup.ToString()); dcMigration.ReportProgress(ProgressResources.ExportAffinityGroupStarted); var affinityGroups = ExportAffinityGroups(affinityGroupResponse); dataCenter.AffinityGroups.AddRange(affinityGroups.ToList()); int stageCount = 1; Logger.Info(methodName, string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages)); dcMigration.ReportProgress(string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages)); List <string> affinityGroupNamesInDC = affinityGroups.Select(ag => ag.AffinityGroupDetails.Name).ToList(); Logger.Info(methodName, ProgressResources.ExportVNetConfigurationStarted, ResourceType.VirtualNetwork.ToString()); dcMigration.ReportProgress(ProgressResources.ExportVNetConfigurationStarted); // Filter and Export network configuration file. dataCenter.NetworkConfiguration = ExportVNetConfiguration(networkResponse, affinityGroupNamesInDC); Logger.Info(methodName, string.Format(ProgressResources.CompletedStages, ++stageCount, Constants.ExportTotalStages)); dcMigration.ReportProgress(string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages)); Logger.Info(methodName, ProgressResources.ExportCloudServicesStarted, ResourceType.CloudService.ToString()); dcMigration.ReportProgress(ProgressResources.ExportCloudServicesStarted); // Get cloud services for affinityGroupNamesInDC or for SourceDCName dataCenter.CloudServices.AddRange(ExportCloudServices(affinityGroupNamesInDC, cloudserviceResponse)); Logger.Info(methodName, string.Format(ProgressResources.CompletedStages, ++stageCount, Constants.ExportTotalStages)); dcMigration.ReportProgress(string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages)); Logger.Info(methodName, ProgressResources.ExportStorageAccountStarted, ResourceType.StorageAccount.ToString()); dcMigration.ReportProgress(ProgressResources.ExportStorageAccountStarted); // Get list of storage accounts dataCenter.StorageAccounts.AddRange(ExportStorageAccounts(affinityGroupNamesInDC, storageAccountResponse)); Logger.Info(methodName, string.Format(ProgressResources.CompletedStages, ++stageCount, Constants.ExportTotalStages)); dcMigration.ReportProgress(string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages)); // Add the data center into subscription. subscription.DataCenters.Add(dataCenter); Logger.Info(methodName, string.Format(ProgressResources.ExportDataCenterCompleted, dataCenter.LocationName), ResourceType.DataCenter.ToString()); Logger.Info(methodName, ProgressResources.ExecutionCompleted); return(subscription); }
/// <summary> /// Exports Vnetconfig data from Source Subscription. Serializes the exported configurations into NetworkConfiguration class /// </summary> /// <param name="configuration">The network configuration for subscription</param> /// <param name="affinityGroupNames">List of affinity group</param> /// <returns>Network configurations </returns> private NetworkConfiguration ExportVNetConfiguration(NetworkGetConfigurationResponse configuration, List <string> affinityGroupNames) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; Logger.Info(methodName, ProgressResources.ExportVNetConfigurationStarted, ResourceType.VirtualNetwork.ToString()); try { if (configuration == null) { return(null); } var reader = new StringReader(configuration.Configuration); var serializer = new XmlSerializer(typeof(NetworkConfiguration)); NetworkConfiguration netConfiguration = (NetworkConfiguration)serializer.Deserialize(reader); ////Check condition for any virtual network is available or not ////Issue Work item:3865 if (netConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites == null) { return(null); } if (netConfiguration.VirtualNetworkConfiguration != null && netConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites != null) { // Filter the virtaul networks - Find the networks for which we have considered affinity groups var requiredVirtualNetworkSites = (netConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites. Where(vn => affinityGroupNames.Contains(vn.AffinityGroup) || string.Compare(vn.Location, exportParameters.SourceDCName, StringComparison.CurrentCultureIgnoreCase) == 0)).ToArray(); List <string> dnsNames = new List <string>(); List <string> localNetNames = new List <string>(); foreach (var vns in requiredVirtualNetworkSites) { if (vns.DnsServersRef != null) { dnsNames.AddRange(vns.DnsServersRef.Select(dns => dns.name).ToList()); } if (vns.Gateway != null && vns.Gateway.ConnectionsToLocalNetwork != null && vns.Gateway.ConnectionsToLocalNetwork.LocalNetworkSiteRef != null) { localNetNames.Add(vns.Gateway.ConnectionsToLocalNetwork.LocalNetworkSiteRef.name); } } if (netConfiguration.VirtualNetworkConfiguration.Dns != null && netConfiguration.VirtualNetworkConfiguration.Dns.DnsServers != null) { ////Remove DnsServers which are not related to required virtual networks netConfiguration.VirtualNetworkConfiguration.Dns.DnsServers = netConfiguration.VirtualNetworkConfiguration.Dns.DnsServers.Where(dns => dnsNames.Distinct().Contains(dns.name)).ToArray(); } if (netConfiguration.VirtualNetworkConfiguration.LocalNetworkSites != null) { ////Remove LocalNetworks which are not related to required virtual networks netConfiguration.VirtualNetworkConfiguration.LocalNetworkSites = netConfiguration.VirtualNetworkConfiguration.LocalNetworkSites.Where(lns => localNetNames.Distinct().Contains(lns.name)).ToArray(); } ////Set VirtualNetworkSites netConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites = requiredVirtualNetworkSites; Logger.Info(methodName, ProgressResources.ExportVNetConfigurationCompleted, ResourceType.VirtualNetwork.ToString()); } return(netConfiguration); } catch (Exception ex) { Logger.Error(methodName, ex, ResourceType.VirtualNetwork.ToString()); throw; } }
/// <summary> /// Rollback all virtual networks /// </summary> /// <param name="networkConfiguration">Network configuration</param> private void RollBackVirtualNetworks(NetworkConfiguration networkConfiguration) { Stopwatch swVirtualNetwork = new Stopwatch(); swVirtualNetwork.Start(); string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; Logger.Info(methodName, ProgressResources.ExecutionStarted, ResourceType.NetworkConfiguration.ToString()); // Get destination subscription network configuration NetworkGetConfigurationResponse destinationNetworkResponse = GetNetworkConfigurationFromMSAzure( importParameters.DestinationSubscriptionSettings.Credentials, importParameters.DestinationSubscriptionSettings.ServiceUrl); NetworkConfiguration destinationNetConfiguration = null; XmlSerializer serializer = new XmlSerializer(typeof(NetworkConfiguration)); if (destinationNetworkResponse != null && !(string.IsNullOrEmpty(destinationNetworkResponse.Configuration))) { var destinationReader = new StringReader(destinationNetworkResponse.Configuration); destinationNetConfiguration = (NetworkConfiguration)serializer.Deserialize(destinationReader); } try { if (networkConfiguration != null) { if (networkConfiguration.VirtualNetworkConfiguration != null) { if (networkConfiguration.VirtualNetworkConfiguration.Dns != null && networkConfiguration.VirtualNetworkConfiguration.Dns.DnsServers != null && destinationNetConfiguration != null && destinationNetConfiguration.VirtualNetworkConfiguration != null && destinationNetConfiguration.VirtualNetworkConfiguration.Dns != null && destinationNetConfiguration.VirtualNetworkConfiguration.Dns.DnsServers != null) { foreach (var virtualNetworkSite in networkConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites) { foreach (var dns in networkConfiguration.VirtualNetworkConfiguration.Dns.DnsServers) { string dnsDestination = resourceImporter.GetDestinationResourceName(ResourceType.DnsServer, dns.name, ResourceType.VirtualNetworkSite, resourceImporter.GetDestinationResourceName(ResourceType.VirtualNetworkSite, virtualNetworkSite.name)); if (!string.IsNullOrEmpty(dnsDestination)) { destinationNetConfiguration.VirtualNetworkConfiguration.Dns.DnsServers = destinationNetConfiguration.VirtualNetworkConfiguration.Dns.DnsServers.Where(s => s.name != dnsDestination).ToArray(); } } } } if (networkConfiguration.VirtualNetworkConfiguration.LocalNetworkSites != null && destinationNetConfiguration != null && destinationNetConfiguration.VirtualNetworkConfiguration != null && destinationNetConfiguration.VirtualNetworkConfiguration.LocalNetworkSites != null) { foreach (var virtualNetworkSite in networkConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites) { foreach (var localNetwork in networkConfiguration.VirtualNetworkConfiguration.LocalNetworkSites) { string localNetworkDestination = resourceImporter.GetDestinationResourceName(ResourceType.LocalNetworkSite, localNetwork.name, ResourceType.VirtualNetworkSite, resourceImporter.GetDestinationResourceName(ResourceType.VirtualNetworkSite, virtualNetworkSite.name)); if (!string.IsNullOrEmpty(localNetworkDestination)) { destinationNetConfiguration.VirtualNetworkConfiguration.LocalNetworkSites = destinationNetConfiguration.VirtualNetworkConfiguration.LocalNetworkSites.Where(s => s.name != localNetworkDestination).ToArray(); } } } } if (networkConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites != null && destinationNetConfiguration != null && destinationNetConfiguration.VirtualNetworkConfiguration != null && destinationNetConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites != null) { destinationNetConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites = destinationNetConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites. Where(x => !networkConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites. Any(x1 => resourceImporter.GetDestinationResourceName(ResourceType.VirtualNetworkSite, x1.name) == x.name)).ToArray(); } } } MemoryStream memoryStream = new MemoryStream(); XmlWriter writer = XmlWriter.Create(memoryStream, new XmlWriterSettings { Encoding = Encoding.UTF8 }); serializer.Serialize(writer, destinationNetConfiguration); using (var vnetClient = new NetworkManagementClient(importParameters.DestinationSubscriptionSettings.Credentials, importParameters.DestinationSubscriptionSettings.ServiceUrl)) { OperationStatusResponse response = Retry.RetryOperation(() => vnetClient.Networks.SetConfiguration( new NetworkSetConfigurationParameters { Configuration = Encoding.UTF8.GetString(memoryStream.ToArray()) }), (BaseParameters)importParameters, ResourceType.NetworkConfiguration); } writer.Close(); memoryStream.Close(); resourceImporter.UpdateMedatadaFile(ResourceType.NetworkConfiguration, null, false); Logger.Info(methodName, ProgressResources.RollbackVirtualNetworksWaiting, ResourceType.NetworkConfiguration.ToString()); dcMigrationManager.ReportProgress(ProgressResources.RollbackVirtualNetworksWaiting); Task.Delay(Constants.DelayTimeInMilliseconds_Rollback).Wait(); Logger.Info(methodName, ProgressResources.RollbackVirtualNetwork, ResourceType.NetworkConfiguration.ToString()); swVirtualNetwork.Stop(); Logger.Info(methodName, string.Format(ProgressResources.ExecutionCompletedWithTime, swVirtualNetwork.Elapsed.Days, swVirtualNetwork.Elapsed.Hours, swVirtualNetwork.Elapsed.Minutes, swVirtualNetwork.Elapsed.Seconds), ResourceType.NetworkConfiguration.ToString()); } catch (CloudException ex) { if (string.Compare(ex.ErrorCode, Constants.ResourceNotFound, StringComparison.CurrentCultureIgnoreCase) != 0) { Logger.Error(methodName, ex, ResourceType.VirtualNetwork.ToString()); } else { throw; } } }