Esempio n. 1
0
        /// <summary>
        /// Returns all server in a list.
        /// </summary>
        /// <param name="page">optional parameter to get a specific page. default is page 1.</param>
        /// <returns>a list with the server-objects.</returns>
        public static async Task <List <Server> > GetAsync(int page = 1)
        {
            if ((_maxPages > 0 && (page <= 0 || page > _maxPages)))
            {
                throw new InvalidPageException("invalid page number (" + page + "). valid values between 1 and " + _maxPages + "");
            }

            List <Server> serverList = new List <Server>();

            string url = string.Format("/servers");

            if (page > 1)
            {
                url += "?page=" + page.ToString();
            }

            string responseContent = await ApiCore.SendRequest(url);

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

            // load meta
            SaveResponseMetaData(response);

            foreach (Objects.Server.Universal.Server responseServer in response.servers)
            {
                Server server = GetServerFromResponseData(responseServer);

                serverList.Add(server);
            }

            return(serverList);
        }
        private async Task Reconcile(int transId)
        {
            Transaction.Reconciled = true;
            await ApiCore.ReconcileTransaction(transId);

            await _navigation.PopAsync();
        }
        /// <summary>
        /// Returns all datacenter in a list.
        /// </summary>
        /// <returns></returns>
        public static async Task <List <PrivateNetwork> > GetAsync(int page = 1, string token = null)
        {
            if ((_maxPages > 0 && (page <= 0 || page > _maxPages)))
            {
                throw new InvalidPageException("invalid page number (" + page + "). valid values between 1 and " + _maxPages + "");
            }

            List <PrivateNetwork> networksList = new List <PrivateNetwork>();

            string url = string.Format("/networks");

            if (page > 1)
            {
                url += "?page=" + page.ToString();
            }

            string responseContent = await ApiCore.SendRequest(url, token);

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

            // load meta
            CurrentPage = response.meta.pagination.page;
            float pagesDValue = ((float)response.meta.pagination.total_entries / (float)response.meta.pagination.per_page);

            MaxPages = (int)Math.Ceiling(pagesDValue);

            foreach (var network in response.networks)
            {
                networksList.Add(GetNetworkFromResponseData(network));
            }

            return(networksList);
        }
Esempio n. 4
0
        private void GetAllTransactions()
        {
            List <Transaction> allTransactions = ApiCore.GetHouseholdTransactions(APIConstants.HouseId, 0, 0).Result;

            allTransactions = allTransactions.OrderByDescending(t => t.Date).ToList();
            transactions    = new ObservableCollection <Transaction>(allTransactions);
        }
Esempio n. 5
0
        public async Task CallHouseTransactions()
        {
            List <Transaction> transactions = await ApiCore.GetHouseholdTransactions(Constants.APIConstants.HouseId, DateTimeOffset.Now.Month, DateTimeOffset.Now.Year).ConfigureAwait(false);

            entries = new List <Entry>();
            var categoryValues   = new Dictionary <string, decimal>();
            var uniqueCategories = transactions.Select(t => t.CatName).Distinct();

            foreach (var cat in uniqueCategories)
            {
                if (cat != "Transfer")
                {
                    decimal total = Math.Ceiling(transactions.Where(t => t.CatName == cat).Select(t => Math.Abs(t.Amount)).Sum());
                    categoryValues.Add(cat, total);
                }
            }
            categoryValues = categoryValues.OrderByDescending(c => c.Value).Take(6).ToDictionary(l => l.Key, v => v.Value);
            int counter = 0;

            foreach (KeyValuePair <string, decimal> category in categoryValues)
            {
                entries.Add(new Entry((float)category.Value)
                {
                    Color = SkiaSharp.SKColor.Parse(_colors[counter]), Label = category.Key, ValueLabel = $"{category.Value}"
                });
                counter++;
            }
        }
        /// <summary>
        /// Returns all datacenter in a list.
        /// </summary>
        /// <returns></returns>
        public static async Task <List <Location> > GetAsync(int page = 1, string token = null)
        {
            if ((_maxPages > 0 && (page <= 0 || page > _maxPages)))
            {
                throw new InvalidPageException("invalid page number (" + page + "). valid values between 1 and " + _maxPages + "");
            }

            List <Location> locationsList = new List <Location>();

            string url = string.Format("/locations");

            if (page > 1)
            {
                url += "?page=" + page.ToString();
            }

            string responseContent = await ApiCore.SendRequest(url, token);

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

            // load meta
            CurrentPage = response.meta.pagination.page;
            float pagesDValue = ((float)response.meta.pagination.total_entries / (float)response.meta.pagination.per_page);

            MaxPages = (int)Math.Ceiling(pagesDValue);

            foreach (Objects.Location.Universal.Location responseDatacenter in response.locations)
            {
                Location location = GetLocationFromResponseData(responseDatacenter);

                locationsList.Add(location);
            }

            return(locationsList);
        }
