Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isoImage"></param>
        /// <returns></returns>
        private static IsoImage GetIsoImageFromResponseData(Objects.Isos.Get.Iso isoImage)
        {
            IsoImage image = new IsoImage();

            image.Id          = isoImage.id;
            image.Name        = isoImage.name;
            image.Type        = isoImage.type;
            image.Description = isoImage.description;

            if (!string.IsNullOrEmpty(isoImage.deprecated) &&
                !string.IsNullOrWhiteSpace(isoImage.deprecated))
            {
                image.Deprecated = DateTime.Parse(isoImage.deprecated);
            }

            return(image);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns all server in a list.
        /// </summary>
        /// <returns></returns>
        public static async Task <List <IsoImage> > 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 <IsoImage> isoImageList = new List <IsoImage>();

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

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

            string responseContent = await ApiCore.SendRequest(url);

            Objects.Isos.Get.Response response = JsonConvert.DeserializeObject <Objects.Isos.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);

            // load iso-images
            foreach (Objects.Isos.Get.Iso responseIsoImage in response.isos)
            {
                IsoImage isoImage = GetIsoImageFromResponseData(responseIsoImage);

                isoImageList.Add(isoImage);
            }

            return(isoImageList);
        }