コード例 #1
0
ファイル: Chat.cs プロジェクト: pakimov863/VKClient2
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static Chat FromJson(VkResponse response)
        {
            var chat = new Chat
            {
                Id      = response["id"],
                Type    = response["type"],
                Title   = response["title"],
                AdminId = Utilities.GetNullableLongId(response["admin_id"]),
                Users   = response["users"],

                #region Поля найденые експерементально

                Left = response.ContainsKey("left") && response["left"]
            };

            if (response.ContainsKey("push_settings"))
            {
                chat.Sound         = response["push_settings"]["sound"];
                chat.DisabledUntil = response["push_settings"]["disabled_until"];
            }
            else
            {
                chat.Sound         = null;
                chat.DisabledUntil = null;
            }
            #endregion

            return(chat);
        }
コード例 #2
0
ファイル: Message.cs プロジェクト: igofed/vk
        internal static Message FromJson(VkResponse response)
        {
            var message = new Message();

            message.Unread = response.ContainsKey("unread") ? response["unread"] : 0;

            if (response.ContainsKey("message"))
            {
                response = response["message"];
            }

            message.Id                  = response["id"];
            message.UserId              = response["user_id"];
            message.Date                = response["date"];
            message.ReadState           = response["read_state"];
            message.Type                = response["out"];
            message.Title               = response["title"];
            message.Body                = response["body"];
            message.Attachments         = response["attachments"];
            message.Geo                 = response["geo"];
            message.ForwardedMessages   = response["fwd_messages"];
            message.ContainsEmojiSmiles = response["emoji"];
            message.IsImportant         = response["important"];
            message.IsDeleted           = response["deleted"];

            // дополнительные поля бесед

            message.ChatId        = response["chat_id"];
            message.ChatActiveIds = response["chat_active"];
            message.UsersCount    = response["users_count"];
            message.AdminId       = response["admin_id"];
            message.PhotoPreviews = response;

            return(message);
        }
コード例 #3
0
ファイル: Chat.cs プロジェクト: kadkin/vk
		/// <summary>
		/// Разобрать из json.
		/// </summary>
		/// <param name="response">Ответ сервера.</param>
		/// <returns></returns>
		internal static Chat FromJson(VkResponse response)
		{
			var chat = new Chat
			{
				Id = response["id"],
				Type = response["type"],
				Title = response["title"],
				AdminId = Utilities.GetNullableLongId(response["admin_id"]),
				Users = response["users"],

				#region Поля найденые експерементально

				Left = response.ContainsKey("left") && response["left"]
			};
			if (response.ContainsKey("push_settings"))
			{
				chat.Sound = response["push_settings"]["sound"];
				chat.DisabledUntil = response["push_settings"]["disabled_until"];
			} else
			{
				chat.Sound = null;
				chat.DisabledUntil = null;
			}
			#endregion

			return chat;
		}
コード例 #4
0
ファイル: Chat.cs プロジェクト: HEYHEYHEEEEY/vk
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static Chat FromJson(VkResponse response)
        {
            var chat = new Chat
            {
                Id           = response["id"],
                Type         = response["type"],
                Title        = response["title"],
                AdminId      = Utilities.GetNullableLongId(response["admin_id"]),
                Users        = response["users"].ToReadOnlyCollectionOf <long>(x => x),
                Left         = response.ContainsKey("left") && response["left"],
                Kicked       = response["kicked"],
                Photo50      = response["photo_50"],
                Photo100     = response["photo_100"],
                Photo200     = response["photo_200"],
                PushSettings = response["push_settings"]
            };

            #region Поля найденые експерементально
            if (response.ContainsKey("push_settings"))
            {
                chat.Sound         = response["push_settings"]["sound"];
                chat.DisabledUntil = response["push_settings"]["disabled_until"];
            }
            else
            {
                chat.Sound         = null;
                chat.DisabledUntil = null;
            }
            #endregion

            return(chat);
        }
