private AdaptiveChoiceSetInput GetAdaptiveChoiceSetInput(
            IEnumerable <ChannelInfo> channels,
            string targetChannelId)
        {
            if (channels == null)
            {
                throw new ArgumentNullException(nameof(channels));
            }

            if (string.IsNullOrWhiteSpace(targetChannelId))
            {
                throw new ArgumentNullException(nameof(targetChannelId));
            }

            var result = new AdaptiveChoiceSetInput
            {
                Id            = TaskModuleConstants.ChangeMessageTargetChoiceSetInputId,
                IsMultiSelect = false,
                Choices       = new List <AdaptiveChoice>(),
                Style         = AdaptiveChoiceInputStyle.Compact,
                Value         = targetChannelId,
            };

            foreach (var channel in channels)
            {
                var adaptiveChoice = new AdaptiveChoice
                {
                    Title = string.IsNullOrWhiteSpace(channel.Name) ? "General" : channel.Name,
                    Value = channel.Id,
                };
                result.Choices.Add(adaptiveChoice);
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Generate ToAdaptiveCardAttachmentWithoutSpeech.
        /// </summary>
        /// <param name="todos">To Do activities.</param>
        /// <param name="allTaskCount">all tasks count.</param>
        /// <param name="taskContent">the task content.</param>
        /// <param name="botResponse1">the bot response 1.</param>
        /// <param name="botResponse2">the bot response 2.</param>
        /// <returns>Generated adaptive card attachment.</returns>
        public static Microsoft.Bot.Schema.Attachment ToAdaptiveCardAttachmentForOtherFlows(
            List <ToDoTaskActivityModel> todos,
            int allTaskCount,
            string taskContent,
            BotResponse botResponse1,
            BotResponse botResponse2)
        {
            var toDoCard = new AdaptiveCard();
            var showText = Format(botResponse2.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }
            });
            var speakText = Format(botResponse1.Reply.Speak, new StringDictionary()
            {
                { "taskContent", taskContent }
            })
                            + Format(botResponse2.Reply.Speak, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }
            });

            toDoCard.Speak = speakText;

            var body      = new List <AdaptiveElement>();
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);
            var choiceSet = new AdaptiveChoiceSetInput();

            choiceSet.IsMultiSelect = true;
            string value = Guid.NewGuid().ToString() + ",";

            foreach (var todo in todos)
            {
                var choice = new AdaptiveChoice();
                choice.Title = todo.Topic;
                choice.Value = todo.Id;
                choiceSet.Choices.Add(choice);
                if (todo.IsCompleted)
                {
                    value += todo.Id + ",";
                }
            }

            value           = value.Remove(value.Length - 1);
            choiceSet.Value = value;
            body.Add(choiceSet);
            toDoCard.Body = body;

            var attachment = new Microsoft.Bot.Schema.Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = toDoCard,
            };

            return(attachment);
        }
