// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IStringLocalizer<Startup> sr)
        {
            var options = new RequestLocalizationOptions()
            {
                DefaultRequestCulture = new RequestCulture(new CultureInfo("en-US")),
                SupportedCultures = new CultureInfo[]
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("de-AT"),
                    new CultureInfo("de")
                },
                SupportedUICultures = new CultureInfo[]
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("de-AT"),
                    new CultureInfo("de")
                }
            };

            app.UseRequestLocalization(options);

            app.Run(async (context) =>
            {
                IRequestCultureFeature requestCultureFeature =
                    context.Features.Get<IRequestCultureFeature>();
                RequestCulture requestCulture = requestCultureFeature.RequestCulture;

                var today = DateTime.Today;
                context.Response.StatusCode = 200;
                await context.Response.WriteAsync("<h1>Sample Localization</h1>");
                await context.Response.WriteAsync(
                $"<div>{requestCulture.Culture} {requestCulture.UICulture}</div>");
                await context.Response.WriteAsync($"<div>{today:D}</div>");
                await context.Response.WriteAsync($"<div>{sr["message1"]}</div>");
                await context.Response.WriteAsync($"<div>{sr.WithCulture(new CultureInfo("de-DE")).GetString("message1")}</div>");
                await context.Response.WriteAsync($"<div>{WebUtility.HtmlEncode(sr.GetString("message1"))}</div>");
                await context.Response.WriteAsync(
                  $"<div>{sr.GetString("message2", requestCulture.Culture, requestCulture.UICulture)}</div>");
            });
        }
        public UserResult CreateUser(string userName, string displayName, string emailAddress, string password, string twitterUserName)
        {
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(userName));
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(displayName));
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(emailAddress));
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(password));

            var userNameExistsCommand = new SqlCommand("security.UserNameExists")
            {
                CommandType = CommandType.StoredProcedure,
                Connection  = _securitySqlConnectionWrapper.SqlConnection
            };

            userNameExistsCommand.Parameters.AddWithValue("userName", userName);

            var userNameExists = Convert.ToBoolean(userNameExistsCommand.ExecuteScalar());

            var emailAddressExistsCommand = new SqlCommand("security.EmailAddressExists")
            {
                CommandType = CommandType.StoredProcedure,
                Connection  = _securitySqlConnectionWrapper.SqlConnection
            };

            emailAddressExistsCommand.Parameters.AddWithValue("emailAddress", emailAddress);

            var emailExists = Convert.ToBoolean(emailAddressExistsCommand.ExecuteScalar());

            if (userNameExists || emailExists)
            {
                var result = new UserResult(false);

                if (userNameExists)
                {
                    result.AddValidationMessage("UserName", _stringLocalizer.GetString("UsernameInUse"));
                }

                if (emailExists)
                {
                    result.AddValidationMessage("EmailAddress", _stringLocalizer.GetString("EmailAddressInUse"));
                    // Nb - This is proof of concept code, production systems should probably include email
                    // validation as part of the process and email the address provided to state the address
                    // is already in use to prevent enumeration attacks.
                }

                return(result);
            }

            var defaultIdentityVersionCommand = new SqlCommand("security.GetDefaultIdentityVersion")
            {
                CommandType = CommandType.StoredProcedure,
                Connection  = _securitySqlConnectionWrapper.SqlConnection
            };

            var identityId = 1;

            var hashIterations = 2500;

            using (var defaultIdentityVersion = defaultIdentityVersionCommand.ExecuteReader())
            {
                if (defaultIdentityVersion.Read())
                {
                    var identityVersionIndex = defaultIdentityVersion.GetOrdinal("IdentityVersion");

                    identityId = defaultIdentityVersion.GetInt32(identityVersionIndex);

                    var hashIterationsIndex = defaultIdentityVersion.GetOrdinal("HashIterations");

                    hashIterations = defaultIdentityVersion.GetInt32(hashIterationsIndex);
                }
            }

            var salt = UserExtensions.GenerateSalt();

            var passwordHash = UserExtensions.HashPassword(Encoding.UTF8.GetBytes(password), salt, hashIterations);

            var createUserCommand = new SqlCommand("security.CreateUser")
            {
                CommandType = CommandType.StoredProcedure,
                Connection  = _securitySqlConnectionWrapper.SqlConnection
            };

            createUserCommand.Parameters.AddWithValue("userName", userName);
            createUserCommand.Parameters.AddWithValue("displayName", displayName);
            createUserCommand.Parameters.AddWithValue("emailAddress", emailAddress);
            createUserCommand.Parameters.AddWithValue("passwordHash", Convert.ToBase64String(passwordHash));
            createUserCommand.Parameters.AddWithValue("passwordSalt", Convert.ToBase64String(salt));
            createUserCommand.Parameters.AddWithValue("twitterUserName", twitterUserName);
            createUserCommand.Parameters.AddWithValue("userIdentityVersion", identityId);

            createUserCommand.ExecuteNonQuery();

            return(new UserResult(true));
        }
        /// <summary>
        /// Construct validation message card to show on task module.
        /// </summary>
        /// <param name="introductionEntity">New hire introduction details.</param>
        /// <param name="localizer">The current culture's string localizer.</param>
        /// <returns>Validation message card attachment.</returns>
        public static Attachment GetValidationMessageCard(IntroductionEntity introductionEntity, IStringLocalizer <Strings> localizer)
        {
            introductionEntity = introductionEntity ?? throw new ArgumentNullException(nameof(introductionEntity));

            AdaptiveCard validationCard = new AdaptiveCard(new AdaptiveSchemaVersion(CardConstants.AdaptiveCardVersion))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveTextBlock
                    {
                        Text = introductionEntity.ApprovalStatus == (int)IntroductionStatus.PendingForApproval ? localizer.GetString("PendingMessageText") : localizer.GetString("ApprovedMessageText"),
                        Wrap = true,
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = validationCard,
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the goal status card in channel.
        /// </summary>
        /// <param name="teamGoalStatuses">Team goal status for each team goal.</param>
        /// <param name="teamGoalStartDate">Team goal start date for team goal cycle.</param>
        /// <param name="teamGoalEndDate">Team goal end date for team goal cycle.</param>
        /// <param name="applicationBasePath">Application base URL.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>Goal status card as attachment in teams channel.</returns>
        public static Attachment GetGoalStatusCard(IEnumerable <TeamGoalStatus> teamGoalStatuses, string teamGoalStartDate, string teamGoalEndDate, string applicationBasePath, IStringLocalizer <Strings> localizer)
        {
            var          startDate      = CardHelper.FormatDateStringToAdaptiveCardDateFormat(teamGoalStartDate);
            var          endDate        = CardHelper.FormatDateStringToAdaptiveCardDateFormat(teamGoalEndDate);
            AdaptiveCard goalStatusCard = new AdaptiveCard(Constants.AdaptiveCardVersion)
            {
                Height         = AdaptiveHeight.Stretch,
                PixelMinHeight = 150,
                Body           = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        Text   = localizer.GetString("GoalStatusCardTitle"),
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Large,
                                        Wrap   = true,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        Text = localizer.GetString("GoalStatusGoalCycleText"),
                                        Wrap = true,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                Width = AdaptiveColumnWidth.Stretch,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        Text   = $"{startDate} - {endDate}",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Stretch,
                                Items = new List <AdaptiveElement>
                                { // Represents empty column required for alignment.
                                },
                            },
                        },
                    },
                },
            };

            List <AdaptiveElement> teamGoalStatusList = GetAllTeamGoalStatuses(teamGoalStatuses, applicationBasePath, localizer);

            goalStatusCard.Body.AddRange(teamGoalStatusList);

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

            return(card);
        }
