Esempio n. 1
0
        private async Task SelectMusic(IDialogContext context, IAwaitable <string> result)
        {
            try
            {
                string optionSelected = await result;
                switch (optionSelected)
                {
                case RelaxMsc:
                    var      data  = MusicList.GetAllMusicRelax();
                    Activity reply = context.MakeMessage() as Activity;
                    //reply.Attachments.Add(GetAudioRelaxCard().ToAttachment());
                    reply.Attachments      = new List <Attachment>();
                    reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    foreach (var item in data)
                    {
                        var audioCard = new AudioCard
                        {
                            Title    = item.Title,
                            Subtitle = item.SubTitle,
                            Text     = item.Text,
                            Image    = new ThumbnailUrl
                            {
                                Url = item.Img,
                            },
                            Media = new List <MediaUrl>
                            {
                                new MediaUrl()
                                {
                                    Url = item.Url,
                                }
                            }
                        };
                        reply.Attachments.Add(audioCard.ToAttachment());
                    }
                    await context.PostAsync(reply);

                    context.Wait(MessageReceivedAsync);
                    break;

                case UpliftMsc:
                    var      dataRock  = MusicList.GetAllMusicSpirit();
                    Activity replyRock = context.MakeMessage() as Activity;
                    //reply.Attachments.Add(GetAudioRelaxCard().ToAttachment());
                    replyRock.Attachments      = new List <Attachment>();
                    replyRock.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                    foreach (var item in dataRock)
                    {
                        var audioCard = new AudioCard
                        {
                            Title    = item.Title,
                            Subtitle = item.SubTitle,
                            Text     = item.Text,
                            Image    = new ThumbnailUrl
                            {
                                Url = item.Img,
                            },
                            Media = new List <MediaUrl>
                            {
                                new MediaUrl()
                                {
                                    Url = item.Url,
                                }
                            }
                        };
                        replyRock.Attachments.Add(audioCard.ToAttachment());
                    }
                    await context.PostAsync(replyRock);

                    context.Wait(MessageReceivedAsync);
                    break;
                }
            }
            catch (TooManyAttemptsException ex)
            {
                await context.PostAsync(MESSAGESINFO.TOO_MANY_ATTEMPT);

                context.Wait(this.MessageReceivedAsync);
            }
        }