public void TextBlock()
        {
            AdaptiveTextBlock textBlock = new AdaptiveTextBlock
            {
                Color               = ForegroundColor.Accent,
                FontType            = FontType.Monospace,
                Height              = HeightType.Stretch,
                HorizontalAlignment = HAlignment.Center,
                Id        = "TextBlockId",
                IsSubtle  = true,
                IsVisible = false,
                Language  = "en",
                MaxLines  = 3,
                Separator = true,
                Size      = TextSize.Large,
                Spacing   = Spacing.Large,
                Text      = "This is a text block",
                Weight    = TextWeight.Bolder,
                Wrap      = true
            };

            ValidateBaseElementProperties(textBlock, "TextBlockId", false, true, Spacing.Large, HeightType.Stretch);

            Assert.AreEqual(ForegroundColor.Accent, textBlock.Color);
            Assert.AreEqual(FontType.Monospace, textBlock.FontType);
            Assert.AreEqual(HAlignment.Center, textBlock.HorizontalAlignment);
            Assert.IsTrue(textBlock.IsSubtle);
            Assert.AreEqual("en", textBlock.Language);
            Assert.AreEqual <uint>(3, textBlock.MaxLines);
            Assert.AreEqual(TextSize.Large, textBlock.Size);
            Assert.AreEqual("This is a text block", textBlock.Text);
            Assert.AreEqual(TextWeight.Bolder, textBlock.Weight);
            Assert.IsTrue(textBlock.Wrap);

            var jsonString = textBlock.ToJson().ToString();

            Assert.AreEqual("{\"color\":\"Accent\",\"fontType\":\"Monospace\",\"height\":\"Stretch\",\"horizontalAlignment\":\"center\",\"id\":\"TextBlockId\",\"isSubtle\":true,\"isVisible\":false,\"maxLines\":3,\"separator\":true,\"size\":\"Large\",\"spacing\":\"large\",\"text\":\"This is a text block\",\"type\":\"TextBlock\",\"weight\":\"Bolder\",\"wrap\":true}", jsonString);
        }
Esempio n. 2
0
        public HtmlTag Render(AdaptiveTypedElement element)
        {
            // If non-inertactive, inputs should just render text
            if (!Config.SupportsInteractivity && element is AdaptiveInput input)
            {
                var tb = new AdaptiveTextBlock();
                tb.Text = input.GetNonInteractiveValue();
                Warnings.Add(new AdaptiveWarning(-1, $"Rendering non-interactive input element '{element.Type}'"));
                return(Render(tb));
            }

            var renderer = ElementRenderers.Get(element.GetType());

            if (renderer != null)
            {
                return(renderer.Invoke(element, this));
            }
            else
            {
                Warnings.Add(new AdaptiveWarning(-1, $"No renderer for element '{element.Type}'"));
                return(null);
            }
        }
        public void TestSpacingAndSeparatorDefaults()
        {
            AdaptiveCard card = AdaptiveCard.FromJson(@"{
  ""type"": ""AdaptiveCard"",
  ""version"": ""1.0"",
  ""body"": [
    {
      ""type"": ""TextBlock"",
      ""text"": ""Adaptive Card design session""
    }
  ]
}").Card;

            AdaptiveTextBlock tb = card.Body[0] as AdaptiveTextBlock;

            Assert.AreEqual(AdaptiveSpacing.Default, tb.Spacing);
            Assert.AreEqual(false, tb.Separator);

            string json = card.ToJson();

            Assert.IsFalse(json.Contains("spacing"));
            Assert.IsFalse(json.Contains("separator"));
        }
Esempio n. 4
0
        public static FrameworkElement Render(AdaptiveDateInput input, AdaptiveRenderContext context)
        {
            if (!context.Config.SupportsInteractivity)
            {
                AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
                textBlock.Text = XamlUtilities.GetFallbackText(input) ?? input.Placeholder;

                return(context.Render(textBlock));
            }

            DatePicker datePicker = new DatePicker
            {
                DataContext = input,
                ToolTip     = input.Placeholder,
                Style       = context.GetStyle("Adaptive.Input.Date")
            };


            if (DateTime.TryParse(input.Value, out DateTime value))
            {
                datePicker.SelectedDate = value;
            }

            if (DateTime.TryParse(input.Min, out DateTime minValue))
            {
                datePicker.DisplayDateStart = minValue;
            }

            if (DateTime.TryParse(input.Max, out DateTime maxValue))
            {
                datePicker.DisplayDateEnd = maxValue;
            }

            context.InputBindings.Add(input.Id, () => datePicker.SelectedDate?.ToString("yyyy-MM-dd") ?? "");

            return(datePicker);
        }
