示例#1
0
        /// <summary>
        /// Get child resource source or destination name as per isDestinationNameRequired true or false
        /// if false, resource source name is returned
        /// else get destination name
        /// </summary>
        /// <param name="root"></param>
        /// <param name="childResourceType"></param>
        /// <param name="resourceName"></param>
        /// <param name="isDestinationNameRequired"></param>
        /// <returns></returns>
        internal string GetChildResourceName(ResourceNameMapper root, ResourceType childResourceType, string resourceName,
                                             bool isDestinationNameRequired = true)
        {
            string name = string.Empty;;

            foreach (ResourceNameMapper res in root.ChildResources)
            {
                if (isDestinationNameRequired && res.SourceName.Equals(resourceName) && res.ResourceType.Equals(childResourceType.ToString()))
                {
                    name = res.DestinationName;
                    break;
                }
                else if (!isDestinationNameRequired && res.DestinationName.Equals(resourceName) && res.ResourceType.Equals(childResourceType.ToString()))
                {
                    name = res.SourceName;
                    break;
                }
                else if (res.ChildResources.Count() > 0)
                {
                    for (int i = 0; i < res.ChildResources.Count(); i++)
                    {
                        name = GetChildResourceName(res, childResourceType, resourceName, isDestinationNameRequired);
                        if (name != null && !string.IsNullOrEmpty(name))
                        {
                            return(name);
                        }
                    }
                }
            }
            return(name);
        }
示例#2
0
        private void GetAllChildResources(ResourceNameMapper resource, XElement parent)
        {
            XElement childElement = new XElement(resource.ResourceType,
                                                 new XAttribute(Constants.ResourceNameMapper.SourceName, resource.SourceName),
                                                 new XAttribute(Constants.ResourceNameMapper.DestinationName, resource.DestinationName)
                                                 //,new XAttribute(Constants.ResourceNameMapper.Import, resource.Import)
                                                 );

            parent.Add(childElement);
            foreach (ResourceNameMapper child in resource.ChildResources)
            {
                GetAllChildResources(child, childElement);
            }
            ;
        }
示例#3
0
        private ResourceNameMapper GetResourcesFromXml(XElement element)
        {
            ResourceNameMapper resourceNameMapper = new ResourceNameMapper()
            {
                SourceName      = element.Attribute(Constants.ResourceNameMapper.SourceName).Value,
                DestinationName = element.Attribute(Constants.ResourceNameMapper.DestinationName).Value,
                //Import = Boolean.Parse(element.Attribute(Constants.ResourceNameMapper.Import).Value),
                ResourceType = element.Name.ToString()
            };

            foreach (var innerElement in element.Elements())
            {
                resourceNameMapper.ChildResources.Add(GetResourcesFromXml(innerElement));
            }
            return(resourceNameMapper);
        }
