Exemplo n.º 1
0
        public ChooseItem()
        {
            InitializeComponent();

            // >> chat-chatpicker-itempicker
            ItemPickerContext context = new ItemPickerContext
            {
                ItemsSource = new List <string>()
                {
                    "2 days", "5 days", "7 days", "Another period"
                }
            };
            PickerItem pickerItem = new PickerItem {
                Context = context, HeaderText = "Select an item"
            };

            chat.Items.Add(pickerItem);
            context.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "SelectedItem")
                {
                    if (context.SelectedItem != null)
                    {
                        chat.Items.Remove(pickerItem);
                        chat.Items.Add(new TextMessage {
                            Author = chat.Author, Text = "" + context.SelectedItem
                        });
                    }
                }
            };
            // << chat-chatpicker-itempicker
        }
Exemplo n.º 2
0
        private void HandleDateSelection(Activity activity)
        {
            if (activity.Text.Contains("Please, choose a date for visiting"))
            {
                ItemPickerContext itemPickerContext = new ItemPickerContext
                {
                    ItemsSource = new List <CardAction>()
                    {
                        new CardAction()
                        {
                            Title = "Choose a Date"
                        }
                    }
                };

                PickerItem pickerItem = new PickerItem();
                pickerItem.Context = itemPickerContext;

                itemPickerContext.PropertyChanged += (s, e) =>
                {
                    if (e.PropertyName == nameof(ItemPickerContext.SelectedItem))
                    {
                        if (itemPickerContext.SelectedItem != null)
                        {
                            this.chat.Items.Remove(pickerItem);
                            this.chat.Items.Add(this.CreateDatePickerChatItem());
                        }
                    }
                };

                this.chat.Items.Add(pickerItem);
            }
        }
Exemplo n.º 3
0
        private void HandleDateSelection(Activity activity)
        {
            if (activity.Text == "When do you want your vacation to start?" || activity.Text.Contains("This doesn't seem to be a valid date."))
            {
                ItemPickerContext itemPickerContext = new ItemPickerContext
                {
                    ItemsSource = new List <CardAction>()
                    {
                        new CardAction()
                        {
                            Title = "Select Start Date"
                        }
                    }
                };

                PickerItem pickerItem = new PickerItem();
                pickerItem.Data    = itemPickerContext;
                pickerItem.Context = itemPickerContext;

                itemPickerContext.PropertyChanged += (s, e) =>
                {
                    if (e.PropertyName == nameof(ItemPickerContext.SelectedItem))
                    {
                        if (itemPickerContext.SelectedItem != null)
                        {
                            this.Items.Remove(pickerItem);
                            this.Items.Add(this.CreateDatePickerChatItem());
                        }
                    }
                };

                this.Items.Add(pickerItem);
            }
        }
Exemplo n.º 4
0
        private void RenderHeroCard(Attachment attachment)
        {
            HeroCard heroCard = JsonConvert.DeserializeObject <HeroCard>(attachment.Content.ToString());

            if (heroCard.Buttons == null || heroCard.Buttons.Count == 0)
            {
                return;
            }

            List <AirlineCompany> airlineCards = new List <AirlineCompany>();

            foreach (CardAction action in heroCard.Buttons)
            {
                AirlineCompany airline = new AirlineCompany();
                airline.Name        = action.Title;
                airline.CompanyLogo = action.Image;
                airline.Value       = action.Value.ToString();
                airlineCards.Add(airline);
            }

            ItemPickerContext itemPickerContext = new ItemPickerContext {
                ItemsSource = airlineCards
            };

            this.Context             = itemPickerContext;
            this.PickerHeaderText    = "Select an Airline Company";
            this.IsChatPickerVisible = true;
        }
Exemplo n.º 5
0
        private void HandleSuggestedActions(Activity activity)
        {
            if (activity.SuggestedActions == null)
            {
                return;
            }

            ItemPickerContext itemPickerContext = new ItemPickerContext {
                ItemsSource = activity.SuggestedActions.Actions
            };
            PickerItem pickerItem = new PickerItem();

            pickerItem.Context = itemPickerContext;

            itemPickerContext.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(ItemPickerContext.SelectedItem))
                {
                    if (itemPickerContext.SelectedItem != null)
                    {
                        this.chat.Items.Remove(pickerItem);
                        string selectedItem = ((CardAction)itemPickerContext.SelectedItem).Title;
                        this.chat.Items.Add(new TextMessage {
                            Author = this.chat.Author, Text = selectedItem
                        });
                    }
                }
            };

            this.chat.Items.Add(pickerItem);
        }