Esempio n. 3
0
        protected Attachment ToAdaptiveCardForReadMore(
            List <TaskItem> todos,
            int startIndexOfTasksToBeRead,
            int toBeReadTasksCount,
            int allTasksCount)
        {
            var toDoCard = new AdaptiveCard();
            var body     = new List <AdaptiveElement>();
            var showText = Format(ToDoSharedResponses.ShowToDoTasks.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTasksCount.ToString() }
            });
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);

            var choiceSet = new AdaptiveChoiceSetInput
            {
                IsMultiSelect = true,
            };

            var value = Guid.NewGuid().ToString() + ",";
            var index = 0;

            foreach (var todo in todos)
            {
                var choice = new AdaptiveChoice
                {
                    Title = todo.Topic,
                    Value = todo.Id,
                };
                choiceSet.Choices.Add(choice);
                if (todo.IsCompleted)
                {
                    value += todo.Id + ",";
                }

                index++;
                if (index > startIndexOfTasksToBeRead && index <= toBeReadTasksCount + startIndexOfTasksToBeRead)
                {
                    toDoCard.Speak += index + " " + todo.Topic + " ";
                }
            }

            value           = value.Remove(value.Length - 1);
            choiceSet.Value = value;
            body.Add(choiceSet);
            toDoCard.Body = body;

            var attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = toDoCard,
            };

            return(attachment);
        }
        public static Attachment Create()
        {
            var adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
            var container    = new AdaptiveContainer();

            container.Items.Add(new AdaptiveTextBlock
            {
                Text = "Please select your country",
                HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                Weight = AdaptiveTextWeight.Bolder,
                Size   = AdaptiveTextSize.Large,
            });

            var choices = new List <AdaptiveChoice>();
            //plugin to get country names
            var countries = TZNames.GetCountryNames("en-us");

            foreach (var country in countries)
            {
                var choice = new AdaptiveChoice
                {
                    Title = country.Value,
                    Value = country.Key,
                };

                choices.Add(choice);
            }

            container.Items.Add(new AdaptiveChoiceSetInput
            {
                Id      = "country",
                Style   = AdaptiveChoiceInputStyle.Compact,
                Choices = choices,
                Value   = "US",
            });

            adaptiveCard.Body.Add(container);
            adaptiveCard.Actions.Add(new AdaptiveSubmitAction
            {
                Id    = "country-submit",
                Title = "Submit",
                Type  = "Action.Submit",
            });

            var attachment = new Attachment
            {
                Content     = adaptiveCard,
                ContentType = "application/vnd.microsoft.card.adaptive",
            };

            return(attachment);
        }
Esempio n. 5
0
        public static Attachment Create(IChannelClient client)
        {
            var adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
            var container    = new AdaptiveContainer();

            container.Items.Add(new AdaptiveTextBlock
            {
                Text = "Which tags do you wish to search for?",
                HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                Weight = AdaptiveTextWeight.Bolder,
                Size   = AdaptiveTextSize.Medium,
            });

            var choices   = new List <AdaptiveChoice>();
            var tagsInUse = client.GetTagsInUse().Result;

            foreach (var tag in tagsInUse)
            {
                var choice = new AdaptiveChoice
                {
                    Title = tag.Name,
                    Value = tag.Id.ToString(),
                };

                choices.Add(choice);
            }

            container.Items.Add(new AdaptiveChoiceSetInput
            {
                Id            = "tags",
                Style         = AdaptiveChoiceInputStyle.Expanded,
                Choices       = choices,
                IsMultiSelect = true,
                Value         = "US",
            });

            adaptiveCard.Body.Add(container);
            adaptiveCard.Actions.Add(new AdaptiveSubmitAction
            {
                Id    = "tags-submit",
                Title = "Submit",
                Type  = "Action.Submit",
            });

            var attachment = new Attachment
            {
                Content     = adaptiveCard,
                ContentType = "application/vnd.microsoft.card.adaptive",
            };

            return(attachment);
        }
