Пример #1
0
        internal static VkGeo FromJson(JToken json)
        {
            if (json == null)
            {
                throw new Exception("Json can't be null");
            }

            var result = new VkGeo();

            result.Type = (string)json["type"];

            var coordinatesString = (string)json["coordinates"];

            if (!string.IsNullOrEmpty(coordinatesString))
            {
                var coordinates = coordinatesString.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (coordinates.Length == 2)
                {
                    double lat;
                    double.TryParse(coordinates[0], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out lat);

                    double lon;
                    double.TryParse(coordinates[1], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out lon);

                    result.Longitude = lon;
                    result.Latitude  = lat;
                }
            }

            if (json["place"] != null)
            {
                result.Place = VkPlace.FromJson(json["place"]);
            }

            return(result);
        }
Пример #2
0
        public static VkMessage FromJson(JToken json, string apiVersion = null)
        {
            if (json == null)
            {
                throw new Exception("Json can't be null");
            }

            var result = new VkMessage();

            if (json["id"] != null)
            {
                result.Id = (long)json["id"];
            }

            if (json["user_id"] != null)
            {
                result.UserId = (long)json["user_id"];
            }
            result.Date = DateTimeExtensions.UnixTimeStampToDateTime((long)json["date"]);

            if (json["read_state"] != null)
            {
                result.IsRead = (int)json["read_state"] == 1;
            }

            if (json["out"] != null)
            {
                result.IsOut = (int)json["out"] == 1;
            }

            result.Title = (string)json["title"];
            result.Body  = (string)json["body"];

            if (json["deleted"] != null)
            {
                result.IsDeleted = (int)json["deleted"] == 1;
            }

            if (json["attachments"] != null)
            {
                result.Attachments = VkAttachment.FromJson(json["attachments"]);
            }

            if (json["geo"] != null)
            {
                result.Geo = VkGeo.FromJson(json["geo"]);
            }

            if (json["fwd_messages"] != null)
            {
                result.ForwardMessages = new List <VkMessage>();
                foreach (var fwdMessage in json["fwd_messages"])
                {
                    var message = VkMessage.FromJson(fwdMessage);
                    result.ForwardMessages.Add(message);
                }
            }

            if (json["emoji"] != null)
            {
                result.ContainsEmoji = (int)json["emoji"] == 1;
            }

            if (json["chat_id"] != null)
            {
                result.ChatId = (long)json["chat_id"];
            }

            if (json["chat_active"] != null)
            {
                result.ChatUsers = json["chat_active"].Select(t => t.Value <long>()).ToList();
            }

            if (json["users_count"] != null)
            {
                result.UsersCount = (int)json["users_count"];
            }

            if (json["admin_id"] != null)
            {
                result.AdminId = (long)json["admin_id"];
            }

            if (json["action"] != null)
            {
                result.Action = (string)json["action"];
            }

            if (json["action_text"] != null)
            {
                result.ActionText = (string)json["action_text"];
            }

            if (json["photo_50"] != null)
            {
                result.Photo50 = (string)json["photo_50"];
            }

            if (json["photo_100"] != null)
            {
                result.Photo100 = (string)json["photo_100"];
            }

            if (json["photo_200"] != null)
            {
                result.Photo200 = (string)json["photo_200"];
            }

            return(result);
        }