Esempio n. 1
0
 public static UpdateInfo FromJson(ApiResponse response)
 {
     return(new UpdateInfo
     {
         Version = response["version"],
         Description = response["description"],
         Link = response["link"],
         Date = response["date"]
     });
 }
Esempio n. 2
0
 public static NoticeInfo FromJson(ApiResponse response)
 {
     return(new NoticeInfo
     {
         Id = response["id"],
         Text = response["text"],
         Image = response["image"],
         Link = response["link"]
     });
 }
Esempio n. 3
0
 public static LicenseInfo FromJson(ApiResponse response)
 {
     return(new LicenseInfo
     {
         Code = response["code"],
         Message = response["message"],
         Expires = response["expires"],
         ActiveFrom = response["active_from"],
         BannedTo = response["banned_to"],
         BannedInfo = response["banned_info"]
     });
 }
Esempio n. 4
0
        public static ApiCollection <T> ToApiCollectionOf <T>(this SkServ.Utils.ApiResponse response, Func <SkServ.Utils.ApiResponse, T> selector)
        {
            if (response == null)
            {
                return(new ApiCollection <T>(0, Enumerable.Empty <T>()));
            }

            var data             = response.ContainsKey("items") ? response["items"] : response;
            var resultCollection = data.ToCollectionOf(selector);
            var totalCount       = response.ContainsKey("count") ? response["count"] : (ulong)resultCollection.Count;

            return(new ApiCollection <T>(totalCount, resultCollection));
        }
Esempio n. 5
0
        public static List <T> ToListOf <T>(this SkServ.Utils.ApiResponse response, Func <SkServ.Utils.ApiResponse, T> selector)
        {
            if (response == null)
            {
                return(new List <T>());
            }

            var responseArray = (ApiResponseArray)response;

            if (responseArray == null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false.
            {
                return(new List <T>());
            }

            return(responseArray.Select(selector).Where(i => i != null).ToList()); //TODO: V3111 http://www.viva64.com/en/w/V3111 Checking value of 'i' for null will always return false when generic type is instantiated with a value type.
        }
Esempio n. 6
0
        public static ReadOnlyCollection <T> ToReadOnlyCollectionOf <T>(
            this SkServ.Utils.ApiResponse response, Func <SkServ.Utils.ApiResponse, T> selector) where T : class
        {
            if (response == null)
            {
                return(new ReadOnlyCollection <T>(new List <T>()));
            }

            var responseArray = (ApiResponseArray)response;

            if (responseArray == null) //TODO: V3022 http://www.viva64.com/en/w/V3022 Expression 'responseArray == null' is always false.
            {
                return(new ReadOnlyCollection <T>(new List <T>()));
            }

            return(responseArray.Select(selector).Where(i => i != null).ToReadOnlyCollection());
        }
Esempio n. 7
0
 /// <summary>
 /// Получение идентификатора.
 ///
 /// Применять когда id может быть задано как строкой так и числом в json'e.
 /// </summary>
 /// <param name="response">Ответ от сервера vk.com</param>
 /// <returns>Число типа long или null</returns>
 public static long?GetNullableLongId(SkServ.Utils.ApiResponse response)
 {
     return(!string.IsNullOrWhiteSpace(response?.ToString()) ? System.Convert.ToInt64(response.ToString()) : (long?)null);
 }