Esempio n. 6
0
        public static string CreateSelectReceiveLocationListAdaptiveCard(List <ReceiveLocation> receiveLocations, string message, string command)
        {
            #region TopLevelColumn
            AdaptiveColumnSet topLevelColumnSet = CreateTopLevelColumnSet();
            #endregion


            #region ChoiceList

            AdaptiveChoiceSetInput choiceSetInput = new AdaptiveChoiceSetInput()
            {
                Id        = "receiveLocationsChoiceSet",
                Separator = true,
                Style     = AdaptiveChoiceInputStyle.Compact,
            };

            foreach (ReceiveLocation receiveLocation in  receiveLocations)
            {
                string name = receiveLocation.Name;

                AdaptiveChoice choice = new AdaptiveChoice()
                {
                    Title = name,
                    Value = name
                };

                choiceSetInput.Choices.Add(choice);
            }
            AdaptiveCard adaptiveCard = new AdaptiveCard();
            adaptiveCard.Body.Add(topLevelColumnSet);
            adaptiveCard.Body.Add(new AdaptiveTextBlock()
            {
                Id = "header", Text = message, Wrap = true, Color = AdaptiveTextColor.Accent, IsSubtle = true
            });
            adaptiveCard.Body.Add(choiceSetInput);
            adaptiveCard.Actions = new List <AdaptiveAction>()
            {
                new AdaptiveSubmitAction()
                {
                    Id       = "submit",
                    Title    = "Submit",
                    DataJson = "{\"command\":\"" + command + "\"}"
                }
            };

            #endregion

            string adaptiveCardJson = adaptiveCard.ToJson();
            adaptiveCardJson = RenderStaticImage(adaptiveCardJson, Constants.BizManDummyUrl, Constants.BizManImagePath);
            return(adaptiveCardJson);
        }
        private static async Task adaptivecard(ITurnContext turnContext)
        {
            var card = new AdaptiveCard();
            List <AdaptiveChoice> Choice = new List <AdaptiveChoice>();
            AdaptiveChoice        c1     = new AdaptiveChoice()
            {
                Title = "How to activate project in enterproj application",
                Value = "How to activate project in enterproj application"
            };
            AdaptiveChoice c2 = new AdaptiveChoice()
            {
                Title = "How to Add a team member in enterproj application",
                Value = "How to Add a team member in enterproj application"
            };
            AdaptiveChoice c3 = new AdaptiveChoice()
            {
                Title = "How to assign ownership in enterproj application",
                Value = "How to assign ownership in enterproj application"
            };
            AdaptiveChoice c4 = new AdaptiveChoice()
            {
                Title = "How to create new project in enterproj application",
                Value = "How to create new project in enterproj application"
            };

            Choice.Add(c1); Choice.Add(c2); Choice.Add(c3); Choice.Add(c4);

            card.Body.Add(new AdaptiveTextBlock()
            {
                Text = "Select an enterproj query", Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Bolder
            });
            card.Body.Add(new AdaptiveChoiceSetInput()
            {
                Id = "query", Style = AdaptiveChoiceInputStyle.Compact, Choices = Choice
            });
            card.Actions.Add(new AdaptiveSubmitAction()
            {
                Title = "Submit"
            });
            var returncard = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card
            };
            var reply = MessageFactory.Attachment(returncard);

            await turnContext.SendActivityAsync(reply);
        }
