Beispiel #1
0
        public static ComposeExtensionResponse HandleMessageExtensionQuery(ConnectorClient connector, Activity activity)
        {
            var query = activity.GetComposeExtensionQueryData();

            if (query == null || query.CommandId != "getRandomText")
            {
                // We only process the 'getRandomText' queries with this message extension
                return(null);
            }

            var title      = "";
            var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "cardTitle");

            if (titleParam != null)
            {
                title = titleParam.Value.ToString();
            }

            var attachments = new ComposeExtensionAttachment[5];

            for (int i = 0; i < 5; i++)
            {
                attachments[i] = GetAttachment(title);
            }

            var response = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));

            response.ComposeExtension.Attachments = attachments.ToList();

            return(response);
        }
        //gavdcodeend 01

        //gavdcodebegin 02
        private static ComposeExtensionResponse CreateCard(Activity myActivity)
        {
            ComposeExtensionResponse rtnResponse = null;

            dynamic activityValue = JObject.FromObject(myActivity.Value);

            string myFirst  = activityValue.data.firstNumber;
            string mySecond = activityValue.data.secondNumber;

            int myAdd = int.Parse(myFirst) + int.Parse(mySecond);

            HeroCard myCard = new HeroCard
            {
                Title    = "Add Card",
                Subtitle = "Adding " + myFirst + " + " + mySecond,
                Text     = "The result is " + myAdd.ToString(),
                Images   = new List <CardImage>(),
                Buttons  = new List <CardAction>(),
            };

            myCard.Images.Add(new CardImage
            {
                Url = "http://wiki.opensemanticframework.org/images/0/0b/Add-72.png"
            });

            var myAttachs = new ComposeExtensionAttachment[1];

            myAttachs[0] = myCard.ToAttachment().ToComposeExtensionAttachment();

            rtnResponse = new ComposeExtensionResponse(
                new ComposeExtensionResult("list", "result"));
            rtnResponse.ComposeExtension.Attachments = myAttachs.ToList();

            return(rtnResponse);
        }
        //gavdcodeend 01

        //gavdcodebegin 02
        private async Task <ComposeExtensionResponse> CreateCard(Activity myActivity)
        {
            ComposeExtensionResponse rtnResponse = null;

            ComposeExtensionQuery queryData = myActivity.GetComposeExtensionQueryData();
            string myQuery = string.Empty;
            ComposeExtensionParameter queryParam = queryData.Parameters?.FirstOrDefault(
                par => par.Name == "wikipediaQuery");

            if (queryParam != null)
            {
                myQuery = queryParam.Value.ToString();
            }

            string myText = string.Empty;

            if (string.IsNullOrEmpty(myQuery) == true)
            {
                myText = "Get a query to create the card";
            }
            else
            {
                myText = myQuery;
            }

            string wikiResult = await GetWikipediaSnippet(myText);

            HeroCard myCard = new HeroCard
            {
                Title    = "Wikipedia Card",
                Subtitle = "Searching for: " + myText,
                Text     = wikiResult,
                Images   = new List <CardImage>(),
                Buttons  = new List <CardAction>(),
            };

            myCard.Images.Add(new CardImage
            {
                Url = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/" +
                      "Orange_Icon_Pale_Wiki.png/120px-Orange_Icon_Pale_Wiki.png"
            });

            ComposeExtensionAttachment[] myAttachs = new ComposeExtensionAttachment[1];
            myAttachs[0] = myCard.ToAttachment().ToComposeExtensionAttachment();

            rtnResponse = new ComposeExtensionResponse(
                new ComposeExtensionResult("list", "result"));
            rtnResponse.ComposeExtension.Attachments = myAttachs.ToList();

            return(rtnResponse);
        }