Esempio n. 5
0
        private static AdaptiveTextBlock ResponseCardTextBlockFromResponse(ResponseStatus response)
        {
            var textBlock = new AdaptiveTextBlock();

            switch (response)
            {
            case ResponseStatus.Approved:
                textBlock.Color = AdaptiveTextColor.Good;
                textBlock.Text  = "Approved";
                break;

            case ResponseStatus.Rejected:
                textBlock.Color = AdaptiveTextColor.Attention;
                textBlock.Text  = "Rejected";
                break;

            default:
                textBlock.Color = AdaptiveTextColor.Warning;
                textBlock.Text  = "Not responded";
                break;
            }

            return(textBlock);
        }
        public void TestSpacingAndSeparator()
        {
            AdaptiveCard card = AdaptiveCard.FromJson(@"{
  ""type"": ""AdaptiveCard"",
  ""version"": ""1.0"",
  ""body"": [
    {
      ""type"": ""TextBlock"",
      ""text"": ""Adaptive Card design session"",
      ""spacing"": ""large"",
      ""separator"": true
    }
  ]
}").Card;

            AdaptiveTextBlock tb = card.Body[0] as AdaptiveTextBlock;

            Assert.AreEqual(AdaptiveSpacing.Large, tb.Spacing);
            Assert.AreEqual(true, tb.Separator);

            string json = card.ToJson();

            Assert.IsTrue(json.Contains(@"""separator"": true"));
        }
Esempio n. 7
0
        protected static HtmlTag TextBlockRender(AdaptiveTextBlock textBlock, AdaptiveRendererContext context)
        {
            int fontSize;

            switch (textBlock.Size)
            {
            case AdaptiveTextSize.Small:
                fontSize = context.Config.FontSizes.Small;
                break;

            case AdaptiveTextSize.Medium:
                fontSize = context.Config.FontSizes.Medium;
                break;

            case AdaptiveTextSize.Large:
                fontSize = context.Config.FontSizes.Large;
                break;

            case AdaptiveTextSize.ExtraLarge:
                fontSize = context.Config.FontSizes.ExtraLarge;
                break;

            case AdaptiveTextSize.Default:
            default:
                fontSize = context.Config.FontSizes.Default;
                break;
            }
            int weight = 400;

            switch (textBlock.Weight)
            {
            case AdaptiveTextWeight.Lighter:
                weight = 200;
                break;

            case AdaptiveTextWeight.Bolder:
                weight = 600;
                break;
            }

            // Not sure where this magic value comes from?
            var lineHeight = fontSize * 1.33;

            var uiTextBlock = new HtmlTag("div", false)
                              .AddClass($"ac-{textBlock.Type.Replace(".", "").ToLower()}")
                              .Style("box-sizing", "border-box")
                              .Style("text-align", textBlock.HorizontalAlignment.ToString().ToLower())
                              .Style("color", context.GetColor(textBlock.Color, textBlock.IsSubtle))
                              .Style("line-height", $"{lineHeight.ToString("F")}px")
                              .Style("font-size", $"{fontSize}px")
                              .Style("font-weight", $"{weight}");


            if (textBlock.MaxLines > 0)
            {
                uiTextBlock = uiTextBlock
                              .Style("max-height", $"{lineHeight * textBlock.MaxLines}px")
                              .Style("overflow", "hidden");
            }

            var setWrapStyleOnParagraph = false;

            if (textBlock.Wrap == false)
            {
                uiTextBlock = uiTextBlock
                              .Style("white-space", "nowrap");
                setWrapStyleOnParagraph = true;
            }
            else
            {
                uiTextBlock = uiTextBlock
                              .Style("word-wrap", "break-word");
            }

            var textTags = MarkdownToHtmlTagConverter.Convert(RendererUtilities.ApplyTextFunctions(textBlock.Text));

            uiTextBlock.Children.AddRange(textTags);

            Action <HtmlTag> setParagraphStyles = null;

            setParagraphStyles = (HtmlTag htmlTag) =>
            {
                if (htmlTag.Element?.ToLowerInvariant() == "p")
                {
                    htmlTag.Style("margin-top", "0px");
                    htmlTag.Style("margin-bottom", "0px");
                    htmlTag.Style("width", "100%");

                    if (setWrapStyleOnParagraph)
                    {
                        htmlTag.Style("text-overflow", "ellipsis");
                        htmlTag.Style("overflow", "hidden");
                    }
                }

                foreach (var child in htmlTag.Children)
                {
                    setParagraphStyles(child);
                }
            };

            setParagraphStyles(uiTextBlock);

            return(uiTextBlock);
        }
Esempio n. 8
0
 public static HtmlTag CallTextBlockRender(AdaptiveTextBlock element, AdaptiveRenderContext context)
 {
     return(TextBlockRender(element, context));
 }
Esempio n. 9
0
        protected Attachment ToAdaptiveCardForOtherFlows(
            List <TaskItem> todos,
            int allTaskCount,
            string taskContent,
            BotResponse botResponse1,
            BotResponse botResponse2,
            string listType)
        {
            var toDoCard = new AdaptiveCard();
            var showText = Format(botResponse2.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }, { "listType", listType }
            });
            var speakText = Format(botResponse1.Reply.Speak, new StringDictionary()
            {
                { "taskContent", taskContent }
            })
                            + " " + Format(botResponse2.Reply.Speak, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }, { "listType", listType }
            });

            toDoCard.Speak = speakText.Remove(speakText.Length - 1) + ".";

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

            body.Add(textBlock);

            var container = new AdaptiveContainer();

            foreach (var todo in todos)
            {
                var columnSet = new AdaptiveColumnSet();

                var icon = new AdaptiveImage();
                icon.UrlString = todo.IsCompleted ? IconImageSource.CheckIconSource : IconImageSource.UncheckIconSource;
                var iconColumn = new AdaptiveColumn();
                iconColumn.Width = "auto";
                iconColumn.Items.Add(icon);
                columnSet.Columns.Add(iconColumn);

                var content       = new AdaptiveTextBlock(todo.Topic);
                var contentColumn = new AdaptiveColumn();
                iconColumn.Width = "auto";
                contentColumn.Items.Add(content);
                columnSet.Columns.Add(contentColumn);

                container.Items.Add(columnSet);
            }

            body.Add(container);
            toDoCard.Body = body;

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

            return(attachment);
        }
Esempio n. 10
0
 private void SetValue(AdaptiveTextBlock textBlock, object value)
 {
     textBlock.Text = Convert.ToString(value);
 }
        protected Attachment ToAdaptiveCardForPreviousPage(
            List <TaskItem> todos,
            int allTasksCount,
            bool isFirstPage,
            string listType)
        {
            var response  = ResponseManager.GetResponseTemplate(ShowToDoResponses.PreviousTasks);
            var speakText = response.Reply.Speak;

            if (isFirstPage)
            {
                if (todos.Count == 1)
                {
                    response = ResponseManager.GetResponseTemplate(ShowToDoResponses.PreviousFirstSingleTask);
                }
                else
                {
                    response = ResponseManager.GetResponseTemplate(ShowToDoResponses.PreviousFirstTasks);
                }

                speakText = ResponseManager.Format(response.Reply.Speak, new StringDictionary()
                {
                    { "taskCount", todos.Count.ToString() }
                });
            }

            var toDoCard = new AdaptiveCard();

            toDoCard.Speak = speakText;
            var body = new List <AdaptiveElement>();

            response = ResponseManager.GetResponseTemplate(ToDoSharedResponses.CardSummaryMessageForMultipleTasks);
            var showText = ResponseManager.Format(response.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTasksCount.ToString() }, { "listType", listType }
            });
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);

            var container = new AdaptiveContainer();
            var index     = 0;

            foreach (var todo in todos)
            {
                var columnSet = new AdaptiveColumnSet();

                var icon = new AdaptiveImage
                {
                    UrlString = todo.IsCompleted ? IconImageSource.CheckIconSource : IconImageSource.UncheckIconSource
                };
                var iconColumn = new AdaptiveColumn
                {
                    Width = "auto"
                };
                iconColumn.Items.Add(icon);
                columnSet.Columns.Add(iconColumn);

                var content       = new AdaptiveTextBlock(todo.Topic);
                var contentColumn = new AdaptiveColumn();
                iconColumn.Width = "auto";
                contentColumn.Items.Add(content);
                columnSet.Columns.Add(contentColumn);
                container.Items.Add(columnSet);

                if (index < todos.Count)
                {
                    if (index == todos.Count - 2)
                    {
                        toDoCard.Speak += todo.Topic;
                    }
                    else if (index == todos.Count - 1)
                    {
                        toDoCard.Speak += string.Format(ToDoStrings.And, todo.Topic);
                    }
                    else
                    {
                        toDoCard.Speak += todo.Topic + ", ";
                    }
                }

                index++;
            }

            body.Add(container);
            toDoCard.Body = body;

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

            return(attachment);
        }
Esempio n. 12
0
        public void Card()
        {
            AdaptiveCard card = new AdaptiveCard
            {
                BackgroundImage = new AdaptiveBackgroundImage
                {
                    Url = "https://www.stuff.com/background.jpg"
                },
                FallbackText             = "Fallback Text",
                Height                   = HeightType.Stretch,
                InputNecessityIndicators = InputNecessityIndicators.RequiredInputs,
                Language                 = "en",
                Speak   = "This is a card",
                Style   = ContainerStyle.Emphasis,
                Version = "1.3",
                VerticalContentAlignment = VerticalContentAlignment.Center,
            };

            Assert.AreEqual("https://www.stuff.com/background.jpg", card.BackgroundImage.Url);
            Assert.AreEqual("Fallback Text", card.FallbackText);
            Assert.AreEqual(HeightType.Stretch, card.Height);
            Assert.AreEqual(InputNecessityIndicators.RequiredInputs, card.InputNecessityIndicators);
            Assert.AreEqual("en", card.Language);
            Assert.AreEqual("This is a card", card.Speak);
            Assert.AreEqual(ContainerStyle.Emphasis, card.Style);
            Assert.AreEqual("1.3", card.Version);
            Assert.AreEqual(VerticalContentAlignment.Center, card.VerticalContentAlignment);

            card.SelectAction = new AdaptiveSubmitAction
            {
                Title = "Select Action"
            };
            Assert.IsNotNull(card.SelectAction);
            Assert.AreEqual("Select Action", card.SelectAction.Title);

            AdaptiveTextBlock textBlock = new AdaptiveTextBlock
            {
                Text = "This is a text block"
            };

            card.Body.Add(textBlock);

            AdaptiveTextBlock textBlock2 = new AdaptiveTextBlock
            {
                Text = "This is another text block"
            };

            card.Body.Add(textBlock2);

            Assert.AreEqual("This is a text block", (card.Body[0] as AdaptiveTextBlock).Text);
            Assert.AreEqual("This is another text block", (card.Body[1] as AdaptiveTextBlock).Text);

            AdaptiveSubmitAction submitAction = new AdaptiveSubmitAction
            {
                Title = "Submit One"
            };

            card.Actions.Add(submitAction);

            AdaptiveSubmitAction submitAction2 = new AdaptiveSubmitAction
            {
                Title = "Submit Two"
            };

            card.Actions.Add(submitAction2);

            Assert.AreEqual("Submit One", card.Actions[0].Title);
            Assert.AreEqual("Submit Two", card.Actions[1].Title);

            var jsonString = card.ToJson().ToString();

            Assert.AreEqual("{\"actions\":[{\"title\":\"Submit One\",\"type\":\"Action.Submit\"},{\"title\":\"Submit Two\",\"type\":\"Action.Submit\"}],\"backgroundImage\":\"https://www.stuff.com/background.jpg\",\"body\":[{\"text\":\"This is a text block\",\"type\":\"TextBlock\"},{\"text\":\"This is another text block\",\"type\":\"TextBlock\"}],\"fallbackText\":\"Fallback Text\",\"height\":\"Stretch\",\"inputNecessityIndicators\":\"RequiredInputs\",\"lang\":\"en\",\"speak\":\"This is a card\",\"style\":\"Emphasis\",\"type\":\"AdaptiveCard\",\"version\":\"1.3\",\"verticalContentAlignment\":\"Center\"}", jsonString);
        }
Esempio n. 13
0
        private AdaptiveCard SetCard()
        {
            AdaptiveCard _card = new AdaptiveCard("1.0");

            var _container = new AdaptiveContainer();

            var colum = new AdaptiveColumnSet();

            var _columnImage = new AdaptiveColumn()
            {
                Width = AdaptiveColumnWidth.Auto
            };

            _columnImage.Items.Add(new AdaptiveImage()
            {
                Url     = new Uri(this.UrlImage),
                Size    = AdaptiveImageSize.Small,
                Style   = AdaptiveImageStyle.Person,
                AltText = "Bootty"
            });

            var _columnContent = new AdaptiveColumn()
            {
                Width = AdaptiveColumnWidth.Stretch
            };

            _columnContent.Items.Add(new AdaptiveTextBlock()
            {
                Text    = "Booty",
                Size    = AdaptiveTextSize.Medium,
                Weight  = AdaptiveTextWeight.Default,
                Color   = AdaptiveTextColor.Default,
                Wrap    = true,
                Spacing = AdaptiveSpacing.Default
            });

            _columnContent.Items.Add(new AdaptiveTextBlock()
            {
                Text     = DateTime.Now.ToString(),
                Size     = AdaptiveTextSize.Small,
                Color    = AdaptiveTextColor.Default,
                Wrap     = true,
                IsSubtle = true,
                Spacing  = AdaptiveSpacing.None
            });

            var _textMessage = new AdaptiveTextBlock()
            {
                Text     = this.Title,
                Size     = AdaptiveTextSize.Medium,
                Color    = AdaptiveTextColor.Default,
                Weight   = AdaptiveTextWeight.Bolder,
                Wrap     = true,
                IsSubtle = false
            };

            var _textMessage2 = new AdaptiveTextBlock()
            {
                Text     = this.Description,
                Size     = AdaptiveTextSize.Small,
                Color    = AdaptiveTextColor.Default,
                Weight   = AdaptiveTextWeight.Default,
                Wrap     = true,
                IsSubtle = false
            };


            colum.Columns.Add(_columnImage);
            colum.Columns.Add(_columnContent);
            _container.Items.Add(colum);

            _card.Body.Add(_container);
            _card.Body.Add(_textMessage);
            _card.Body.Add(_textMessage2);

            //Form

            var _texDataSubtitle = new AdaptiveTextBlock()
            {
                Text   = "Tus Datos",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Bolder,
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left
            };


            var _textTitleName = new AdaptiveTextBlock()
            {
                Text   = "Tú Nombre",
                Size   = AdaptiveTextSize.Small,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };

            var _textName = new AdaptiveTextInput()
            {
                Id          = "UserName",
                Placeholder = "Apellido, Nombre"
            };

            var _textTitleEmail = new AdaptiveTextBlock()
            {
                Text   = "Dirección de correo",
                Size   = AdaptiveTextSize.Small,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };

            var _textEmail = new AdaptiveTextInput()
            {
                Id          = "Email",
                Placeholder = "correo electronico"
            };

            var _texDatesSubtitle = new AdaptiveTextBlock()
            {
                Text   = "Fechas",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Bolder,
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left
            };

            var _textTitleDeparture = new AdaptiveTextBlock()
            {
                Text   = "Fecha de salida",
                Size   = AdaptiveTextSize.Small,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };

            var _textDeparture = new AdaptiveDateInput()
            {
                Id = "Departure"
            };

            var _textTitleArrival = new AdaptiveTextBlock()
            {
                Text   = "Fecha de regreso",
                Size   = AdaptiveTextSize.Small,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };

            var _textArrival = new AdaptiveDateInput()
            {
                Id = "Arrival"
            };

            var _texOptionsSubtitle = new AdaptiveTextBlock()
            {
                Text   = "Tipo de viaje",
                Size   = AdaptiveTextSize.Normal,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Bolder,
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left
            };

            var _textTrasportOpciones = new AdaptiveTextBlock()
            {
                Text   = "Tipo de transporte",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };
            //traport
            var _transportChoice = new AdaptiveChoiceSetInput();

            _transportChoice.Id    = "TransporChoice";
            _transportChoice.Value = "bus";
            _transportChoice.Style = AdaptiveChoiceInputStyle.Expanded;
            _transportChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Omnibus",
                Value = "Omnibus"
            });
            _transportChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Avion",
                Value = "Avion"
            });

            var _textClassOpciones = new AdaptiveTextBlock()
            {
                Text   = "Clase",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };
            //traport
            var _classChoice = new AdaptiveChoiceSetInput();

            _classChoice.Id    = "ClassChoice";
            _classChoice.Value = "Economica";
            _classChoice.Style = AdaptiveChoiceInputStyle.Expanded;
            _classChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Economica",
                Value = "Economica"
            });
            _classChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Primera",
                Value = "Primera"
            });

            var _textCashOpciones = new AdaptiveTextBlock()
            {
                Text   = "¿Forma de Pago?",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };
            //traport
            var _cashChoice = new AdaptiveChoiceSetInput();

            _cashChoice.Id    = "CashChoice";
            _cashChoice.Value = "Efectivo";
            _cashChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Efectivo",
                Value = "Efectivo"
            });
            _cashChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Tarjeta de Credito",
                Value = "Tarjeta de Credito"
            });

            var _checkConditions = new AdaptiveToggleInput()
            {
                Id    = "checkConditions",
                Value = "accept",
                Title = "Acepto los terminos y condiciones."
            };

            var _submitButton = new AdaptiveSubmitAction()
            {
                Title    = "Contratar",
                DataJson = JsonConvert.SerializeObject(new JsonDataAux()
                {
                    From   = TypeCards.FORM.ToString(),
                    Action = "MDZFORM"
                })
            };

            _card.Body.Add(_texDataSubtitle);
            _card.Body.Add(_textTitleName);
            _card.Body.Add(_textName);
            _card.Body.Add(_textTitleEmail);
            _card.Body.Add(_textEmail);
            _card.Body.Add(_texDatesSubtitle);
            _card.Body.Add(_textTitleDeparture);
            _card.Body.Add(_textDeparture);
            _card.Body.Add(_textTitleArrival);
            _card.Body.Add(_textArrival);

            _card.Body.Add(_texOptionsSubtitle);
            _card.Body.Add(_textTrasportOpciones);
            _card.Body.Add(_transportChoice);
            _card.Body.Add(_textClassOpciones);
            _card.Body.Add(_classChoice);
            _card.Body.Add(_textCashOpciones);
            _card.Body.Add(_cashChoice);

            _card.Body.Add(_checkConditions);

            _card.Actions.Add(_submitButton);

            return(_card);
        }
Esempio n. 14
0
        private async Task HandleBotHelpful(Microsoft.Bot.Connector.Activity activity)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            // Question has been answered
            // store answer in db.

            // get question details
            int    questionId = Convert.ToInt32((activity.Value as dynamic)["questionId"]);
            string answer     = (activity.Value as dynamic)["answer"];
            int    answerId   = Convert.ToInt32((activity.Value as dynamic)["qnaId"]);
            var    question   = SQLService.GetQuestion(questionId);

            // get user details
            var channelData = activity.GetChannelData <Microsoft.Bot.Connector.Teams.Models.TeamsChannelData>();
            var members     = await connector.Conversations.GetConversationMembersAsync(channelData.Team.Id);

            var teamsMembers = members.AsTeamsChannelAccounts();
            var currentUser  = teamsMembers.Where(x => x.ObjectId == activity.From.Properties["aadObjectId"].ToString()).FirstOrDefault();
            var studentUPN   = currentUser.UserPrincipalName;
            var isUserAdmin  = SQLService.IsUserAdmin(studentUPN);

            // store question in qna
            string      teamId = channelData.Team.Id;
            TeamDetails teamDetails;

            try
            {
                teamDetails = connector.GetTeamsConnectorClient().Teams.FetchTeamDetails(teamId);
            }
            catch (Exception e)
            {
                teamDetails = connector.GetTeamsConnectorClient().Teams.FetchTeamDetails(teamId);
                Trace.TraceError(e.ToString());
            }

            var teamName = teamDetails.Name;
            var courseID = SQLService.GetCourseIDByName(teamName.Trim());

            // check if user can set question status
            if (isUserAdmin || (studentUPN == question.OriginalPoster.Email) || (studentUPN == question.OriginalPoster.UserName)) // double check question to course? not sure
            {
                var answeredBy = SQLService.GetBotUser(courseID);

                // update question model
                question.QuestionStatus   = Constants.QUESTION_STATUS_ANSWERED;
                question.QuestionAnswered = DateTime.Now;
                question.AnswerText       = answer;
                question.AnswerPoster     = answeredBy;

                SQLService.CreateOrUpdateQuestion(question);

                // update old activity
                Microsoft.Bot.Connector.Activity updatedReply = activity.CreateReply();

                var card        = new AdaptiveCard();
                var answerBlock = new AdaptiveTextBlock("Answer: " + question.AnswerText.ReplaceLinksWithMarkdown());
                answerBlock.Weight = AdaptiveTextWeight.Bolder;
                answerBlock.Size   = AdaptiveTextSize.Medium;
                answerBlock.Wrap   = true;

                var markedBlock = new AdaptiveTextBlock($"Marked as " + question.QuestionStatus + " by " + currentUser.Name);
                markedBlock.Wrap = true;

                var answeredBlock = new AdaptiveTextBlock("Answered by: " + question.AnswerPoster.FullName);
                answeredBlock.Weight = AdaptiveTextWeight.Bolder;
                answeredBlock.Wrap   = true;

                card.Body.Add(answerBlock);
                card.Body.Add(answeredBlock);
                card.Body.Add(markedBlock);

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

                updatedReply.Attachments.Add(attachment);

                await connector.Conversations.UpdateActivityAsync(activity.Conversation.Id, activity.ReplyToId, updatedReply);

                var predictiveQnAService = new PredictiveQnAService(courseID);
                var res = await predictiveQnAService.UpdateQnAPair(new List <string> {
                    question.QuestionText
                }, null, answer, answerId);
            }
        }
        private static async Task CreateAdaptiveCard(IDialogContext context, List <TotaledSpan> showPunchesResponse, string payPeriod, LoginResponse response, string assignedHours, string allHours)
        {
            var          message = context.MakeMessage();
            AdaptiveCard card    = new AdaptiveCard("1.0");

            var staticContainer  = new AdaptiveContainer();
            var dynamicContainer = new AdaptiveContainer();
            var staticItems      = new List <AdaptiveElement>();
            var dynamicItems     = new List <AdaptiveElement>();

            // Static items
            var title = new AdaptiveTextBlock
            {
                Size   = AdaptiveTextSize.Medium,
                Weight = AdaptiveTextWeight.Bolder,
                Text   = KronosResourceText.ShowPunchesCardTitleText,
                Wrap   = true,
            };

            var titleColumnSet = new AdaptiveColumnSet
            {
                Columns = new List <AdaptiveColumn>
                {
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveImage
                            {
                                Style = AdaptiveImageStyle.Person,
                                Url   = new Uri("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAASuSURBVGhD7ZpZyFdFGIe/yooWCi1B224iKMMMEyIsBAlaoJWiRXKBjEJaIKKrumhRW4iCsqK6iCIioohWumghKgLLiIQuMrXCNtvLitbnOTUwHM//nJn5L1/K94MHnf85M+c9Z7b3fecbm9B2rANhIdwDL8En8C38Db/BN/A+PAHXw/GwG/wvNAUuhdWgwblsgYfhBNgBRq59YSX8AMGor+Fx8MXmwwGwByiNnAyHw5lwI7wJf0Co/y6cBSORBl0IX4EP/wuegdNgZ8jVfnA1rIfwQg7Lw2Bo2gc0OjzwaZgFg5AfYTFsAtv+BS6CgetQ2AA+5DM4FVK1O+z47387tRfcCfa0z7oPdoKBaA5sBht+BaZBLzn0ToK7YS38CNYTV7EH4Qjo0unwPVjvKdgF+tIM+BJs8FFoa1ADncDB8F64FF8BLhhtOhLsfev47OKecU58DDb0CLQ1ZK99B7HBXfwKy6Gt3UMgfMhb/CFXDpEwsV+Gtp5wLwlfroQHoE1Hg5PfeXOKP+RoKfiQz6FtTih36bpxuRwHbboEvM/ecT9KkmM3TO6U1elDiI0q4SHo0rPgvS4kSboJrOA+0SU3tNigUlzRunQwOMR+B+dOqxzvLpmOx5n+0KFjoMmwXP6EFM/APcb7u+bV2GXgjSm9oY6F2KB+2Bu6dBDYI/ZM6/1vg42mrg6DehGNmwQpCnPFBalRvq03ONFTHUCdu9igUj6CVJ0H1vGFGqXT5g2PVaU0+RXd2GKjSngRUuWq6pwyhGj84PeCjS6rSulaA3XDcrkBcvQeWG92VarpVfDivKqULr9mbFQJF0COdJms5zDbSp+CF/evSmnyXrs5NqqE1FUy6Dqw3jVVqaYQtuYkBI6C2KBS3oEchW3i1qpUkxfcCHM0FWKDSjGzkqMlYL1VVakm13Iv5uoNiI0qwTRSjgyDrXdXVaopxBOGmzkybg8xQwn2Rm7QdCVYd0VVqsnQ1ItGhbnyi8bGpeLH2xVydTtY//KqVJMrhxdzEgtB+j0hq5hD49BIUHBTTq5KNbkpeTF3cwoyPxUb2YVetkm8XBm9hqFsmnYrmbb04utVKV+6KzkT35WnRIYX1l9XlRq0J/wMpjGn+0OBUveVt6BU14JtmCzvKdMu3uSqUKLwtboofRGH1QdgG+aXe+pE8Cbd6tT4IFZqxKjTVyInt/W1rzV76RuHZXiRP2QqZDu6MAmuV5AjbQtz0Ix/p84Fb9aJdN6kyL3gKjAEjQ1uw0MfI8xUnQ/WM2mY5A/65q+Ble7whxaZ3L4NQvqoBA+JLoa2GNxgKmTqfaFkubt7mtSU3fOB+jqD8LFiwumVR3Lx+PfDhqznc/+Vs2SkaGXdCFcjX0DfJj6lGhYOu7NB+Ux/+wK6sp49dT/YiPMlBF6jxDjFf83gz4VimbwOfs144QZ9DvQtX+ZJaHrIsLEnBnpAarxwMzQ9bFg4J/oaTm06AzxqaHrwIHkeTJAPVa7pOmwhNB4kGyE3NdS3TJe6qrn+NxmVg2csRnvj+icdHkX4RwQvwE/QZGgTHnd7aKMXm3p8PTLpMZvGXAAmzwxlTcWKroxf3VA6Jwk4oW1QY2P/ANttdsxdJ2yfAAAAAElFTkSuQmCC"),
                                Size  = AdaptiveImageSize.Small,
                            },
                        },
                        Width = "auto",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Weight = AdaptiveTextWeight.Bolder,
                                Text   = response.Name,
                                Wrap   = true,
                            },
                            new AdaptiveTextBlock
                            {
                                Spacing  = AdaptiveSpacing.None,
                                Text     = $"{KronosResourceText.Employee} #{response.PersonNumber}",
                                IsSubtle = true,
                                Wrap     = true,
                            },
                        },
                    },
                },
            };

            staticItems.Add(title);
            staticItems.Add(titleColumnSet);
            staticContainer.Items = staticItems;

            var dynamicColumnSetHeading = new AdaptiveColumnSet
            {
                Columns = new List <AdaptiveColumn>
                {
                    new AdaptiveColumn
                    {
                        Width = "25",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text     = KronosResourceText.ShowPunchesCardPunchInColumnHeader,
                                IsSubtle = true,
                                Wrap     = true,
                            },
                        },
                        Width = "20",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text     = KronosResourceText.ShowPunchesCardPunchOutColumnHeader,
                                IsSubtle = true,
                                Wrap     = true,
                            },
                        },
                        Width = "20",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                Text     = KronosResourceText.ShowPunchesCardWorkRuleColumnHeader,
                                IsSubtle = true,
                            },
                        },
                        Width = "35",
                    },
                },
            };

            dynamicItems.Add(dynamicColumnSetHeading);

            // Placeholder to hold previous date
            var prevDate = string.Empty;

            for (int i = 0; i < showPunchesResponse.Count(); i++)
            {
                var dynamicColumnData = new AdaptiveColumnSet();
                var punchDate         = string.Empty;
                var showSeparator     = false;

                if (showPunchesResponse[i]?.InPunch?.Punch?.EnteredOnDate != null && prevDate != showPunchesResponse[i]?.InPunch?.Punch?.Date)
                {
                    showSeparator = true;
                    prevDate      = showPunchesResponse[i].InPunch.Punch.Date;
                    punchDate     = DateTime.Parse(prevDate, CultureInfo.InvariantCulture, DateTimeStyles.None).ToString("dd MMMM, yyyy", CultureInfo.InvariantCulture);
                }

                dynamicColumnData.Columns = new List <AdaptiveColumn>
                {
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text   = punchDate ?? string.Empty,
                                Weight = AdaptiveTextWeight.Bolder,
                                Wrap   = true,
                            },
                        },
                        Width = "25",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text = showPunchesResponse[i]?.InPunch?.Punch?.Time,
                                Wrap = true,
                            },
                        },
                        Width = "20",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text = showPunchesResponse[i]?.OutPunch?.Punch?.Time ?? string.Empty,
                                Wrap = true,
                            },
                        },
                        Width = "20",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text = showPunchesResponse[i]?.InPunch?.Punch?.WorkRuleName ?? showPunchesResponse[i]?.OrgJobName.Substring(showPunchesResponse[i].OrgJobName.LastIndexOf('/') + 1),
                                Wrap = true,
                            },
                        },
                        Width = "35",
                    },
                };

                if (showSeparator)
                {
                    dynamicColumnData.Separator = showSeparator;
                }

                dynamicItems.Add(dynamicColumnData);
            }

            var dynamicColumnSetFooter = new AdaptiveColumnSet
            {
                Separator = true,
                Columns   = new List <AdaptiveColumn>
                {
                    new AdaptiveColumn
                    {
                        Width = "20",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                Spacing             = AdaptiveSpacing.None,
                                Text = KronosResourceText.ShowPunchesCardTotalHoursLabel,
                            },
                        },
                        Width = "30",
                    },
                    new AdaptiveColumn
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Spacing             = AdaptiveSpacing.None,
                                Weight              = AdaptiveTextWeight.Bolder,
                                Text                = $"{allHours} {KronosResourceText.GenericHoursOfText} {assignedHours} {KronosResourceText.GenericHoursText}",
                                HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                Wrap                = true,
                            },
                        },
                        Width = "30",
                    },
                },
            };

            dynamicItems.Add(dynamicColumnSetFooter);
            dynamicContainer.Items = dynamicItems;

            card.Body.Add(staticContainer);
            card.Body.Add(dynamicContainer);

            if (payPeriod == Constants.PreviousPayPeriodPunchesText || string.IsNullOrWhiteSpace(payPeriod))
            {
                card.Actions.Add(
                    new AdaptiveSubmitAction()
                {
                    Title = Constants.CurrentpayPeriodPunchesText,
                    Data  = new AdaptiveCardAction
                    {
                        msteams = new Msteams
                        {
                            type        = "messageBack",
                            displayText = Constants.CurrentpayPeriodPunchesText,
                            text        = Constants.CurrentpayPeriodPunchesText,
                        },
                    },
                });
            }
            else if (payPeriod == Constants.CurrentpayPeriodPunchesText || string.IsNullOrWhiteSpace(payPeriod))
            {
                card.Actions.Add(
                    new AdaptiveSubmitAction()
                {
                    Title = Constants.PreviousPayPeriodPunchesText,
                    Data  = new AdaptiveCardAction
                    {
                        msteams = new Msteams
                        {
                            type        = "messageBack",
                            displayText = Constants.PreviousPayPeriodPunchesText,
                            text        = Constants.PreviousPayPeriodPunchesText,
                        },
                    },
                });
            }

            card.Actions.Add(
                new AdaptiveSubmitAction()
            {
                Title = Constants.DateRangeText,
                Data  = new AdaptiveCardAction
                {
                    msteams = new Msteams
                    {
                        type        = "messageBack",
                        displayText = Constants.DateRangeText,
                        text        = Constants.DateRangePunches,
                    },
                },
            });

            if (message.Attachments == null)
            {
                message.Attachments = new List <Attachment>();
            }

            message.Attachments.Add(new Attachment()
            {
                Content     = card,
                ContentType = "application/vnd.microsoft.card.adaptive",
                Name        = "Show Punches",
            });

            await context.PostAsync(message);
        }
        private async Task CreateBlankAdaptiveCard(IDialogContext context, string payPeriod, string titles)
        {
            var          message = context.MakeMessage();
            AdaptiveCard card    = new AdaptiveCard("1.0");

            var container = new AdaptiveContainer();
            var items     = new List <AdaptiveElement>();

            var title = new AdaptiveTextBlock
            {
                Size = AdaptiveTextSize.Medium,
                Text = titles,
                Wrap = true,
            };

            items.Add(title);
            container.Items = items;
            card.Body.Add(container);

            if (payPeriod == Constants.PreviousPayPeriodPunchesText || string.IsNullOrWhiteSpace(payPeriod))
            {
                card.Actions.Add(
                    new AdaptiveSubmitAction()
                {
                    Title = Constants.CurrentpayPeriodPunchesText,
                    Data  = new AdaptiveCardAction
                    {
                        msteams = new Msteams
                        {
                            type        = "messageBack",
                            displayText = Constants.CurrentpayPeriodPunchesText,
                            text        = Constants.CurrentpayPeriodPunchesText,
                        },
                    },
                });
            }
            else if (payPeriod == Constants.CurrentpayPeriodPunchesText || string.IsNullOrWhiteSpace(payPeriod))
            {
                card.Actions.Add(
                    new AdaptiveSubmitAction()
                {
                    Title = Constants.PreviousPayPeriodPunchesText,
                    Data  = new AdaptiveCardAction
                    {
                        msteams = new Msteams
                        {
                            type        = "messageBack",
                            displayText = Constants.PreviousPayPeriodPunchesText,
                            text        = Constants.PreviousPayPeriodPunchesText,
                        },
                    },
                });
            }

            card.Actions.Add(
                new AdaptiveSubmitAction()
            {
                Title = Constants.DateRangeText,
                Data  = new AdaptiveCardAction
                {
                    msteams = new Msteams
                    {
                        type        = "messageBack",
                        displayText = Constants.DateRangeText,
                        text        = Constants.DateRangePunches,
                    },
                },
            });

            if (message.Attachments == null)
            {
                message.Attachments = new List <Attachment>();
            }

            message.Attachments.Add(new Attachment()
            {
                Content     = card,
                ContentType = "application/vnd.microsoft.card.adaptive",
                Name        = "Show Punches",
            });

            await context.PostAsync(message);
        }
Esempio n. 17
0
        public static Activity Recipe(Activity activity, List <EdamamRecipe> recipes, IMessagesService messagesService)
        {
            var result = new List <Attachment>();

            var reply = activity.CreateReply();

            foreach (var item in recipes)
            {
                var body = new List <AdaptiveContainer>();

                #region Tittle
                var tittle = new AdaptiveTextBlock
                {
                    Text   = item.label,
                    Weight = AdaptiveTextWeight.Bolder,
                    Size   = AdaptiveTextSize.Medium
                };

                body.Add(new AdaptiveContainer {
                    Items = new List <AdaptiveElement> {
                        tittle
                    }
                });
                #endregion

                #region Imagen
                var imagen = new AdaptiveImage {
                    Url = new Uri(item.image), Size = AdaptiveImageSize.Large, AltText = item.label
                };

                body.Add(new AdaptiveContainer {
                    Items = new List <AdaptiveElement> {
                        imagen
                    }
                });
                #endregion

                #region Allergies
                string allergyText = string.Empty;

                foreach (var allergy in item.healthLabels)
                {
                    allergyText += messagesService.Get(allergy).Value;
                }

                var allergyEmojis = new AdaptiveTextBlock
                {
                    Text   = allergyText,
                    Weight = AdaptiveTextWeight.Bolder,
                    Size   = AdaptiveTextSize.Medium
                };

                body.Add(new AdaptiveContainer {
                    Items = new List <AdaptiveElement> {
                        allergyEmojis
                    }
                });
                #endregion

                #region Ingredients
                var ingredientContainer = new AdaptiveContainer()
                {
                    Items = new List <AdaptiveElement>()
                };

                ingredientContainer.Items.Add(new AdaptiveTextBlock {
                    Text = "Ingredientes:", Weight = AdaptiveTextWeight.Bolder, Size = AdaptiveTextSize.Medium,
                });

                foreach (var ingredient in item.ingredientLines)
                {
                    ingredientContainer.Items.Add(new AdaptiveTextBlock {
                        Text = ingredient, Weight = AdaptiveTextWeight.Default, Size = AdaptiveTextSize.Default
                    });
                }

                body.Add(ingredientContainer);
                #endregion

                #region Button
                var action = new AdaptiveOpenUrlAction {
                    Title = "ver mas", Url = new Uri(item.url),
                };

                List <AdaptiveAction> actions = new List <AdaptiveAction> {
                    action
                };
                #endregion

                result.AddRange(CreateAdaptiveCard(body, actions));
            }

            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;

            reply.Attachments = result;

            reply.Text = messagesService.Get(MessagesKey.Key.RecipeSearch_result.ToString()).Value;

            return(reply);
        }
Esempio n. 18
0
        private AdaptiveCard SetCard()
        {
            AdaptiveCard _card = new AdaptiveCard("1.0");

            var _container = new AdaptiveContainer();

            var colum = new AdaptiveColumnSet();

            var _columnImage = new AdaptiveColumn()
            {
                Width = AdaptiveColumnWidth.Auto
            };

            _columnImage.Items.Add(new AdaptiveImage()
            {
                Url     = new Uri(this.UrlImage),
                Size    = AdaptiveImageSize.Medium,
                Style   = AdaptiveImageStyle.Person,
                AltText = "Brainy"
            });

            var _columnContent = new AdaptiveColumn()
            {
                Width = AdaptiveColumnWidth.Stretch
            };

            _columnContent.Items.Add(new AdaptiveTextBlock()
            {
                Text    = "Brainy",
                Size    = AdaptiveTextSize.Medium,
                Weight  = AdaptiveTextWeight.Default,
                Color   = AdaptiveTextColor.Default,
                Wrap    = true,
                Spacing = AdaptiveSpacing.Small
            });

            _columnContent.Items.Add(new AdaptiveTextBlock()
            {
                Text     = DateTime.Now.ToString(),
                Size     = AdaptiveTextSize.Small,
                Color    = AdaptiveTextColor.Default,
                Wrap     = true,
                IsSubtle = true,
                Spacing  = AdaptiveSpacing.Small
            });

            var _textMessage = new AdaptiveTextBlock()
            {
                Text     = "Has seleccionado: " + this.Title,
                Size     = AdaptiveTextSize.Large,
                Color    = AdaptiveTextColor.Default,
                Weight   = AdaptiveTextWeight.Bolder,
                Wrap     = true,
                IsSubtle = false
            };

            _columnContent.Items.Add(_textMessage);

            var _textMessage2 = new AdaptiveTextBlock()
            {
                Text     = this.Description,
                Size     = AdaptiveTextSize.Normal,
                Color    = AdaptiveTextColor.Default,
                Weight   = AdaptiveTextWeight.Default,
                Wrap     = true,
                IsSubtle = false
            };

            colum.Columns.Add(_columnContent);
            colum.Columns.Add(_columnImage);

            _container.Items.Add(colum);

            _card.Body.Add(_container);
            //_card.Body.Add(_textMessage);
            _card.Body.Add(_textMessage2);

            _card.Actions.AddRange(this.GetAdaptiveActions());

            return(_card);
        }
Esempio n. 19
0
        protected Attachment ToAdaptiveCardForPreviousPage(
            List <TaskItem> todos,
            int toBeReadTasksCount)
        {
            var toDoCard  = new AdaptiveCard();
            var speakText = Format(ShowToDoResponses.ShowPreviousToDoTasks.Reply.Speak, new StringDictionary()
            {
            })
                            + Format(ShowToDoResponses.FirstToDoTasks.Reply.Speak, new StringDictionary()
            {
                { "taskCount", toBeReadTasksCount.ToString() }
            });

            toDoCard.Speak = speakText;

            var body     = new List <AdaptiveElement>();
            var showText = Format(ShowToDoResponses.ShowPreviousToDoTasks.Reply.Text, new StringDictionary()
            {
            });
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);

            var container = new AdaptiveContainer();
            var index     = 0;

            foreach (var todo in todos)
            {
                var columnSet = new AdaptiveColumnSet();

                var icon = new AdaptiveImage();
                icon.UrlString = todo.IsCompleted ? IconImageSource.CheckIconSource : IconImageSource.UncheckIconSource;
                var iconColumn = new AdaptiveColumn();
                iconColumn.Width = "auto";
                iconColumn.Items.Add(icon);
                columnSet.Columns.Add(iconColumn);

                var content       = new AdaptiveTextBlock(todo.Topic);
                var contentColumn = new AdaptiveColumn();
                iconColumn.Width = "auto";
                contentColumn.Items.Add(content);
                columnSet.Columns.Add(contentColumn);

                container.Items.Add(columnSet);

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

            body.Add(container);
            toDoCard.Body = body;

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

            return(attachment);
        }
Esempio n. 20
0
        public static FrameworkElement Render(AdaptiveTextBlock textBlock, AdaptiveRenderContext context)
        {
            var uiTextBlock = CreateControl(textBlock, context);

            FontColorConfig colorOption;

            switch (textBlock.Color)
            {
            case AdaptiveTextColor.Accent:
                colorOption = context.Config.ContainerStyles.Default.ForegroundColors.Accent;
                break;

            case AdaptiveTextColor.Attention:
                colorOption = context.Config.ContainerStyles.Default.ForegroundColors.Attention;
                break;

            case AdaptiveTextColor.Dark:
                colorOption = context.Config.ContainerStyles.Default.ForegroundColors.Dark;
                break;

            case AdaptiveTextColor.Good:
                colorOption = context.Config.ContainerStyles.Default.ForegroundColors.Good;
                break;

            case AdaptiveTextColor.Light:
                colorOption = context.Config.ContainerStyles.Default.ForegroundColors.Light;
                break;

            case AdaptiveTextColor.Warning:
                colorOption = context.Config.ContainerStyles.Default.ForegroundColors.Warning;
                break;

            case AdaptiveTextColor.Default:
            default:
                colorOption = context.Config.ContainerStyles.Default.ForegroundColors.Default;
                break;
            }

            if (textBlock.IsSubtle)
            {
                uiTextBlock.SetColor(colorOption.Subtle, context);
            }
            else
            {
                uiTextBlock.SetColor(colorOption.Default, context);
            }

            switch (textBlock.Size)
            {
            case AdaptiveTextSize.Small:
                uiTextBlock.FontSize = context.Config.FontSizes.Small;
                break;

            case AdaptiveTextSize.Medium:
                uiTextBlock.FontSize = context.Config.FontSizes.Medium;
                break;

            case AdaptiveTextSize.Large:
                uiTextBlock.FontSize = context.Config.FontSizes.Large;
                break;

            case AdaptiveTextSize.ExtraLarge:
                uiTextBlock.FontSize = context.Config.FontSizes.ExtraLarge;
                break;

            case AdaptiveTextSize.Default:
            default:
                uiTextBlock.FontSize = context.Config.FontSizes.Default;
                break;
            }


            if (textBlock.MaxLines > 0)
            {
                var uiGrid = new Grid();
                uiGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });


                // create hidden textBlock with appropriate linebreaks that we can use to measure the ActualHeight
                // using same style, fontWeight settings as original textblock
                var measureBlock = new System.Windows.Controls.TextBlock()
                {
                    Style               = uiTextBlock.Style,
                    FontWeight          = uiTextBlock.FontWeight,
                    FontSize            = uiTextBlock.FontSize,
                    Visibility          = Visibility.Hidden,
                    TextWrapping        = TextWrapping.NoWrap,
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top,
                    DataContext         = textBlock.MaxLines
                };

                measureBlock.Inlines.Add(uiTextBlock.Text);

                // bind the real textBlock's Height => MeasureBlock.ActualHeight
                uiTextBlock.SetBinding(Control.MaxHeightProperty, new Binding()
                {
                    Path      = new PropertyPath("ActualHeight"),
                    Source    = measureBlock,
                    Mode      = BindingMode.OneWay,
                    Converter = new MultiplyConverter(textBlock.MaxLines)
                });

                // Add both to a grid so they go as a unit
                uiGrid.Children.Add(measureBlock);

                uiGrid.Children.Add(uiTextBlock);
                return(uiGrid);
            }

            return(uiTextBlock);
        }
    public static AdaptiveCard CreateFullCardForCandidate(Candidate c)
    {
        AdaptiveCard card = new AdaptiveCard();

        card.Body = new List <AdaptiveElement>();
        AdaptiveContainer header = new AdaptiveContainer();

        card.Body.Add(header);

        header.Items = new List <AdaptiveElement>();
        header.Items.Add(new AdaptiveTextBlock()
        {
            Text   = c.Name,
            Weight = AdaptiveTextWeight.Bolder,
            Size   = AdaptiveTextSize.Large
        });

        AdaptiveColumnSet headerDetails = new AdaptiveColumnSet();

        header.Items.Add(headerDetails);

        AdaptiveColumn col1 = new AdaptiveColumn();

        col1.Width = AdaptiveColumnWidth.Auto;
        col1.Items = new List <AdaptiveElement>
        {
            new AdaptiveImage()
            {
                Url   = new Uri(c.ProfilePicture),
                Size  = AdaptiveImageSize.Small,
                Style = AdaptiveImageStyle.Person
            }
        };

        AdaptiveColumn col2 = new AdaptiveColumn();

        col2.Width = AdaptiveColumnWidth.Stretch;
        col2.Items = new List <AdaptiveElement>
        {
            new AdaptiveTextBlock()
            {
                Text = $"Applied {DateTime.Today.ToString("MM/dd/yyyy")}",
                Wrap = true
            },
            new AdaptiveTextBlock()
            {
                Text     = $"Current role {c.CurrentRole}",
                Spacing  = AdaptiveSpacing.None,
                Wrap     = true,
                IsSubtle = true
            }
        };

        headerDetails.Columns = new List <AdaptiveColumn>
        {
            col1,
            col2
        };

        AdaptiveContainer details = new AdaptiveContainer();

        AdaptiveTextBlock candidateSummary = new AdaptiveTextBlock()
        {
            Text = new CandidatesDataController().GetCandidateBio(c),
            Wrap = true
        };

        AdaptiveFactSet factsCol1 = new AdaptiveFactSet();

        factsCol1.Facts = new List <AdaptiveFact>
        {
            new AdaptiveFact("Applied to position", c.ReqId),
            new AdaptiveFact("Interview date", "Not set")
        };

        AdaptiveFactSet factsCol2 = new AdaptiveFactSet();

        factsCol2.Facts = new List <AdaptiveFact>
        {
            new AdaptiveFact("Hires", c.Hires.ToString()),
            new AdaptiveFact("No hires", c.NoHires.ToString())
        };

        AdaptiveColumnSet factColumns = new AdaptiveColumnSet()
        {
            Columns = new List <AdaptiveColumn>
            {
                new AdaptiveColumn()
                {
                    Items = new List <AdaptiveElement>
                    {
                        factsCol1
                    },
                    Width = AdaptiveColumnWidth.Stretch
                },

                new AdaptiveColumn()
                {
                    Items = new List <AdaptiveElement>
                    {
                        factsCol2
                    },
                    Width = AdaptiveColumnWidth.Stretch
                }
            }
        };

        details.Items = new List <AdaptiveElement>
        {
            candidateSummary,
            factColumns
        };

        card.Body.Add(details);

        AdaptiveImageSet referrals = new AdaptiveImageSet();

        referrals.ImageSize = AdaptiveImageSize.Small;
        referrals.Images    = new List <AdaptiveImage>();

        foreach (Candidate referral in new CandidatesDataController().GetReferrals(c))
        {
            referrals.Images.Add(new AdaptiveImage()
            {
                Url   = new Uri(referral.ProfilePicture),
                Style = AdaptiveImageStyle.Person
            });
        }

        card.Body.Add(new AdaptiveTextBlock()
        {
            Text = "Referrals",
            Size = AdaptiveTextSize.Large
        });
        card.Body.Add(referrals);

        AdaptiveAction setInterview = new AdaptiveShowCardAction()
        {
            Title = "Set interview date",
            Card  = new AdaptiveCard()
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveDateInput()
                    {
                        Id          = "InterviewDate",
                        Placeholder = "Enter in a date for the interview"
                    }
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction()
                    {
                        Title = "OK"
                    }
                }
            }
        };

        AdaptiveAction setComment = new AdaptiveShowCardAction()
        {
            Title = "Add comment",
            Card  = new AdaptiveCard()
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveTextInput()
                    {
                        Id          = "Comment",
                        Placeholder = "Add a comment for this candidate",
                        IsMultiline = true
                    }
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction()
                    {
                        Title = "OK"
                    }
                }
            }
        };

        card.Actions = new List <AdaptiveAction>
        {
            setInterview,
            setComment
        };

        return(card);
    }
Esempio n. 22
0
        protected Attachment ToAdaptiveCardForReadMore(
            List <TaskItem> todos,
            int startIndexOfTasksToBeRead,
            int toBeReadTasksCount,
            int allTasksCount,
            string listType)
        {
            var toDoCard = new AdaptiveCard();
            var response = new ResponseTemplate();

            if (toBeReadTasksCount == 1)
            {
                response       = ResponseManager.GetResponseTemplate(ShowToDoResponses.NextOneTask);
                toDoCard.Speak = response.Reply.Speak + " ";
            }
            else if (toBeReadTasksCount == 2)
            {
                response        = ResponseManager.GetResponseTemplate(ShowToDoResponses.NextTwoTasks);
                toDoCard.Speak += response.Reply.Speak + " ";
            }
            else
            {
                response        = ResponseManager.GetResponseTemplate(ShowToDoResponses.NextThreeOrMoreTask);
                toDoCard.Speak += ResponseManager.Format(response.Reply.Speak, new StringDictionary()
                {
                    { "taskCount", toBeReadTasksCount.ToString() }
                }) + " ";
            }

            var body = new List <AdaptiveElement>();

            response = ResponseManager.GetResponseTemplate(ToDoSharedResponses.CardSummaryMessage);
            var showText = ResponseManager.Format(response.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTasksCount.ToString() }, { "listType", listType }
            });
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);

            var container = new AdaptiveContainer();
            int index     = 0;

            foreach (var todo in todos)
            {
                var columnSet = new AdaptiveColumnSet();

                var icon = new AdaptiveImage
                {
                    UrlString = todo.IsCompleted ? IconImageSource.CheckIconSource : IconImageSource.UncheckIconSource
                };
                var iconColumn = new AdaptiveColumn
                {
                    Width = "auto"
                };
                iconColumn.Items.Add(icon);
                columnSet.Columns.Add(iconColumn);

                var content       = new AdaptiveTextBlock(todo.Topic);
                var contentColumn = new AdaptiveColumn();
                iconColumn.Width = "auto";
                contentColumn.Items.Add(content);
                columnSet.Columns.Add(contentColumn);

                container.Items.Add(columnSet);
                if (index >= startIndexOfTasksToBeRead && index < startIndexOfTasksToBeRead + toBeReadTasksCount)
                {
                    if (toBeReadTasksCount == 1)
                    {
                        toDoCard.Speak += todo.Topic + ". ";
                    }
                    else if (index == startIndexOfTasksToBeRead + toBeReadTasksCount - 2)
                    {
                        toDoCard.Speak += todo.Topic;
                    }
                    else if (index == startIndexOfTasksToBeRead + toBeReadTasksCount - 1)
                    {
                        toDoCard.Speak += string.Format(ToDoStrings.And, todo.Topic);
                    }
                    else
                    {
                        toDoCard.Speak += todo.Topic + ", ";
                    }
                }

                index++;
            }

            body.Add(container);
            toDoCard.Body = body;

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

            return(attachment);
        }
Esempio n. 23
0
        public void ColumnSet()
        {
            AdaptiveColumn column1 = new AdaptiveColumn
            {
                Bleed     = true,
                Height    = HeightType.Stretch,
                Id        = "ColumnId",
                IsVisible = false,
                Width     = "50px",
                Separator = true,
                Spacing   = Spacing.Small,
                Style     = ContainerStyle.Emphasis,
                VerticalContentAlignment = VerticalContentAlignment.Bottom,
            };

            ValidateBaseElementProperties(column1, "ColumnId", false, true, Spacing.Small, HeightType.Stretch);

            Assert.IsTrue(column1.Bleed);
            Assert.AreEqual("50px", column1.Width);
            Assert.AreEqual <uint>(50, column1.PixelWidth);
            Assert.AreEqual(ContainerStyle.Emphasis, column1.Style);
            Assert.AreEqual(VerticalContentAlignment.Bottom, column1.VerticalContentAlignment);

            column1.SelectAction = new AdaptiveSubmitAction
            {
                Title = "Select Action"
            };
            Assert.IsNotNull(column1.SelectAction);
            Assert.AreEqual("Select Action", column1.SelectAction.Title);

            AdaptiveTextBlock textBlock = new AdaptiveTextBlock
            {
                Text = "This is a text block"
            };

            column1.Items.Add(textBlock);

            AdaptiveTextBlock textBlock2 = new AdaptiveTextBlock
            {
                Text = "This is another text block"
            };

            column1.Items.Add(textBlock2);

            Assert.AreEqual("This is a text block", (column1.Items[0] as AdaptiveTextBlock).Text);
            Assert.AreEqual("This is another text block", (column1.Items[1] as AdaptiveTextBlock).Text);

            column1.FallbackType    = FallbackType.Content;
            column1.FallbackContent = new AdaptiveColumn();

            Assert.AreEqual(FallbackType.Content, column1.FallbackType);
            Assert.AreEqual(ElementType.Column, column1.FallbackContent.ElementType);

            AdaptiveColumn column2 = new AdaptiveColumn
            {
                Id = "Column2Id"
            };
            AdaptiveTextBlock textBlock3 = new AdaptiveTextBlock
            {
                Text = "This is a text block"
            };

            column2.Items.Add(textBlock3);

            AdaptiveColumnSet columnSet = new AdaptiveColumnSet
            {
                Bleed     = true,
                Height    = HeightType.Stretch,
                Id        = "ColumnSetId",
                IsVisible = false,
                Separator = true,
                Spacing   = Spacing.Small,
                Style     = ContainerStyle.Emphasis,
            };

            Assert.IsTrue(columnSet.Bleed);
            ValidateBaseElementProperties(columnSet, "ColumnSetId", false, true, Spacing.Small, HeightType.Stretch);

            columnSet.Columns.Add(column1);
            columnSet.Columns.Add(column2);

            Assert.AreEqual("ColumnId", columnSet.Columns[0].Id);
            Assert.AreEqual("Column2Id", columnSet.Columns[1].Id);

            var jsonString = columnSet.ToJson().ToString();

            Assert.AreEqual("{\"bleed\":true,\"columns\":[{\"bleed\":true,\"fallback\":{\"items\":[],\"type\":\"Column\",\"width\":\"auto\"},\"height\":\"Stretch\",\"id\":\"ColumnId\",\"isVisible\":false,\"items\":[{\"text\":\"This is a text block\",\"type\":\"TextBlock\"},{\"text\":\"This is another text block\",\"type\":\"TextBlock\"}],\"selectAction\":{\"title\":\"Select Action\",\"type\":\"Action.Submit\"},\"separator\":true,\"spacing\":\"small\",\"style\":\"Emphasis\",\"type\":\"Column\",\"verticalContentAlignment\":\"Bottom\",\"width\":\"50px\"},{\"id\":\"Column2Id\",\"items\":[{\"text\":\"This is a text block\",\"type\":\"TextBlock\"}],\"type\":\"Column\",\"width\":\"auto\"}],\"height\":\"Stretch\",\"id\":\"ColumnSetId\",\"isVisible\":false,\"separator\":true,\"spacing\":\"small\",\"style\":\"Emphasis\",\"type\":\"ColumnSet\"}", jsonString);
        }
Esempio n. 24
0
        public static string GetBoardAdaptiveCard(Board board)
        {
            string text         = "";
            var    adaptiveCard = new AdaptiveCard("1.0")
            {
                Body = new List <AdaptiveElement>()
            };

            if (board.getStatus() == Board.GameState.INPROGRESS)
            {
                if (board.getCurrentPlayerName().Equals("Your"))
                {
                    text = board.getCurrentPlayerName() + " Turn [" + board.getCurrentPlayerToken() + "]";
                }
                else
                {
                    text = board.getCurrentPlayerName() + "'s Turn [" + board.getCurrentPlayerToken() + "]";
                }
            }
            else if (board.getStatus() == Board.GameState.WIN)
            {
                if (board.getWinnerName().Equals("Your"))
                {
                    text = "You Win";
                }
                else
                {
                    text = board.getWinnerName() + " Wins!";
                }
            }
            else
            {
                text = "No winner";
            }

            var textBlock = new AdaptiveTextBlock()
            {
                Text = text,
                HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                Size    = AdaptiveTextSize.Large,
                Spacing = AdaptiveSpacing.Small
            };

            var horizontalAlignment = new AdaptiveHorizontalAlignment[] { AdaptiveHorizontalAlignment.Right, AdaptiveHorizontalAlignment.Center, AdaptiveHorizontalAlignment.Left };
            var index = 0;

            adaptiveCard.Body.Add(textBlock);
            for (var i = 0; i < 3; i++)
            {
                var columnSet = new AdaptiveColumnSet()
                {
                    Separator = false,
                    Spacing   = AdaptiveSpacing.Medium
                };

                for (var j = 0; j < 3; j++)
                {
                    columnSet.Columns.Add(new AdaptiveColumn()
                    {
                        Width = AdaptiveColumnWidth.Stretch,
                        Items = new List <AdaptiveElement>()
                        {
                            new AdaptiveImage()
                            {
                                AltText             = "",
                                Url                 = new Uri(board.getCDN(board.getCellState(index), index++)),
                                Size                = AdaptiveImageSize.Medium,
                                HorizontalAlignment = horizontalAlignment[j]
                            }
                        },
                        Spacing = AdaptiveSpacing.Small,
                    });
                }

                adaptiveCard.Body.Add(columnSet);
            }

            return(adaptiveCard.ToJson());
        }
        protected Attachment ToAdaptiveCardForDeletionRefusedFlow(
            List <TaskItem> todos,
            int allTasksCount,
            string listType)
        {
            var toDoCard = new AdaptiveCard();
            var response = ResponseManager.GetResponseTemplate(DeleteToDoResponses.DeletionAllConfirmationRefused);

            toDoCard.Speak = ResponseManager.Format(response.Reply.Speak, new StringDictionary()
            {
                { "taskCount", allTasksCount.ToString() }, { "listType", listType }
            });

            var body = new List <AdaptiveElement>();

            if (allTasksCount == 1)
            {
                response = ResponseManager.GetResponseTemplate(ToDoSharedResponses.CardSummaryMessageForSingleTask);
            }
            else
            {
                response = ResponseManager.GetResponseTemplate(ToDoSharedResponses.CardSummaryMessageForMultipleTasks);
            }

            var showText = ResponseManager.Format(response.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTasksCount.ToString() }, { "listType", listType }
            });
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);

            var container = new AdaptiveContainer();

            foreach (var todo in todos)
            {
                var columnSet = new AdaptiveColumnSet();

                var icon = new AdaptiveImage
                {
                    UrlString = todo.IsCompleted ? IconImageSource.CheckIconSource : IconImageSource.UncheckIconSource
                };
                var iconColumn = new AdaptiveColumn
                {
                    Width = "auto"
                };
                iconColumn.Items.Add(icon);
                columnSet.Columns.Add(iconColumn);

                var content       = new AdaptiveTextBlock(todo.Topic);
                var contentColumn = new AdaptiveColumn();
                iconColumn.Width = "auto";
                contentColumn.Items.Add(content);
                columnSet.Columns.Add(contentColumn);

                container.Items.Add(columnSet);
            }

            body.Add(container);
            toDoCard.Body = body;

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

            return(attachment);
        }
Esempio n. 26
0
        private async Task <HttpResponseMessage> HandleSelectAnswerFromMessageAction(Microsoft.Bot.Connector.Activity activity)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            TeamsMessage selectedReply = JsonConvert.DeserializeObject <TeamsMessage>(JsonConvert.SerializeObject((activity.Value as dynamic)["messagePayload"]));

            if (selectedReply.From.User == null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            var question = SQLService.GetQuestionByMessageId(selectedReply.ReplyToId);

            if (question == null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            // get user details
            var channelData = activity.GetChannelData <Microsoft.Bot.Connector.Teams.Models.TeamsChannelData>();
            var members     = await connector.Conversations.GetConversationMembersAsync(channelData.Team.Id);

            var teamsMembers = members.AsTeamsChannelAccounts();
            var currentUser  = teamsMembers.Where(x => x.ObjectId == activity.From.Properties["aadObjectId"].ToString()).FirstOrDefault();
            var studentUPN   = currentUser.UserPrincipalName;
            var isUserAdmin  = SQLService.IsUserAdmin(studentUPN);

            // check if user can set question status
            if (isUserAdmin || (studentUPN == question.OriginalPoster.Email) || (studentUPN == question.OriginalPoster.UserName))
            {
                var selectedReplyUser = teamsMembers.Where(x => x.ObjectId == selectedReply.From.User.Id).FirstOrDefault();
                var answeredBy        = SQLService.GetUser(selectedReplyUser.UserPrincipalName);

                // update question model
                question.QuestionStatus   = Constants.QUESTION_STATUS_ANSWERED;
                question.QuestionAnswered = DateTime.Now;
                question.AnswerText       = MicrosoftTeamsChannelHelper.StripMentionAndHtml(selectedReply.Body.Content);
                question.AnswerPoster     = answeredBy;

                SQLService.CreateOrUpdateQuestion(question);

                Microsoft.Bot.Connector.Activity updatedReply = activity.CreateReply();

                var card        = new AdaptiveCard();
                var answerBlock = new AdaptiveTextBlock("Answer: " + question.AnswerText.ReplaceLinksWithMarkdown());
                answerBlock.Weight = AdaptiveTextWeight.Bolder;
                answerBlock.Size   = AdaptiveTextSize.Medium;
                answerBlock.Wrap   = true;

                var markedBlock = new AdaptiveTextBlock($"Marked as " + question.QuestionStatus + " by " + currentUser.Name);
                markedBlock.Wrap = true;

                var answeredBlock = new AdaptiveTextBlock("Answered by: " + question.AnswerPoster.FullName);
                answeredBlock.Weight = AdaptiveTextWeight.Bolder;
                answeredBlock.Wrap   = true;

                card.Body.Add(answerBlock);
                card.Body.Add(answeredBlock);
                card.Body.Add(markedBlock);

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

                updatedReply.Attachments.Add(attachment);

                if (question.AnswerCardActivityId == null)
                {
                    var r = await connector.Conversations.ReplyToActivityAsync(updatedReply.Conversation.Id, updatedReply.ReplyToId, updatedReply);

                    question.AnswerCardActivityId = r.Id;
                    SQLService.CreateOrUpdateQuestion(question);
                }
                else
                {
                    updatedReply.ReplyToId = question.AnswerCardActivityId;
                    var r = await connector.Conversations.UpdateActivityAsync(updatedReply.Conversation.Id, updatedReply.ReplyToId, updatedReply);

                    question.AnswerCardActivityId = r.Id;
                    SQLService.CreateOrUpdateQuestion(question);
                }
            }

            var baseUrl  = ServiceHelper.BaseUrl;
            var taskInfo = new Models.TaskInfo();

            taskInfo.Title  = "Select Answer";
            taskInfo.Height = 300;
            taskInfo.Width  = 400;
            taskInfo.Url    = baseUrl + @"/home/selectanswer?json=" + "Answer Updated";

            Models.TaskEnvelope taskEnvelope = new Models.TaskEnvelope
            {
                Task = new Models.Task()
                {
                    Type     = Models.TaskType.Continue,
                    TaskInfo = taskInfo,
                },
            };
            return(Request.CreateResponse(HttpStatusCode.OK, taskEnvelope));
        }
Esempio n. 27
0
 public virtual void Visit(AdaptiveTextBlock textBlock)
 {
 }
Esempio n. 28
0
        protected Microsoft.Bot.Schema.Attachment ToAdaptiveCardAttachmentForOtherFlows(
            List <TaskItem> 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
            {
                IsMultiSelect = true,
            };
            var value = Guid.NewGuid().ToString() + ",";

            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 + ",";
                }
            }

            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 HtmlTag Render(AdaptiveTypedElement element)
        {
            HtmlTag htmlTagOut             = null;
            var     oldAncestorHasFallback = AncestorHasFallback;
            var     elementHasFallback     = element != null && element.Fallback != null && (element.Fallback.Type != AdaptiveFallbackElement.AdaptiveFallbackType.None);

            AncestorHasFallback = AncestorHasFallback || elementHasFallback;

            try
            {
                if (AncestorHasFallback && !element.MeetsRequirements(FeatureRegistration))
                {
                    throw new AdaptiveFallbackException("Element requirements aren't met");
                }

                // If non-interactive, inputs should just render text
                if (!Config.SupportsInteractivity && element is AdaptiveInput input)
                {
                    var tb = new AdaptiveTextBlock();
                    tb.Text = input.GetNonInteractiveValue();
                    Warnings.Add(new AdaptiveWarning(-1, $"Rendering non-interactive input element '{element.Type}'"));
                    htmlTagOut = Render(tb);
                }

                if (htmlTagOut == null)
                {
                    var renderer = ElementRenderers.Get(element.GetType());
                    if (renderer != null)
                    {
                        htmlTagOut = renderer.Invoke(element, this);
                    }
                }
            }
            catch (AdaptiveFallbackException)
            {
                if (!elementHasFallback)
                {
                    throw;
                }
            }

            if (htmlTagOut == null)
            {
                // Since no renderer exists for this element, add warning and render fallback (if available)
                if (element.Fallback != null && element.Fallback.Type != AdaptiveFallbackElement.AdaptiveFallbackType.None)
                {
                    if (element.Fallback.Type == AdaptiveFallbackElement.AdaptiveFallbackType.Drop)
                    {
                        Warnings.Add(new AdaptiveWarning(-1, $"Dropping element for fallback '{element.Type}'"));
                    }
                    else if (element.Fallback.Type == AdaptiveFallbackElement.AdaptiveFallbackType.Content && element.Fallback.Content != null)
                    {
                        // Render fallback content
                        htmlTagOut = Render(element.Fallback.Content);
                    }
                }
                else if (AncestorHasFallback)
                {
                    throw new AdaptiveFallbackException();
                }
                else
                {
                    Warnings.Add(new AdaptiveWarning(-1, $"No renderer for element '{element.Type}'"));
                }
            }

            AncestorHasFallback = oldAncestorHasFallback;
            return(htmlTagOut);
        }
Esempio n. 30
0
        private AdaptiveCard SetCard()
        {
            AdaptiveCard _card = new AdaptiveCard("1.0");

            var _container = new AdaptiveContainer();

            var colum = new AdaptiveColumnSet();

            var _columnImage = new AdaptiveColumn()
            {
                Width = AdaptiveColumnWidth.Auto
            };

            _columnImage.Items.Add(new AdaptiveImage()
            {
                Url     = new Uri("http://localhost:3978/img/bot-avatar_.png"),
                Size    = AdaptiveImageSize.Small,
                Style   = AdaptiveImageStyle.Person,
                AltText = "Bootty"
            });

            var _columnContent = new AdaptiveColumn()
            {
                Width = AdaptiveColumnWidth.Stretch
            };

            _columnContent.Items.Add(new AdaptiveTextBlock()
            {
                Text    = "Booty",
                Size    = AdaptiveTextSize.Medium,
                Weight  = AdaptiveTextWeight.Default,
                Color   = AdaptiveTextColor.Default,
                Wrap    = true,
                Spacing = AdaptiveSpacing.Default
            });

            _columnContent.Items.Add(new AdaptiveTextBlock()
            {
                Text     = DateTime.Now.ToString(),
                Size     = AdaptiveTextSize.Small,
                Color    = AdaptiveTextColor.Default,
                Wrap     = true,
                IsSubtle = true,
                Spacing  = AdaptiveSpacing.None
            });

            var _textMessage = new AdaptiveTextBlock()
            {
                Text     = this.Title,
                Size     = AdaptiveTextSize.Medium,
                Color    = AdaptiveTextColor.Default,
                Weight   = AdaptiveTextWeight.Bolder,
                Wrap     = true,
                IsSubtle = false
            };

            var _textMessage2 = new AdaptiveTextBlock()
            {
                Text     = this.Description,
                Size     = AdaptiveTextSize.Small,
                Color    = AdaptiveTextColor.Default,
                Weight   = AdaptiveTextWeight.Default,
                Wrap     = true,
                IsSubtle = false
            };

            colum.Columns.Add(_columnImage);
            colum.Columns.Add(_columnContent);
            _container.Items.Add(colum);

            _card.Body.Add(_container);
            _card.Body.Add(_textMessage);
            _card.Body.Add(_textMessage2);

            _card.Actions.AddRange(this.GetAdaptiveActions());

            return(_card);
        }