From a4f2c7dc7fdd8579651a9f5179847b64311b2aaa Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 25 Aug 2018 15:57:18 +0200 Subject: [PATCH] - added the post loading for server-type. --- cloud-api-net/Api/FloatingIp.cs | 13 ++- cloud-api-net/Api/ServerType.cs | 171 ++++++++++++++++++++++++++++++-- 2 files changed, 171 insertions(+), 13 deletions(-) diff --git a/cloud-api-net/Api/FloatingIp.cs b/cloud-api-net/Api/FloatingIp.cs index dcf4079..a62d85a 100644 --- a/cloud-api-net/Api/FloatingIp.cs +++ b/cloud-api-net/Api/FloatingIp.cs @@ -7,9 +7,11 @@ namespace lkcode.hetznercloudapi.Api { public class FloatingIp { + #region # public properties # + private bool _isInitialized { get; set; } /// - /// If false, this floating-ip is not loaded (only the object from the server). access a field like floatingIp.Description and the object will load the data in the background. + /// If false, this floating-ip is not loaded (only the object with the id). access a field like floatingIp.Description and the object will load the data in the background. /// public bool IsInitialized { @@ -175,6 +177,10 @@ public List DnsPointer } } + #endregion + + #region # public methods # + /// /// /// @@ -184,8 +190,10 @@ public FloatingIp(int id) this._id = id; } + #endregion + #region # public methods # - + /// /// Returns a floating-id by the given id. /// @@ -235,6 +243,7 @@ private async void LoadData() this.Protection = floatingIp.Protection; this.DnsPointer = floatingIp.DnsPointer; this.HomeLocation = floatingIp.HomeLocation; + this._isInitialized = true; } diff --git a/cloud-api-net/Api/ServerType.cs b/cloud-api-net/Api/ServerType.cs index d48dc9f..9f0c442 100644 --- a/cloud-api-net/Api/ServerType.cs +++ b/cloud-api-net/Api/ServerType.cs @@ -41,50 +41,173 @@ public static int MaxPages #region # public properties # + private bool _isInitialized { get; set; } + /// + /// If false, this server-type is not loaded (only the object with the id). access a field like serverType.Description and the object will load the data in the background. + /// + public bool IsInitialized + { + get + { + return this._isInitialized; + } + } + + private long _id { get; set; } /// /// ID of the server type. /// - public int Id { get; set; } + public long Id + { + get + { + return this._id; + } + } + private string _name { get; set; } /// /// Unique identifier of the server type. /// - public string Name { get; set; } + public string Name + { + get + { + this.LoadData(); // load data if not initialized + + return this._name; + } + set + { + this._name = value; + } + } + private string _description { get; set; } /// /// Description of the server type. /// - public string Description { get; set; } + public string Description + { + get + { + this.LoadData(); // load data if not initialized + return this._description; + } + set + { + this._description = value; + } + } + + private int _cores { get; set; } /// /// Number of cpu cores a server of this type will have. /// - public int Cores { get; set; } + public int Cores + { + get + { + this.LoadData(); // load data if not initialized + return this._cores; + } + set + { + this._cores = value; + } + } + + private double _memory { get; set; } /// /// Memory a server of this type will have in GB. /// - public double Memory { get; set; } + public double Memory + { + get + { + this.LoadData(); // load data if not initialized + + return this._memory; + } + set + { + this._memory = value; + } + } + private int _disc { get; set; } /// /// Disk size a server of this type will have in GB. /// - public int Disc { get; set; } + public int Disc + { + get + { + this.LoadData(); // load data if not initialized + + return this._disc; + } + set + { + this._disc = value; + } + } + private string _storageType { get; set; } /// /// Type of server boot drive. Local has higher speed. Network has better availability.. /// - public string StorageType { get; set; } + public string StorageType + { + get + { + this.LoadData(); // load data if not initialized + + return this._storageType; + } + set + { + this._storageType = value; + } + } + private string _cpuType { get; set; } /// /// Type of cpu. /// - public string CpuType { get; set; } + public string CpuType + { + get + { + this.LoadData(); // load data if not initialized + return this._cpuType; + } + set + { + this._cpuType = value; + } + } + + private List _prices { get; set; } /// /// Prices in different ServerTypes. /// - public List Prices { get; set; } + public List Prices + { + get + { + this.LoadData(); // load data if not initialized + + return this._prices; + } + set + { + this._prices = value; + } + } #endregion @@ -202,13 +325,38 @@ public ServerType() public ServerType(int id) { - this.Id = id; + this._id = id; } #endregion #region # private methods for processing # + /// + /// loads the data for this floating-ip. + /// + private async void LoadData() + { + if (this.IsInitialized) + { + return; + } + + ServerType serverType = await GetAsync(this.Id); + + serverType._id = serverType.Id; + serverType.Name = serverType.Name; + serverType.Description = serverType.Description; + serverType.Cores = serverType.Cores; + serverType.CpuType = serverType.CpuType; + serverType.Disc = serverType.Disc; + serverType.Memory = serverType.Memory; + serverType.StorageType = serverType.StorageType; + serverType.Prices = serverType.Prices; + + this._isInitialized = true; + } + /// /// /// @@ -218,7 +366,8 @@ private static ServerType GetServerTypeFromResponseData(Objects.ServerType.Unive { ServerType serverType = new ServerType(); - serverType.Id = responseData.id; + serverType._isInitialized = true; + serverType._id = responseData.id; serverType.Name = responseData.name; serverType.Description = responseData.description; serverType.Cores = responseData.cores;