示例#4
0
        /// <summary>
        /// return xml string for the resource name mapping
        /// </summary>
        /// <param name="subscription"></param>
        /// <param name="destinationPrefixValue"></param>
        /// <returns></returns>
        internal string GenerateMapperXml(Subscription subscription, string destinationPrefixValue)
        {
            foreach (var datacenter in subscription.DataCenters)
            {
                foreach (var affinityGroup in datacenter.AffinityGroups)
                {
                    GenerateNewResourceName(ResourceType.AffinityGroup, affinityGroup.AffinityGroupDetails.Name, destinationPrefixValue);
                }
                foreach (var storageAccount in datacenter.StorageAccounts)
                {
                    GenerateNewResourceName(ResourceType.StorageAccount, storageAccount.StorageAccountDetails.Name, destinationPrefixValue);
                }

                foreach (var cloudService in datacenter.CloudServices)
                {
                    GenerateNewResourceName(ResourceType.CloudService, cloudService.CloudServiceDetails.ServiceName, destinationPrefixValue);

                    ResourceNameMapper resourceCloudService = resourceNameCollection[ResourceType.CloudService].Where
                                                                  (s => s.SourceName.Equals(cloudService.CloudServiceDetails.ServiceName)).FirstOrDefault();

                    if (cloudService.DeploymentDetails != null)
                    {
                        if (resourceCloudService.ChildResources == null)
                        {
                            resourceCloudService.ChildResources = new List <ResourceNameMapper>();
                        }
                        ResourceNameMapper resourceDeployment = new ResourceNameMapper
                        {
                            SourceName      = cloudService.DeploymentDetails.Name,
                            DestinationName = GenerateNewResourceName(ResourceType.Deployment, cloudService.DeploymentDetails.Name,
                                                                      destinationPrefixValue, false),
                            //Import = true,
                            ResourceType = ResourceType.Deployment.ToString()
                        };
                        foreach (var virtualMachine in cloudService.DeploymentDetails.VirtualMachines)
                        {
                            ResourceNameMapper resourceVirtaulMachine = new ResourceNameMapper
                            {
                                SourceName      = virtualMachine.VirtualMachineDetails.RoleName,
                                DestinationName = virtualMachine.VirtualMachineDetails.RoleName,
                                // Import = true,
                                ResourceType = ResourceType.VirtualMachine.ToString()
                            };

                            resourceVirtaulMachine.ChildResources.Add(new ResourceNameMapper
                            {
                                SourceName      = virtualMachine.VirtualMachineDetails.OSVirtualHardDisk.Name,
                                DestinationName = string.Format("{0}{1}", destinationPrefixValue,
                                                                virtualMachine.VirtualMachineDetails.OSVirtualHardDisk.Name),
                                //Import = true,
                                ResourceType = ResourceType.OSDisk.ToString()
                            });
                            foreach (var disk in virtualMachine.VirtualMachineDetails.DataVirtualHardDisks)
                            {
                                resourceVirtaulMachine.ChildResources.Add(new ResourceNameMapper
                                {
                                    SourceName      = disk.Name,
                                    DestinationName = string.Format("{0}{1}", destinationPrefixValue, disk.Name),
                                    // Import = true,
                                    ResourceType = ResourceType.HardDisk.ToString()
                                });
                            }
                            resourceDeployment.ChildResources.Add(resourceVirtaulMachine);
                        }
                        resourceCloudService.ChildResources.Add(
                            resourceDeployment);
                    }
                }
                #region Network Configuration
                if (datacenter.NetworkConfiguration != null && datacenter.NetworkConfiguration.VirtualNetworkConfiguration != null)
                {
                    if (datacenter.NetworkConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites != null)
                    {
                        foreach (var virtualNetworkSite in datacenter.NetworkConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites)
                        {
                            GenerateNewResourceName(ResourceType.VirtualNetworkSite,
                                                    virtualNetworkSite.name, destinationPrefixValue);

                            ResourceNameMapper resourceVirtualNetworkSite = resourceNameCollection[ResourceType.VirtualNetworkSite].Where
                                                                                (s => s.SourceName.Equals(virtualNetworkSite.name)).FirstOrDefault();

                            if (resourceVirtualNetworkSite.ChildResources == null)
                            {
                                resourceVirtualNetworkSite.ChildResources = new List <ResourceNameMapper>();
                            }

                            if (virtualNetworkSite.DnsServersRef != null)
                            {
                                foreach (var dns in virtualNetworkSite.DnsServersRef)
                                {
                                    ResourceNameMapper resourceDNS = new ResourceNameMapper
                                    {
                                        SourceName      = dns.name,
                                        DestinationName = GenerateNewResourceName(ResourceType.DnsServer, dns.name,
                                                                                  destinationPrefixValue, false),
                                        //Import = true,
                                        ResourceType = ResourceType.DnsServer.ToString()
                                    };
                                    resourceVirtualNetworkSite.ChildResources.Add(resourceDNS);
                                }
                            }
                            if (virtualNetworkSite.Gateway != null && virtualNetworkSite.Gateway.ConnectionsToLocalNetwork != null &&
                                virtualNetworkSite.Gateway.ConnectionsToLocalNetwork.LocalNetworkSiteRef != null)
                            {
                                ResourceNameMapper resourceLocalNetwork = new ResourceNameMapper
                                {
                                    SourceName      = virtualNetworkSite.Gateway.ConnectionsToLocalNetwork.LocalNetworkSiteRef.name,
                                    DestinationName = GenerateNewResourceName(ResourceType.LocalNetworkSite,
                                                                              virtualNetworkSite.Gateway.ConnectionsToLocalNetwork.LocalNetworkSiteRef.name,
                                                                              destinationPrefixValue, false),
                                    //Import = true,
                                    ResourceType = ResourceType.LocalNetworkSite.ToString()
                                };
                                resourceVirtualNetworkSite.ChildResources.Add(resourceLocalNetwork);
                            }
                        }
                    }
                }
                #endregion
            }
            var xmlRoot = new XElement("Resources", new XAttribute(Constants.Parameters.DestinationPrefixName,
                                                                   destinationPrefixValue));
            foreach (var item in resourceNameCollection)
            {
                XElement child = new XElement(item.Key + "s");
                foreach (var resourceMapper in item.Value)
                {
                    GetAllChildResources(resourceMapper, child);
                }
                xmlRoot.Add(child);
            }
            return((new XDocument(xmlRoot)).ToString());
        }