コード例 #5
0
ファイル: PushSettings.cs プロジェクト: ProESM/vk
		/// <summary>
		/// Разобрать из json.
		/// </summary>
		/// <param name="response">Ответ сервера.</param>
		/// <returns></returns>
		internal static PushSettings FromJson(VkResponse response)
		{
			var settings = new PushSettings
			{
				Sound = response.ContainsKey("sound") && response["sound"],
				DisabledUntil = response.ContainsKey("disabled_until") ? response["disabled_until"] : null
			};
			return settings;
		}
コード例 #6
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static PushSettings FromJson(VkResponse response)
        {
            var settings = new PushSettings
            {
                Sound         = response.ContainsKey("sound") && response["sound"],
                DisabledUntil = response.ContainsKey("disabled_until") ? response["disabled_until"] : null
            };

            return(settings);
        }
コード例 #7
0
        /// <summary>
        /// </summary>
        /// <param name="response"> </param>
        /// <returns> </returns>
        public static Message FromJson(VkResponse response)
        {
            if (response.ContainsKey("message"))
            {
                response = response["message"];
            }

            var message = new Message
            {
                Unread            = response.ContainsKey("unread") ? response["unread"] : 0,
                Id                = response["id"],
                UserId            = response["user_id"],
                Date              = response["date"],
                PeerId            = response["peer_id"],
                FromId            = response["from_id"],
                Text              = response["text"],
                RandomId          = response["random_id"],
                Attachments       = response["attachments"].ToReadOnlyCollectionOf <Attachment>(x => x),
                Important         = response["important"],
                Geo               = response["geo"],
                Payload           = response["payload"],
                ForwardedMessages = response["fwd_messages"].ToReadOnlyCollectionOf <Message>(x => x),
                ReadState         = response["read_state"],
                Action            = response["action"],
                Type              = response["out"],
                Title             = response["title"],
                Body              = response["body"],
                Emoji             = response["emoji"],
                Deleted           = response["deleted"],

                // дополнительные поля бесед
                ChatId        = response["chat_id"],
                ChatActive    = response["chat_active"].ToReadOnlyCollectionOf <long>(x => x),
                UsersCount    = response["users_count"],
                AdminId       = response["admin_id"],
                PhotoPreviews = response,
                PushSettings  = response["push_settings"],
                ActionMid     = response["action_mid"],
                ActionEmail   = response["action_email"],
                ActionText    = response["action_text"],
                Photo50       = response["photo_50"],
                Photo100      = response["photo_100"],
                Photo200      = response["photo_200"],
                InRead        = response["in_read"],
                OutRead       = response["out_read"],
                Out           = response["out"],
                UpdateTime    = response["update_time"],

                Keyboard = response["keyboard"]
            };

            return(message);
        }
コード例 #8
0
ファイル: WallGetObject.cs プロジェクト: HappyIllumd/vk
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static WallGetObject FromJson(VkResponse response)
        {
            WallGetObject wallGetObject;

            if (response.ContainsKey("items"))
            {
                wallGetObject = new WallGetObject
                {
                    WallPosts  = response["items"].ToReadOnlyCollectionOf <Post>(r => r),
                    Profiles   = response["profiles"].ToReadOnlyCollectionOf <User>(r => r),
                    Groups     = response["groups"].ToReadOnlyCollectionOf <Group>(r => r),
                    TotalCount = response["count"] ?? 1UL
                };
            }
            else
            {
                wallGetObject = new WallGetObject
                {
                    WallPosts = response.ToReadOnlyCollectionOf <Post>(r => r)
                };
                wallGetObject.TotalCount = (ulong)wallGetObject.WallPosts.Count;
            }

            return(wallGetObject);
        }
