private async void GetPricingsButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.AddLogMessage("load pricings");

                lkcode.hetznercloudapi.Api.Pricing pricing = await lkcode.hetznercloudapi.Api.Pricing.GetAsync();

                // set values
                this.PricingCurrencyTextBlock.Text = pricing.Currency;
                this.PricingVatTextBlock.Text      = Math.Round(Convert.ToDecimal(pricing.VatRate, CultureInfo.InvariantCulture.NumberFormat), 0) + " %";

                this.PricingImageNetTextBlock.Text   = Math.Round(Convert.ToDecimal(pricing.Image.PricePerGbMonth.Net, CultureInfo.InvariantCulture.NumberFormat), 2) + " " + pricing.Currency;
                this.PricingImageGrossTextBlock.Text = Math.Round(Convert.ToDecimal(pricing.Image.PricePerGbMonth.Gross, CultureInfo.InvariantCulture.NumberFormat), 2) + " " + pricing.Currency;

                this.PricingFloatingIpNetTextBlock.Text   = Math.Round(Convert.ToDecimal(pricing.FloatingIp.PriceMontly.Net, CultureInfo.InvariantCulture.NumberFormat), 2) + " " + pricing.Currency;
                this.PricingFloatingIpGrossTextBlock.Text = Math.Round(Convert.ToDecimal(pricing.FloatingIp.PriceMontly.Gross, CultureInfo.InvariantCulture.NumberFormat), 2) + " " + pricing.Currency;

                this.PricingTrafficNetTextBlock.Text   = Math.Round(Convert.ToDecimal(pricing.Traffic.PricePerTb.Net, CultureInfo.InvariantCulture.NumberFormat), 2) + " " + pricing.Currency;
                this.PricingTrafficGrossTextBlock.Text = Math.Round(Convert.ToDecimal(pricing.Traffic.PricePerTb.Gross, CultureInfo.InvariantCulture.NumberFormat), 2) + " " + pricing.Currency;

                this.PricingServerBackupPercentageTextBlock.Text = Math.Round(Convert.ToDecimal(pricing.ServerBackup.Percentage, CultureInfo.InvariantCulture.NumberFormat), 0) + " %";

                this.ServerTypePricingDataGrid.ItemsSource = pricing.ServerTypes;

                this.AddLogMessage(string.Format("loaded pricings"));
            }
            catch (Exception err)
            {
                this.AddLogMessage(string.Format("error: {0}", err.Message));
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static async Task <Pricing> GetAsync()
        {
            Pricing pricings = new Pricing();

            string responseContent = await ApiCore.SendRequest("/pricing");

            Objects.Pricing.Get.Response response = JsonConvert.DeserializeObject <Objects.Pricing.Get.Response>(responseContent);

            pricings = GetPricingsFromResponseData(response);

            return(pricings);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        private static Pricing GetPricingsFromResponseData(Objects.Pricing.Get.Response responseData)
        {
            Pricing pricings = new Pricing();

            pricings.Currency = responseData.pricing.currency;
            pricings.VatRate  = responseData.pricing.vat_rate;
            pricings.Image    = new ImagePricing()
            {
                PricePerGbMonth = new PricingValue()
                {
                    Net   = responseData.pricing.image.price_per_gb_month.net,
                    Gross = responseData.pricing.image.price_per_gb_month.gross
                }
            };
            pricings.FloatingIp = new FloatingIpPricing()
            {
                PriceMontly = new PricingValue()
                {
                    Net   = responseData.pricing.floating_ip.price_monthly.net,
                    Gross = responseData.pricing.floating_ip.price_monthly.gross
                }
            };
            pricings.Traffic = new TrafficPricing()
            {
                PricePerTb = new PricingValue()
                {
                    Net   = responseData.pricing.traffic.price_per_tb.net,
                    Gross = responseData.pricing.traffic.price_per_tb.gross
                }
            };
            pricings.ServerBackup = new ServerBackupPricing()
            {
                Percentage = responseData.pricing.server_backup.percentage
            };
            pricings.ServerTypes = new List <ServerTypePricing>();

            foreach (var serverType in responseData.pricing.server_types)
            {
                ServerTypePricing stp = ServerType.GetServerTypePricingFromResponseData(serverType);

                pricings.ServerTypes.Add(stp);
            }

            return(pricings);
        }