Esempio n. 7
0
        /// <summary>
        /// Rebuilds a server overwriting its disk with the content of an image, thereby destroying all data on the target server
        /// The image can either be one you have created earlier(backup or snapshot image) or it can be a completely fresh system image provided by us.You can get a list of all available images with GET /images.
        /// Your server will automatically be powered off before the rebuild command executes.
        /// </summary>
        /// <param name="image">ID or name of image to rebuilt from.</param>
        /// <returns>the serialized ServerActionResponse</returns>
        public async Task <ServerActionResponse> RebuildImage(string image)
        {
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(image.Trim()) &&
                !string.IsNullOrWhiteSpace(image.Trim()))
            {
                arguments.Add("image", image);
            }

            string responseContent = await ApiCore.SendPostRequest(string.Format("/servers/{0}/actions/rebuild", this.Id), arguments);

            JObject responseObject = JObject.Parse(responseContent);

            if (responseObject["error"] != null)
            {
                // error
                Objects.Server.Universal.ErrorResponse error = JsonConvert.DeserializeObject <Objects.Server.Universal.ErrorResponse>(responseContent);
                ServerActionResponse response = new ServerActionResponse();
                response.Error = GetErrorFromResponseData(error);

                return(response);
            }
            else
            {
                // success
                Objects.Server.PostRebuild.Response response = JsonConvert.DeserializeObject <Objects.Server.PostRebuild.Response>(responseContent);

                ServerActionResponse actionResponse = GetServerActionFromResponseData(response.action);
                //actionResponse.AdditionalActionContent = GetServerImageFromResponseData(response.image);

                return(actionResponse);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Returns all datacenter in a list.
        /// </summary>
        /// <returns></returns>
        public static async Task <List <ServerType> > GetAsync(int page = 1)
        {
            if ((_maxPages > 0 && (page <= 0 || page > _maxPages)))
            {
                throw new InvalidPageException("invalid page number (" + page + "). valid values between 1 and " + _maxPages + "");
            }

            List <ServerType> serverTypesList = new List <ServerType>();

            string url = string.Format("/server_types");

            if (page > 1)
            {
                url += "?page=" + page.ToString();
            }

            string responseContent = await ApiCore.SendRequest(url);

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

            // load meta
            CurrentPage = response.meta.pagination.page;
            float pagesDValue = ((float)response.meta.pagination.total_entries / (float)response.meta.pagination.per_page);

            MaxPages = (int)Math.Ceiling(pagesDValue);

            foreach (Objects.ServerType.Universal.ServerType responseServerType in response.server_types)
            {
                ServerType serverType = GetServerTypeFromResponseData(responseServerType);

                serverTypesList.Add(serverType);
            }

            return(serverTypesList);
        }
        /// <summary>
        /// Creates an image (snapshot) from a server by copying the contents of its disks. This creates a snapshot of the current state of the disk and copies it into an image. If the server is currently running you must make sure that its disk content is consistent. Otherwise, the created image may not be readable.
        /// To make sure disk content is consistent, we recommend to shut down the server prior to creating an image.
        /// You can either create a backup image that is bound to the server and therefore will be deleted when the server is deleted, or you can create an snapshot image which is completely independent of the server it was created from and will survive server deletion. Backup images are only available when the backup option is enabled for the Server. Snapshot images are billed on a per GB basis.
        /// </summary>
        /// <param name="description">Description of the image. If you do not set this we auto-generate one for you.</param>
        /// <param name="type">Type of image to create (default: snapshot) Choices: snapshot, backup (Use lkcode.hetznercloudapi.Components.ServerImageType)</param>
        /// <returns>the serialized ServerActionResponse</returns>
        public async Task <ServerActionResponse> CreateImage(string description, string type)
        {
            Dictionary <string, object> arguments = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(description.Trim()) &&
                !string.IsNullOrWhiteSpace(description.Trim()))
            {
                arguments.Add("description", description);
            }

            if (!string.IsNullOrEmpty(type.Trim()) &&
                !string.IsNullOrWhiteSpace(type.Trim()))
            {
                arguments.Add("type", type);
            }

            string responseContent = await ApiCore.SendPostRequest(string.Format("/servers/{0}/actions/create_image", this.Id), arguments);

            var result = GetServerActionFromResponseDataEx <Objects.Server.PostCreateImage.Response>(
                responseContent,
                onSuccess: (res, resp) =>
            {
                res.AdditionalActionContent = GetServerImageFromResponseData(resp.image);
            });

            return(result);
        }
        /// <summary>
        /// Deletes a server. This immediately removes the server from your account, and it is no longer accessible.
        /// </summary>
        /// <returns>the serialized ServerActionResponse</returns>
        public async Task <ServerActionResponse> Delete(string token = null)
        {
            string responseContent = await ApiCore.SendDeleteRequest(string.Format("/servers/{0}", this.Id), token : token);

            ServerActionResponse actionResponse = GetServerActionFromResponseDataEx <Objects.Server.Delete.Response>(responseContent);

            return(actionResponse);
        }
        /// <summary>
        /// Starts a server by turning its power on.
        /// </summary>
        /// <returns>the serialized ServerActionResponse</returns>
        public async Task <ServerActionResponse> PowerOn(string token = null)
        {
            string responseContent = await ApiCore.SendPostRequest(string.Format("/servers/{0}/actions/poweron", this.Id), token : token);

            ServerActionResponse actionResponse = GetServerActionFromResponseDataEx <Objects.Server.PostPoweron.Response>(responseContent);

            return(actionResponse);
        }