Esempio n. 8
0
        public static FrameworkElement Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            var chosen = input.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>();

            var uiGrid = new Grid();

            uiGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            uiGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });

            var uiComboBox = new ComboBox();

            uiComboBox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBox");
            uiComboBox.DataContext = input;

            var uiChoices = new StackPanel();

            uiChoices.DataContext = input;
            uiChoices.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput");

            foreach (var choice in input.Choices)
            {
                if (input.IsMultiSelect == true)
                {
                    var uiCheckbox = new CheckBox();
                    SetContent(uiCheckbox, choice.Title, input.Wrap);
                    uiCheckbox.IsChecked   = chosen.Contains(choice.Value);
                    uiCheckbox.DataContext = choice;
                    uiCheckbox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox");
                    uiChoices.Children.Add(uiCheckbox);
                }
                else
                {
                    if (input.Style == AdaptiveChoiceInputStyle.Compact)
                    {
                        var uiComboItem = new ComboBoxItem();
                        uiComboItem.HorizontalAlignment = HorizontalAlignment.Stretch;
                        uiComboItem.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBoxItem");

                        TextBlock content = SetContent(uiComboItem, choice.Title, input.Wrap);
                        // The content TextBlock is binded to the width of the comboBox container
                        if (input.Wrap && content != null)
                        {
                            BindingOperations.SetBinding(content, TextBlock.MaxWidthProperty,
                                                         new Binding("ActualWidth")
                            {
                                Source = uiComboBox
                            });
                        }

                        uiComboItem.DataContext = choice;

                        uiComboBox.Items.Add(uiComboItem);

                        // If multiple values are specified, no option is selected
                        if (chosen.Contains(choice.Value) && chosen.Count == 1)
                        {
                            uiComboBox.SelectedItem = uiComboItem;
                        }
                    }
                    else
                    {
                        var uiRadio = new RadioButton();
                        SetContent(uiRadio, choice.Title, input.Wrap);

                        // When isMultiSelect is false, only 1 specified value is accepted.
                        // Otherwise, don't set any option
                        if (chosen.Count == 1)
                        {
                            uiRadio.IsChecked = chosen.Contains(choice.Value);
                        }
                        uiRadio.GroupName   = input.Id;
                        uiRadio.DataContext = choice;
                        uiRadio.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.Radio");
                        uiChoices.Children.Add(uiRadio);
                    }
                }
            }
            context.InputBindings.Add(input.Id, () =>
            {
                if (input.IsMultiSelect == true)
                {
                    string values = string.Empty;
                    foreach (var item in uiChoices.Children)
                    {
                        CheckBox checkBox             = (CheckBox)item;
                        AdaptiveChoice adaptiveChoice = checkBox.DataContext as AdaptiveChoice;
                        if (checkBox.IsChecked == true)
                        {
                            values += (values == string.Empty ? "" : ",") + adaptiveChoice.Value;
                        }
                    }
                    return(values);
                }
                else
                {
                    if (input.Style == AdaptiveChoiceInputStyle.Compact)
                    {
                        ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem;
                        if (item != null)
                        {
                            AdaptiveChoice adaptiveChoice = item.DataContext as AdaptiveChoice;
                            return(adaptiveChoice.Value);
                        }
                        return(null);
                    }
                    else
                    {
                        foreach (var item in uiChoices.Children)
                        {
                            RadioButton radioBox          = (RadioButton)item;
                            AdaptiveChoice adaptiveChoice = radioBox.DataContext as AdaptiveChoice;
                            if (radioBox.IsChecked == true)
                            {
                                return(adaptiveChoice.Value);
                            }
                        }
                        return(null);
                    }
                }
            });

            if (!input.IsMultiSelect && input.Style == AdaptiveChoiceInputStyle.Compact)
            {
                Grid.SetRow(uiComboBox, 1);
                uiGrid.Children.Add(uiComboBox);
                return(uiGrid);
            }
            else
            {
                Grid.SetRow(uiChoices, 1);
                uiGrid.Children.Add(uiChoices);
                return(uiGrid);
            }
        }
