public async Task <string> GetUSSDCSV(int minSize = 0, string region = "europe-west", string currency = "usd", bool store = false, string date = null) { DateTime?dt; VmList vml = new VmList(configuration); String regionSlug; try { dt = excelAzureBackend.excelAzureHelpers.parseDTString(date); regionSlug = await vml.FindRegionSlug(region); var validCurrency = excelAzureHelpers.validateCurrency(currency); } catch (Exception) { this.Response.StatusCode = 400; return(""); } UltraSSDs md = new UltraSSDs(configuration); List <UltraSSD> mdiskList = await md.GetUltraSSDs(region, currency, dt); var result = mdiskList.Where(i => i.size >= minSize).OrderBy(x => x.size); StringBuilder s = new StringBuilder(); DataTable datbl = JsonConvert.DeserializeObject <DataTable>(JsonConvert.SerializeObject(result), new JsonSerializerSettings { FloatParseHandling = FloatParseHandling.Decimal }); foreach (DataColumn column in datbl.Columns) { s.Append(column.ColumnName + ";"); } s.Append(Environment.NewLine); foreach (DataRow row in datbl.Rows) { for (var i = 0; i < datbl.Columns.Count; i++) { s.Append(row[i] + ";"); } s.Append(Environment.NewLine); } return(s.ToString()); }
public async Task <string> GetStorageCSV2(int minSize = 0, string region = "europe-west", string currency = "usd", bool store = false, string date = null) { DateTime?dt; VmList vml = new VmList(configuration); String regionSlug; try { dt = excelAzureBackend.excelAzureHelpers.parseDTString(date); regionSlug = await vml.FindRegionSlug(region); var validCurrency = excelAzureHelpers.validateCurrency(currency); } catch (Exception) { this.Response.StatusCode = 400; return(""); } UltraSSDs ussds = new UltraSSDs(configuration); var ussdisks = await ussds.GetUltraSSDs(region, currency, dt); mdisk md = new mdisk(configuration); List <mdisk> mdiskList = await md.GetMdisks(regionSlug, currency, dt); List <mdisk> ussdMdiskList = new List <mdisk>(); foreach (var item in mdiskList) { var compare_ussd = ussds.findUSSD(ussdisks, item.size, item.iops, item.speed, item.pricemonth); if (compare_ussd.Count <UltraSSD>() > 0) { var ussdPriceMonth = ussds.calculatePriceMonth(compare_ussd[0], item.iops, item.speed); // If the USSD is cheaper, replace the disk with USSD string mdiskname = item.name.Split("-")[1]; item.name = "ultrassd-" + mdiskname; item.displayName = compare_ussd[0].displayName; item.isPreview = false; item.size = compare_ussd[0].size; item.pricemonth = ussdPriceMonth; item.priceyear = ussdPriceMonth * 12; item.snapshotPrice = null; item.transactionPrice = null; item.snapshotPriceLrs = null; item.snapshotPriceZrs = null; //ussdMdiskList.Add(new mdisk(configuration) { name = compare_ussd[0].name, displayName = compare_ussd[0].displayName, isPreview = false, size = compare_ussd[0].size, iops = item.iops, speed = item.speed, pricemonth = ussdPriceMonth, priceyear = ussdPriceMonth*12, snapshotPrice = null, transactionPrice = null }); } } ussdMdiskList.ForEach(p => mdiskList.Add(p)); var result = mdiskList.Where(i => i.size >= minSize && i.pricemonth.HasValue).OrderBy(x => x.pricemonth); StringBuilder s = new StringBuilder(); DataTable datbl = JsonConvert.DeserializeObject <DataTable>(JsonConvert.SerializeObject(result)); foreach (DataColumn column in datbl.Columns) { s.Append(column.ColumnName + ";"); } s.Append(Environment.NewLine); foreach (DataRow row in datbl.Rows) { for (var i = 0; i < datbl.Columns.Count; i++) { s.Append(row[i] + ";"); } s.Append(Environment.NewLine); } return(s.ToString()); }