コード例 #9
0
ファイル: Previews.cs プロジェクト: kadkin/vk
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static Previews FromJson(VkResponse response)
        {

            var previews = new Previews
            {
                Photo50 = response["photo_50"],
                Photo100 = response["photo_100"] ?? response["photo_medium"],
                Photo130 = response["photo_130"],
                Photo200 = response["photo_200"] ?? response["photo_200_orig"],
                Photo400 = response["photo_400_orig"]
            };
            if (response.ContainsKey("photo"))
            {
                if (Uri.IsWellFormedUriString(response["photo"].ToString(), UriKind.Absolute))
                {
                    previews.Photo50 = response["photo"];
                }
                else
                {
                    previews.Photo = response["photo"];
                }
            }
            
            previews.PhotoMax = response["photo_max"] ?? response["photo_max_orig"] ?? response["photo_big"] ?? previews.Photo400 ?? previews.Photo200 ?? previews.Photo100 ?? previews.Photo50;

            return previews;
        }
コード例 #10
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static WallGetObject FromJson(VkResponse response)
        {
            WallGetObject wallGetObject;

            if (response.ContainsKey("items"))
            {
                wallGetObject = new WallGetObject
                {
                    WallPosts = response["items"].ToReadOnlyCollectionOf <Post>(r => r),
                    Profiles  = response["profiles"].ToReadOnlyCollectionOf <User>(r => r),
                    Groups    = response["groups"].ToReadOnlyCollectionOf <Group>(r => r)
                };
                if (response["count"] != null)
                {
                    wallGetObject.TotalCount = response["count"];
                }
                else
                {
                    wallGetObject.TotalCount = 1;
                }
            }
            else
            {
                wallGetObject = new WallGetObject
                {
                    WallPosts = response.ToReadOnlyCollectionOf <Post>(r => r)
                };
            }

            return(wallGetObject);
        }
コード例 #11
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static Previews FromJson(VkResponse response)
        {
            var previews = new Previews
            {
                Photo50  = response["photo_50"],
                Photo100 = response["photo_100"] ?? response["photo_medium"],
                Photo130 = response["photo_130"],
                Photo200 = response["photo_200"] ?? response["photo_200_orig"],
                Photo400 = response["photo_400_orig"]
            };

            if (response.ContainsKey("photo"))
            {
                if (Uri.IsWellFormedUriString(response["photo"].ToString(), UriKind.Absolute))
                {
                    previews.Photo50 = response["photo"];
                }
                else
                {
                    previews.Photo = response["photo"];
                }
            }

            previews.PhotoMax = response["photo_max"] ?? response["photo_max_orig"] ?? response["photo_big"] ?? previews.Photo400 ?? previews.Photo200 ?? previews.Photo100 ?? previews.Photo50;

            return(previews);
        }
コード例 #12
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static PollAnswerVoters FromJson(VkResponse response)
        {
            bool isLongMode = false;

            if (response.ContainsKey("users") &&
                response["users"].ContainsKey("items"))
            {
                var array = (VkResponseArray)response["users"]["items"];
                if (array.Count > 0 && !array[0].ContainsKey("id"))
                {
                    isLongMode = true;
                }
            }
            var answer = new PollAnswerVoters
            {
                AnswerId = response["answer_id"],
            };

            if (isLongMode)
            {
                answer.UsersIds = response["users"].ToVkCollectionOf <long>(x => x);
            }
            else
            {
                answer.Users = response["users"].ToVkCollectionOf <User>(x => x);
            }

            return(answer);
        }
コード例 #13
0
        internal static PhotoAlbum FromJson(VkResponse response)
        {
            var album = new PhotoAlbum();

            if (response.ContainsKey("aid"))
            {
                album.Id = response["aid"];
            }
            else
            {
                album.Id = response["id"];
            }
            album.ThumbId        = Utilities.GetNullableLongId(response["thumb_id"]);
            album.OwnerId        = Utilities.GetNullableLongId(response["owner_id"]);
            album.Title          = response["title"];
            album.Description    = response["description"];
            album.Created        = response["created"];
            album.Updated        = response["updated"];
            album.Size           = response["size"];
            album.Privacy        = Utilities.GetNullableLongId(response["privacy"]);
            album.CommentPrivacy = Utilities.GetNullableLongId(response["comment_privacy"]);
            album.CanUpload      = response["can_upload"];
            album.PrivacyView    = response["privacy_view"];
            album.ThumbSrc       = response["thumb_src"];

            return(album);
        }