Exemplo n.º 6
0
        private void OnOkPickerCommandExecuted(object obj)
        {
            ItemPickerContext itemPickerContext = this.Context as ItemPickerContext;

            if (itemPickerContext != null && itemPickerContext.SelectedItem != null)
            {
                string selectedItem;
                if (itemPickerContext.SelectedItem is TravelCardAction)
                {
                    selectedItem = ((TravelCardAction)itemPickerContext.SelectedItem).DestinationName;
                }
                else
                {
                    selectedItem = ((AirlineCompany)itemPickerContext.SelectedItem).Value;
                }

                TextMessage pickerMessage = new TextMessage();
                pickerMessage.Text   = selectedItem;
                pickerMessage.Author = this.Me;

                this.Items.Add(pickerMessage);
            }

            this.IsChatPickerVisible = false;
        }
Exemplo n.º 7
0
        private void CreateItemPickerHeroCard(HeroCard heroCard)
        {
            this.innerChatPicker.HeaderText = heroCard.Text;
            ItemPickerContext itemPickerContext = new ItemPickerContext {
                ItemsSource = heroCard.Buttons
            };

            itemPickerContext.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(ItemPickerContext.SelectedItem))
                {
                    if (itemPickerContext.SelectedItem != null)
                    {
                        this.chat.Items.Add(new TextMessage {
                            Author = this.chat.Author, Text = ((CardAction)itemPickerContext.SelectedItem).Value.ToString()
                        });
                        this.innerChatPicker.Context   = null;
                        this.innerChatPicker.IsVisible = false;
                    }
                }
            };

            this.innerChatPicker.Context   = itemPickerContext;
            this.innerChatPicker.IsVisible = true;
        }