示例#5
0
        /// <summary>
        /// return xml string for the resource name mapping
        /// </summary>
        /// <param name="subscription"></param>
        /// <param name="destinationPrefixValue"></param>
        /// <returns></returns>
        internal string GenerateMapperXml(Subscription subscription, string destinationPrefixValue)
        {
            foreach (var datacenter in subscription.DataCenters)
            {
                foreach (var affinityGroup in datacenter.AffinityGroups)
                {
                    GenerateNewResourceName(ResourceType.AffinityGroup, affinityGroup.AffinityGroupDetails.Name, destinationPrefixValue);
                }
                foreach (var storageAccount in datacenter.StorageAccounts)
                {
                    GenerateNewResourceName(ResourceType.StorageAccount, storageAccount.StorageAccountDetails.Name, destinationPrefixValue);
                }

                foreach (var cloudService in datacenter.CloudServices)
                {
                    GenerateNewResourceName(ResourceType.CloudService, cloudService.CloudServiceDetails.ServiceName, destinationPrefixValue);

                    ResourceNameMapper resourceCloudService = resourceNameCollection[ResourceType.CloudService].Where
                        (s => s.SourceName.Equals(cloudService.CloudServiceDetails.ServiceName)).FirstOrDefault();

                    if (cloudService.DeploymentDetails != null)
                    {
                        if (resourceCloudService.ChildResources == null)
                        {
                            resourceCloudService.ChildResources = new List<ResourceNameMapper>();
                        }
                        ResourceNameMapper resourceDeployment = new ResourceNameMapper
                                {
                                    SourceName = cloudService.DeploymentDetails.Name,
                                    DestinationName = GenerateNewResourceName(ResourceType.Deployment, cloudService.DeploymentDetails.Name,
                                    destinationPrefixValue, false),
                                    //Import = true,
                                    ResourceType = ResourceType.Deployment.ToString()
                                };
                        foreach (var virtualMachine in cloudService.DeploymentDetails.VirtualMachines)
                        {
                            ResourceNameMapper resourceVirtaulMachine = new ResourceNameMapper
                                  {
                                      SourceName = virtualMachine.VirtualMachineDetails.RoleName,
                                      DestinationName = virtualMachine.VirtualMachineDetails.RoleName,
                                      // Import = true,
                                      ResourceType = ResourceType.VirtualMachine.ToString()
                                  };

                            resourceVirtaulMachine.ChildResources.Add(new ResourceNameMapper
                            {
                                SourceName = virtualMachine.VirtualMachineDetails.OSVirtualHardDisk.Name,
                                DestinationName = string.Format("{0}{1}", destinationPrefixValue,
                                virtualMachine.VirtualMachineDetails.OSVirtualHardDisk.Name),
                                //Import = true,
                                ResourceType = ResourceType.OSDisk.ToString()
                            });
                            foreach (var disk in virtualMachine.VirtualMachineDetails.DataVirtualHardDisks)
                            {
                                resourceVirtaulMachine.ChildResources.Add(new ResourceNameMapper
                                {
                                    SourceName = disk.Name,
                                    DestinationName = string.Format("{0}{1}", destinationPrefixValue, disk.Name),
                                    // Import = true,
                                    ResourceType = ResourceType.HardDisk.ToString()
                                });
                            }
                            resourceDeployment.ChildResources.Add(resourceVirtaulMachine);
                        }
                        resourceCloudService.ChildResources.Add(
                              resourceDeployment);
                    }
                }
                #region Network Configuration
                if (datacenter.NetworkConfiguration != null && datacenter.NetworkConfiguration.VirtualNetworkConfiguration != null)
                {
                    if (datacenter.NetworkConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites != null)
                    {
                        foreach (var virtualNetworkSite in datacenter.NetworkConfiguration.VirtualNetworkConfiguration.VirtualNetworkSites)
                        {
                            GenerateNewResourceName(ResourceType.VirtualNetworkSite,
                                virtualNetworkSite.name, destinationPrefixValue);

                            ResourceNameMapper resourceVirtualNetworkSite = resourceNameCollection[ResourceType.VirtualNetworkSite].Where
                       (s => s.SourceName.Equals(virtualNetworkSite.name)).FirstOrDefault();

                            if (resourceVirtualNetworkSite.ChildResources == null)
                            {
                                resourceVirtualNetworkSite.ChildResources = new List<ResourceNameMapper>();
                            }

                            if (virtualNetworkSite.DnsServersRef != null)
                            {
                                foreach (var dns in virtualNetworkSite.DnsServersRef)
                                {
                                    ResourceNameMapper resourceDNS = new ResourceNameMapper
                                    {
                                        SourceName = dns.name,
                                        DestinationName = GenerateNewResourceName(ResourceType.DnsServer, dns.name,
                                        destinationPrefixValue, false),
                                        //Import = true,
                                        ResourceType = ResourceType.DnsServer.ToString()
                                    };
                                    resourceVirtualNetworkSite.ChildResources.Add(resourceDNS);
                                }
                            }
                            if (virtualNetworkSite.Gateway != null && virtualNetworkSite.Gateway.ConnectionsToLocalNetwork != null &&
                                virtualNetworkSite.Gateway.ConnectionsToLocalNetwork.LocalNetworkSiteRef != null)
                            {
                                ResourceNameMapper resourceLocalNetwork = new ResourceNameMapper
                                {
                                    SourceName = virtualNetworkSite.Gateway.ConnectionsToLocalNetwork.LocalNetworkSiteRef.name,
                                    DestinationName = GenerateNewResourceName(ResourceType.LocalNetworkSite,
                                    virtualNetworkSite.Gateway.ConnectionsToLocalNetwork.LocalNetworkSiteRef.name,
                                    destinationPrefixValue, false),
                                    //Import = true,
                                    ResourceType = ResourceType.LocalNetworkSite.ToString()
                                };
                                resourceVirtualNetworkSite.ChildResources.Add(resourceLocalNetwork);
                            }
                        }
                    }
                }
                #endregion
            }
            var xmlRoot = new XElement("Resources", new XAttribute(Constants.Parameters.DestinationPrefixName,
                destinationPrefixValue));
            foreach (var item in resourceNameCollection)
            {
                XElement child = new XElement(item.Key + "s");
                foreach (var resourceMapper in item.Value)
                {
                    GetAllChildResources(resourceMapper, child);
                }
                xmlRoot.Add(child);
            }
            return (new XDocument(xmlRoot)).ToString();
        }