コード例 #14
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response"> Ответ сервера. </param>
        /// <returns> </returns>
        public static GroupsLongPollHistoryResponse FromJson(VkResponse response)
        {
            if (response.ContainsKey("failed"))
            {
                int code = response["failed"];
                if (code == 1)
                {
                    throw new BotsLongPollHistoryOutdateException(response["ts"]);
                }
                if (code == 2)
                {
                    throw new BotsLongPollHistoryKeyExpiredException();
                }
                if (code == 3)
                {
                    throw new BotsLongPollHistoryInfoLostException();
                }
            }

            var fromJson = new GroupsLongPollHistoryResponse
            {
                Ts = response["ts"],
            };

            VkResponseArray updates    = response[key : "updates"];
            var             updateList = new List <GroupUpdate>();

            foreach (var update in updates)
            {
                updateList.Add(GroupUpdate.FromJson(update));
            }

            fromJson.Updates = updateList;
            return(fromJson);
        }
コード例 #15
0
        public ReadOnlyCollection <Message> GetDialogs(out int totalCount, out int unreadCount, uint count = 20, int?offset = null, bool unread = false, long?startMessageId = null, int?previewLength = null)
        {
            var parameters = new VkParameters
            {
                { "start_message_id", startMessageId },
                { "offset", offset },
                { "unread", unread },
                { "preview_length", previewLength }
            };

            if (count <= 200)
            {
                parameters.Add("count", count);
            }
            VkResponse response = _vk.Call("messages.getDialogs", parameters);

            // При загрузке списка непрочитанных диалогов в параметре count передается значение unreadCount,
            // а значение totalCount не возвращаеться
            totalCount = response["count"];
            VkResponseArray items = response["items"];

            if (unread)
            {
                unreadCount = totalCount;
            }
            else
            {
                unreadCount = response.ContainsKey("unread_dialogs") ? response["unread_dialogs"] : 0;
            }
            return(items.ToReadOnlyCollectionOf <Message>(r => r));
        }
コード例 #16
0
ファイル: Message.cs プロジェクト: 8Observer8/vk
        internal static Message FromJson(VkResponse response)
        {
            if (response.ContainsKey("message"))
            {
                response = response["message"];
            }
            var message = new Message
            {
                Unread              = response.ContainsKey("unread") ? response["unread"] : 0,
                Id                  = response["id"],
                UserId              = response["user_id"],
                Date                = response["date"],
                ReadState           = response["read_state"],
                Type                = response["out"],
                Title               = response["title"],
                Body                = response["body"],
                Attachments         = response["attachments"],
                Geo                 = response["geo"],
                ForwardedMessages   = response["fwd_messages"],
                ContainsEmojiSmiles = response["emoji"],
                IsImportant         = response["important"],
                IsDeleted           = response["deleted"],
                FromId              = response["from_id"],
                // дополнительные поля бесед
                ChatId        = response["chat_id"],
                ChatActiveIds = response["chat_active"],
                UsersCount    = response["users_count"],
                AdminId       = response["admin_id"],
                PhotoPreviews = response,
                PushSettings  = response["push_settings"],
                Action        = response["action"],
                ActionMid     = response["action_mid"],
                ActionEmail   = response["action_email"],
                ActionText    = response["action_text"],
                Photo50       = response["photo_50"],
                Photo100      = response["photo_100"],
                Photo200      = response["photo_200"],

                InRead  = response["in_read"],
                OutRead = response["out_read"]
            };


            return(message);
        }
コード例 #17
0
        internal static Relative FromJson(VkResponse response)
        {
            var relative = new Relative();

            // Согласно документации VK API, должно возвращаться поле id, однако фактически может возвращаться uid (для старых версий API).
            // Можно будет парсить только id после перевода всех методов на более новые версии (как минимум Users.Search).
            if (response.ContainsKey("id"))
            {
                relative.Id = response["id"];
            }
            else if (response.ContainsKey("uid"))
            {
                relative.Id = response["uid"];
            }

            relative.Type = response["type"];
            relative.Name = response["name"];

            return(relative);
        }
