public async Task <string> GetVM(int minCores = 0, int minRam = 0, string os = "linux", string tier = "standard", string region = "europe-west", int ri = 0, string format = "", string currency = "usd") { VmList vml = new VmList(configuration); var taskList = new List <Task <VmList> >(); taskList.Add(vml.GetVmsAsync(region: region, bindingPeriod: 0, currency: currency)); taskList.Add(vml.GetVmsAsync(region: region, bindingPeriod: 1, currency: currency)); taskList.Add(vml.GetVmsAsync(region: region, bindingPeriod: 3, currency: currency)); taskList.Add(vml.GetVmsAsyncSoftware(region: region, bindingPeriod: 0, currency: currency)); taskList.Add(vml.GetVmsAsyncSoftware(region: region, bindingPeriod: 1, currency: currency)); taskList.Add(vml.GetVmsAsyncSoftware(region: region, bindingPeriod: 3, currency: currency)); await Task.WhenAll(taskList.ToArray()); List <vm> vms = new List <vm>(); //VmList vms = new VmList(); for (int i = 0; i < taskList.Count; i++) { vms.AddRange(taskList[i].Result.vms); } var result = vms.Where(i => i.cores >= minCores && i.ram >= minRam && i.name.Contains(tier) && i.price.HasValue).OrderBy(x => x.price); StringBuilder s = new StringBuilder(); DataTable dt = JsonConvert.DeserializeObject <DataTable>(JsonConvert.SerializeObject(result)); foreach (DataColumn column in dt.Columns) { s.Append(column.ColumnName + ";"); } s.Append(Environment.NewLine); foreach (DataRow row in dt.Rows) { for (var i = 0; i < dt.Columns.Count; i++) { s.Append(row[i] + ";"); } s.Append(Environment.NewLine); } return(s.ToString()); }
public async Task <IOrderedEnumerable <vm> > Get(int minCores = 0, int minRam = 0, string os = "linux", string tier = "standard", string region = "europe-west", int ri = 0, string format = "") { VmList vml = new VmList(configuration); var vmlist = await vml.GetVmsAsync(region : region, bindingPeriod : ri); var result = vmlist.vms.Where(i => i.cores >= minCores && i.ram >= minRam && i.name.IndexOf(os) > -1 && i.name.Contains(tier) && i.price.HasValue).OrderBy(x => x.price); return(result); }
public async Task <IOrderedEnumerable <vm> > Get(string date = "", int minCores = 0, int minRam = 0, string os = "linux", string tier = "standard", string region = "europe-west", int ri = 0, string format = "", string currency = "usd") { 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(null); } var taskList = new List <Task <VmList> >(); taskList.Add(vml.GetVmsAsync(region: region, bindingPeriod: 0, currency: currency, date: dt)); taskList.Add(vml.GetVmsAsync(region: region, bindingPeriod: 1, currency: currency, date: dt)); taskList.Add(vml.GetVmsAsync(region: region, bindingPeriod: 3, currency: currency, date: dt)); await Task.WhenAll(taskList.ToArray()); VmList vms = new VmList(configuration); for (int i = 0; i < taskList.Count; i++) { vms.vms.AddRange(taskList[i].Result.vms); } //var result = vms.vms.Where(i => i.cores >= minCores && i.ram >= minRam && i.name.Contains(tier) && i.price.HasValue).OrderBy(x => x.price); var result = vms.vms.Where(i => i.cores >= minCores && i.ram >= minRam && i.name.Contains(tier?.ToString() ?? "") && i.price.HasValue).OrderBy(x => x.price); //var responsetext = JsonConvert.SerializeObject(result); return(result); }
public async Task <string> GetVM(int minCores = 0, int minRam = 0, string os = "", string tier = "standard", string region = "europe-west", int ri = 0, string format = "", string currency = "usd", string date = "") { 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(""); } // Search for region slug var taskList = new List <Task <VmList> >(); taskList.Add(vml.GetVmsAsync(region: regionSlug, bindingPeriod: 0, currency: currency, date: dt)); taskList.Add(vml.GetVmsAsync(region: regionSlug, bindingPeriod: 1, currency: currency, date: dt)); taskList.Add(vml.GetVmsAsync(region: regionSlug, bindingPeriod: 3, currency: currency, date: dt)); await Task.WhenAll(taskList.ToArray()); VmList vms = new VmList(configuration); for (int i = 0; i < taskList.Count; i++) { vms.vms.AddRange(taskList[i].Result.vms); } var result = vms.vms.Where(i => i.cores >= minCores && i.ram >= minRam && i.name.Contains(tier?.ToString() ?? "") && i.name.Contains(os?.ToString() ?? "") && i.price.HasValue).OrderBy(x => x.price); /* if (store) * { * string EndpointUri = configuration.GetValue<string>("CosmosDBSettings:EndpointUri"); * string PrimaryKey = configuration.GetValue<string>("CosmosDBSettings:PrimaryKey"); * string databaseName = configuration.GetValue<string>("CosmosDBSettings:databaseName"); * * DocumentClient Dbclient; * * Dbo dbo = new Dbo(); * dbo.vms = result.ToList<vm>(); * dbo.region = region; * dbo.currency = currency; * dbo.date = DateTime.Now; * // Save result to DocumentDB * Dbclient = new DocumentClient(new Uri(EndpointUri), PrimaryKey); * await Dbclient.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, "vm"), dbo); * * * * }*/ 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()); }