Пример #1
0
        public Activity CreateMainActivity(Competition competition)
        {
            var isInitial = competition.Competitors.Count <= 0;

            var activity = Activity.CreateMessageActivity() as Activity;

            if (isInitial)
            {
                activity.From         = new ChannelAccount(_botSettings.Id, "bot name");
                activity.Conversation = new ConversationAccount(id: competition.ChannelId);
            }

            var localization          = _localizationFactory.Create(competition.Locale);
            var plannedDrawTimeString = competition.PlannedDrawTime.ToOffset(TimeSpan.FromHours(competition.OffsetHours))
                                        .ToString("f", CultureInfo.GetCultureInfo(competition.Locale));
            var viewDetailAction = new CardAction
            {
                Title = localization["MainActivity.ViewDetailButton"],
                Type  = "invoke",
                Value = new InvokeActionData {
                    Type = InvokeActionData.TypeTaskFetch, UserAction = InvokeActionType.ViewDetail, CompetitionId = competition.Id
                }
            };
            var joinAction = new CardAction
            {
                Title = localization["MainActivity.JoinButton"],
                Type  = "invoke",
                Value = new InvokeActionData {
                    UserAction = InvokeActionType.Join, CompetitionId = competition.Id
                }
            };

            activity.Attachments = new List <Attachment>
            {
                new Attachment
                {
                    ContentType = HeroCard.ContentType,
                    Content     = new HeroCard()
                    {
                        Title    = competition.Gift,
                        Subtitle = localization["MainActivity.Description", competition.WinnerCount, plannedDrawTimeString],
                        Text     = GenerateCompetitorsText(competition),
                        Images   = string.IsNullOrEmpty(competition.GiftImageUrl) ? null : new List <CardImage>()
                        {
                            new CardImage()
                            {
                                Url = competition.GiftImageUrl
                            }
                        },
                        Buttons = competition.IsCompleted ? new List <CardAction> {
                            viewDetailAction
                        } : new List <CardAction> {
                            joinAction, viewDetailAction
                        }
                    }
                }
            };
            return(activity);
        }
Пример #2
0
        private async Task HandleDisplayHelp(Activity activity)
        {
            var localization = _localizationFactory.Create(activity.Locale);
            var help         = activity.CreateReply(localization["Help.Message"]);

            using (var botClient = _botClientFactory.CreateBotClient(activity.ServiceUrl))
            {
                await botClient.SendToConversationAsync(help);
            }
        }
Пример #3
0
        public void Create()
        {
            var content      = new Content();
            var localization = factory.Create(content);

            //content.AddLocalization(localization);
        }
        private string CanActivateCompetition(Competition competition)
        {
            var localization = _localizationFactory.Create(competition.Locale);
            var errors       = new List <string>();

            if (string.IsNullOrEmpty(competition.Gift))
            {
                errors.Add(localization["EditCompetition.Form.Gift.Invalid"]);
            }
            if (competition.WinnerCount <= 0)
            {
                errors.Add(localization["EditCompetition.Form.WinnerCount.Invalid"]);
            }
            if (competition.PlannedDrawTime < _dateTimeService.UtcNow)
            {
                errors.Add(localization["EditCompetition.Form.PlannedDrawTime.Invalid"]);
            }
            var giftImageUrl = competition.GiftImageUrl;

            if (!string.IsNullOrEmpty(giftImageUrl) &&
                !giftImageUrl.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) &&
                !giftImageUrl.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
            {
                errors.Add(localization["EditCompetition.Form.GiftImageUrl.Invalid"]);
            }
            return(string.Join(' ', errors));
        }
Пример #5
0
        private string CanPreviewCompetition(string gift, int winnerCount, DateTimeOffset plannedDrawTime, string giftImageUrl, string locale)
        {
            var localization = _localizationFactory.Create(locale);
            var errors       = new List <string>();

            if (string.IsNullOrEmpty(gift))
            {
                errors.Add(localization["EditCompetition.Form.Gift.Invalid"]);
            }
            if (winnerCount <= 0)
            {
                errors.Add(localization["EditCompetition.Form.WinnerCount.Invalid"]);
            }
            if (plannedDrawTime < _dateTimeService.UtcNow)
            {
                errors.Add(localization["EditCompetition.Form.PlannedDrawTime.Invalid"]);
            }
            if (!string.IsNullOrEmpty(giftImageUrl) &&
                !giftImageUrl.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase) &&
                !giftImageUrl.StartsWith("https://", StringComparison.InvariantCultureIgnoreCase))
            {
                errors.Add(localization["EditCompetition.Form.GiftImageUrl.Invalid"]);
            }
            return(string.Join(' ', errors));
        }
        public async Task Handle(Activity activity)
        {
            var localization        = _localizationFactory.Create(activity.Locale);
            var unknownCommandReply = activity.CreateReply(localization["UnknownCommand.Message"]);

            using (var botClient = _botClientFactory.CreateBotClient(activity.ServiceUrl))
            {
                await botClient.SendToConversationAsync(unknownCommandReply);
            }
        }
 /// <summary>
 /// The create local resources.
 /// </summary>
 /// <returns>
 /// The <see cref="ILocalization"/>.
 /// </returns>
 public static ILocalization CreateLocalResources()
 {
     return(currentLocalResourcesFactory?.Create());
 }
Пример #8
0
 /// <summary>
 /// Como forzamos a que el parámetro sea una factory, nos aseguramos
 /// que solo se puede crear a través de la clase con la lógica correcta para crear
 /// </summary>
 /// <param name="factory"></param>
 public void CreateLocalization(ILocalizationFactory factory)
 {
     Localizations.Add(factory.Create(this));
 }
Пример #9
0
 public static ILocalization CreateLocalResources()
 {
     return((_currentLocalResourcesFactory != null) ? _currentLocalResourcesFactory.Create() : null);
 }