Exemplo n.º 8
0
        private void CreateInsurancePickerHeroCard(HeroCard heroCard)
        {
            this.outerChatPicker.HeaderText = heroCard.Text;
            ItemPickerContext itemPickerContext = new ItemPickerContext()
            {
                ItemsSource = heroCard.Buttons
            };

            this.outerChatPicker.Context   = itemPickerContext;
            this.outerChatPicker.IsVisible = true;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Determines whether this addin will provide navigation information,
        /// based on the given the context.
        /// </summary>
        /// <param name="context">Describes the situation in which the ItemPicker is being
        /// displayed to the user.</param>
        /// <returns></returns>
        public bool CanHandleItemSelection(ItemPickerContext context)
        {
            // Only use this navigation in TaskMode and when selecting Universe items.
            if (context.IsTaskMode &&
                context.TypeToSelect == DdiItemType.Universe)
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Determines whether this addin will provide navigation information,
        /// based on the given the context.
        /// </summary>
        /// <param name="context">Describes the situation in which the ItemPicker is being 
        /// displayed to the user.</param>
        /// <returns></returns>
        public bool CanHandleItemSelection(ItemPickerContext context)
        {
            // Only use this navigation in TaskMode and when selecting Universe items.
            if (context.IsTaskMode &&
                context.TypeToSelect == DdiItemType.Universe)
            {
                return true;
            }

            return false;
        }
Exemplo n.º 11
0
        private void HandleSuggestedActions(Activity activity)
        {
            if (activity.SuggestedActions != null)
            {
                ItemPickerContext itemPickerContext = null;
                if (activity.Text == "Here are some recommended locations for you:")
                {
                    List <TravelCardAction> travelActions = new List <TravelCardAction>();
                    foreach (CardAction action in activity.SuggestedActions.Actions)
                    {
                        travelActions.Add(new TravelCardAction()
                        {
                            DestinationName = action.Title
                        });
                    }

                    itemPickerContext = new ItemPickerContext {
                        ItemsSource = travelActions
                    };

                    this.Context             = itemPickerContext;
                    this.PickerHeaderText    = "Select a Location";
                    this.IsChatPickerVisible = true;
                }
                else
                {
                    itemPickerContext = new ItemPickerContext {
                        ItemsSource = activity.SuggestedActions.Actions
                    };
                    PickerItem pickerItem = new PickerItem();
                    pickerItem.Data    = itemPickerContext;
                    pickerItem.Context = itemPickerContext;

                    itemPickerContext.PropertyChanged += (s, e) =>
                    {
                        if (e.PropertyName == nameof(ItemPickerContext.SelectedItem))
                        {
                            if (itemPickerContext.SelectedItem != null)
                            {
                                this.Items.Remove(pickerItem);

                                string selectedItem = ((CardAction)itemPickerContext.SelectedItem).Title;
                                this.Items.Add(new TextMessage {
                                    Author = this.Me, Text = selectedItem
                                });
                            }
                        }
                    };

                    this.Items.Add(pickerItem);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the navigation nodes to be displayed on the left side of the ItemPicker.
        /// </summary>
        /// <param name="context">Describes the situation in which the ItemPicker is being
        /// displayed to the user.</param>
        /// <returns></returns>
        public Collection <Node> GetNavigationNodes(ItemPickerContext context)
        {
            var results = new Collection <Node>();

            // Only include the Checkouts node in the navigation.
            // Alternatively, we could search for certain items to include in the navigation,
            // and only include those.
            var checkoutsNode = new CheckoutsFolderNode(null);

            results.Add(checkoutsNode);

            return(results);
        }
Exemplo n.º 13
0
        private void RenderReplyMessages(JObject message)
        {
            JArray replies = message.Value <JArray>("replies");

            if (replies == null)
            {
                return;
            }

            List <InsuranceService> options = new List <InsuranceService>();

            foreach (JValue reply in replies)
            {
                InsuranceService option = new InsuranceService();
                option.Type = reply.ToString();
                options.Add(option);
            }

            ItemPickerContext insurancePickerContext = new ItemPickerContext();

            insurancePickerContext.ItemsSource = options;

            PickerItem insurancePickerItem = new PickerItem()
            {
                Context = insurancePickerContext
            };

            insurancePickerContext.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(ItemPickerContext.SelectedItem))
                {
                    if (insurancePickerContext.SelectedItem != null)
                    {
                        this.chat.Items.Remove(insurancePickerItem);

                        string insuranceServiceType = ((InsuranceService)insurancePickerContext.SelectedItem).Type;
                        this.chat.Items.Add(new TextMessage()
                        {
                            Author = this.chat.Author, Text = insuranceServiceType
                        });
                    }
                }
            };

            this.chat.Items.Add(insurancePickerItem);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets the search results to be displayed on the right side of the ItemPicker.
        /// </summary>
        /// <param name="context">Describes the situation in which the ItemPicker is being
        /// displayed to the user.</param>
        /// <param name="selectedNode">The node selected on the left side of the ItemPicker.</param>
        /// <param name="searchText">The search text entered by the user.</param>
        /// <returns></returns>
        public Collection <Node> GetSearchResults(ItemPickerContext context, Node selectedNode, string searchText)
        {
            var client    = selectedNode.GetClient();
            var navigator = new NavigatorHelper(client);

            var provider = selectedNode as IVersionableProvider;
            Collection <Node> results = null;

            if (provider != null)
            {
                // If an item is selected in the navigator, find items of the target type within that selected item.
                results = navigator.FindItems(provider.Metadata.CompositeId, context.TypeToSelect, selectedNode, false);
            }
            else
            {
                // No item is selected in the navigator, so search the entire repository.
                results = navigator.FindItems(context.TypeToSelect, selectedNode, false);
            }

            return(results);
        }
Exemplo n.º 15
0
        private void RenderSuggestedActions(JToken suggestedActions)
        {
            List <SuggestedAction> actions = new List <SuggestedAction>();

            foreach (var action in suggestedActions)
            {
                actions.Add(new SuggestedAction()
                {
                    Type = Convert.ToString(action["title"])
                });
            }

            ItemPickerContext pickerContext = new ItemPickerContext();

            pickerContext.ItemsSource = actions;

            PickerItem pickerItem = new PickerItem()
            {
                Context = pickerContext
            };

            pickerContext.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(ItemPickerContext.SelectedItem))
                {
                    if (pickerContext.SelectedItem != null)
                    {
                        this.chat.Items.Remove(pickerItem);

                        string insuranceServiceType = ((SuggestedAction)pickerContext.SelectedItem).Type;
                        this.chat.Items.Add(new TextMessage()
                        {
                            Author = this.chat.Author, Text = insuranceServiceType
                        });
                    }
                }
            };

            this.chat.Items.Add(pickerItem);
        }
        /// <summary>
        /// Gets the navigation nodes to be displayed on the left side of the ItemPicker.
        /// </summary>
        /// <param name="context">Describes the situation in which the ItemPicker is being 
        /// displayed to the user.</param>
        /// <returns></returns>
        public Collection<Node> GetNavigationNodes(ItemPickerContext context)
        {
            var results =  new Collection<Node>();

            // Only include the Checkouts node in the navigation.
            // Alternatively, we could search for certain items to include in the navigation,
            // and only include those.
            var checkoutsNode = new CheckoutsFolderNode(null);
            results.Add(checkoutsNode);

            return results;
        }
        /// <summary>
        /// Gets the search results to be displayed on the right side of the ItemPicker.
        /// </summary>
        /// <param name="context">Describes the situation in which the ItemPicker is being
        /// displayed to the user.</param>
        /// <param name="selectedNode">The node selected on the left side of the ItemPicker.</param>
        /// <param name="searchText">The search text entered by the user.</param>
        /// <returns></returns>
        public Collection<Node> GetSearchResults(ItemPickerContext context, Node selectedNode, string searchText)
        {
            var client = selectedNode.GetClient();
            var navigator = new NavigatorHelper(client);

            var provider = selectedNode as IVersionableProvider;
            Collection<Node> results = null;
            if (provider != null)
            {
                // If an item is selected in the navigator, find items of the target type within that selected item.
                results = navigator.FindItems(provider.Metadata.CompositeId, context.TypeToSelect, selectedNode, false);
            }
            else
            {
                // No item is selected in the navigator, so search the entire repository.
                results = navigator.FindItems(context.TypeToSelect, selectedNode, false);
            }

            return results;
        }