Ejemplo n.º 1
0
        public async Task <DailyChallengeTeam> getDailyChallengeTeamInfo()
        {
            string rowKey       = "DailyChallengeTeam";
            string partitionKey = typeof(DailyChallengeTeam).ToString();

            try
            {
                TableOperation retrieveOperation = TableOperation.Retrieve <DailyChallengeTeam>(partitionKey, rowKey);
                TableResult    result            = await cloudTable.ExecuteAsync(retrieveOperation);

                DailyChallengeTeam team = result.Result as DailyChallengeTeam;
                if (team == null)
                {
                    team = new DailyChallengeTeam()
                    {
                        PartitionKey = partitionKey,
                        RowKey       = rowKey
                    };
                }

                if (!string.IsNullOrEmpty(team.ChannelDataSerialized))
                {
                    team.ChannelData = JsonConvert.DeserializeObject <TeamsChannelData>(team.ChannelDataSerialized);
                }
                return(team);
            }
            catch (Exception exp)
            {
                // TODO: add logging
                throw exp;
            }
        }
Ejemplo n.º 2
0
        public async Task SaveDailyChallengeTeamInfo(DailyChallengeTeam team)
        {
            team.PartitionKey          = typeof(DailyChallengeTeam).ToString();
            team.RowKey                = "DailyChallengeTeam";
            team.ChannelDataSerialized = JsonConvert.SerializeObject(team.ChannelData);
            TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(team);

            // Execute the operation.
            TableResult result = await cloudTable.ExecuteAsync(insertOrMergeOperation);
        }
Ejemplo n.º 3
0
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            TelemetryClient.TrackTrace("Main dialog started", Severity.Information, null);
            if (string.IsNullOrEmpty(Configuration["DailyChallengeTableConnectionString"]))
            {
                TelemetryClient.TrackTrace("Connection String not defined", Severity.Error, null);
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: Storage Connection String is not configured. To continue, add 'DailyChallengeTableConnectionString' to the appsettings.json file."), cancellationToken);

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
            else
            {
                IMessageActivity reply = null;

                TelemetryClient.TrackTrace("Get Daily Challenge and Team Info", Severity.Information, null);
                DailyChallenge dailyChallenge = await tableService.GetDailyChallenge();

                DailyChallengeTeam team = await tableService.getDailyChallengeTeamInfo();

                TelemetryClient.TrackTrace("Check whether today's challenge exists", Severity.Information, null);
                if (dailyChallenge.photoUrl == null)
                {
                    TelemetryClient.TrackTrace("No Daily Challenge so check details", Severity.Information, null);
                    var activity = stepContext.Context.Activity;
                    if (team.ChannelData == null)
                    {
                        team.ChannelData = activity.GetChannelData <TeamsChannelData>();
                    }
                    var teamsChannelData = team.ChannelData;

                    var    channelId = teamsChannelData.Channel.Id;
                    var    tenantId  = teamsChannelData.Tenant.Id;
                    string myBotId   = activity.Recipient.Id;
                    string teamId    = teamsChannelData.Team.Id;
                    string teamName  = teamsChannelData.Team.Name;

                    await this.tableService.SaveDailyChallengeTeamInfo(new DailyChallengeTeam()
                    {
                        ServiceUrl    = activity.ServiceUrl,
                        TeamId        = teamId,
                        TeamName      = teamName,
                        TenantId      = tenantId,
                        InstallerName = "Automatic",
                        BotId         = myBotId,
                        ChannelId     = channelId,
                        ChannelData   = teamsChannelData
                    });

                    reply = MessageFactory.Attachment(new List <Attachment>());
                    Attachment attachment = null;

                    DailyChallengeInfo info = await GetInfo(stepContext);

                    if (info.currentSource == ImageSource.Google)
                    {
                        TelemetryClient.TrackTrace("Current source is Google so get an image", Severity.Information, null);
                        attachment = await GetGoogleImageChoiceAttachment();

                        TelemetryClient.TrackTrace("Loaded Google image", Severity.Information, null);
                    }
                    else
                    {
                        TelemetryClient.TrackTrace("Current source is Bing so get the latest image", Severity.Information, null);
                        int imageIndex = info.currentImageIndex;
                        attachment = await GetBingImageChoiceAttachment(imageIndex);

                        TelemetryClient.TrackTrace("Loaded Bing image", Severity.Information, null);
                    }

                    reply.Attachments.Add(attachment);
                    TelemetryClient.TrackTrace("Sending image reply", Severity.Information, null);
                    return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = (Activity)reply }, cancellationToken));
                }
                else
                {
                    if (!dailyChallenge.resultSet)
                    {
                        // Pass on the check results message from the proactive controller if set
                        PromptOptions options = null;
                        if (stepContext != null && stepContext.Options != null)
                        {
                            options = (PromptOptions)stepContext.Options;
                        }
                        return(await stepContext.ReplaceDialogAsync(nameof(ChallengeGuesserDialog), options, cancellationToken));
                    }
                    else
                    {
                        IMessageActivity winningReply = MessageFactory.Attachment(new List <Attachment>());

                        winningReply.Attachments.Add(AttachmentHelper.ResultCardAttachment(dailyChallenge.winnerName, dailyChallenge.photoUrl, dailyChallenge.winnerGuess, dailyChallenge.distanceToEntry.ToString("#.##"), dailyChallenge.extractedLocation, dailyChallenge.text));
                        await stepContext.Context.SendActivityAsync(winningReply);

                        return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken));
                    }
                }
            }
        }