//********************************************************************* /// /// <summary> /// This method fetches OS information from WAP DB. /// </summary> /// //********************************************************************* private void FetchVmOsFromDb() { var cwdb = new CmpWapDb(); var list = cwdb.FetchOsInfoList(onlyActiveOnes: true); osList.Clear(); osList.AddRange(list); }
private static void UpdateRegionVmOsMappings(IEnumerable <AzureCatalogue> azureCatalogueResult) { var cmpWapDb = new CmpWapDb(); var cmpWapRegions = cmpWapDb.FetchAzureRegionList(onlyActiveOnes: false).ToList(); var cmpWapVmOses = cmpWapDb.FetchOsInfoList(onlyActiveOnes: false).ToList(); var newMappings = new List <AzureRegionVmOsMapping>(); try { foreach (var regionInCatalogue in azureCatalogueResult) { foreach (var vmOs in regionInCatalogue.VmOses) { //Since we format the VmOs name when inserting it into the DB table, to look it up, we will need to do the same format operation as before var vmOsName = (vmOs.Publisher + ", " + vmOs.Offer + ", " + vmOs.SKU).Length >= 100 ? (vmOs.Publisher + ", " + vmOs.Offer + ", " + vmOs.SKU).Substring(0, 100) : (vmOs.Publisher + ", " + vmOs.Offer + ", " + vmOs.SKU); //Adjusting for DB limitations in length, so that the logic comparison does not fail //We need to get the IDs to make the mapping object. Query the VmOs and Region tables to get them. var vmOsToMap = cmpWapVmOses.FirstOrDefault(x => string.Equals(vmOsName, x.Name, StringComparison.InvariantCultureIgnoreCase)); var regionToMap = cmpWapRegions.FirstOrDefault(y => string.Equals(regionInCatalogue.RegionName.Replace(" ", string.Empty), y.Name.Replace(" ", string.Empty), StringComparison.InvariantCultureIgnoreCase)); if (vmOsToMap == null || regionToMap == null) { continue; //something's wrong here if we reach this. } var newMapping = new AzureRegionVmOsMapping { AzureRegionId = regionToMap.AzureRegionId, VmOsId = vmOsToMap.VmOsId, IsActive = true }; newMappings.Add(newMapping); } } if (newMappings.Any()) { cmpWapDb.SetRegionVmOsMappingsByBatch(newMappings); } } catch (Exception ex) { throw new Exception("Exception caught in UpdateRegionVmOsMappings: " + ex.ToString()); } }
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()); } }
private void FetchOsInfoTest() { var ctr = new CmpWapDb(); var result = ctr.FetchOsInfoList("Novihmnodnl"); }