コード例 #1
0
        public async Task <List <UltraSSD> > GetUltraSSDs(string region = "us-east", string currency = "usd", DateTime?date = null)
        {
            List <UltraSSD>   usds = new List <UltraSSD>();
            excelAzureHelpers xhlp = new excelAzureHelpers(configuration);
            var response           = await client.GetAsync(xhlp.GetMdiskURL(currency, date));

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                var     result             = JsonConvert.DeserializeObject <JObject>(content);
                JObject maxIopsPerGb       = (JObject)result["maxIopsPerGb"];
                JObject maxThroughputPerGb = (JObject)result["maxThroughputPerGb"];
                int     minIopsPerGb       = result["minIops"].Value <int>();
                int     minThroughput      = result["minThroughput"].Value <int>();

                try
                {
                    foreach (JObject item in result["ultraSizes"])
                    {
                        UltraSSD disk = new UltraSSD();
                        disk.name          = "ultrassd-u" + item["slug"].Value <string>();
                        disk.currency      = currency;
                        disk.size          = item["slug"].Value <int>();
                        disk.displayName   = "Ultra SSD " + item["displayName"].Value <string>();
                        disk.minIops       = minIopsPerGb;
                        disk.minThroughput = minThroughput;

                        disk.maxIops       = maxIopsPerGb.SelectToken(disk.size.ToString()).Value <int>();
                        disk.maxThroughput = maxThroughputPerGb.SelectToken(disk.size.ToString()).Value <int>();
                        disk.priceIops     = result["offers"]["ultrassd-iops"]["prices"][region]["value"].Value <decimal>();

                        disk.priceThroughput = result["offers"]["ultrassd-throughput"]["prices"][region]["value"].Value <decimal>();
                        disk.priceVCpu       = result["offers"]["ultrassd-vcpu"]["prices"][region]["value"].Value <decimal>();
                        disk.priceSize       = result["offers"]["ultrassd-stored"]["prices"][region]["value"].Value <decimal>();

                        usds.Add(disk);
                    }
                }
                catch (Exception)
                {
                    // Ignore Exceptions
                    //throw;
                }
            }
            return(usds);
        }
コード例 #2
0
        public async Task <List <mdisk> > GetMdisks(string region = "europe-west", string currency = "usd", DateTime?date = null)
        {
            List <mdisk>      mds  = new List <mdisk>();
            excelAzureHelpers xhlp = new excelAzureHelpers(configuration);

            var response = await client.GetAsync(xhlp.GetMdiskURL(currency, date));

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                var result = JsonConvert.DeserializeObject <JObject>(content);

                decimal?snapshotPriceStandardHHD_LRS = (decimal?)result.SelectToken("offers.standardhdd-snapshot-lrs.prices." + region + ".value");
                decimal?snapshotPriceStandardHDD_ZRS = (decimal?)result.SelectToken("offers.standardhdd-snapshot-zrs.prices." + region + ".value");

                decimal?snapshotPriceStandardSSD = (decimal?)result.SelectToken("offers.standardssd-snapshot.prices." + region + ".value");
                decimal?snapshotPricePremium     = (decimal?)result.SelectToken("offers.premiumssd-snapshot.prices." + region + ".value");
                decimal?transactionPriceHDD      = (decimal?)result.SelectToken("offers.transactions-hdd.prices." + region + ".value");
                decimal?transactionPriceSSD      = (decimal?)result.SelectToken("offers.transactions-ssd.prices." + region + ".value");

                foreach (JProperty item in result["offers"])
                {
                    if (!item.Name.Contains("snapshot") && item.Name != "standardssd-snapshot" && item.Name != "premiumssd-snapshot" && !item.Name.Contains("transactions"))
                    {
                        // switch to take out non disk elements
                        var     productname     = item.Name.Split('-').Last().ToLower();
                        var     seriesname      = item.Name.Split('-').First().ToLower();
                        var     dispName        = mdiskSearchDispName(seriesname, result["tiers"]) + " " + mdiskSearchDispName(productname, result["sizes"]);
                        bool    isPre           = false;
                        decimal pricemultiplier = 1;

                        if (dispName.ToLower().Contains("preview") || dispName.ToLower().Contains("promo") || dispName.ToLower().Contains("offer"))
                        {
                            isPre           = true;
                            pricemultiplier = 2;
                        }


                        decimal?pricemonth;
                        decimal?priceyear;

                        try
                        {
                            pricemonth = (decimal?)item.Value.SelectToken("prices." + region + ".value") * pricemultiplier; // Value["prices"][region]["value"].Value<decimal>();
                            if (pricemonth != null)
                            {
                                priceyear = (decimal?)pricemonth * 12 * pricemultiplier;
                            }
                            else
                            {
                                priceyear = null;
                            }

                            if (item.Name.Contains("premiumssd"))
                            {
                                mds.Add(new mdisk(configuration)
                                {
                                    name = item.Name, displayName = dispName, isPreview = isPre, size = item.Value["size"].Value <int>(), iops = item.Value["iops"].Value <int>(), speed = item.Value["speed"].Value <int>(), pricemonth = pricemonth, priceyear = priceyear, snapshotPrice = snapshotPricePremium, transactionPrice = transactionPriceSSD
                                });
                            }
                            else if (item.Name.Contains("standardssd"))
                            {
                                mds.Add(new mdisk(configuration)
                                {
                                    name = item.Name, displayName = dispName, isPreview = isPre, size = item.Value["size"].Value <int>(), iops = item.Value["iops"].Value <int>(), speed = speed = item.Value["speed"].Value <int>(), pricemonth = pricemonth, priceyear = priceyear, snapshotPrice = snapshotPriceStandardSSD, transactionPrice = transactionPriceSSD
                                });
                            }

                            else if (item.Name.Contains("standardhdd"))
                            {
                                mds.Add(new mdisk(configuration)
                                {
                                    name = item.Name, displayName = dispName, isPreview = isPre, size = item.Value["size"].Value <int>(), iops = item.Value["iops"].Value <int>(), speed = speed = item.Value["speed"].Value <int>(), pricemonth = pricemonth, priceyear = priceyear, snapshotPrice = null, snapshotPriceLrs = snapshotPriceStandardHHD_LRS, snapshotPriceZrs = snapshotPriceStandardHDD_ZRS, transactionPrice = transactionPriceHDD
                                });
                            }
                        }
                        catch (Exception)
                        {
                            System.Diagnostics.Trace.TraceWarning("Issues with : " + item.ToString());
                            throw;
                        }
                    }
                }
            }
            else
            {
                System.Diagnostics.Trace.TraceError("endpoint unresponsive : " + mdiskUrl);
            }


            return(mds);
        }