示例#6
0
 private ResourceNameMapper GetResourcesFromXml(XElement element)
 {
     ResourceNameMapper resourceNameMapper = new ResourceNameMapper()
     {
         SourceName = element.Attribute(Constants.ResourceNameMapper.SourceName).Value,
         DestinationName = element.Attribute(Constants.ResourceNameMapper.DestinationName).Value,
         //Import = Boolean.Parse(element.Attribute(Constants.ResourceNameMapper.Import).Value),
         ResourceType = element.Name.ToString()
     };
     foreach (var innerElement in element.Elements())
     {
         resourceNameMapper.ChildResources.Add(GetResourcesFromXml(innerElement));
     }
     return resourceNameMapper;
 }
示例#7
0
 private void GetAllChildResources(ResourceNameMapper resource, XElement parent)
 {
     XElement childElement = new XElement(resource.ResourceType,
            new XAttribute(Constants.ResourceNameMapper.SourceName, resource.SourceName),
        new XAttribute(Constants.ResourceNameMapper.DestinationName, resource.DestinationName)
         //,new XAttribute(Constants.ResourceNameMapper.Import, resource.Import)
             );
     parent.Add(childElement);
     foreach (ResourceNameMapper child in resource.ChildResources)
     {
         GetAllChildResources(child, childElement);
     };
 }
示例#8
0
        /// <summary>
        /// Get child resource source or destination name as per isDestinationNameRequired true or false
        /// if false, resource source name is returned
        /// else get destination name
        /// </summary>
        /// <param name="root"></param>
        /// <param name="childResourceType"></param>
        /// <param name="resourceName"></param>
        /// <param name="isDestinationNameRequired"></param>
        /// <returns></returns>
        internal string GetChildResourceName(ResourceNameMapper root, ResourceType childResourceType, string resourceName,
            bool isDestinationNameRequired = true)
        {
            string name = string.Empty; ;

            foreach (ResourceNameMapper res in root.ChildResources)
            {
                if (isDestinationNameRequired && res.SourceName.Equals(resourceName) && res.ResourceType.Equals(childResourceType.ToString()))
                {
                    name = res.DestinationName;
                    break;
                }
                else if (!isDestinationNameRequired && res.DestinationName.Equals(resourceName) && res.ResourceType.Equals(childResourceType.ToString()))
                {
                    name = res.SourceName;
                    break;
                }
                else if (res.ChildResources.Count() > 0)
                {
                    for (int i = 0; i < res.ChildResources.Count(); i++)
                    {
                        name = GetChildResourceName(res, childResourceType, resourceName, isDestinationNameRequired);
                        if (name != null && !string.IsNullOrEmpty(name))
                        {
                            return name;
                        }
                    }
                }
            }
            return name;
        }