Пример #1
0
        private static void UpdateVmOs(IEnumerable <AzureCatalogue> azureCatalogueResult)
        {
            try
            {
                var cmpWapDb             = new CmpWapDb();
                var cmpVmOses            = cmpWapDb.FetchOsInfoList(onlyActiveOnes: false).ToList();
                var newVmOses            = new List <VmOs>();
                var azureCatalogueVmOses = new List <AzureVmOsArmData>();

                //Eliminate dupes, we only need them to establish the mappings in another method.
                foreach (var regionInCatalogue in azureCatalogueResult)
                {
                    azureCatalogueVmOses.AddRange(regionInCatalogue.VmOses);
                }
                azureCatalogueVmOses = azureCatalogueVmOses.Distinct(new AzureVmOsArmData.AzureVmOsArmDataComparer()).ToList();

                //Translate and convert each AzureVmOsArmData object into a VmOs object.
                var azureVmOses = azureCatalogueVmOses.Select(data => new VmOs
                {
                    Name                  = (data.Publisher + ", " + data.Offer + ", " + data.SKU).Length >= 100 ? (data.Publisher + ", " + data.Offer + ", " + data.SKU).Substring(0, 100) : (data.Publisher + ", " + data.Offer + ", " + data.SKU),//Adjusting for DB limitations in length, so that the logic comparison does not fail
                    Description           = string.Empty,
                    OsFamily              = string.Empty,
                    AzureImageName        = string.Empty,
                    IsCustomImage         = false,
                    IsActive              = false,
                    CreatedOn             = DateTime.UtcNow,
                    CreatedBy             = @"CMP WAP Extension",
                    LastUpdatedOn         = DateTime.UtcNow,
                    LastUpdatedBy         = @"CMP WAP Extension",
                    AzureImagePublisher   = data.Publisher,
                    AzureImageOffer       = data.Offer,
                    AzureWindowsOSVersion = data.SKU
                });

                newVmOses.AddRange(azureVmOses.Where(azureItem => !cmpVmOses.Any(cmpItem => string.Equals(azureItem.Name, cmpItem.Name, StringComparison.InvariantCultureIgnoreCase))).ToList());

                if (newVmOses.Any())
                {
                    cmpWapDb.InsertOsInfoByBatch(newVmOses);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception caught in UpdateVmOs: " + ex.ToString());
            }
        }