Beispiel #4
0
        public static ComposeExtensionResponse HandleMessageExtensionQuery(ConnectorClient connector, Activity activity)
        {
            GetDataHelper helper = new GetDataHelper();
            List <News>   news   = helper.GetNews();


            var query = activity.GetComposeExtensionQueryData();

            if (query == null /*|| (query.CommandId != "Speakers" || query.CommandId != "Sessions")*/)
            {
                return(null);
            }

            /* if (query.CommandId == "speaker")
             * {
             *   var title = "";
             *   var titleParam = query.Parameters?.FirstOrDefault(p => p.category == "speakerTitle");
             *   var response = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
             *   ComposeExtensionAttachment[] attachments = null;
             *   if (titleParam != null)
             *   {
             *       title = titleParam.Value.ToString();
             *
             *       List<string> searchNames = speakers.Select(a => a.SpeakerName).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
             *       List<string> searchImages = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Snap).ToList();
             *       List<string> searchBio = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Bio).ToList();
             *       List<string> searchTitle = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Title).ToList();
             *       int attacCount = searchNames.Count();
             *
             *       attachments = new ComposeExtensionAttachment[attacCount];
             *       for (int i = 0; i < attacCount; i++)
             *       {
             *           attachments[i] = GetAttachment(searchImages[i], searchNames[i], searchTitle[i], searchBio[i]);
             *       }
             *       response.ComposeExtension.Attachments = attachments.ToList();
             *   }
             *   else
             *   {
             *       List<string> searchNames = speakers.Select(c => c.SpeakerName).ToList();
             *       List<string> searchImages = speakers.Select(c => c.Snap).ToList();
             *       List<string> searchTitle = speakers.Select(c => c.Title).ToList();
             *       List<string> searchBio = speakers.Select(c => c.Bio).ToList();
             *       attachments = new ComposeExtensionAttachment[searchNames.Count];
             *       for (int i = 0; i < searchNames.Count; i++)
             *       {
             *           attachments[i] = GetAttachment(searchImages[i], searchNames[i], searchTitle[i], searchBio[i]);
             *       }
             *       response.ComposeExtension.Attachments = attachments.ToList();
             *   }
             *
             *   return response;
             * }*/
            else if (query.CommandId == "EventsTrainings")
            {
                List <EventsAndTrainings> eventsTrainings = helper.GetEandT();

                var title      = "";
                var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "ETTitle");
                var response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();

                    List <string> searchTitle  = eventsTrainings.Select(a => a.ETTitle).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchdate   = eventsTrainings.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETStartDate).ToList();
                    List <string> searchend    = eventsTrainings.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETEndDate).ToList();
                    List <string> searchETType = eventsTrainings.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETType).ToList();;
                    int           attacCount   = searchTitle.Count();

                    attachments = new ComposeExtensionAttachment[attacCount];
                    for (int i = 0; i < attacCount; i++)
                    {
                        // string Type = searchSpeaker[i] + " - " + searchSessionType[i];
                        attachments[i] = GetAttachment(searchdate[i], searchend[i], searchTitle[i], searchETType[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> searchTitle  = eventsTrainings.Select(c => c.ETTitle).Take(20).ToList();
                    List <string> searchdate   = eventsTrainings.Select(c => c.ETStartDate).Take(20).ToList();
                    List <string> searchend    = eventsTrainings.Select(c => c.ETEndDate).Take(20).ToList();
                    List <string> searchETType = eventsTrainings.Select(c => c.ETType).ToList();
                    attachments = new ComposeExtensionAttachment[searchTitle.Count];
                    for (int i = 0; i < searchTitle.Count; i++)
                    {
                        //string speakerAndSessionType = searchSpeaker[i] + " - " + searchSessionType[i];
                        attachments[i] = GetAttachment(searchdate[i], searchend[i], searchTitle[i], searchETType[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }

                return(response);
            }

            return(null);
        }
        public static ComposeExtensionResponse HandleMessageExtensionQuery(ConnectorClient connector, Activity activity)
        {
            var query = activity.GetComposeExtensionQueryData();

            if (query == null)
            {
                // We only process the 'getRandomText' queries with this message extension
                return(null);
            }
            if (query.CommandId == "News")
            {
                NewsModel news       = GetDataHelper.GetNews();
                var       title      = "";
                var       titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "newsTitle");
                var       response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();
                    List <string> searchtitle    = news.news.Select(a => a.NewsTitle).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchImages   = news.news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsThumbnailUrl).ToList();
                    List <string> searchDateTime = news.news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsDateTIme).ToList();
                    List <string> searchdetail   = news.news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.DetailedNews).ToList();
                    List <string> searchby       = news.news.Where(a => a.NewsTitle.ToLower().Contains(title.ToLower())).Select(c => c.NewsBy).ToList();
                    int           attacCount     = searchtitle.Count();
                    attachments = new ComposeExtensionAttachment[attacCount];
                    for (int i = 0; i < attacCount; i++)
                    {
                        attachments[i] = GetNewsAttachment(searchImages[i], searchtitle[i], searchby[i], searchdetail[i]);
                    }

                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> searchtitle    = news.news.Select(c => c.NewsTitle).Take(20).ToList();
                    List <string> searchImages   = news.news.Select(c => c.NewsThumbnailUrl).Take(20).ToList();
                    List <string> searchDateTime = news.news.Select(c => c.NewsDateTIme).Take(20).ToList();
                    List <string> searchdetail   = news.news.Select(c => c.DetailedNews).Take(20).ToList();
                    List <string> searchby       = news.news.Select(c => c.NewsBy).Take(20).ToList();
                    attachments = new ComposeExtensionAttachment[searchtitle.Count()];
                    for (int i = 0; i < searchtitle.Count(); i++)
                    {
                        attachments[i] = GetNewsAttachment(searchImages[i], searchtitle[i], searchby[i], searchdetail[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                return(response);
            }
            else if (query.CommandId == "Task")
            {
                SpfxPurchaseOrder task = GetDataHelper.GetPOs();
                var title      = "";
                var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "tasktitle");
                var response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();
                    //List<string> description = task.PurchaseOrder.Select(a => a.Description).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    //List<string> totamount = task.PurchaseOrder.Where(a => a.Description.ToLower().Contains(title.ToLower())).Select(c => c.TotalAmount).ToList();
                    List <string> description = task.value.Select(a => a.Description).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> totamount   = task.value.Where(a => a.Description.ToLower().Contains(title.ToLower())).Select(c => c.TotalAmount).ToList();

                    int attacCount = description.Count();
                    attachments = new ComposeExtensionAttachment[attacCount];
                    for (int i = 0; i < attacCount; i++)
                    {
                        attachments[i] = GetTaskAttachments(description[i], totamount[i]);
                    }

                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> description = task.value.Where(b => b.PoStatus == "pending").Select(c => c.Description).Take(20).ToList();
                    List <string> totamount   = task.value.Where(b => b.PoStatus == "pending").Select(c => c.TotalAmount).Take(20).ToList();
                    attachments = new ComposeExtensionAttachment[description.Count()];
                    for (int i = 0; i < description.Count(); i++)
                    {
                        attachments[i] = GetTaskAttachments(description[i], totamount[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                return(response);
            }
            else if (query.CommandId == "EventsAndTrainings")

            {
                EandTModel eventsTrainings = GetDataHelper.GetEandT();
                var        title           = "";
                var        titleParam      = query.Parameters?.FirstOrDefault(p => p.Name == "EventsAndTrainingstitle");
                var        response        = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;

                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();
                    List <string> searchTitle   = eventsTrainings.EventsAndtraining.Select(a => a.ETTitle).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchdetails = eventsTrainings.EventsAndtraining.Select(a => a.ETDetails).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchdate    = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETStartDate).ToList();
                    List <string> searchimage   = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETThumbnailUrl).ToList();
                    List <string> searchETType  = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETType).ToList();
                    List <string> searchETid    = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.ETID).ToList();
                    List <bool>   searchETar    = eventsTrainings.EventsAndtraining.Where(a => a.ETTitle.ToLower().Contains(title.ToLower())).Select(d => d.UserAdded).ToList();

                    int attacCount = searchTitle.Count();

                    attachments = new ComposeExtensionAttachment[attacCount];

                    for (int i = 0; i < attacCount; i++)
                    {
                        attachments[i] = GetEventsAttachment(searchimage[i], searchTitle[i] + ',' + searchETType[i], searchdate[i], searchdetails[i], searchETid[i], searchETar[i]);
                    }

                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> searchTitle   = eventsTrainings.EventsAndtraining.Select(c => c.ETTitle).ToList();
                    List <string> searchdetails = eventsTrainings.EventsAndtraining.Select(c => c.ETDetails).ToList();
                    List <string> searchdate    = eventsTrainings.EventsAndtraining.Select(c => c.ETStartDate).ToList();
                    List <string> searchimage   = eventsTrainings.EventsAndtraining.Select(c => c.ETThumbnailUrl).ToList();
                    List <string> searchETType  = eventsTrainings.EventsAndtraining.Select(c => c.ETType).ToList();
                    List <string> searchETid    = eventsTrainings.EventsAndtraining.Select(c => c.ETID).ToList();
                    List <bool>   searchETar    = eventsTrainings.EventsAndtraining.Select(c => c.UserAdded).ToList();
                    attachments = new ComposeExtensionAttachment[searchTitle.Count];
                    for (int i = 0; i < searchTitle.Count; i++)
                    {
                        attachments[i] = GetEventsAttachment(searchimage[i], searchTitle[i] + ',' + searchETType[i], searchdate[i], searchdetails[i], searchETid[i], searchETar[i]);
                    }

                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                return(response);
            }
            else
            {
                return(null);
            }
        }
        public static ComposeExtensionResponse HandleMessageExtensionQuery(ConnectorClient connector, Activity activity, Dictionary <int, StudentValues> results)
        {
            Helperr            helper   = new Helperr();
            List <SpeakerBios> speakers = helper.SpeakerInformation();


            var query = activity.GetComposeExtensionQueryData();

            if (query == null /*|| (query.CommandId != "Speakers" || query.CommandId != "Sessions")*/)
            {
                return(null);
            }

            if (query.CommandId == "Speakers")
            {
                var title      = "";
                var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "SpeakerTitle");
                var response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();

                    List <string> searchNames  = speakers.Select(a => a.SpeakerName).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchImages = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Snap).ToList();
                    List <string> searchBio    = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Bio).ToList();
                    List <string> searchTitle  = speakers.Where(a => a.SpeakerName.ToLower().Contains(title.ToLower())).Select(c => c.Title).ToList();
                    int           attacCount   = searchNames.Count();

                    attachments = new ComposeExtensionAttachment[attacCount];
                    for (int i = 0; i < attacCount; i++)
                    {
                        attachments[i] = GetAttachment(searchImages[i], searchNames[i], searchTitle[i], searchBio[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> searchNames  = speakers.Select(c => c.SpeakerName).ToList();
                    List <string> searchImages = speakers.Select(c => c.Snap).ToList();
                    List <string> searchTitle  = speakers.Select(c => c.Title).ToList();
                    List <string> searchBio    = speakers.Select(c => c.Bio).ToList();
                    attachments = new ComposeExtensionAttachment[searchNames.Count];
                    for (int i = 0; i < searchNames.Count; i++)
                    {
                        attachments[i] = GetAttachment(searchImages[i], searchNames[i], searchTitle[i], searchBio[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }

                return(response);
            }
            else if (query.CommandId == "Sessions")
            {
                List <SessionList> sessions = helper.SessionInformation();

                var title      = "";
                var titleParam = query.Parameters?.FirstOrDefault(p => p.Name == "sessionTitle");
                var response   = new ComposeExtensionResponse(new ComposeExtensionResult("list", "result"));
                ComposeExtensionAttachment[] attachments = null;
                if (titleParam != null)
                {
                    title = titleParam.Value.ToString();

                    List <string> searchSessionNames    = sessions.Select(a => a.Session).Where(c => c.ToLower().Contains(title.ToLower())).Select(d => d).ToList();
                    List <string> searchSpeaker         = sessions.Where(a => a.Session.ToLower().Contains(title.ToLower())).Select(d => d.Speaker).ToList();
                    List <string> searchSessionAbstract = sessions.Where(a => a.Session.ToLower().Contains(title.ToLower())).Select(d => d.Abstract).ToList();
                    List <string> searchSessionType     = sessions.Where(a => a.Session.ToLower().Contains(title.ToLower())).Select(d => d.SessionType).ToList();;
                    int           attacCount            = searchSessionNames.Count();

                    attachments = new ComposeExtensionAttachment[attacCount];
                    for (int i = 0; i < attacCount; i++)
                    {
                        string speakerAndSessionType = searchSpeaker[i] + " - " + searchSessionType[i];
                        attachments[i] = GetAttachments(searchSessionNames[i], speakerAndSessionType, searchSessionAbstract[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }
                else
                {
                    List <string> searchSessionNames    = sessions.Select(c => c.Session).Take(20).ToList();
                    List <string> searchSpeaker         = sessions.Select(c => c.Speaker).Take(20).ToList();
                    List <string> searchSessionAbstract = sessions.Select(c => c.Abstract).Take(20).ToList();
                    List <string> searchSessionType     = sessions.Select(c => c.SessionType).ToList();
                    attachments = new ComposeExtensionAttachment[searchSessionNames.Count];
                    for (int i = 0; i < searchSessionNames.Count; i++)
                    {
                        string speakerAndSessionType = searchSpeaker[i] + " - " + searchSessionType[i];
                        attachments[i] = GetAttachments(searchSessionNames[i], speakerAndSessionType, searchSessionAbstract[i]);
                    }
                    response.ComposeExtension.Attachments = attachments.ToList();
                }

                return(response);
            }

            return(null);
        }