Ejemplo n.º 1
0
        protected async override void OnActivated(IActivatedEventArgs args)
        {
            base.OnActivated(args);

            var continuationEventArgs = args as IContinuationActivatedEventArgs;

            if (continuationEventArgs != null)
            {
                switch (continuationEventArgs.Kind)
                {
                case ActivationKind.PickFileContinuation:
                    FileOpenPickerContinuationEventArgs arguments = continuationEventArgs as FileOpenPickerContinuationEventArgs;
                    StorageFile file      = arguments.Files.FirstOrDefault();
                    var         messenger = Mvx.Resolve <IMvxMessenger>();

                    using (var imgStream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        var buffer = new byte[imgStream.Size];
                        await imgStream.ReadAsync(buffer.AsBuffer(), (uint)imgStream.Size, InputStreamOptions.None);

                        var properties = await file.Properties.GetImagePropertiesAsync();

                        var message = new PictureMessage(this)
                        {
                            Width   = properties.Width,
                            Height  = properties.Height,
                            Picture = buffer
                        };
                        messenger.Publish(message);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create new unified picture message from viber picture message
 /// </summary>
 /// <param name="message">Viber picture message</param>
 /// <returns>Unified message</returns>
 private InMessage CreatePictureMessage(PictureMessage message)
 {
     return(new InMessage
     {
         Picture = message.Media
     });
 }
Ejemplo n.º 3
0
        void handlePictureMessage(BasicDeliverEventArgs e, Dictionary <string, string> headers)
        {
            headers.TryGetValue("senderDeviceId", out var pictureSenderDeviceId);
            headers.TryGetValue("senderOwnerName", out var pictureSenderOwnerName);
            return;

            // still_todo: implement this on VM with event raising
#if __ANDROID__
            Helper.RunOnUiThread(() => MainActivity.PictureMessages.Add(PictureMessage.FromRabbitMessage(e.Body.ToArray(), pictureSenderDeviceId, pictureSenderOwnerName)));
#elif WINDOWS_UWP
            var status = await Helper.GetDoNotDisturbStatusAsync();

            if (status.DoNotDisturb)
            {
                return;
            }
            if (Helper.IsDisplayOff())
            {
                Helper.WakeupApp();
            }
            await AppServiceBridge.SendData(new ValueSet()
            {
                [AppServiceConstants.PictureData]            = e.Body.ToArray(),
                [AppServiceConstants.PictureSenderDeviceId]  = pictureSenderDeviceId,
                [AppServiceConstants.PictureSenderOwnerName] = pictureSenderOwnerName,
            });
#elif __IOS__
            // still_TODO
#endif
            //Helper.Vibrate();
            return;
        }
Ejemplo n.º 4
0
        public async override Task Execute(Callback callback, IViberBotClient client)
        {
            PictureMessage msg = await GetImage(callback);

            long result = await client.SendPictureMessageAsync(msg);

            TeamsCommand teamsCommand = new TeamsCommand(_leagueRepository, version);
            await teamsCommand.Execute(callback, client);
        }
Ejemplo n.º 5
0
 public async void PictureMessage(string receiver, string url, string text = "")
 {
     var message = new PictureMessage {
         Receiver = receiver,
         Media = url,
         Text = text,
         Sender = new Sender { Name = _botOptions.Sender.Name }
     };
     var response = await _api.SendMessage(message);            
     HandleResponse(response);
 }
Ejemplo n.º 6
0
        public void AddPhoto(Bitmap img, string time, PictureMessage.MessageType mt)
        {
            PictureMessage msg = new PictureMessage(img, time, mt);

            msg.Location = messageBox1.Location;
            //msg.Size = messageBox1.Size;
            msg.Anchor = messageBox1.Anchor;
            msg.Top    = panel2.Controls[panel2.Controls.Count - 1].Bottom + message_padding;
            if (mt == PictureMessage.MessageType.Out)
            {
                msg.Left = (Size.Width - msg.MessageWidth) - 40;
            }
            panel2.Controls.Add(msg);
        }
Ejemplo n.º 7
0
        private void AppMessaging_Click(object sender, AGConnectAppMessagingOnClickEventArgs e)
        {
            //You can get App message data from AGConnectAppMessagingOnDisplayEventArgs
            AppMessage message = e.AppMessage;

            if (message.MessageType == MessageType.Banner)
            {
                //Cast app message to BannerMessage
                BannerMessage banner = (BannerMessage)message;
                //Get banner detail
                Banner detail = banner.GetBanner();

                string title               = detail.Title;
                string pictureUrl          = detail.PictureUrl;
                int    bodyColorOpen       = detail.BodyColorOpenness;
                string bodyColor           = detail.BodyColor;
                string body                = detail.Body;
                int    backgroundColorOpen = detail.BackgroundColorOpenness;
                string actionUrl           = detail.ActionUrl;
                string titleColor          = detail.TitleColor;
                string backgroundColor     = detail.BackgroundColor;
                int    titleColorOpen      = detail.TitleColorOpenness;
            }
            else if (message.MessageType == MessageType.Picture)
            {
                //Cast app message to PictureMessage
                PictureMessage banner = (PictureMessage)message;
                //Get picture detail
                Picture detail = banner.GetPicture();

                string pictureUrl = detail.PictureUrl;
                string sctionUrl  = detail.ActionUrl;
            }
            else if (message.MessageType == MessageType.Card)
            {
                //Cast app message to CardMessage
                CardMessage banner = (CardMessage)message;
                //Get card detail
                Card detail = banner.GetCard();

                CardMessage.Button majorButton = detail.MajorButton;
                CardMessage.Button minorButton = detail.MinorButton;

                string text              = majorButton.Text;
                string actionUrl         = majorButton.ActionUrl;
                string textColor         = majorButton.TextColor;
                int    textColorOpenness = majorButton.TextColorOpenness;
            }
            SetAppMessageDetails(message);
        }
Ejemplo n.º 8
0
        private Tuple <string, SqlParameter[]> GetUpdateQuery(Message message)
        {
            PictureMessage pictureMessage = message as PictureMessage;

            if (pictureMessage != null)
            {
                return(GetDefaultPictureUpdateQuery(pictureMessage));
            }
            VideoMessage videoMessage = message as VideoMessage;

            if (videoMessage != null)
            {
                return(GetDefaultVideoUpdateQuery(videoMessage));
            }
            return(GetDefaultTextUpdateQuery(message));
        }
Ejemplo n.º 9
0
        private Tuple <string, SqlParameter[]> GetInsertQuery(Message message)
        {
            PictureMessage pictureMessage = message as PictureMessage;

            if (pictureMessage != null)
            {
                return(GetPictureInsertQuery(pictureMessage));
            }
            VideoMessage videoMessage = message as VideoMessage;

            if (videoMessage != null)
            {
                return(GetVideoInsertQuery(videoMessage));
            }
            return(GetTextInsertQuery(message));
        }
Ejemplo n.º 10
0
        private Tuple <string, SqlParameter[]> GetPictureInsertQuery(PictureMessage pictureMessage)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter(MessageParameter.MESSAGE_TEXT, GetDBValue(pictureMessage.MessageText)),
                new SqlParameter(MessageParameter.SENDER_ID, GetDBValue(pictureMessage.SenderId)),
                new SqlParameter(MessageParameter.SENDER_EMAIL_ADDRESS, GetDBValue(pictureMessage.SenderEmailAddress)),
                new SqlParameter(MessageParameter.MESSAGE_CREATED, GetDBValue(pictureMessage.MessageCreated)),
                new SqlParameter(MessageParameter.MULTI_MEDIA_TYPE, GetDBValue(MessageTypeConstant.Picture)),
                new SqlParameter(MessageParameter.UNIQUE_QUID, GetDBValue(pictureMessage.UniqueGuid)),
                new SqlParameter(MessageParameter.FILE_NAME, GetDBValue(pictureMessage.FileName)),
                new SqlParameter(MessageParameter.MEDIA_FILE_TYPE, GetDBValue(pictureMessage.MediaFileType)),
                new SqlParameter(MessageParameter.FILE_SIZE, GetDBValue(pictureMessage.FileSize)),
                new SqlParameter(MessageParameter.IMAGE_TYPE, GetDBValue(pictureMessage.ImageType)),
            };

            string insertColumns = string.Format(@"INSERT INTO {0}({1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10})",
                                                 TableName,
                                                 MessageColumn.MESSAGE_TEXT,
                                                 MessageColumn.SENDER_ID,
                                                 MessageColumn.SENDER_EMAIL_ADDRESS,
                                                 MessageColumn.MESSAGE_CREATED,
                                                 MessageColumn.MULTI_MEDIA_TTPE,
                                                 MessageColumn.UNIQUE_QUID,
                                                 MessageColumn.FILE_NAME,
                                                 MessageColumn.MEDIA_FILE_TYPE,
                                                 MessageColumn.FILE_SIZE,
                                                 MessageColumn.IMAGE_TYPE);

            string valueSection = string.Format(@"VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9})",
                                                MessageParameter.MESSAGE_TEXT,
                                                MessageParameter.SENDER_ID,
                                                MessageParameter.SENDER_EMAIL_ADDRESS,
                                                MessageParameter.MESSAGE_CREATED,
                                                MessageParameter.MULTI_MEDIA_TYPE,
                                                MessageParameter.UNIQUE_QUID,
                                                MessageParameter.FILE_NAME,
                                                MessageParameter.MEDIA_FILE_TYPE,
                                                MessageParameter.FILE_SIZE,
                                                MessageParameter.IMAGE_TYPE);

            string query = string.Format("{0} {1}", insertColumns, valueSection);

            return(Tuple.Create(query, sqlParameters));
        }
Ejemplo n.º 11
0
        public async Task <PictureMessage> GetImage(Callback callback)
        {
            string link = await _leagueRepository.GetTableLink(callback.Message.TrackingData, version);

            var pictureMessage = new PictureMessage(callback.Sender.Id)
            {
                Sender = new UserBase
                {
                    Name   = MessageConstant.BOT_NAME,
                    Avatar = MessageConstant.BOT_AVATAR,
                },
                Text      = $"{MessageConstant.TABLE} {callback.Message.TrackingData}",
                Media     = link,
                Thumbnail = link,
            };

            return(pictureMessage);
        }
Ejemplo n.º 12
0
        public async Task SendPictureMessageAsync(int botId, string receiverId, OutMessage message)
        {
            //
            if (message.Picture == null)
            {
                throw new ArgumentNullException("picture");
            }

            //
            var pictureMessage = new PictureMessage
            {
                Receiver      = receiverId,
                MinApiVersion = 4,
                Media         = message.Picture
            };

            await viberBotClient.SendPictureMessageAsync(pictureMessage);
        }
Ejemplo n.º 13
0
        private Message ExtractMessage(string messagetype, DbDataReader dbDataReader)
        {
            if (string.IsNullOrEmpty(messagetype) ||
                messagetype == MessageTypeConstant.Text)
            {
                Message message = new Message();
                PopulateTextMessage(message, dbDataReader);
                return(message);
            }
            if (messagetype == MessageTypeConstant.Video)
            {
                VideoMessage videoMessage = new VideoMessage();
                PopulateTextMessage(videoMessage, dbDataReader);
                PopulateMediaMessage(videoMessage, dbDataReader);

                if (dbDataReader[MessageColumn.LENGTH] != null &&
                    double.TryParse(dbDataReader[MessageColumn.LENGTH].ToString(), out double length))
                {
                    videoMessage.Length = length;
                }
                return(videoMessage);
            }
            if (messagetype == MessageTypeConstant.Picture)
            {
                PictureMessage pictureMessage = new PictureMessage();
                PopulateTextMessage(pictureMessage, dbDataReader);
                PopulateMediaMessage(pictureMessage, dbDataReader);

                if (dbDataReader[MessageColumn.IMAGE_TYPE] != null)
                {
                    pictureMessage.ImageType = dbDataReader[MessageColumn.IMAGE_TYPE].ToString();
                }
                return(pictureMessage);
            }
            return(null);
        }
Ejemplo n.º 14
0
 public Task <long> SendPictureMessageAsync(PictureMessage message) => SendMessageAsync(message);
Ejemplo n.º 15
0
        async Task OnPictureReceivedAsync(PictureMessage message)
        {
            var nutritionTable = await OCRService.GetTableAsync(message.Picture, message.Width, message.Height);

            ShowViewModel <InfoViewModel>(nutritionTable);
        }
Ejemplo n.º 16
0
        private Tuple <string, SqlParameter[]> GetDefaultPictureUpdateQuery(PictureMessage pictureMessage)
        {
            SqlParameter[] sqlParameters = new SqlParameter[]
            {
                new SqlParameter(MessageParameter.MESSAGE_TEXT, GetDBValue(pictureMessage.MessageText)),
                new SqlParameter(MessageParameter.SENDER_ID, GetDBValue(pictureMessage.SenderId)),
                new SqlParameter(MessageParameter.SENDER_EMAIL_ADDRESS, GetDBValue(pictureMessage.SenderEmailAddress)),
                new SqlParameter(MessageParameter.MESSAGE_CREATED, GetDBValue(pictureMessage.MessageCreated)),
                new SqlParameter(MessageParameter.UNIQUE_QUID, GetDBValue(pictureMessage.UniqueGuid)),
                new SqlParameter(MessageParameter.FILE_NAME, GetDBValue(pictureMessage.FileName)),
                new SqlParameter(MessageParameter.MEDIA_FILE_TYPE, GetDBValue(pictureMessage.MediaFileType)),
                new SqlParameter(MessageParameter.FILE_SIZE, GetDBValue(pictureMessage.FileSize)),
                new SqlParameter(MessageParameter.IMAGE_TYPE, GetDBValue(pictureMessage.ImageType)),
                new SqlParameter(MessageParameter.ID, GetDBValue(pictureMessage.Id))
            };

            string updateTable = string.Format("UPDATE {0} SET", TableName);

            string setText = string.Format("{0} = {1}", MessageColumn.MESSAGE_TEXT,
                                           MessageParameter.MESSAGE_TEXT);

            string setSenderId = string.Format("{0} = {1}", MessageColumn.SENDER_ID,
                                               MessageParameter.SENDER_ID);

            string setSenderEmailAddress = string.Format("{0} = {1}", MessageColumn.SENDER_EMAIL_ADDRESS,
                                                         MessageParameter.SENDER_EMAIL_ADDRESS);

            string setMessageCreated = string.Format("{0} = {1}", MessageColumn.MESSAGE_CREATED,
                                                     MessageParameter.MESSAGE_CREATED);

            string setUniqueQuId = string.Format("{0} = {1}", MessageColumn.UNIQUE_QUID,
                                                 MessageParameter.UNIQUE_QUID);

            string setFileName = string.Format("{0} = {1}", MessageColumn.FILE_NAME,
                                               MessageParameter.FILE_NAME);

            string setMediaFileType = string.Format("{0} = {1}", MessageColumn.MEDIA_FILE_TYPE,
                                                    MessageParameter.MEDIA_FILE_TYPE);

            string setFileSize = string.Format("{0} = {1}", MessageColumn.FILE_SIZE,
                                               MessageParameter.FILE_SIZE);

            string setImageType = string.Format("{0} = {1}", MessageColumn.IMAGE_TYPE,
                                                MessageParameter.IMAGE_TYPE);

            string whereId = string.Format("WHERE {0} = {1}", MessageColumn.ID,
                                           MessageParameter.ID);

            string query = string.Format("{0} {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9} {10}", updateTable,
                                         setText,
                                         setSenderId,
                                         setSenderEmailAddress,
                                         setMessageCreated,
                                         setUniqueQuId,
                                         setFileName,
                                         setMediaFileType,
                                         setFileSize,
                                         setImageType,
                                         whereId);

            return(Tuple.Create(query, sqlParameters));
        }