Exemplo n.º 1
0
        private static void UpdateAzureRegions(IEnumerable <AzureCatalogue> azureCatalogueResult)
        {
            try
            {
                var cmpWapDb     = new CmpWapDb();
                var cmpRegions   = cmpWapDb.FetchAzureRegionList(onlyActiveOnes: false);
                var azureRegions = azureCatalogueResult.Select(ac => new AzureRegion
                {
                    Name             = ac.RegionName,
                    Description      = ac.RegionDisplayName,
                    OsImageContainer = null,
                    IsActive         = true,
                    CreatedBy        = "CMP WAP Extension",
                    LastUpdatedBy    = "CMP WAP Extension",
                    CreatedOn        = DateTime.UtcNow,
                    LastUpdatedOn    = DateTime.UtcNow
                });

                var newRegions = azureRegions.Where(azureItem => !cmpRegions.Any(cmpItem => string.Equals(azureItem.Name.Replace(" ", string.Empty), cmpItem.Name.Replace(" ", string.Empty), StringComparison.InvariantCultureIgnoreCase))).ToList();

                if (newRegions.Any())
                {
                    cmpWapDb.InsertAzureRegionByBatch(newRegions);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception caught in UpdateAzureRegions: " + ex.ToString());
            }
        }