private async void GetOneFloatingIpButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.AddLogMessage("load floating ip");

                string serverId = await this.ShowInputAsync(
                    "FloatingIp-ID",
                    "enter the floating-ip id");

                long id = Convert.ToInt64(serverId);

                lkcode.hetznercloudapi.Api.FloatingIp floatingIp = await lkcode.hetznercloudapi.Api.FloatingIp.GetAsync(id);

                List <lkcode.hetznercloudapi.Api.FloatingIp> floatingIpList = new List <lkcode.hetznercloudapi.Api.FloatingIp>();
                floatingIpList.Add(floatingIp);

                this.FloatingIpDataGrid.ItemsSource = null;
                this.FloatingIpDataGrid.ItemsSource = floatingIpList;

                this.AddLogMessage(string.Format("loaded floating ip with id {0}", floatingIp.Id));
            }
            catch (Exception err)
            {
                this.AddLogMessage(string.Format("error: {0}", err.Message));
            }
        }
예제 #2
0
        /// <summary>
        /// Returns a floating-id by the given id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static async Task <FloatingIp> GetAsync(long id)
        {
            string responseContent = await ApiCore.SendRequest(string.Format("/floating_ips/{0}", id.ToString()));

            Objects.FloatingIp.GetOne.Response response = JsonConvert.DeserializeObject <Objects.FloatingIp.GetOne.Response>(responseContent);

            FloatingIp floatingIp = GetFloatingIpFromResponseData(response.floating_ip);

            return(floatingIp);
        }
        private async void DeleteFloatingIpButton_Click(object sender, RoutedEventArgs e)
        {
            lkcode.hetznercloudapi.Api.FloatingIp floatingIp = this.FloatingIpDataGrid.SelectedItem as lkcode.hetznercloudapi.Api.FloatingIp;

            try
            {
                this.AddLogMessage("delete floating ip");

                await floatingIp.DeleteAsync();

                this.AddLogMessage(string.Format("deleted floating ip with id {0}", floatingIp.Id));
            }
            catch (Exception err)
            {
                this.AddLogMessage(string.Format("error: {0}", err.Message));
            }
        }
예제 #4
0
        /// <summary>
        /// loads the data for this floating-ip.
        /// </summary>
        private async void LoadData()
        {
            if (this.IsInitialized)
            {
                return;
            }

            FloatingIp floatingIp = await GetAsync(this.Id);

            this.Description  = floatingIp.Description;
            this.Ip           = floatingIp.Ip;
            this.Type         = floatingIp.Type;
            this.ServerId     = floatingIp.ServerId;
            this.Blocked      = floatingIp.Blocked;
            this.Protection   = floatingIp.Protection;
            this.DnsPointer   = floatingIp.DnsPointer;
            this.HomeLocation = floatingIp.HomeLocation;

            this._isInitialized = true;
        }
예제 #5
0
        /// <summary>
        /// returns a FloatingIp-Object for the given data
        /// </summary>
        /// <param name="responseData"></param>
        /// <returns></returns>
        private static FloatingIp GetFloatingIpFromResponseData(Objects.FloatingIp.GetOne.FloatingIp responseData)
        {
            FloatingIp floatingIp = new FloatingIp(responseData.id);

            floatingIp._isInitialized = true;
            floatingIp.Description    = responseData.description;
            floatingIp.Ip             = responseData.ip;
            floatingIp.Type           = responseData.type;
            floatingIp.ServerId       = responseData.server;
            floatingIp.Blocked        = responseData.blocked;

            floatingIp.Protection = new FloatingIpProtection()
            {
                Delete = responseData.protection.delete
            };

            floatingIp.HomeLocation = new Location()
            {
                Id          = responseData.home_location.id,
                Name        = responseData.home_location.name,
                City        = responseData.home_location.city,
                Country     = responseData.home_location.country,
                Description = responseData.home_location.description,
                Latitude    = responseData.home_location.latitude,
                Longitude   = responseData.home_location.longitude,
            };

            floatingIp.DnsPointer = new List <FloatingIpDnsPointer>();
            foreach (var dnsPtr in responseData.dns_ptr)
            {
                floatingIp.DnsPointer.Add(new FloatingIpDnsPointer()
                {
                    Ip         = dnsPtr.ip,
                    DnsPointer = dnsPtr.dns_ptr
                });
            }

            return(floatingIp);
        }