コード例 #18
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        internal static Group FromJson(VkResponse response)
        {
            var group = new Group();

            group.Id            = response["id"] ?? response["gid"];
            group.Name          = response["name"];
            group.ScreenName    = response["screen_name"];
            group.IsClosed      = response["is_closed"];
            group.IsAdmin       = response["is_admin"];
            group.AdminLevel    = response["admin_level"];
            group.IsMember      = response["is_member"];
            group.Type          = response["type"];
            group.PhotoPreviews = response;

            // опциональные поля
            group.CityId             = response.ContainsKey("city") ? response["city"]["id"] : null;
            group.CountryId          = response.ContainsKey("country") ? response["country"]["id"] : null;
            group.Place              = response["place"];
            group.Description        = response["description"];
            group.WikiPage           = response["wiki_page"];
            group.MembersCount       = response["members_count"];
            group.Counters           = response["counters"];
            group.StartDate          = response["start_date"];
            group.EndDate            = response["finish_date"] ?? response["end_date"];
            group.CanPost            = response["can_post"];
            group.CanSeelAllPosts    = response["can_see_all_posts"];
            group.CanUploadDocuments = response["can_upload_doc"];
            group.CanCreateTopic     = response["can_create_topic"];
            group.Activity           = response["activity"];
            group.Status             = response["status"];
            group.Contacts           = response["contacts"];
            group.Links              = response["links"];
            group.FixedPostId        = response["fixed_post"];
            group.IsVerified         = response["verified"];
            group.Site       = response["site"];
            group.InvitedBy  = response["invited_by"];
            group.IsFavorite = response["is_favorite"];
            group.BanInfo    = response["ban_info"];

            return(group);
        }
コード例 #19
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static PushSettings FromJson(VkResponse response)
        {
            var result = new PushSettings
            {
                Msg            = response["msg"],
                Chat           = response["chat"],
                Friend         = response.ContainsKey("friend") && response["mutual"],
                FriendFound    = response["friend_found"],
                FriendAccepted = response["friend_accepted"],
                Reply          = response["reply"],
                Comment        = response.ContainsKey("comment") && response["fr_of_fr"],
                Mention        = response.ContainsKey("mention") && response["fr_of_fr"],
                Like           = response.ContainsKey("like") && response["fr_of_fr"],
                Repost         = response.ContainsKey("repost") && response["fr_of_fr"],
                WallPost       = response["wall_post"],
                WallPublish    = response["wall_publish"],
                GroupInvite    = response["group_invite"],
                GroupAccepted  = response["group_accepted"],
                EventSoon      = response["event_soon"],
                TagPhoto       = response.ContainsKey("tag_photo") && response["fr_of_fr"],
                AppRequest     = response["app_request"],
                SdkOpen        = response["sdk_open"],
                NewPost        = response["new_post"],
                Birthday       = response["birthday"]
            };

            return(result);
        }
コード例 #20
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response"> Ответ сервера. </param>
        /// <returns> </returns>
        public static Coordinates FromJson(VkResponse response)
        {
            // TODO: TEST IT!!!!!

            double latitude;
            double longitude;

            if (response.ContainsKey("latitude") && response.ContainsKey("longitude"))             //приходит в messages.geo
            {
                latitude  = response["latitude"];
                longitude = response["longitude"];
            }
            else             //geo со стены
            {
                var latitudeWithLongitude = ((string)response).Split(' ');

                if (latitudeWithLongitude.Length != 2)
                {
                    throw new VkApiException(message: "Coordinates must have latitude and longitude!");
                }

                if (!double.TryParse(s: latitudeWithLongitude[0].Replace(oldValue: ".", newValue: ","), result: out latitude))
                {
                    throw new VkApiException(message: "Invalid latitude!");
                }

                if (!double.TryParse(s: latitudeWithLongitude[1].Replace(oldValue: ".", newValue: ","), result: out longitude))
                {
                    throw new VkApiException(message: "Invalid longitude!");
                }
            }
            var coordinates = new Coordinates
            {
                Latitude  = latitude,
                Longitude = longitude
            };

            return(coordinates);
        }