Exemplo n.º 5
0
 public IActionResult Get([FromServices] IStringLocalizer <EmptyControllerResources> localizer)
 => Request.Headers[HeaderNames.Accept].ToString().Contains("text/html")
         ? (IActionResult) new RedirectResult("/docs")
         : new OkObjectResult(localizer.GetString(x => x.ApiWelcomeMessage, Assembly.GetEntryAssembly().GetName().Version));
Exemplo n.º 6
0
 public static string GetPlural(this IStringLocalizer resource, string key, double number, bool supportNoneState = false)
 {
     return(GetPluralInternal <IStringLocalizer>((reskey) => resource.GetString(reskey), key, number, supportNoneState));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Get adaptive card attachment for auto registered attendees.
        /// </summary>
        /// <param name="applicationBasePath">Base URL of application.</param>
        /// <param name="localizer">String localizer for localizing user facing text.</param>
        /// <param name="eventEntity">Event details which is cancelled.</param>
        /// <param name="applicationManifestId">The unique manifest Id for application</param>
        /// <returns>An adaptive card attachment.</returns>
        public static Attachment GetAutoRegisteredCard(string applicationBasePath, IStringLocalizer <Strings> localizer, EventEntity eventEntity, string applicationManifestId)
        {
            eventEntity = eventEntity ?? throw new ArgumentNullException(nameof(eventEntity), "Event details cannot be null");

            AdaptiveCard autoRegisteredCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("AutoRegisteredHeader")}**",
                                        Size   = AdaptiveTextSize.Large,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url                 = new Uri($"{applicationBasePath}/images/Mandatory.png"),
                                        PixelWidth          = 96,
                                        PixelHeight         = 32,
                                        Spacing             = AdaptiveSpacing.None,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = $"{localizer.GetString("AutoRegisteredCardSubTitle")}",
                        Wrap    = true,
                        Size    = AdaptiveTextSize.Small,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Height = AdaptiveHeight.Auto,
                                Width  = AdaptiveColumnWidth.Auto,
                                Items  = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url = new Uri(eventEntity.Photo),
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                        PixelHeight         = 45,
                                        PixelWidth          = 45,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = eventEntity.Name,
                                        Size   = AdaptiveTextSize.Default,
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = eventEntity.CategoryName,
                                        Wrap    = true,
                                        Size    = AdaptiveTextSize.Small,
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Color   = AdaptiveTextColor.Warning,
                                        Spacing = AdaptiveSpacing.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Medium,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("DateAndTimeLabel")}:**",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = string.Format(CultureInfo.CurrentCulture, "{0} {1}-{2}", "{{DATE(" + eventEntity.StartDate.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", CultureInfo.InvariantCulture) + ", SHORT)}}", "{{TIME(" + eventEntity.StartTime.Value.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}", "{{TIME(" + eventEntity.EndTime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'", CultureInfo.InvariantCulture) + ")}}"),
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = eventEntity.Type != (int)EventType.InPerson ? new List <AdaptiveColumn>() : new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Venue")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Venue,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.Small,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "100px",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = $"**{localizer.GetString("Description")}:** ",
                                        Wrap   = true,
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Spacing = AdaptiveSpacing.None,
                                Items   = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = eventEntity.Description,
                                        Wrap = true,
                                        Size = AdaptiveTextSize.Small,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveColumnSet
                    {
                        Spacing = AdaptiveSpacing.ExtraLarge,
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveActionSet
                                    {
                                        Actions = new List <AdaptiveAction>
                                        {
                                            new AdaptiveOpenUrlAction
                                            {
                                                Url   = new Uri($"https://teams.microsoft.com/l/entity/{applicationManifestId}/my-events"),
                                                Title = $"{localizer.GetString("ReminderCardRegisteredEventButton")}",
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = autoRegisteredCard,
            });
        }
Exemplo n.º 8
0
 public string GetString(string key)
 {
     return(_localizer.GetString(key));
 }
Exemplo n.º 9
0
        /// <summary>
        /// Get welcome card attachment to show on Microsoft Teams team scope when bot is installed in team.
        /// </summary>
        /// <param name="applicationBasePath">Application base URL to get the logo of the application.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>Welcome card attachment.</returns>
        public static Attachment GetWelcomeCardAttachmentForChannel(string applicationBasePath, IStringLocalizer <Strings> localizer)
        {
            AdaptiveCard welcomeCard = new AdaptiveCard(Constants.AdaptiveCardVersion)
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AppLogoColumnWidth,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri($"{applicationBasePath}/Artifacts/appLogo.png"),
                                        Size = AdaptiveImageSize.Large,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Width = HeaderColumnWidth,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Size   = AdaptiveTextSize.Large,
                                        Wrap   = true,
                                        Text   = localizer.GetString("WelcomeCardTitle"),
                                        Weight = AdaptiveTextWeight.Bolder,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Size = AdaptiveTextSize.Default,
                                        Wrap = true,
                                        Text = localizer.GetString("WelcomeCardSubtitleText"),
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                        Text = $"{localizer.GetString("WelcomeCardStartScrumTextHeading")}: {localizer.GetString("WelcomeCardStartScrumTextDesc")}",
                        Wrap = true,
                    },
                    new AdaptiveTextBlock
                    {
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                        Text = $"{localizer.GetString("WelcomeCardEndScrumTextHeading")}: {localizer.GetString("WelcomeCardEndScrumTextDesc")}",
                        Wrap = true,
                    },
                    new AdaptiveTextBlock
                    {
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                        Text = localizer.GetString("WelcomeCardWantToStartScrumText"),
                        Wrap = true,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("SettingsButtonText"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            MsTeams = new TaskModuleAction(
                                localizer.GetString("SettingsButtonText"),
                                new AdaptiveSubmitActionData
                            {
                                AdaptiveActionType = Constants.Settings,
                            }),
                        },
                    },
                },
            };
            var adaptiveCardAttachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = welcomeCard,
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Convert json template to Adaptive card.
        /// </summary>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="cardTemplate">Adaptive card template.</param>
        /// <param name="showDateValidation">true if need to show validation message else false.</param>
        /// <param name="ticketDetails">Ticket details key value pair.</param>
        /// <returns>Adaptive card item element json string.</returns>
        public static List <AdaptiveElement> ConvertToAdaptiveCard(IStringLocalizer <Strings> localizer, string cardTemplate, bool showDateValidation, Dictionary <string, string> ticketDetails = null)
        {
            var cardTemplates        = JsonConvert.DeserializeObject <List <JObject> >(cardTemplate);
            var cardTemplateElements = new List <JObject>();

            foreach (var template in cardTemplates)
            {
                var templateMapping = template.ToObject <AdaptiveCardPlaceHolderMapper>();
                if (templateMapping.InputType != "TextBlock")
                {
                    // get first observed display text if parsed from appSettings; rest all values will be set up directly in JSON payload.
                    if (templateMapping.Id == CardConstants.IssueOccurredOnId)
                    {
                        templateMapping.DisplayName = localizer.GetString("FirstObservedText");
                    }

                    // every input elements display name is integrated with the JSON payload
                    // and is converted to text block corresponding to input element
                    cardTemplateElements.Add(JObject.FromObject(new AdaptiveTextBlock
                    {
                        Type = AdaptiveTextBlock.TypeName,
                        Text = templateMapping.DisplayName,
                    }));

                    var templateMappingFieldValues = template.ToObject <Dictionary <string, object> >();

                    if (ticketDetails != null)
                    {
                        templateMappingFieldValues["value"] = TryParseTicketDetailsKeyValuePair(ticketDetails, templateMapping.Id);
                    }

                    cardTemplateElements.Add(JObject.FromObject(templateMappingFieldValues));
                }
                else
                {
                    // Enabling validation message for First observed on date time field.
                    if (templateMapping.Id == "DateValidationMessage")
                    {
                        if (showDateValidation)
                        {
                            cardTemplateElements.Add(JObject.FromObject(new AdaptiveTextBlock
                            {
                                Type      = AdaptiveTextBlock.TypeName,
                                Id        = "DateValidationMessage",
                                Spacing   = AdaptiveSpacing.None,
                                Color     = AdaptiveTextColor.Attention,
                                IsVisible = true,
                                Text      = localizer.GetString("DateValidationText"),
                            }));
                        }
                    }
                    else
                    {
                        cardTemplateElements.Add(template);
                    }
                }
            }

            // Parse and convert each elements to adaptive elements
            return(ConvertToAdaptiveCardItemElement(cardTemplateElements));
        }
Exemplo n.º 11
0
 public string TestLocale()
 {
     return(_localizer.GetString(LocaleResourceConstants.UserNotFound));
 }
Exemplo n.º 12
0
        /// <summary>
        /// Methods mentions user in respective channel of which they are part after grouping.
        /// </summary>
        /// <param name="mentionToEmails">List of email ID whom to be mentioned.</param>
        /// <param name="userObjectId">Azure active directory object id of the user.</param>
        /// <param name="teamId">Team id where bot is installed.</param>
        /// <param name="turnContext">Provides context for a turn of a bot.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="logger">Instance to send logs to the application insights service.</param>
        /// <param name="mentionType">Mention activity type.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>A task that sends notification in newly created channel and mention its members.</returns>
        internal static async Task <Activity> GetMentionActivityAsync(IEnumerable <string> mentionToEmails, string userObjectId, string teamId, ITurnContext turnContext, IStringLocalizer <Strings> localizer, ILogger logger, MentionActivityType mentionType, CancellationToken cancellationToken)
        {
            try
            {
                StringBuilder  mentionText = new StringBuilder();
                List <Entity>  entities    = new List <Entity>();
                List <Mention> mentions    = new List <Mention>();
                IEnumerable <TeamsChannelAccount> channelMembers = await TeamsInfo.GetTeamMembersAsync(turnContext, teamId, cancellationToken);

                IEnumerable <ChannelAccount> mentionToMemberDetails = channelMembers.Where(member => mentionToEmails.Contains(member.Email)).Select(member => new ChannelAccount {
                    Id = member.Id, Name = member.Name
                });
                ChannelAccount mentionByMemberDetails = channelMembers.Where(member => member.AadObjectId == userObjectId).Select(member => new ChannelAccount {
                    Id = member.Id, Name = member.Name
                }).FirstOrDefault();

                foreach (ChannelAccount member in mentionToMemberDetails)
                {
                    Mention mention = new Mention
                    {
                        Mentioned = new ChannelAccount()
                        {
                            Id   = member.Id,
                            Name = member.Name,
                        },
                        Text = $"<at>{XmlConvert.EncodeName(member.Name)}</at>",
                    };
                    mentions.Add(mention);
                    entities.Add(mention);
                    mentionText.Append(mention.Text).Append(", ");
                }

                Mention mentionBy = new Mention
                {
                    Mentioned = new ChannelAccount()
                    {
                        Id   = mentionByMemberDetails.Id,
                        Name = mentionByMemberDetails.Name,
                    },
                    Text = $"<at>{XmlConvert.EncodeName(mentionByMemberDetails.Name)}</at>",
                };

                string text = string.Empty;

                switch (mentionType)
                {
                case MentionActivityType.SetAdmin:
                    entities.Add(mentionBy);
                    text = localizer.GetString("SetAdminMentionText", mentionText.ToString().Trim().TrimEnd(','), mentionBy.Text);
                    break;

                case MentionActivityType.Nomination:
                    entities.Add(mentionBy);
                    text = localizer.GetString("NominationMentionText", mentionText.ToString().Trim().TrimEnd(','), mentionBy.Text);
                    break;

                case MentionActivityType.Winner:
                    text = $"{localizer.GetString("WinnerMentionText")} {mentionText.ToString().Trim().TrimEnd(',')}";
                    break;

                default:
                    break;
                }

                Activity notificationActivity = MessageFactory.Text(text);
                notificationActivity.Entities = entities;
                return(notificationActivity);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Error while mentioning channel member in respective channels.");
                return(null);
            }
        }
 public string JsonLocalizer() => _jsonLocalizer.GetString("BaseName1");
        /// <summary>
        /// Gets Edit card for task module.
        /// </summary>
        /// <param name="ticketDetail">Ticket details from user.</param>
        /// <param name="cardConfiguration">Card configuration.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="existingTicketDetail">Existing ticket details.</param>
        /// <returns>Returns an attachment of edit card.</returns>
        public static Attachment GetEditRequestCard(TicketDetail ticketDetail, CardConfigurationEntity cardConfiguration, IStringLocalizer <Strings> localizer, TicketDetail existingTicketDetail = null)
        {
            cardConfiguration = cardConfiguration ?? throw new ArgumentNullException(nameof(cardConfiguration));
            ticketDetail      = ticketDetail ?? throw new ArgumentNullException(nameof(ticketDetail));

            string issueTitle                = string.Empty;
            string issueDescription          = string.Empty;
            var    dynamicElements           = new List <AdaptiveElement>();
            var    ticketAdditionalFields    = new List <AdaptiveElement>();
            bool   showTitleValidation       = false;
            bool   showDescriptionValidation = false;
            bool   showDateValidation        = false;

            if (string.IsNullOrWhiteSpace(ticketDetail.Title))
            {
                showTitleValidation = true;
            }
            else
            {
                issueTitle = ticketDetail.Title;
            }

            if (string.IsNullOrWhiteSpace(ticketDetail.Description))
            {
                showDescriptionValidation = true;
            }
            else
            {
                issueDescription = ticketDetail.Description;
            }

            if (ticketDetail.IssueOccuredOn == null || DateTimeOffset.Compare(ticketDetail.IssueOccuredOn, DateTime.Today) > 0 || string.IsNullOrEmpty(ticketDetail.IssueOccuredOn.ToString(CultureInfo.InvariantCulture)))
            {
                showDateValidation = true;
            }
            else if (existingTicketDetail != null && DateTimeOffset.Compare(ticketDetail.IssueOccuredOn, existingTicketDetail.IssueOccuredOn) > 0)
            {
                showDateValidation = true;
            }

            var ticketAdditionalDetails = JsonConvert.DeserializeObject <Dictionary <string, string> >(ticketDetail.AdditionalProperties);

            ticketAdditionalFields = CardHelper.ConvertToAdaptiveCard(localizer, cardConfiguration.CardTemplate, showDateValidation, ticketAdditionalDetails);

            dynamicElements.AddRange(new List <AdaptiveElement>
            {
                new AdaptiveTextBlock()
                {
                    Text    = localizer.GetString("TitleDisplayText"),
                    Spacing = AdaptiveSpacing.Medium,
                },
                new AdaptiveTextInput()
                {
                    Id          = "Title",
                    MaxLength   = 100,
                    Placeholder = localizer.GetString("TitlePlaceHolderText"),
                    Spacing     = AdaptiveSpacing.Small,
                    Value       = issueTitle,
                },
                new AdaptiveTextBlock()
                {
                    Text      = localizer.GetString("TitleValidationText"),
                    Spacing   = AdaptiveSpacing.None,
                    IsVisible = showTitleValidation,
                    Color     = AdaptiveTextColor.Attention,
                },
                new AdaptiveTextBlock()
                {
                    Text    = localizer.GetString("DescriptionText"),
                    Spacing = AdaptiveSpacing.Medium,
                },
                new AdaptiveTextInput()
                {
                    Id          = "Description",
                    MaxLength   = 500,
                    IsMultiline = true,
                    Placeholder = localizer.GetString("DesciptionPlaceHolderText"),
                    Spacing     = AdaptiveSpacing.Small,
                    Value       = issueDescription,
                },
                new AdaptiveTextBlock()
                {
                    Text      = localizer.GetString("DescriptionValidationText"),
                    Spacing   = AdaptiveSpacing.None,
                    IsVisible = showDescriptionValidation,
                    Color     = AdaptiveTextColor.Attention,
                },
                new AdaptiveTextBlock()
                {
                    Text    = localizer.GetString("RequestTypeText"),
                    Spacing = AdaptiveSpacing.Medium,
                },
                new AdaptiveChoiceSetInput
                {
                    Choices = new List <AdaptiveChoice>
                    {
                        new AdaptiveChoice
                        {
                            Title = localizer.GetString("NormalText"),
                            Value = localizer.GetString("NormalText"),
                        },
                        new AdaptiveChoice
                        {
                            Title = localizer.GetString("UrgentText"),
                            Value = localizer.GetString("UrgentText"),
                        },
                    },
                    Id    = "RequestType",
                    Value = !string.IsNullOrEmpty(ticketDetail?.RequestType) ? ticketDetail?.RequestType : localizer.GetString("NormalText"),
                    Style = AdaptiveChoiceInputStyle.Expanded,
                },
            });

            dynamicElements.AddRange(ticketAdditionalFields);

            AdaptiveCard ticketDetailsPersonalChatCard = new AdaptiveCard(Constants.AdaptiveCardVersion)
            {
                Body    = dynamicElements,
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("UpdateActionText"),
                        Id    = "UpdateRequest",
                        Data  = new AdaptiveCardAction
                        {
                            Command  = Constants.UpdateRequestAction,
                            TeamId   = cardConfiguration?.TeamId,
                            TicketId = ticketDetail.TicketId,
                            CardId   = ticketDetail.CardId,
                        },
                    },
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("CancelButtonText"),
                        Id    = "Cancel",
                        Data  = new AdaptiveCardAction
                        {
                            Command = Constants.CancelCommand,
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = ticketDetailsPersonalChatCard,
            });
        }
 public string TranslateSetting(string settingName, params string[] additionalParams)
 {
     return(_localizer.GetString(settingName, additionalParams));
 }
 public FileInvalidTypeBadRequestException(IStringLocalizer <object> localizer) : base()
 {
     CustomCode    = 400007;
     CustomMessage = localizer.GetString(CustomCode.ToString());
 }
        /// <summary>
        /// This method will construct the user welcome card when bot is added in team scope.
        /// </summary>
        /// <param name="applicationBasePath">Application base URL.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>User welcome card.</returns>
        public static Attachment GetCard(string applicationBasePath, IStringLocalizer <Strings> localizer)
        {
            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(Constants.AdaptiveCardVersion))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = "1",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Artifacts/AppIcon.png", applicationBasePath?.Trim('/'))),
                                        Size = AdaptiveImageSize.Large,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Width = "5",
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = localizer.GetString("WelcomeCardTitle"),
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Large,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = localizer.GetString("WelcomeTeamCardContent"),
                                        Wrap    = true,
                                        Spacing = AdaptiveSpacing.None,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                        Text    = localizer.GetString("WelcomeSubHeaderText"),
                        Spacing = AdaptiveSpacing.Small,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("TeamRequestBulletPoint"),
                        Spacing = AdaptiveSpacing.None,
                        Wrap    = true,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("ExperListBulletPoint"),
                        Spacing = AdaptiveSpacing.None,
                        Wrap    = true,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("ContentText"),
                        Spacing = AdaptiveSpacing.Small,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("ExpertListTitle"),
                        Data  = new AdaptiveCardAction
                        {
                            MsteamsCardAction = new CardAction
                            {
                                Type = Constants.MessageBackActionType,
                                Text = localizer.GetString("ExpertList"),
                            },
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = card,
            });
        }
 public EmailInUseBadRequestException(IStringLocalizer<object> localizer) : base()
 {
     CustomCode = 400001;
     CustomMessage = localizer.GetString(CustomCode.ToString());
 }
