Exemplo n.º 1
0
        /// <summary>
        /// Parses the specified json object.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        internal MessageInfo(JObject jsonObject)
        {
            MessageId = jsonObject["message_id"].Value <int>();

            From = jsonObject["from"] != null
                ? new UserInfo(jsonObject["from"].Value <JObject>())
                : new UserInfo();

            DateUnix = jsonObject["date"].Value <long>();
            Date     = DateUnix.ToDateTime();
            Chat     = new ChatInfo(jsonObject["chat"].Value <JObject>());

            ForwardFrom = jsonObject["forward_from"] != null
                ? new UserInfo(jsonObject["forward_from"].Value <JObject>())
                : new UserInfo();

            ForwardFromChat = jsonObject["forward_from_chat"] != null
                ? new ChatInfo(jsonObject["forward_from_chat"].Value <JObject>())
                : new ChatInfo {
                Photo = new ChatPhotoInfo()
            };

            if (jsonObject["forward_from_message_id"] != null)
            {
                ForwardFromMessageId = jsonObject["forward_from_message_id"].Value <int>();
            }

            ForwardSignature = jsonObject["forward_signature"] != null
                ? jsonObject["forward_signature"].Value <string>()
                : string.Empty;

            if (jsonObject["forward_date"] != null)
            {
                ForwardDateUnix = jsonObject["forward_date"].Value <long>();
                ForwardDate     = ForwardDateUnix.ToDateTime();
            }

            ReplyToMessage = jsonObject["reply_to_message"] != null
                ? new MessageInfo(jsonObject["reply_to_message"].Value <JObject>())
                : GetNewMessageInfo(GetNewMessageInfo(), GetNewMessageInfo());

            if (jsonObject["edit_date"] != null)
            {
                EditDateUnix = jsonObject["edit_date"].Value <long>();
                EditDate     = EditDateUnix.ToDateTime();
            }

            AuthorSignature = jsonObject["author_signature"] != null
                ? jsonObject["author_signature"].Value <string>()
                : string.Empty;

            Text = jsonObject["text"] != null
                ? jsonObject["text"].Value <string>()
                : string.Empty;

            Entities = jsonObject["entities"] != null
                ? MessageEntityInfo.ParseArray(jsonObject["entities"].Value <JArray>())
                : new MessageEntityInfo[0];

            CaptionEntities = jsonObject["caption_entities"] != null
                ? MessageEntityInfo.ParseArray(jsonObject["caption_entities"].Value <JArray>())
                : new MessageEntityInfo[0];

            Audio = jsonObject["audio"] != null
                ? new AudioInfo(jsonObject["audio"].Value <JObject>())
                : new AudioInfo();

            Document = jsonObject["document"] != null
                ? new DocumentInfo(jsonObject["document"].Value <JObject>())
                : new DocumentInfo {
                Thumb = new PhotoSizeInfo()
            };

            Game = jsonObject["game"] != null
                ? new GameInfo(jsonObject["game"].Value <JObject>())
                : new GameInfo {
                Photo     = new PhotoSizeInfo[0], Entities = new MessageEntityInfo[0],
                Animation = new AnimationInfo {
                    Thumb = new PhotoSizeInfo()
                }
            };

            Photo = jsonObject["photo"] != null
                ? PhotoSizeInfo.ParseArray(jsonObject["photo"].Value <JArray>())
                : new PhotoSizeInfo[0];

            Sticker = jsonObject["sticker"] != null
                ? new StickerInfo(jsonObject["sticker"].Value <JObject>())
                : new StickerInfo {
                Thumb = new PhotoSizeInfo()
            };

            Video = jsonObject["video"] != null
                ? new VideoInfo(jsonObject["video"].Value <JObject>())
                : new VideoInfo {
                Thumb = new PhotoSizeInfo()
            };

            Voice = jsonObject["voice"] != null
                ? new VoiceInfo(jsonObject["voice"].Value <JObject>())
                : new VoiceInfo();

            VideoNote = jsonObject["video_note"] != null
                ? new VideoNoteInfo(jsonObject["video_note"].Value <JObject>())
                : new VideoNoteInfo {
                Thumb = new PhotoSizeInfo()
            };

            Caption = jsonObject["caption"] != null
                ? jsonObject["caption"].Value <string>()
                : string.Empty;

            Contact = jsonObject["contact"] != null
                ? new ContactInfo(jsonObject["contact"].Value <JObject>())
                : new ContactInfo();

            Location = jsonObject["location"] != null
                ? new LocationInfo(jsonObject["location"].Value <JObject>())
                : new LocationInfo();

            Venue = jsonObject["venue"] != null
                ? new VenueInfo(jsonObject["venue"].Value <JObject>())
                : new VenueInfo {
                Location = new LocationInfo()
            };

            NewChatMember = jsonObject["new_chat_member"] != null
                ? new UserInfo(jsonObject["new_chat_member"].Value <JObject>())
                : new UserInfo();

            NewChatMembers = jsonObject["new_chat_members"] != null
                ? UserInfo.ParseArray(jsonObject["new_chat_members"].Value <JArray>())
                : new UserInfo[0];

            LeftChatMember = jsonObject["left_chat_member"] != null
                ? new UserInfo(jsonObject["left_chat_member"].Value <JObject>())
                : new UserInfo();

            NewChatTitle = jsonObject["new_chat_title"] != null
                ? jsonObject["new_chat_title"].Value <string>()
                : string.Empty;

            NewChatPhoto = jsonObject["new_chat_photo"] != null
                ? PhotoSizeInfo.ParseArray(jsonObject["new_chat_photo"].Value <JArray>())
                : new PhotoSizeInfo[0];

            if (jsonObject["delete_chat_photo"] != null)
            {
                DeleteChatPhoto = true;
            }

            if (jsonObject["group_chat_created"] != null)
            {
                GroupChatCreated = true;
            }

            if (jsonObject["supergroup_chat_created"] != null)
            {
                SuperGroupChatCreated = true;
            }

            if (jsonObject["channel_chat_created"] != null)
            {
                ChannelChatCreated = true;
            }

            if (jsonObject["migrate_to_chat_id"] != null)
            {
                MigrateToChatId = jsonObject["migrate_to_chat_id"].Value <int>();
            }

            if (jsonObject["migrate_from_chat_id"] != null)
            {
                MigrateFromChatId = jsonObject["migrate_from_chat_id"].Value <int>();
            }

            PinnedMessage = jsonObject["pinned_message"] != null
                ? new MessageInfo(jsonObject["pinned_message"].Value <JObject>())
                : GetNewMessageInfo(GetNewMessageInfo(), GetNewMessageInfo());

            Invoice = jsonObject["invoice"] != null
                ? new InvoceInfo(jsonObject["invoice"].Value <JObject>())
                : new InvoceInfo();

            SuccessfulPayment = jsonObject["successful_payment"] != null
                ? new SuccessfulPaymentInfo(jsonObject["successful_payment"].Value <JObject>())
                : new SuccessfulPaymentInfo {
                OrderInfo = new OrderInfo {
                    ShippingAddress = new ShippingAddressInfo()
                }
            };
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses the specified json object.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        private void Parse(JObject jsonObject)
        {
            // Test NetTelebot.Tests.MessageInfoParserTest.MandatoryFieldsMessageInfoTest()
            MessageId = jsonObject["message_id"].Value <int>();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoFromTest()
            From = jsonObject["from"] != null
                ? new UserInfo(jsonObject["from"].Value <JObject>())
                : new UserInfo();

            // Test NetTelebot.Tests.MessageInfoParserTest.MandatoryFieldsMessageInfoTest()
            DateUnix = jsonObject["date"].Value <int>();

            // Test NetTelebot.Tests.MessageInfoParserTest.MandatoryFieldsMessageInfoTest()
            Date = DateUnix.ToDateTime();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoChatTest()
            Chat = new ChatInfo(jsonObject["chat"].Value <JObject>());

            // Test NetTelebot.Tests.MesageInfoParserTest.MessageInfoForwardFromTest()
            ForwardFrom = jsonObject["forward_from"] != null
                ? new UserInfo(jsonObject["forward_from"].Value <JObject>())
                : new UserInfo();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoForwardFromChatTest()
            ForwardFromChat = jsonObject["forward_from_chat"] != null
                ? new ChatInfo(jsonObject["forward_from_chat"].Value <JObject>())
                : new ChatInfo {
                Photo = new ChatPhotoInfo()
            };

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoForwardFromMessageIdTest()
            if (jsonObject["forward_from_message_id"] != null)
            {
                ForwardFromMessageId = jsonObject["forward_from_message_id"].Value <int>();
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoForwardDateUnixTest()
            if (jsonObject["forward_date"] != null)
            {
                ForwardDateUnix = jsonObject["forward_date"].Value <int>();
                ForwardDate     = ForwardDateUnix.ToDateTime();
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoReplyToMessageTest()
            ReplyToMessage = jsonObject["reply_to_message"] != null
                ? new MessageInfo(jsonObject["reply_to_message"].Value <JObject>())
                : MessageInfoWithNullField();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoEditDateTest()
            if (jsonObject["edit_date"] != null)
            {
                EditDateUnix = jsonObject["edit_date"].Value <int>();
                EditDate     = EditDateUnix.ToDateTime();
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoTextTest()
            Text = jsonObject["text"] != null
                ? jsonObject["text"].Value <string>()
                : string.Empty;

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoEntitiesTest()
            Entities = jsonObject["entities"] != null
                ? MessageEntityInfo.ParseArray(jsonObject["entities"].Value <JArray>())
                : new MessageEntityInfo[0];

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoAudioTest()
            Audio = jsonObject["audio"] != null
                ? new AudioInfo(jsonObject["audio"].Value <JObject>())
                : new AudioInfo();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoDocumentTest()
            Document = jsonObject["document"] != null
                ? new DocumentInfo(jsonObject["document"].Value <JObject>())
                : new DocumentInfo {
                Thumb = new PhotoSizeInfo()
            };

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoPhotoTest()
            Photo = jsonObject["photo"] != null
                ? PhotoSizeInfo.ParseArray(jsonObject["photo"].Value <JArray>())
                : new PhotoSizeInfo[0];

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoStickerTest()
            Sticker = jsonObject["sticker"] != null
                ? new StickerInfo(jsonObject["sticker"].Value <JObject>())
                : new StickerInfo {
                Thumb = new PhotoSizeInfo()
            };

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoVideoTest()
            Video = jsonObject["video"] != null
                ? new VideoInfo(jsonObject["video"].Value <JObject>())
                : new VideoInfo {
                Thumb = new PhotoSizeInfo()
            };

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoCaptionTest()
            Caption = jsonObject["caption"] != null
                ? jsonObject["caption"].Value <string>()
                : string.Empty;

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoContactTest()
            Contact = jsonObject["contact"] != null
                ? new ContactInfo(jsonObject["contact"].Value <JObject>())
                : new ContactInfo();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoLocationTest()
            Location = jsonObject["location"] != null
                ? new LocationInfo(jsonObject["location"].Value <JObject>())
                : new LocationInfo();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoNewChatMemberTest()
            NewChatMember = jsonObject["new_chat_member"] != null
                ? new UserInfo(jsonObject["new_chat_member"].Value <JObject>())
                : new UserInfo();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoLeftChatMemberTest()
            LeftChatMember = jsonObject["left_chat_member"] != null
                ? new UserInfo(jsonObject["left_chat_member"].Value <JObject>())
                : new UserInfo();

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoNewChatTitleTest()
            NewChatTitle = jsonObject["new_chat_title"] != null
                ? jsonObject["new_chat_title"].Value <string>()
                : string.Empty;

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoNewChatPhotoTest()
            NewChatPhoto = jsonObject["new_chat_photo"] != null
                ? PhotoSizeInfo.ParseArray(jsonObject["new_chat_photo"].Value <JArray>())
                : new PhotoSizeInfo[0];

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoDeleteChatPhotoTest()
            if (jsonObject["delete_chat_photo"] != null)
            {
                DeleteChatPhoto = true;
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoGroupChatPhotoTest()
            if (jsonObject["group_chat_created"] != null)
            {
                GroupChatCreated = true;
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoSuperGroupChatPhotoTest()
            if (jsonObject["supergroup_chat_created"] != null)
            {
                SuperGroupChatCreated = true;
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoChannelChatCreatedTest()
            if (jsonObject["channel_chat_created"] != null)
            {
                ChannelChatCreated = true;
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoMigrateToChatIdTest()
            if (jsonObject["migrate_to_chat_id"] != null)
            {
                MigrateToChatId = jsonObject["migrate_to_chat_id"].Value <int>();
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoMigrateFromChatIdTest()
            if (jsonObject["migrate_from_chat_id"] != null)
            {
                MigrateFromChatId = jsonObject["migrate_from_chat_id"].Value <int>();
            }

            // Test NetTelebot.Tests.MessageInfoParserTest.MessageInfoPinnedMessageTest()
            PinnedMessage = jsonObject["pinned_message"] != null
                ? new MessageInfo(jsonObject["pinned_message"].Value <JObject>())
                : MessageInfoWithNullField();
        }
Exemplo n.º 3
0
 private void Parse(JObject jsonObject)
 {
     MessageId = jsonObject["message_id"].Value <int>();
     From      = new UserInfo(jsonObject["from"].Value <JObject>());
     DateUnix  = jsonObject["date"].Value <int>();
     Date      = DateUnix.ToDateTime();
     Chat      = ParseChat(jsonObject["chat"].Value <JObject>());
     if (jsonObject["forward_from"] != null)
     {
         ForwardFrom = new UserInfo(jsonObject["forward_from"].Value <JObject>());
     }
     if (jsonObject["forward_date"] != null)
     {
         ForwardDateUnix = jsonObject["forward_date"].Value <int>();
         ForwardDate     = ForwardDateUnix.ToDateTime();
     }
     if (jsonObject["reply_to_message"] != null)
     {
         ReplyToMessage = new MessageInfo(jsonObject["reply_to_message"].Value <JObject>());
     }
     if (jsonObject["text"] != null)
     {
         Text = jsonObject["text"].Value <string>();
     }
     if (jsonObject["audio"] != null)
     {
         Audio = new AudioInfo(jsonObject["audio"].Value <JObject>());
     }
     if (jsonObject["document"] != null)
     {
         Document = new DocumentInfo(jsonObject["document"].Value <JObject>());
     }
     if (jsonObject["photo"] != null)
     {
         Photo = PhotoSizeInfo.ParseArray(jsonObject["photo"].Value <JArray>());
     }
     if (jsonObject["sticker"] != null)
     {
         Sticker = new StickerInfo(jsonObject["sticker"].Value <JObject>());
     }
     if (jsonObject["video"] != null)
     {
         Video = new VideoInfo(jsonObject["video"].Value <JObject>());
     }
     if (jsonObject["contact"] != null)
     {
         Contact = new ContactInfo(jsonObject["contact"].Value <JObject>());
     }
     if (jsonObject["location"] != null)
     {
         Location = new LocationInfo(jsonObject["location"].Value <JObject>());
     }
     if (jsonObject["new_chat_participant"] != null)
     {
         NewChatParticipant = new UserInfo(jsonObject["new_chat_participant"].Value <JObject>());
     }
     if (jsonObject["left_chat_participant"] != null)
     {
         LeftChatParticipant = new UserInfo(jsonObject["left_chat_participant"].Value <JObject>());
     }
     if (jsonObject["new_chat_title"] != null)
     {
         NewChatTitle = jsonObject["new_chat_title"].Value <string>();
     }
     if (jsonObject["new_chat_photo"] != null)
     {
         NewChatPhoto = PhotoSizeInfo.ParseArray(jsonObject["new_chat_photo"].Value <JArray>());
     }
     if (jsonObject["delete_chat_photo"] != null)
     {
         DeleteChatPhoto = true;
     }
     if (jsonObject["group_chat_created"] != null)
     {
         GroupChatCreated = true;
     }
 }