Esempio n. 12
0
        private async Task CallBudgetList()
        {
            List <Budget> budgets = await ApiCore.GetHouseholdBudgets(Constants.APIConstants.HouseId).ConfigureAwait(false);

            foreach (var b in budgets.Where(b => b.IsDeleted == false))
            {
                testBudgets.Add(b);
            }
        }
Esempio n. 13
0
        private async Task CallAccountList()
        {
            List <PersonalAccount> accounts = await ApiCore.GetPersonalAccounts(Constants.APIConstants.HouseId).ConfigureAwait(false);

            foreach (var a in accounts.Where(b => b.IsDeleted == false))
            {
                accountList.Add(a);
            }
        }
Esempio n. 14
0
        public async void GetAccounts()
        {
            var accounts = await ApiCore.GetPersonalAccounts(Constants.APIConstants.HouseId);

            foreach (var a in accounts)
            {
                accountList.Add(a);
            }
        }
Esempio n. 15
0
        public async void GetBudgets()
        {
            var budgets = await ApiCore.GetHouseholdBudgets(Constants.APIConstants.HouseId);

            foreach (var b in budgets)
            {
                budgetList.Add(b);
            }
        }
Esempio n. 16
0
        public async void GetCategories()
        {
            var categories = await ApiCore.GetHouseholdCategories(Constants.APIConstants.HouseId);

            foreach (var cat in categories)
            {
                categoryList.Add(cat);
            }
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static async Task <IsoImage> GetAsync(long id)
        {
            string responseContent = await ApiCore.SendRequest(string.Format("/isos/{0}", id.ToString()));

            Objects.Isos.Get.Iso response = JsonConvert.DeserializeObject <Objects.Isos.Get.Iso>(responseContent);

            IsoImage isoImage = GetIsoImageFromResponseData(response);

            return(isoImage);
        }
Esempio n. 19
0
        /// <summary>
        /// Cuts power to the server. This forcefully stops it without giving the server operating system time to gracefully stop. May lead to data loss, equivalent to pulling the power cord. Power off should only be used when shutdown does not work.
        /// </summary>
        /// <returns>the serialized ServerActionResponse</returns>
        public async Task <ServerActionResponse> PowerOff()
        {
            string responseContent = await ApiCore.SendPostRequest(string.Format("/servers/{0}/actions/poweroff", this.Id));

            Objects.Server.PostPoweroff.Response response = JsonConvert.DeserializeObject <Objects.Server.PostPoweroff.Response>(responseContent);

            ServerActionResponse actionResponse = GetServerActionFromResponseData(response.action);

            return(actionResponse);
        }
Esempio n. 20
0
        /// <summary>
        /// Deletes a server. This immediately removes the server from your account, and it is no longer accessible.
        /// </summary>
        /// <returns>the serialized ServerActionResponse</returns>
        public async Task <ServerActionResponse> Delete()
        {
            string responseContent = await ApiCore.SendDeleteRequest(string.Format("/servers/{0}", this.Id));

            Objects.Server.Delete.Response response = JsonConvert.DeserializeObject <Objects.Server.Delete.Response>(responseContent);

            ServerActionResponse actionResponse = GetServerActionFromResponseData(response.action);

            return(actionResponse);
        }
Esempio n. 21
0
        /// <summary>
        /// Returns a server by the given id.
        /// </summary>
        /// <param name="id">Returns a specific server object. The server must exist inside the project.</param>
        /// <returns>the returned server object</returns>
        public static async Task <Server> GetAsync(long id)
        {
            string responseContent = await ApiCore.SendRequest(string.Format("/servers/{0}", id.ToString()));

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

            Server server = GetServerFromResponseData(response.server);

            return(server);
        }
Esempio n. 22
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);
        }
