Пример #1
0
        private static void UpdateVmSizes(IEnumerable <AzureCatalogue> azureCatalogueResult)
        {
            try
            {
                var cmpWapDb              = new CmpWapDb();
                var cmpWapVmSizes         = cmpWapDb.FetchVmSizeInfoList(onlyActiveOnes: false).ToList();
                var newVmSizes            = new List <VmSize>();
                var azureCatalogueVmSizes = new List <AzureVmSizeArmData>();

                //Eliminate dupes, we only need them to establish the mappings in another method.
                foreach (var regionInCatalogue in azureCatalogueResult)
                {
                    azureCatalogueVmSizes.AddRange(regionInCatalogue.VmSizes);
                }
                azureCatalogueVmSizes = azureCatalogueVmSizes.Distinct(new AzureVmSizeArmData.AzureVmSizeComparer()).ToList();

                //Translate and convert each AzureVmSizeArmData object into a VmSize object.
                foreach (var vmSize in azureCatalogueVmSizes)
                {
                    if (!cmpWapVmSizes.Any(x => string.Equals(vmSize.name, x.Name, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        var newVmSize = new VmSize
                        {
                            Name             = vmSize.name,
                            Cores            = vmSize.numberOfCores,
                            Memory           = vmSize.memoryInMB,
                            MaxDataDiskCount = vmSize.maxDataDiskCount,
                            IsActive         = true,
                            CreatedBy        = "CMP WAP Extension",
                            LastUpdatedBy    = "CMP WAP Extension",
                            CreatedOn        = DateTime.UtcNow,
                            LastUpdatedOn    = DateTime.UtcNow
                        };

                        if (vmSize.memoryInMB >= 1000)
                        {
                            newVmSize.Description = vmSize.name + " - " + vmSize.numberOfCores + " Cores, " + vmSize.memoryInMB / 1000 + " GB, " + vmSize.maxDataDiskCount + " Disk";
                        }
                        else
                        {
                            newVmSize.Description = vmSize.name + " - " + vmSize.numberOfCores + " Cores, " + vmSize.memoryInMB + " MB, " + vmSize.maxDataDiskCount + " Disk";
                        }

                        newVmSizes.Add(newVmSize);
                    }
                }


                if (newVmSizes.Any())
                {
                    cmpWapDb.InsertVmSizeByBatch(newVmSizes);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception caught in UpdateVmSizes: " + ex.ToString());
            }
        }