コード例 #1
0
        /// <summary>
        /// Save user profile activity information to Azure Table Storage, which is use to uniquely identify activity based on card id.
        /// </summary>
        /// <param name="myProfileCardActivityId">User profile card activity id.</param>
        /// <param name="myProfileCardId">Custom unique user profile card id.</param>
        /// <param name="turnContext">Provides context for a turn of a bot.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        private async Task StoreUserProfileCardActivityInfoAsync(string myProfileCardActivityId, string myProfileCardId, ITurnContext turnContext)
        {
            string conversationId = turnContext.Activity.Conversation.Id;

            try
            {
                UserProfileActivityInfo userProfileActivityEntity = new UserProfileActivityInfo
                {
                    MyProfileCardActivityId = myProfileCardActivityId,
                    MyProfileCardId         = myProfileCardId,
                };

                var isUserActivityInfoSaved = await this.storageHelper.UpsertConverationStateAsync(userProfileActivityEntity).ConfigureAwait(false);

                if (!isUserActivityInfoSaved)
                {
                    await turnContext.SendActivityAsync($"{Strings.ErrorMessage}").ConfigureAwait(false);

                    this.logger.LogInformation($"Saving data to table storage failed for: {conversationId}.");
                }
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, $"Saving data to table storage failed for: {conversationId}.");
            }
        }
        /// <summary>
        /// Store or update user profile activity information entity which holds user profile card activity id and user profile card id in table storage.
        /// </summary>
        /// <param name="entity">Object that contains user profile card activity id and user profile card unique id.</param>
        /// <returns>A task that represents configuration entity is saved or updated.</returns>
        private async Task <TableResult> StoreOrUpdateEntityAsync(UserProfileActivityInfo entity)
        {
            await this.EnsureInitializedAsync().ConfigureAwait(false);

            TableOperation addOrUpdateOperation = TableOperation.InsertOrReplace(entity);

            return(await this.profileCloudTable.ExecuteAsync(addOrUpdateOperation).ConfigureAwait(false));
        }
        /// <summary>
        /// Stores or update user profile card activity id and user profile card id in table storage.
        /// </summary>
        /// <param name="userProfileConversationEntity">Holds user profile activity id and card id to uniquely identify user activity that is being edited.</param>
        /// <returns>A task that represents user profile conversation data is saved or updated.</returns>
        public async Task <bool> UpsertConverationStateAsync(UserProfileActivityInfo userProfileConversationEntity)
        {
            var result = await this.StoreOrUpdateEntityAsync(userProfileConversationEntity).ConfigureAwait(false);

            return(result.HttpStatusCode == (int)HttpStatusCode.NoContent);
        }