Esempio n. 9
0
        protected Microsoft.Bot.Schema.Attachment ToAdaptiveCardAttachmentForShowToDos(
            List <TaskItem> todos,
            int allTaskCount,
            BotResponse botResponse1,
            BotResponse botResponse2)
        {
            var toDoCard  = new AdaptiveCard();
            var speakText = Format(botResponse1.Reply.Speak, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }
            });

            if (botResponse2 != null)
            {
                speakText += Format(botResponse2.Reply.Speak, new StringDictionary()
                {
                    { "taskCount", todos.Count.ToString() }
                });
            }

            var showText = Format(botResponse1.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }
            });

            toDoCard.Speak = speakText;
            var body      = new List <AdaptiveElement>();
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);
            var choiceSet = new AdaptiveChoiceSetInput
            {
                IsMultiSelect = true,
            };
            var value = Guid.NewGuid().ToString() + ",";
            var index = 0;

            foreach (var todo in todos)
            {
                var choice = new AdaptiveChoice
                {
                    Title = todo.Topic,
                    Value = todo.Id,
                };
                choiceSet.Choices.Add(choice);
                if (todo.IsCompleted)
                {
                    value += todo.Id + ",";
                }

                toDoCard.Speak += (++index) + "." + todo.Topic + " ";
            }

            value           = value.Remove(value.Length - 1);
            choiceSet.Value = value;
            body.Add(choiceSet);
            toDoCard.Body = body;

            var attachment = new Microsoft.Bot.Schema.Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = toDoCard,
            };

            return(attachment);
        }
        public static FrameworkElement Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            var chosen = input.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>();

            var uiGrid = new Grid();

            uiGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            uiGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });

            var uiComboBox = new ComboBox();

            uiComboBox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBox");
            uiComboBox.DataContext = input;

            var uiChoices = new ListBox();

            ScrollViewer.SetHorizontalScrollBarVisibility(uiChoices, ScrollBarVisibility.Disabled);
            var itemsPanelTemplate = new ItemsPanelTemplate();
            var factory            = new FrameworkElementFactory(typeof(WrapPanel));

            itemsPanelTemplate.VisualTree = factory;
            uiChoices.ItemsPanel          = itemsPanelTemplate;
            uiChoices.DataContext         = input;
            uiChoices.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput");

            foreach (var choice in input.Choices)
            {
                if (input.IsMultiSelect == true)
                {
                    var uiCheckbox = new CheckBox();
                    uiCheckbox.Content     = choice.Title;
                    uiCheckbox.IsChecked   = chosen.Contains(choice.Value);
                    uiCheckbox.DataContext = choice;
                    uiCheckbox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox");
                    uiChoices.Items.Add(uiCheckbox);
                }
                else
                {
                    if (input.Style == AdaptiveChoiceInputStyle.Compact)
                    {
                        var uiComboItem = new ComboBoxItem();
                        uiComboItem.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBoxItem");
                        uiComboItem.Content     = choice.Title;
                        uiComboItem.DataContext = choice;
                        uiComboBox.Items.Add(uiComboItem);

                        // If multiple values are specified, no option is selected
                        if (chosen.Contains(choice.Value) && chosen.Count == 1)
                        {
                            uiComboBox.SelectedItem = uiComboItem;
                        }
                    }
                    else
                    {
                        var uiRadio = new RadioButton();
                        uiRadio.Content = choice.Title;

                        // When isMultiSelect is false, only 1 specified value is accepted.
                        // Otherwise, don't set any option
                        if (chosen.Count == 1)
                        {
                            uiRadio.IsChecked = chosen.Contains(choice.Value);
                        }
                        uiRadio.GroupName   = input.Id;
                        uiRadio.DataContext = choice;
                        uiRadio.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.Radio");
                        uiChoices.Items.Add(uiRadio);
                    }
                }
            }
            context.InputBindings.Add(input.Id, () =>
            {
                if (input.IsMultiSelect == true)
                {
                    string values = string.Empty;
                    foreach (var item in uiChoices.Items)
                    {
                        CheckBox checkBox             = (CheckBox)item;
                        AdaptiveChoice adaptiveChoice = checkBox.DataContext as AdaptiveChoice;
                        if (checkBox.IsChecked == true)
                        {
                            values += (values == string.Empty ? "" : ",") + adaptiveChoice.Value;
                        }
                    }
                    return(values);
                }
                else
                {
                    if (input.Style == AdaptiveChoiceInputStyle.Compact)
                    {
                        ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem;
                        if (item != null)
                        {
                            AdaptiveChoice adaptiveChoice = item.DataContext as AdaptiveChoice;
                            return(adaptiveChoice.Value);
                        }
                        return(null);
                    }
                    else
                    {
                        foreach (var item in uiChoices.Items)
                        {
                            RadioButton radioBox          = (RadioButton)item;
                            AdaptiveChoice adaptiveChoice = radioBox.DataContext as AdaptiveChoice;
                            if (radioBox.IsChecked == true)
                            {
                                return(adaptiveChoice.Value);
                            }
                        }
                        return(null);
                    }
                }
            });
            if (input.Style == AdaptiveChoiceInputStyle.Compact)
            {
                Grid.SetRow(uiComboBox, 1);
                uiGrid.Children.Add(uiComboBox);
                return(uiGrid);
            }
            else
            {
                Grid.SetRow(uiChoices, 1);
                uiGrid.Children.Add(uiChoices);
                return(uiGrid);
            }
        }
