/// <summary> /// Разобрать из json. /// </summary> /// <param name="response"> Ответ сервера. </param> /// <returns> </returns> public static GroupUpdate FromJson(VkResponse response) { var fromJson = JsonConvert.DeserializeObject <GroupUpdate>(response.ToString()); var resObj = response["object"]; switch (fromJson.Type) { case GroupLongPollUpdateType.MessageNew: case GroupLongPollUpdateType.MessageEdit: case GroupLongPollUpdateType.MessageReply: fromJson.Message = resObj; fromJson.UserId = fromJson.Message.FromId; break; case GroupLongPollUpdateType.MessageAllow: fromJson.MessageAllow = MessageAllow.FromJson(resObj); fromJson.UserId = fromJson.MessageAllow.UserId; break; case GroupLongPollUpdateType.MessageDeny: fromJson.MessageDeny = MessageDeny.FromJson(resObj); fromJson.UserId = fromJson.MessageDeny.UserId; break; case GroupLongPollUpdateType.PhotoNew: fromJson.Photo = resObj; break; case GroupLongPollUpdateType.PhotoCommentNew: case GroupLongPollUpdateType.PhotoCommentEdit: case GroupLongPollUpdateType.PhotoCommentRestore: fromJson.PhotoComment = PhotoComment.FromJson(resObj); fromJson.UserId = fromJson.PhotoComment.FromId; break; case GroupLongPollUpdateType.PhotoCommentDelete: fromJson.PhotoCommentDelete = PhotoCommentDelete.FromJson(resObj); fromJson.UserId = fromJson.PhotoCommentDelete.DeleterId; break; case GroupLongPollUpdateType.AudioNew: fromJson.Audio = resObj; break; case GroupLongPollUpdateType.VideoNew: fromJson.Video = resObj; break; case GroupLongPollUpdateType.VideoCommentNew: case GroupLongPollUpdateType.VideoCommentEdit: case GroupLongPollUpdateType.VideoCommentRestore: fromJson.VideoComment = VideoComment.FromJson(resObj); fromJson.UserId = fromJson.VideoComment.FromId; break; case GroupLongPollUpdateType.VideoCommentDelete: fromJson.VideoCommentDelete = VideoCommentDelete.FromJson(resObj); fromJson.UserId = fromJson.VideoCommentDelete.DeleterId; break; case GroupLongPollUpdateType.WallPostNew: case GroupLongPollUpdateType.WallRepost: fromJson.WallPost = WallPost.FromJson(resObj); fromJson.UserId = fromJson.WallPost.FromId > 0 ? fromJson.WallPost.FromId : null; break; case GroupLongPollUpdateType.WallReplyNew: case GroupLongPollUpdateType.WallReplyEdit: case GroupLongPollUpdateType.WallReplyRestore: fromJson.WallReply = WallReply.FromJson(resObj); fromJson.UserId = fromJson.WallReply.FromId; break; case GroupLongPollUpdateType.WallReplyDelete: fromJson.WallReplyDelete = WallReplyDelete.FromJson(resObj); fromJson.UserId = fromJson.WallReplyDelete.DeleterId; break; case GroupLongPollUpdateType.BoardPostNew: case GroupLongPollUpdateType.BoardPostEdit: case GroupLongPollUpdateType.BoardPostRestore: fromJson.BoardPost = BoardPost.FromJson(resObj); fromJson.UserId = fromJson.BoardPost.FromId > 0 ? fromJson.BoardPost.FromId : (long?)null; break; case GroupLongPollUpdateType.BoardPostDelete: fromJson.BoardPostDelete = BoardPostDelete.FromJson(resObj); break; case GroupLongPollUpdateType.MarketCommentNew: case GroupLongPollUpdateType.MarketCommentEdit: case GroupLongPollUpdateType.MarketCommentRestore: fromJson.MarketComment = MarketComment.FromJson(resObj); fromJson.UserId = fromJson.MarketComment.FromId; break; case GroupLongPollUpdateType.MarketCommentDelete: fromJson.MarketCommentDelete = MarketCommentDelete.FromJson(resObj); fromJson.UserId = fromJson.MarketCommentDelete.DeleterId; break; case GroupLongPollUpdateType.GroupLeave: fromJson.GroupLeave = GroupLeave.FromJson(resObj); fromJson.UserId = fromJson.GroupLeave.IsSelf == true ? fromJson.GroupLeave.UserId : null; break; case GroupLongPollUpdateType.GroupJoin: fromJson.GroupJoin = GroupJoin.FromJson(resObj); fromJson.UserId = fromJson.GroupJoin.UserId; break; case GroupLongPollUpdateType.UserBlock: fromJson.UserBlock = UserBlock.FromJson(resObj); fromJson.UserId = fromJson.UserBlock.AdminId; break; case GroupLongPollUpdateType.UserUnblock: fromJson.UserUnblock = UserUnblock.FromJson(resObj); fromJson.UserId = fromJson.UserUnblock.ByEndDate == true ? null : fromJson.UserUnblock.AdminId; break; case GroupLongPollUpdateType.PollVoteNew: fromJson.PollVoteNew = PollVoteNew.FromJson(resObj); fromJson.UserId = fromJson.PollVoteNew.UserId; break; case GroupLongPollUpdateType.GroupChangePhoto: fromJson.GroupChangePhoto = GroupChangePhoto.FromJson(resObj); fromJson.UserId = fromJson.GroupChangePhoto.UserId; break; case GroupLongPollUpdateType.GroupOfficersEdit: fromJson.GroupOfficersEdit = GroupOfficersEdit.FromJson(resObj); fromJson.UserId = fromJson.GroupOfficersEdit.AdminId; break; } return(fromJson); }