コード例 #21
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response"> Ответ сервера. </param>
        /// <returns> </returns>
        public static FriendOnline FromJson(VkResponse response)
        {
            if (response.ContainsKey(key: "online"))
            {
                return(new FriendOnline
                {
                    MobileOnline = response[key : "online_mobile"].ToReadOnlyCollectionOf <long>(selector : x => x)
                    , Online = response[key : "online"].ToReadOnlyCollectionOf <long>(selector : x => x)
                });
            }

            return(new FriendOnline
            {
                Online = response.ToReadOnlyCollectionOf <long>(selector: x => x)
            });
        }
コード例 #22
0
ファイル: Chat.cs プロジェクト: HappyIllumd/vk
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static Chat FromJson(VkResponse response)
        {
            var chat = new Chat
            {
                Id           = response["id"],
                Type         = response["type"],
                Title        = response["title"],
                AdminId      = Utilities.GetNullableLongId(response["admin_id"]),
                Users        = response["users"].ToReadOnlyCollectionOf <long>(x => x),
                Left         = response.ContainsKey("left") && response["left"],
                Kicked       = response["kicked"],
                Photo50      = response["photo_50"],
                Photo100     = response["photo_100"],
                Photo200     = response["photo_200"],
                PushSettings = response["push_settings"]
            };

            return(chat);
        }