Esempio n. 11
0
        public static View Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            object list;
            string str = input.Value;

            if (str != null)
            {
                list = (
                    from p in str.Split(new char[] { ',' })
                    select p.Trim() into s
                    where !string.IsNullOrEmpty(s)
                    select s).ToList <string>();
            }
            else
            {
                list = null;
            }
            if (list == null)
            {
                list = new List <string>();
            }
            List <string> strs        = (List <string>)list;
            StackLayout   stackLayout = new StackLayout();

            stackLayout.Orientation = StackOrientation.Vertical;
            foreach (AdaptiveChoice choice in input.Choices)
            {
                if (input.IsMultiSelect)
                {
                    var checkBox = new CheckBox()
                    {
                        Text           = choice.Title,
                        IsChecked      = strs.Contains(choice.Value),
                        BindingContext = choice,
                        Style          = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox")
                    };
                    stackLayout.Children.Add(checkBox);


                    checkBox.CheckUnCheckAction = new Action <CheckBox>((c) =>
                    {
                        if (CheckBoxUpdating)
                        {
                            return;
                        }
                        CheckBoxUpdating = true;

                        if (c.Text == "All")
                        {
                            stackLayout.Children.ForEach((i) => (i as CheckBox).IsChecked = c.IsChecked);
                        }
                        else if (c.IsChecked)
                        {
                            CheckBox allCheckBox = null;
                            var isChecked        = true;
                            foreach (var i in stackLayout.Children)
                            {
                                var box = i as CheckBox;
                                if (box.Text == "All")
                                {
                                    allCheckBox = box;
                                }
                                else if (!box.IsChecked)
                                {
                                    isChecked = false;
                                    break;
                                }
                            }
                            if (allCheckBox != null && isChecked)
                            {
                                allCheckBox.IsChecked = true;
                            }
                        }
                        else
                        {
                            foreach (var i in stackLayout.Children)
                            {
                                var box = i as CheckBox;
                                if (box.Text == "All")
                                {
                                    box.IsChecked = false;
                                    break;
                                }
                            }
                        }
                        CheckBoxUpdating = false;
                    });
                }
            }

            context.HideIcon = true;
            context.InputBindings.Add(input.Id, new Func <string>(() =>
            {
                if (input.IsMultiSelect)
                {
                    string value = string.Empty;
                    foreach (var item in stackLayout.Children)
                    {
                        AdaptiveChoice dataContext = item.BindingContext as AdaptiveChoice;
                        var isChecked = (item as CheckBox).IsChecked;
                        if (!isChecked)//(isChecked.GetValueOrDefault() ? !isChecked.HasValue : true))
                        {
                            continue;
                        }
                        value = string.Concat(value, (value == string.Empty ? "" : ";"), dataContext.Value);
                    }
                    return(value);
                }
                return(string.Empty);
            }));

            return(stackLayout);
        }
        public static FrameworkElement Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            var chosen = input.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>();

            if (context.Config.SupportsInteractivity)
            {
                var uiGrid = new Grid();
                uiGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                uiGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });

                var uiComboBox = new ComboBox();
                uiComboBox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBox");
                uiComboBox.DataContext = input;

                var uiChoices = new ListBox();
                ScrollViewer.SetHorizontalScrollBarVisibility(uiChoices, ScrollBarVisibility.Disabled);
                var itemsPanelTemplate = new ItemsPanelTemplate();
                var factory            = new FrameworkElementFactory(typeof(WrapPanel));
                itemsPanelTemplate.VisualTree = factory;
                uiChoices.ItemsPanel          = itemsPanelTemplate;
                uiChoices.DataContext         = input;
                uiChoices.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput");

                foreach (var choice in input.Choices)
                {
                    if (input.IsMultiSelect == true)
                    {
                        var uiCheckbox = new CheckBox();
                        uiCheckbox.Content     = choice.Title;
                        uiCheckbox.IsChecked   = chosen.Contains(choice.Value);
                        uiCheckbox.DataContext = choice;
                        uiCheckbox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox");
                        uiChoices.Items.Add(uiCheckbox);
                    }
                    else
                    {
                        if (input.Style == AdaptiveChoiceInputStyle.Compact)
                        {
                            var uiComboItem = new ComboBoxItem();
                            uiComboItem.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBoxItem");
                            uiComboItem.Content     = choice.Title;
                            uiComboItem.DataContext = choice;
                            uiComboBox.Items.Add(uiComboItem);
                            if (chosen.Contains(choice.Value))
                            {
                                uiComboBox.SelectedItem = uiComboItem;
                            }
                        }
                        else
                        {
                            var uiRadio = new RadioButton();
                            uiRadio.Content     = choice.Title;
                            uiRadio.IsChecked   = chosen.Contains(choice.Value);
                            uiRadio.GroupName   = input.Id;
                            uiRadio.DataContext = choice;
                            uiRadio.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.Radio");
                            uiChoices.Items.Add(uiRadio);
                        }
                    }
                }
                context.InputBindings.Add(input.Id, () =>
                {
                    if (input.IsMultiSelect == true)
                    {
                        string values = string.Empty;
                        foreach (var item in uiChoices.Items)
                        {
                            CheckBox checkBox             = (CheckBox)item;
                            AdaptiveChoice adaptiveChoice = checkBox.DataContext as AdaptiveChoice;
                            if (checkBox.IsChecked == true)
                            {
                                values += (values == string.Empty ? "" : ",") + adaptiveChoice.Value;
                            }
                        }
                        return(values);
                    }
                    else
                    {
                        if (input.Style == AdaptiveChoiceInputStyle.Compact)
                        {
                            ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem;
                            if (item != null)
                            {
                                AdaptiveChoice adaptiveChoice = item.DataContext as AdaptiveChoice;
                                return(adaptiveChoice.Value);
                            }
                            return(null);
                        }
                        else
                        {
                            foreach (var item in uiChoices.Items)
                            {
                                RadioButton radioBox          = (RadioButton)item;
                                AdaptiveChoice adaptiveChoice = radioBox.DataContext as AdaptiveChoice;
                                if (radioBox.IsChecked == true)
                                {
                                    return(adaptiveChoice.Value);
                                }
                            }
                            return(null);
                        }
                    }
                });
                if (input.Style == AdaptiveChoiceInputStyle.Compact)
                {
                    Grid.SetRow(uiComboBox, 1);
                    uiGrid.Children.Add(uiComboBox);
                    return(uiGrid);
                }
                else
                {
                    Grid.SetRow(uiChoices, 1);
                    uiGrid.Children.Add(uiChoices);
                    return(uiGrid);
                }
            }

            string choiceText = XamlUtilities.GetFallbackText(input);

            if (choiceText == null)
            {
                List <string> choices = input.Choices.Select(choice => choice.Title).ToList();
                if (input.Style == AdaptiveChoiceInputStyle.Compact)
                {
                    if (input.IsMultiSelect)
                    {
                        choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " and ")}";
                    }
                    else
                    {
                        choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " or ")}";
                    }
                }
                else // if (adaptiveChoiceSetInput.Style == ChoiceInputStyle.Expanded)
                {
                    choiceText = $"* {RendererUtilities.JoinString(choices, "\n* ", "\n* ")}";
                }
            }
            AdaptiveContainer container = AdaptiveTypedElementConverter.CreateElement <AdaptiveContainer>();

            container.Spacing   = input.Spacing;
            container.Separator = input.Separator;
            AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();

            textBlock.Text = choiceText;
            textBlock.Wrap = true;
            container.Items.Add(textBlock);

            textBlock       = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
            textBlock.Text  = RendererUtilities.JoinString(input.Choices.Where(c => chosen.Contains(c.Value)).Select(c => c.Title).ToList(), ", ", " and ");
            textBlock.Color = AdaptiveTextColor.Accent;
            textBlock.Wrap  = true;
            container.Items.Add(textBlock);
            return(context.Render(container));
        }