Exemplo n.º 19
0
        /// <summary>
        ///  Get refreshed card for rejected request.
        /// </summary>
        /// <param name="userRequestDetails">User request details object.</param>
        /// <param name="rejectedBy">User name who approved the request.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>An attachment.</returns>
        public static Attachment GetRefreshedCardForRejectedRequest(CompanyResponseEntity userRequestDetails, string rejectedBy, IStringLocalizer <Strings> localizer)
        {
            if (userRequestDetails == null)
            {
                throw new ArgumentNullException(nameof(userRequestDetails));
            }

            bool   showRemarkField   = !string.IsNullOrEmpty(userRequestDetails.ApprovalRemark);
            var    formattedDateTime = userRequestDetails.ApprovedOrRejectedDate.ToString(Constants.Rfc3339DateTimeFormat, CultureInfo.InvariantCulture);
            string dateString        = string.Format(CultureInfo.InvariantCulture, localizer.GetString("DateFormat"), "{{DATE(" + formattedDateTime + ", COMPACT)}}", "{{TIME(" + formattedDateTime + ")}}");

            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveContainer
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveColumnSet
                            {
                                Columns = new List <AdaptiveColumn>
                                {
                                    new AdaptiveColumn
                                    {
                                        Items = new List <AdaptiveElement>
                                        {
                                            new AdaptiveTextBlock
                                            {
                                                Text = localizer.GetString("NotificationCardRequestReject"),
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = string.Format(CultureInfo.InvariantCulture, localizer.GetString("RefreshedNotificationCardRequestText"), userRequestDetails.CreatedBy),
                                                Wrap = true,
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveContainer
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveColumnSet
                            {
                                Columns = new List <AdaptiveColumn>
                                {
                                    new AdaptiveColumn
                                    {
                                        Items = new List <AdaptiveElement>
                                        {
                                            new AdaptiveTextBlock
                                            {
                                                Text = localizer.GetString("NotificationCardLabelText"),
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = userRequestDetails.QuestionLabel,
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = localizer.GetString("NotificationCardQuestion"),
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = userRequestDetails.QuestionText,
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = localizer.GetString("NotificationCardResponse"),
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = userRequestDetails.ResponseText,
                                                Wrap = true,
                                            },
                                        },
                                        Style = AdaptiveContainerStyle.Emphasis,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveContainer
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveColumnSet
                            {
                                Columns = new List <AdaptiveColumn>
                                {
                                    new AdaptiveColumn
                                    {
                                        Items = new List <AdaptiveElement>
                                        {
                                            new AdaptiveTextBlock
                                            {
                                                Text      = localizer.GetString("NotificationCardRemark"),
                                                Wrap      = true,
                                                IsVisible = showRemarkField,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text      = userRequestDetails.ApprovalRemark,
                                                Wrap      = true,
                                                IsVisible = showRemarkField,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = string.Format(CultureInfo.InvariantCulture, localizer.GetString("RejectedAdminCardLabelText"), dateString, rejectedBy),
                                                Wrap = true,
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            };
            var adaptiveCardAttachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card,
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 20
0
        public IActionResult Create([FromBody] T model, CancellationToken cancellationToken)
        {
            if (!TryValidateModel(model))
            {
                return(BadRequest(ModelState));
            }

            var uninitialized = model.Id.Equals(Guid.Empty);

            if (uninitialized)
            {
                if (_options.Value.Resources.RequireExplicitIds)
                {
                    return(BadRequestWithDetails("The resource's ID was uninitialized."));
                }
                else
                {
                    var accessor = WriteAccessor.Create(model, AccessorMemberTypes.Properties, AccessorMemberScope.Public);
                    if (!accessor.TrySetValue(model, nameof(IResource.Id), Guid.NewGuid()))
                    {
                        return(BadRequestWithDetails("The resource's ID was uninitialized, and the resource does not permit setting it."));
                    }
                }
            }

            // Save a database call if the server set the ID
            if (!uninitialized && _service.TryGetById(model.Id, out var other, out _, null, false, cancellationToken))
            {
                if (other != null)
                {
                    // FIXME: replace with a ValueHash
                    var equivalent = true;
                    var reads      = ReadAccessor.Create(typeof(T), AccessorMemberTypes.Properties, AccessorMemberScope.Public, out var members);
                    foreach (var member in members)
                    {
                        if (!member.CanRead)
                        {
                            continue;
                        }

                        if (!reads.TryGetValue(model, member.Name, out var left) ||
                            !reads.TryGetValue(other, member.Name, out var right) || !left.Equals(right))
                        {
                            equivalent = false;
                            break;
                        }
                    }

                    if (equivalent)
                    {
                        // See: https://tools.ietf.org/html/rfc7231#section-4.3.3
                        //
                        //  If the result of processing a POST would be equivalent to a
                        //  representation of an existing resource, an origin server MAY redirect
                        //  the user agent to that resource by sending a 303 (See Other) response
                        //  with the existing resource's identifier in the Location field.  This
                        //  has the benefits of providing the user agent a resource identifier
                        //  and transferring the representation via a method more amenable to
                        //  shared caching, though at the cost of an extra request if the user
                        //  agent does not already have the representation cached.
                        //
                        Response.Headers.TryAdd(HeaderNames.Location, $"{Request.Path}/{model.Id}");
                        return(SeeOtherWithDetails("This resource already exists. Did you mean to update it?"));
                    }
                }

                Response.Headers.TryAdd(HeaderNames.Location, $"{Request.Path}/{model.Id}");
                return(BadRequestWithDetails("This resource already exists. Did you mean to update it?"));
            }

            if (!BeforeSave(model, out var error))
            {
                return(error ?? InternalServerErrorWithDetails("Internal error on BeforeSave"));
            }

            //
            // FIXME: The corner-case where we're creating but also have a pre-condition which should block this create operation.
            //        It is unlikely to occur in real life, but technically we should know what the ETag is before we attempt this,
            //        but the LastModifiedDate would always be 'now' since we're not expecting anything to exist.

            if (!_service.TryAdd(model, out _, cancellationToken))
            {
                Logger.LogError(ErrorEvents.ErrorSavingResource, _localizer.GetString("Adding resource {Model} failed to save to the underlying data store."), model);
                return(InternalServerErrorWithDetails("An unexpected error occurred saving this resource. An error was logged. Please try again later."));
            }

            _resourceEvents.Created(model);
            return(Created($"{Request.Path}/{model.Id}", model));
        }
Exemplo n.º 21
0
 /// <summary>
 /// Show approve adaptive card on new response request card.
 /// </summary>
 /// <param name="userRequestDetails">User request details object.</param>
 /// <param name="localizer">The current cultures' string localizer.</param>
 /// <returns>An approve card to show on new response request card.</returns>
 private static AdaptiveCard GetApproveCard(CompanyResponseEntity userRequestDetails, IStringLocalizer <Strings> localizer)
 {
     return(new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
     {
         Body = new List <AdaptiveElement>
         {
             new AdaptiveContainer
             {
                 Items = new List <AdaptiveElement>
                 {
                     new AdaptiveColumnSet
                     {
                         Columns = new List <AdaptiveColumn>
                         {
                             new AdaptiveColumn
                             {
                                 Items = new List <AdaptiveElement>
                                 {
                                     new AdaptiveTextBlock
                                     {
                                         Text = localizer.GetString("ApproveToggleCardCategoryTitle"),
                                         Wrap = true,
                                     },
                                     new AdaptiveTextInput
                                     {
                                         Id = "updatedquestioncategory",
                                         Value = userRequestDetails.QuestionLabel,
                                         Placeholder = localizer.GetString("ApproveToggleCardLabelPlaceholder"),
                                         MaxLength = ApproveToggleCardCategoryFieldMaxLimit,
                                     },
                                     new AdaptiveTextBlock
                                     {
                                         Text = localizer.GetString("ApproveToggleCardQuestionsTitle"),
                                         Wrap = true,
                                     },
                                     new AdaptiveTextInput
                                     {
                                         Id = "updatedquestiontext",
                                         Value = userRequestDetails.QuestionText,
                                         Placeholder = localizer.GetString("ApproveToggleCardQuestionsPlaceholder"),
                                         MaxLength = ApproveToggleCardQuestionFieldMaxLimit,
                                     },
                                     new AdaptiveTextBlock
                                     {
                                         Text = localizer.GetString("ApproveToggleCardQuestionsPlaceholder"),
                                         Wrap = true,
                                         HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                     },
                                     new AdaptiveTextBlock
                                     {
                                         Text = localizer.GetString("ApproveToggleCardResponseTitle"),
                                         Wrap = true,
                                     },
                                     new AdaptiveTextInput
                                     {
                                         Id = "updatedresponsetext",
                                         Value = userRequestDetails.ResponseText,
                                         Placeholder = localizer.GetString("ApproveToggleCardResponsePlaceholder"),
                                         MaxLength = ApproveToggleCardResponseFieldMaxLimit,
                                         IsMultiline = true,
                                     },
                                 },
                             },
                         },
                     },
                 },
             },
         },
         Actions = new List <AdaptiveAction>
         {
             new AdaptiveSubmitAction
             {
                 Title = localizer.GetString("ApproveToggleCardSubmitButtonTitle"),
                 Data = new AdaptiveSubmitActionData
                 {
                     AdaptiveCardActions = new CardAction
                     {
                         Type = ActionTypes.MessageBack,
                         Text = Constants.ApproveCommand,
                     },
                     ResponseId = userRequestDetails.ResponseId,
                     ApprovalStatus = ApprovedRequestStatus,
                 },
             },
         },
     });
 }
Exemplo n.º 22
0
        /// <summary>
        /// This method will construct the user welcome card when bot is added in team scope.
        /// </summary>
        /// <param name="applicationBasePath">Application base URL.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>Welcome card.</returns>
        public static Attachment GetCard(string applicationBasePath, IStringLocalizer <Strings> localizer)
        {
            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(Constants.AdaptiveCardVersion))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Content/AppIcon.png", applicationBasePath)),
                                        Size = AdaptiveImageSize.Large,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Stretch,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text   = localizer.GetString("WelcomeCardTitle"),
                                        Weight = AdaptiveTextWeight.Bolder,
                                        Size   = AdaptiveTextSize.Large,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Text    = localizer.GetString("WelcomeTeamCardContent"),
                                        Wrap    = true,
                                        Spacing = AdaptiveSpacing.None,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                        Text    = localizer.GetString("WelcomeSubHeaderText"),
                        Spacing = AdaptiveSpacing.Small,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("SetAdminBulletPoint"),
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("ManageAwardsBulletPoint"),
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("SetRewardCycleBulletPoint"),
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("NominateBulletPoint"),
                        Wrap    = true,
                        Spacing = AdaptiveSpacing.None,
                    },
                    new AdaptiveTextBlock
                    {
                        Text    = localizer.GetString("ContentText"),
                        Spacing = AdaptiveSpacing.Small,
                    },
                },

                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("SetAdminButtonText"),
                        Data  = new AdaptiveCardAction
                        {
                            MsteamsCardAction = new CardAction
                            {
                                Type = Constants.FetchActionType,
                            },
                            Command = Constants.ConfigureAdminAction,
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = card,
            });
        }
Exemplo n.º 23
0
        /// <summary>
        /// Get new response request card to create new response.
        /// </summary>
        /// <param name="userRequestDetails">User request details object.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="emptyApproveField">Show error message if SME has missed to fill any field while approving the response.</param>
        /// <returns>An new response request card attachment.</returns>
        public static Attachment GetNewResponseRequestCard(CompanyResponseEntity userRequestDetails, IStringLocalizer <Strings> localizer, bool emptyApproveField = false)
        {
            if (userRequestDetails == null)
            {
                throw new ArgumentNullException(nameof(userRequestDetails));
            }

            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveContainer
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveColumnSet
                            {
                                Columns = new List <AdaptiveColumn>
                                {
                                    new AdaptiveColumn
                                    {
                                        Items = new List <AdaptiveElement>
                                        {
                                            new AdaptiveTextBlock
                                            {
                                                Text = localizer.GetString("NotificationRequestCardContentText"),
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = string.Format(CultureInfo.InvariantCulture, localizer.GetString("NotificationCardRequestText"), userRequestDetails.CreatedBy),
                                                Wrap = true,
                                            },
                                        },
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveContainer
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveColumnSet
                            {
                                Columns = new List <AdaptiveColumn>
                                {
                                    new AdaptiveColumn
                                    {
                                        Items = new List <AdaptiveElement>
                                        {
                                            new AdaptiveTextBlock
                                            {
                                                Text = localizer.GetString("NotificationCardLabelText"),
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = userRequestDetails.QuestionLabel,
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = localizer.GetString("NotificationCardQuestion"),
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = userRequestDetails.QuestionText,
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = localizer.GetString("NotificationCardResponse"),
                                                Wrap = true,
                                            },
                                            new AdaptiveTextBlock
                                            {
                                                Text = userRequestDetails.ResponseText,
                                                Wrap = true,
                                            },
                                        },
                                        Style = AdaptiveContainerStyle.Emphasis,
                                    },
                                },
                            },
                        },
                    },
                    new AdaptiveContainer
                    {
                        Items = new List <AdaptiveElement>
                        {
                            new AdaptiveTextBlock
                            {
                                Text      = localizer.GetString("ErrorMessageOnApprove"),
                                Wrap      = true,
                                IsVisible = emptyApproveField,
                                Color     = AdaptiveTextColor.Attention,
                            },
                        },
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveShowCardAction
                    {
                        Title = localizer.GetString("ApproveButtonTitle"),
                        Card  = GetApproveCard(userRequestDetails, localizer: localizer),
                    },
                    new AdaptiveShowCardAction
                    {
                        Title = localizer.GetString("RejectButtonTitle"),
                        Card  = GetRejectCard(userRequestDetails, localizer: localizer),
                    },
                    new AdaptiveOpenUrlAction
                    {
                        Title     = string.Format(CultureInfo.InvariantCulture, localizer.GetString("ChatTextButton"), userRequestDetails.CreatedBy),
                        UrlString = $"https://teams.microsoft.com/l/chat/0/0?users={Uri.EscapeDataString(userRequestDetails.UserPrincipalName)}",
                    },
                },
            };
            var adaptiveCardAttachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card,
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Get user team goal status details card for viewing all user status details.
        /// </summary>
        /// <param name="teamGoalStatus">Team goal status for each team goal.</param>
        /// <param name="applicationBasePath">Application base URL.</param>
        /// <param name="id">Unique id for each row.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>Returns individual goal card as attachment.</returns>
        public static List <AdaptiveElement> GetIndividualTeamGoalStatus(TeamGoalStatus teamGoalStatus, string applicationBasePath, int id, IStringLocalizer <Strings> localizer)
        {
            teamGoalStatus = teamGoalStatus ?? throw new ArgumentNullException(nameof(teamGoalStatus));
            var    notStartedStatusCount = teamGoalStatus.NotStartedGoalCount == null ? 0 : teamGoalStatus.NotStartedGoalCount;
            var    inProgressStatusCount = teamGoalStatus.InProgressGoalCount == null ? 0 : teamGoalStatus.InProgressGoalCount;
            var    completedStatusCount  = teamGoalStatus.CompletedGoalCount == null ? 0 : teamGoalStatus.CompletedGoalCount;
            var    totalStatusCount      = notStartedStatusCount + inProgressStatusCount + completedStatusCount;
            string cardContent           = $"CardContent{id}";
            string chevronUp             = $"ChevronUp{id}";
            string chevronDown           = $"ChevronDown{id}";
            List <AdaptiveElement> individualTeamGoalStatus = new List <AdaptiveElement>
            {
                new AdaptiveColumnSet
                {
                    Spacing = AdaptiveSpacing.Medium,
                    Columns = new List <AdaptiveColumn>
                    {
                        new AdaptiveColumn
                        {
                            VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                            Width = AdaptiveColumnWidth.Stretch,
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                    Text = string.IsNullOrEmpty(teamGoalStatus.TeamGoalName) ? localizer.GetString("GoalStatusDeletedText") : teamGoalStatus.TeamGoalName,
                                    Wrap = true,
                                },
                            },
                        },
                        new AdaptiveColumn
                        {
                            VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                            Width = AdaptiveColumnWidth.Stretch,
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveTextBlock
                                {
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                    Spacing             = AdaptiveSpacing.None,
                                    Text = string.Format(CultureInfo.InvariantCulture, localizer.GetString("GoalStatusAlignedText"), totalStatusCount),
                                    Wrap = true,
                                },
                            },
                        },
                        new AdaptiveColumn
                        {
                            Id = chevronDown,
                            VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                            Width = AdaptiveColumnWidth.Auto,
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveImage
                                {
                                    AltText      = localizer.GetString("GoalStatusChevronDownImageAltText"),
                                    PixelWidth   = 16,
                                    PixelHeight  = 8,
                                    SelectAction = new AdaptiveToggleVisibilityAction
                                    {
                                        Title          = localizer.GetString("GoalStatusChevronDownImageAltText"),
                                        Type           = "Action.ToggleVisibility",
                                        TargetElements = new List <AdaptiveTargetElement>
                                        {
                                            cardContent,
                                            chevronUp,
                                            chevronDown,
                                        },
                                    },
                                    Style = AdaptiveImageStyle.Default,
                                    Url   = new Uri(applicationBasePath + "/Artifacts/chevronDown.png"),
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                },
                            },
                        },
                        new AdaptiveColumn
                        {
                            Id        = chevronUp,
                            IsVisible = false,
                            VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                            Width = AdaptiveColumnWidth.Auto,
                            Items = new List <AdaptiveElement>
                            {
                                new AdaptiveImage
                                {
                                    AltText      = localizer.GetString("GoalStatusChevronUpImageAltText"),
                                    PixelWidth   = 16,
                                    PixelHeight  = 8,
                                    SelectAction = new AdaptiveToggleVisibilityAction
                                    {
                                        Title          = localizer.GetString("GoalStatusChevronUpImageAltText"),
                                        Type           = "Action.ToggleVisibility",
                                        TargetElements = new List <AdaptiveTargetElement>
                                        {
                                            cardContent,
                                            chevronUp,
                                            chevronDown,
                                        },
                                    },
                                    Style = AdaptiveImageStyle.Default,
                                    Url   = new Uri(applicationBasePath + "/Artifacts/chevronUp.png"),
                                    HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                },
                            },
                        },
                    },
                },
                new AdaptiveContainer
                {
                    Id        = cardContent,
                    IsVisible = false,
                    Style     = AdaptiveContainerStyle.Emphasis,
                    Items     = new List <AdaptiveElement>
                    {
                        new AdaptiveColumnSet
                        {
                            Spacing = AdaptiveSpacing.None,
                            Columns = new List <AdaptiveColumn>
                            {
                                new AdaptiveColumn
                                {
                                    VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                    Width = AdaptiveColumnWidth.Stretch,
                                    Items = new List <AdaptiveElement>
                                    {
                                        new AdaptiveTextBlock
                                        {
                                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                            Spacing             = AdaptiveSpacing.None,
                                            Text = localizer.GetString("GoalStatusNotStartedHeader"),
                                            Wrap = true,
                                        },
                                    },
                                },
                                new AdaptiveColumn
                                {
                                    VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                    Width = AdaptiveColumnWidth.Stretch,
                                    Items = new List <AdaptiveElement>
                                    {
                                        new AdaptiveTextBlock
                                        {
                                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                            Spacing             = AdaptiveSpacing.None,
                                            Text = localizer.GetString("GoalStatusInProgressHeader"),
                                            Wrap = true,
                                        },
                                    },
                                },
                                new AdaptiveColumn
                                {
                                    VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                    Width = AdaptiveColumnWidth.Stretch,
                                    Items = new List <AdaptiveElement>
                                    {
                                        new AdaptiveTextBlock
                                        {
                                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                            Spacing             = AdaptiveSpacing.None,
                                            Text = localizer.GetString("GoalStatusCompletedHeader"),
                                            Wrap = true,
                                        },
                                    },
                                },
                                new AdaptiveColumn
                                {
                                    VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                    Width = AdaptiveColumnWidth.Stretch,
                                    Items = new List <AdaptiveElement>
                                    {
                                        new AdaptiveTextBlock
                                        {
                                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                            Spacing             = AdaptiveSpacing.None,
                                            Text = localizer.GetString("GoalStatusTotalHeader"),
                                            Wrap = true,
                                        },
                                    },
                                },
                            },
                        },
                        new AdaptiveColumnSet
                        {
                            Spacing = AdaptiveSpacing.None,
                            Columns = new List <AdaptiveColumn>
                            {
                                new AdaptiveColumn
                                {
                                    VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                    Width = AdaptiveColumnWidth.Stretch,
                                    Items = new List <AdaptiveElement>
                                    {
                                        new AdaptiveTextBlock
                                        {
                                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                            Spacing             = AdaptiveSpacing.None,
                                            Text = notStartedStatusCount.ToString(),
                                            Wrap = true,
                                        },
                                    },
                                },
                                new AdaptiveColumn
                                {
                                    VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                    Width = AdaptiveColumnWidth.Stretch,
                                    Items = new List <AdaptiveElement>
                                    {
                                        new AdaptiveTextBlock
                                        {
                                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                            Spacing             = AdaptiveSpacing.None,
                                            Text = inProgressStatusCount.ToString(),
                                            Wrap = true,
                                        },
                                    },
                                },
                                new AdaptiveColumn
                                {
                                    VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                    Width = AdaptiveColumnWidth.Stretch,
                                    Items = new List <AdaptiveElement>
                                    {
                                        new AdaptiveTextBlock
                                        {
                                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                            Spacing             = AdaptiveSpacing.None,
                                            Text = completedStatusCount.ToString(),
                                            Wrap = true,
                                        },
                                    },
                                },
                                new AdaptiveColumn
                                {
                                    VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                                    Width = AdaptiveColumnWidth.Stretch,
                                    Items = new List <AdaptiveElement>
                                    {
                                        new AdaptiveTextBlock
                                        {
                                            HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                                            Spacing             = AdaptiveSpacing.None,
                                            Text = totalStatusCount.ToString(),
                                            Wrap = true,
                                        },
                                    },
                                },
                            },
                        },
                    },
                },
            };

            return(individualTeamGoalStatus);
        }
        /// <summary>
        /// Get welcome card attachment to show on Microsoft Teams personal scope.
        /// </summary>
        /// <param name="applicationBasePath">Application base path to get the logo of the application.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="applicationManifestId">Application manifest id.</param>
        /// <returns>User welcome card attachment.</returns>
        public static Attachment GetWelcomeCardAttachmentForPersonal(
            string applicationBasePath,
            IStringLocalizer <Strings> localizer,
            string applicationManifestId)
        {
            var          textAlignment = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ? AdaptiveHorizontalAlignment.Right : AdaptiveHorizontalAlignment.Left;
            AdaptiveCard card          = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri($"{applicationBasePath}/images/logo.png"),
                                        Size = AdaptiveImageSize.Medium,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Weight              = AdaptiveTextWeight.Bolder,
                                        Spacing             = AdaptiveSpacing.None,
                                        Text                = localizer.GetString("WelcomeCardTitle"),
                                        Wrap                = true,
                                        HorizontalAlignment = textAlignment,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Spacing             = AdaptiveSpacing.None,
                                        Text                = localizer.GetString("WelcomeCardPersonalIntro"),
                                        Wrap                = true,
                                        IsSubtle            = true,
                                        HorizontalAlignment = textAlignment,
                                    },
                                },
                                Width = AdaptiveColumnWidth.Stretch,
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        Spacing             = AdaptiveSpacing.Medium,
                        Text                = localizer.GetString("WelcomeCardPersonalPoint1"),
                        Wrap                = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardPersonalPoint2"),
                        Wrap = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardPersonalPoint3"),
                        Wrap = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardPersonalPoint4"),
                        Wrap = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Spacing             = AdaptiveSpacing.Medium,
                        Text                = string.Format(CultureInfo.CurrentCulture, localizer.GetString("WelcomeCardPersonalContentFooter"), localizer.GetString("WelcomeCardPersonalDiscoverButtonText")),
                        Wrap                = true,
                        HorizontalAlignment = textAlignment,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveOpenUrlAction
                    {
                        Url   = new Uri($"https://teams.microsoft.com/l/entity/{applicationManifestId}/discover-events"),
                        Title = $"{localizer.GetString("WelcomeCardPersonalDiscoverButtonText")}",
                    },
                },
            };
            var adaptiveCardAttachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card,
            };

            return(adaptiveCardAttachment);
        }
Exemplo n.º 26
0
        private void RunTest(IStringLocalizer <DataStatusResource> localizer, string cultureName)
        {
            CultureInfoUtility.Register(new CultureInfo(cultureName));

            // Groups
            var localized = localizer.GetString(r => r.GlobalGroup);

            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.ScopeGroup);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.StateGroup);
            Assert.False(localized.ResourceNotFound);

            // Global Group
            localized = localizer.GetString(r => r.Default);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.Delete);
            Assert.False(localized.ResourceNotFound);

            // Scope Group
            localized = localizer.GetString(r => r.Public);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.Protect);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.Internal);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.Private);
            Assert.False(localized.ResourceNotFound);

            // State Group
            localized = localizer.GetString(r => r.Active);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.Pending);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.Inactive);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.Locking);
            Assert.False(localized.ResourceNotFound);

            localized = localizer.GetString(r => r.Ban);
            Assert.False(localized.ResourceNotFound);
        }
        /// <summary>
        /// Get welcome card attachment to show on Microsoft Teams channel scope.
        /// </summary>
        /// <param name="applicationBasePath">Application base path to get the logo of the application.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>Team's welcome card as attachment.</returns>
        public static Attachment GetWelcomeCardAttachmentForTeam(string applicationBasePath, IStringLocalizer <Strings> localizer)
        {
            var          textAlignment = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ? AdaptiveHorizontalAlignment.Right : AdaptiveHorizontalAlignment.Left;
            AdaptiveCard card          = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri($"{applicationBasePath}/images/logo.png"),
                                        Size = AdaptiveImageSize.Medium,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Weight              = AdaptiveTextWeight.Bolder,
                                        Spacing             = AdaptiveSpacing.None,
                                        Text                = localizer.GetString("WelcomeCardTitle"),
                                        Wrap                = true,
                                        HorizontalAlignment = textAlignment,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Spacing             = AdaptiveSpacing.None,
                                        Text                = localizer.GetString("WelcomeCardTeamIntro"),
                                        Wrap                = true,
                                        IsSubtle            = true,
                                        HorizontalAlignment = textAlignment,
                                    },
                                },
                                Width = AdaptiveColumnWidth.Stretch,
                            },
                        },
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardTeamHeading"),
                        Wrap = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Spacing             = AdaptiveSpacing.Medium,
                        Text                = localizer.GetString("WelcomeCardTeamPoint1"),
                        Wrap                = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardTeamPoint2"),
                        Wrap = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardTeamPoint3"),
                        Wrap = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Text = localizer.GetString("WelcomeCardTeamPoint4"),
                        Wrap = true,
                        HorizontalAlignment = textAlignment,
                    },
                    new AdaptiveTextBlock
                    {
                        Spacing             = AdaptiveSpacing.Medium,
                        Text                = string.Format(CultureInfo.CurrentCulture, localizer.GetString("WelcomeCardTeamContentFooter"), localizer.GetString("CreateEventButtonWelcomeCard")),
                        Wrap                = true,
                        HorizontalAlignment = textAlignment,
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("CreateEventButtonWelcomeCard"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            MsTeams = new CardAction
                            {
                                Type = "task/fetch",
                                Text = localizer.GetString("CreateEventButtonWelcomeCard"),
                            },
                            Command = BotCommands.CreateEvent,
                        },
                    },
                },
            };

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

            return(adaptiveCardAttachment);
        }
        /// <summary>
        /// This method will construct the edit introduction card for new hire employee.
        /// </summary>
        /// <param name="applicationBasePath">Application base path to get the logo of the application.</param>
        /// <param name="localizer">The current culture's string localizer.</param>
        /// <param name="introductionEntity">New hire introduction details.</param>
        /// <returns>Tell me more card attachment.</returns>
        public static Attachment GetCard(
            string applicationBasePath,
            IStringLocalizer <Strings> localizer,
            IntroductionEntity introductionEntity)
        {
            introductionEntity = introductionEntity ?? throw new ArgumentNullException(nameof(introductionEntity));

            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(CardConstants.AdaptiveCardVersion))
            {
                Body = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Size    = AdaptiveTextSize.Large,
                                        Text    = localizer.GetString("EditIntroCardHeaderText"),
                                        Spacing = AdaptiveSpacing.Small,
                                        Wrap    = true,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Spacing = AdaptiveSpacing.Small,
                                        Text    = localizer.GetString("EditIntroCardSubHeaderText"),
                                        Wrap    = true,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Weight  = AdaptiveTextWeight.Bolder,
                                        Size    = AdaptiveTextSize.Medium,
                                        Spacing = AdaptiveSpacing.Small,
                                        Text    = localizer.GetString("ManagerCommentsTitleText"),
                                        Wrap    = true,
                                    },
                                    new AdaptiveTextBlock
                                    {
                                        Spacing = AdaptiveSpacing.Small,
                                        Text    = introductionEntity.Comments,
                                        Wrap    = true,
                                    },
                                },
                            },
                            new AdaptiveColumn
                            {
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveImage
                                    {
                                        Url  = new Uri($"{applicationBasePath}/Artifacts/moreInformationImage.png"),
                                        Size = AdaptiveImageSize.Large,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Right,
                                        AltText             = localizer.GetString("AlternativeText"),
                                    },
                                },
                            },
                        },
                    },
                },
                Actions = new List <AdaptiveAction>
                {
                    new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("EditIntroButtonText"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            Msteams = new CardAction
                            {
                                Type = CardConstants.FetchActionType,
                                Text = BotCommandConstants.IntroductionAction,
                            },
                            Command = BotCommandConstants.IntroductionAction,
                        },
                    },
                },
            };

            return(new Attachment
            {
                ContentType = AdaptiveCard.ContentType,
                Content = card,
            });
        }