Esempio n. 23
0
        /// <summary>
        /// Resets the root password. Only works for Linux systems that are running the qemu guest agent. Server must be powered on (state on) in order for this operation to succeed.
        /// This will generate a new password for this server and return it.
        /// If this does not succeed you can use the rescue system to netboot the server and manually change your server password by hand.
        /// </summary>
        /// <returns>the serialized ServerActionResponse</returns>
        public async Task <ServerActionResponse> ResetPassword()
        {
            string responseContent = await ApiCore.SendPostRequest(string.Format("/servers/{0}/actions/reset_password", this.Id));

            Objects.Server.ResetPassword.Response response = JsonConvert.DeserializeObject <Objects.Server.ResetPassword.Response>(responseContent);

            ServerActionResponse actionResponse = GetServerActionFromResponseData(response.action);

            actionResponse.AdditionalActionContent = response.root_password;

            return(actionResponse);
        }
Esempio n. 24
0
        private async void submitButton_Clicked(object sender, EventArgs e)
        {
            Budget budget = new Budget
            {
                HouseholdId = Constants.APIConstants.HouseId,
                Amount      = Convert.ToDecimal(amountEntry.Text),
                Name        = nameEntry.Text
            };

            await ApiCore.PostBudget(budget);

            await Navigation.PopAsync();
        }
Esempio n. 25
0
        private async Task Delete(int transId)
        {
            Transaction.IsDeleted = true;
            if (_model != null)
            {
                _model.UpdateBalance(Transaction.Amount);
            }
            await ApiCore.DeleteTransaction(transId);

            await App.dashboardViewModel.CallAllLists();

            await _navigation.PopAsync();
        }
Esempio n. 26
0
        /// <summary>
        /// Returns all datacenter with the given id.
        /// </summary>
        /// <returns></returns>
        public static async Task <ServerType> GetAsync(long id)
        {
            ServerType serverType = new ServerType();

            string url = string.Format("/server_types/{0}", id);

            string responseContent = await ApiCore.SendRequest(url);

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

            serverType = GetServerTypeFromResponseData(response.server_type);

            return(serverType);
        }
Esempio n. 27
0
        /// <summary>
        /// Return a ssh-key by the given id.
        /// </summary>
        /// <returns></returns>
        public static async Task <SshKey> GetAsync(long id)
        {
            SshKey sshKey = new SshKey();

            string url = string.Format("/ssh_keys/{0}", id);

            string responseContent = await ApiCore.SendRequest(url);

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

            sshKey = GetSshKeyFromResponseData(response.ssh_key);

            return(sshKey);
        }
        /// <summary>
        /// Returns all datacenter with the given id.
        /// </summary>
        /// <returns></returns>
        public static async Task <PrivateNetwork> GetAsync(long id, string token = null)
        {
            var network = new PrivateNetwork();

            string url = string.Format("/networks/{0}", id);

            string responseContent = await ApiCore.SendRequest(url, token);

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

            network = GetNetworkFromResponseData(response.network);

            return(network);
        }
Esempio n. 29
0
        /// <summary>
        /// Returns all datacenter with the given id.
        /// </summary>
        /// <returns></returns>
        public static async Task <Datacenter> GetAsync(long id)
        {
            Datacenter datacenter = new Datacenter();

            string url = string.Format("/datacenters/{0}", id);

            string responseContent = await ApiCore.SendRequest(url);

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

            datacenter = GetDatacenterFromResponseData(response.datacenter);

            return(datacenter);
        }
        /// <summary>
        /// Returns all datacenter with the given id.
        /// </summary>
        /// <returns></returns>
        public static async Task <Location> GetAsync(long id)
        {
            Location location = new Location();

            string url = string.Format("/locations/{0}", id);

            string responseContent = await ApiCore.SendRequest(url);

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

            location = GetLocationFromResponseData(response.location);

            return(location);
        }