Esempio n. 13
0
        private async Task MontaAdaptiveCards(IDialogContext context)
        {
            try
            {
                //var txt = File.ReadAllText($@"C:\Users\User\source\repos\Organizze_Bot\OrganizzeBot\AdaptiveCards\card.json");
                //AdaptiveCardParseResult result = AdaptiveCard.FromJson(txt);

                //AdaptiveCard card = result.Card;

                Models.Categoria[] categorias;
                var choices = new List <AdaptiveChoice>();

                using (var client = new Services.CategoriaService())
                {
                    categorias = await client.BuscaCategorias();

                    if (categorias != null)
                    {
                        foreach (var categoria in categorias)
                        {
                            var choice = new AdaptiveChoice()
                            {
                                Title = categoria.Name,
                                Value = categoria.Id.ToString()
                            };

                            choices.Add(choice);
                        }
                    }
                }


                var card = new AdaptiveCard()
                {
                    Body = new List <AdaptiveElement>()
                    {
                        new AdaptiveTextBlock()
                        {
                            Text   = "Adicionar Movimentação",
                            Size   = AdaptiveTextSize.Medium,
                            Weight = AdaptiveTextWeight.Bolder,
                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center
                        },
                        new AdaptiveTextInput()
                        {
                            Placeholder = "Descrição",
                            Style       = AdaptiveTextInputStyle.Text,
                            Id          = "Descricao"
                        },
                        new AdaptiveNumberInput()
                        {
                            Placeholder = "Valor",
                            Min         = 0,
                            Id          = "Valor"
                        },
                        new AdaptiveDateInput()
                        {
                            Placeholder = "Data",
                            Value       = DateTime.Now.ToString("yyyy-MM-dd"),
                            Id          = "Data"
                        },
                        new AdaptiveChoiceSetInput()
                        {
                            Style   = AdaptiveChoiceInputStyle.Compact,
                            Id      = "Categoria",
                            Choices = choices
                        }
                    },
                    Actions = new List <AdaptiveAction>()
                    {
                        new AdaptiveSubmitAction()
                        {
                            Title    = "Salvar",
                            DataJson = "{ \"Type\": \"SaveCommand\" }"
                        }
                    }
                };



                Attachment attachment = new Attachment()
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content     = card
                };

                var reply = context.MakeMessage();
                reply.Attachments.Add(attachment);

                await context.PostAsync(reply, CancellationToken.None);

                context.Wait(MessageReceivedAsync);
            }
            catch (AdaptiveSerializationException ex)
            {
                throw ex;
            }
        }