Exemplo n.º 29
0
        /// <summary>
        /// Get list card for complete learning plan.
        /// </summary>
        /// <param name="learningPlans">Learning plans list object.</param>
        /// <param name="localizer">The current culture's string localizer.</param>
        /// <param name="cardTitle">Learning plan list card title.</param>
        /// <param name="applicationManifestId">Application manifest id.</param>
        /// <param name="applicationBasePath">Application base path.</param>
        /// <returns>An attachment card for learning plan.</returns>
        public static Attachment GetLearningPlanListCard(
            IEnumerable <LearningPlanListItemField> learningPlans,
            IStringLocalizer <Strings> localizer,
            string cardTitle,
            string applicationManifestId,
            string applicationBasePath)
        {
            learningPlans = learningPlans ?? throw new ArgumentNullException(nameof(learningPlans));

            ListCard card = new ListCard
            {
                Title   = cardTitle,
                Items   = new List <ListCardItem>(),
                Buttons = new List <ListCardButton>(),
            };

            if (!learningPlans.Any())
            {
                card.Items.Add(new ListCardItem
                {
                    Type  = "resultItem",
                    Id    = Guid.NewGuid().ToString(),
                    Title = localizer.GetString("CurrentWeekLearningPlanNotExistText"),
                });
            }

            foreach (var learningPlan in learningPlans)
            {
                card.Items.Add(new ListCardItem
                {
                    Type     = "resultItem",
                    Id       = Guid.NewGuid().ToString(),
                    Title    = learningPlan.Topic,
                    Subtitle = learningPlan.TaskName,
                    Icon     = !string.IsNullOrEmpty(learningPlan?.TaskImage?.Url) ? learningPlan.TaskImage.Url : $"{applicationBasePath}/Artifacts/listCardDefaultImage.png",
                    Tap      = new ListCardItemEvent
                    {
                        Type  = CardConstants.MessageBack,
                        Value = $"{learningPlan.CompleteBy} => {learningPlan.Topic} => {learningPlan.TaskName}",
                    },
                });
            }

            var viewCompletePlanActionButton = new ListCardButton()
            {
                Title = localizer.GetString("ViewCompleteLearningPlanButtonText"),
                Type  = CardConstants.OpenUrlType,
                Value = $"{DeepLinkConstants.TabBaseRedirectURL}/{applicationManifestId}/{CardConstants.OnboardingJourneyTabEntityId}",
            };

            card.Buttons.Add(viewCompletePlanActionButton);

            var shareFeedbackActionButton = new ListCardButton()
            {
                Title = localizer.GetString("ShareFeedbackButtonText"),
                Type  = CardConstants.MessageBack,
                Value = BotCommandConstants.ShareFeedback,
            };

            card.Buttons.Add(shareFeedbackActionButton);

            return(new Attachment
            {
                ContentType = CardConstants.ListCardContentType,
                Content = card,
            });
        }
Exemplo n.º 30
0
 public UnauthorizedException(IStringLocalizer <object> localizer) : base()
 {
     CustomCode    = 401001;
     CustomMessage = localizer.GetString(CustomCode.ToString());
 }
Exemplo n.º 31
0
 protected string GetLocalizedResource(string name)
 {
     return(_localizer.GetString(name));
 }