コード例 #23
0
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response"> Ответ сервера. </param>
        /// <returns> </returns>
        /// <exception cref="System.Exception">
        /// "Типа '{0}' не существует. Пожалуйста заведите задачу на сайте проекта:
        /// https://github.com/vknet/vk/issues"
        /// </exception>
        public static UserOrGroup FromJson(VkResponse response)
        {
            var userOrGroup = new UserOrGroup
            {
                Users    = new List <User>()
                , Groups = new List <Group>()
            };

            if (response.ContainsKey(key: "count"))
            {
                userOrGroup.TotalCount = response[key : "count"];
            }

            VkResponseArray result = response;

            foreach (var item in result)
            {
                switch (item[key: "type"].ToString())
                {
                case "group":

                {
                    Group group = item;
                    userOrGroup.Groups.Add(item: group);
                }

                break;

                case "profile":

                {
                    User user = item;
                    userOrGroup.Users.Add(item: user);
                }

                break;

                default:

                {
                    throw new VkApiException(message:
                                             $"Типа '{item[key: "type"]}' не существует. Пожалуйста заведите задачу на сайте проекта: https://github.com/vknet/vk/issues");
コード例 #24
0
ファイル: UserOrGroup.cs プロジェクト: wowbios/vk
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">"Типа '{0}' не существует. Пожалуйста заведите задачу на сайте проекта: https://github.com/vknet/vk/issues"</exception>
        public static UserOrGroup FromJson(VkResponse response)
        {
            var userOrGroup = new UserOrGroup
            {
                Users  = new List <User>(),
                Groups = new List <Group>()
            };

            if (response.ContainsKey("count"))
            {
                userOrGroup.TotalCount = response["count"];
            }

            VkResponseArray result = response;

            foreach (var item in result)
            {
                switch (item["type"].ToString())
                {
                case "group":
                {
                    Group @group = item;
                    userOrGroup.Groups.Add(@group);
                }
                break;

                case "profile":
                {
                    User user = item;
                    userOrGroup.Users.Add(user);
                }
                break;

                default:
                {
                    throw new System.Exception(string.Format("Типа '{0}' не существует. Пожалуйста заведите задачу на сайте проекта: https://github.com/vknet/vk/issues", item["type"]));
                }
                }
            }
            return(userOrGroup);
        }
コード例 #25
0
        public ReadOnlyCollection <Message> GetDialogs(int count, int offset, out int totalCount, out int unreadCount, bool unread = false, long?userId = null, long?chatId = null, int?previewLength = null)
        {
            var parameters = new VkParameters {
                { "uid", userId }, { "chat_id", chatId }, { "count", count }, { "offset", offset }, { "unread", unread ? "1" : "0" }, { "preview_length", previewLength }
            };

            VkResponse response = _vk.Call("messages.getDialogs", parameters);

            // При загрузке списка непрочитанных диалогов в параметре count передаеться значение unreadCount,
            // а значение totalCount не возвращаеться
            totalCount = response["count"];
            if (unread)
            {
                unreadCount = totalCount;
            }
            else
            {
                unreadCount = response.ContainsKey("unread_dialogs") ? response["unread_dialogs"] : 0;
            }

            return(response["items"].ToReadOnlyCollectionOf <Message>(r => r));
        }
コード例 #26
0
ファイル: AppGetObject.cs プロジェクト: wowbios/vk
        /// <summary>
        /// Разобрать из json.
        /// </summary>
        /// <param name="response">Ответ сервера.</param>
        /// <returns></returns>
        public static AppGetObject FromJson(VkResponse response)
        {
            AppGetObject appGetObject;

            if (response.ContainsKey("items"))
            {
                appGetObject = new AppGetObject
                {
                    TotalCount = response["count"],
                    Apps       = response["items"].ToVkCollectionOf <App>(r => r),
                    Friends    = response["profiles"].ToVkCollectionOf <User>(r => r)
                };
            }
            else
            {
                appGetObject = new AppGetObject
                {
                    TotalCount = response["count"],
                    Apps       = response["items"].ToVkCollectionOf <App>(r => r)
                };
            }

            return(appGetObject);
        }
コード例 #27
0
ファイル: Message.cs プロジェクト: ProESM/vk
		internal static Message FromJson(VkResponse response)
		{
			if (response.ContainsKey("message"))
			{
				response = response["message"];
			}
			var message = new Message
			{
				Unread = response.ContainsKey("unread") ? response["unread"] : 0,
				Id = response["id"],
				UserId = response["user_id"],
				Date = response["date"],
				ReadState = response["read_state"],
				Type = response["out"],
				Title = response["title"],
				Body = response["body"],
				Attachments = response["attachments"],
				Geo = response["geo"],
				ForwardedMessages = response["fwd_messages"],
				ContainsEmojiSmiles = response["emoji"],
				IsImportant = response["important"],
				IsDeleted = response["deleted"],
				FromId = response["from_id"],
				// дополнительные поля бесед
				ChatId = response["chat_id"],
				ChatActiveIds = response["chat_active"],
				UsersCount = response["users_count"],
				AdminId = response["admin_id"],
				PhotoPreviews = response,
				PushSettings = response["push_settings"],
				Action = response["action"],
				ActionMid = response["action_mid"],
				ActionEmail = response["action_email"],
				ActionText = response["action_text"],
				Photo50 = response["photo_50"],
				Photo100 = response["photo_100"],
				Photo200 = response["photo_200"],

				InRead = response["in_read"],
				OutRead = response["out_read"]
			};


			return message;
		}
コード例 #28
0
ファイル: Message.cs プロジェクト: SaintCat/VkBot
        internal static Message FromJson(VkResponse response)
        {
            var message = new Message();

            message.Unread = response.ContainsKey("unread") ? response["unread"] : 0;

            if (response.ContainsKey("message"))
                response = response["message"];

            message.Id = response["id"];
            message.UserId = response["user_id"];
            message.Date = response["date"];
            message.ReadState = response["read_state"];
            message.Type = response["out"];
            message.Title = response["title"];
            message.Body = response["body"];
            message.Attachments = response["attachments"];
            message.Geo = response["geo"];
            message.ForwardedMessages = response["fwd_messages"];
            message.ContainsEmojiSmiles = response["emoji"];
            message.IsImportant = response["important"];
            message.IsDeleted = response["deleted"];

            // дополнительные поля бесед

            message.ChatId = response["chat_id"];
            message.ChatActiveIds = response["chat_active"];
            message.UsersCount = response["users_count"];
            message.AdminId = response["admin_id"];
            message.PhotoPreviews = response;

            return message;
        }