Esempio n. 14
0
        public static Attachment Create(string countryCode)
        {
            var adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
            var container    = new AdaptiveContainer();

            container.Items.Add(new AdaptiveTextBlock
            {
                Text = "Please select your time zone",
                HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                Weight = AdaptiveTextWeight.Bolder,
                Size   = AdaptiveTextSize.Large,
            });

            var choices       = new List <AdaptiveChoice>();
            var timezones     = TZNames.GetTimeZonesForCountry(countryCode, "en-us");
            var defaultChoice = new AdaptiveChoice
            {
                Title = "Universal Co-ordinated Time",
                Value = "Etc/GMT",
            };

            if (timezones.Any())
            {
                foreach (var timezone in timezones)
                {
                    var choice = new AdaptiveChoice
                    {
                        Title = timezone.Value,
                        Value = timezone.Key,
                    };

                    choices.Add(choice);
                }
            }
            else
            {
                choices.Add(defaultChoice);
            }

            container.Items.Add(new AdaptiveChoiceSetInput
            {
                Id      = "tz",
                Style   = AdaptiveChoiceInputStyle.Compact,
                Choices = choices,
                Value   = choices.First().Value,
            });

            adaptiveCard.Body.Add(container);
            adaptiveCard.Actions.Add(new AdaptiveSubmitAction
            {
                Id    = "tz-submit",
                Title = "Submit",
                Type  = "Action.Submit",
            });

            var attachment = new Attachment
            {
                Content     = adaptiveCard,
                ContentType = "application/vnd.microsoft.card.adaptive",
            };

            return(attachment);
        }