コード例 #1
0
        private async Task RefreshKnowledgeBaseAsync(KBInfo kb, Guid correlationId, System.Threading.CancellationToken cancelToken)
        {
            Exception refreshError = null;

            try
            {
                await this.refreshHelper.RefreshKnowledgeBaseAsync(kb, correlationId);
            }
            catch (Exception ex)
            {
                refreshError = ex;
                this.logProvider.LogWarning($"Failed to refresh KB {kb.KBId}: {ex.Message}", exception: ex, correlationId: correlationId);
            }

            // Log success/failure of the knowledge base refresh
            var properties = new Dictionary <string, string>
            {
                { "KnowledgeBaseId", kb.KBId },
                { "KnowledgeBaseName", kb.KBName },
                { "Success", (refreshError != null).ToString() },
            };

            if (refreshError != null)
            {
                properties["LastRefreshDateTime"] = kb.LastRefreshDateTime.ToString("u");
                properties["ErrorMessage"]        = refreshError.Message;
            }

            this.logProvider.LogEvent("KnowledgeBaseRefresh", properties, correlationId: correlationId);
        }
コード例 #2
0
        public async Task <ActionResult> SaveKB(KBInfo kbInfo)
        {
            if (string.IsNullOrWhiteSpace(kbInfo.KBId))
            {
                string kbId = await this.CreateEmptyKB(kbInfo.KBName, this.qnaMakerService);

                if (!string.IsNullOrEmpty(kbId))
                {
                    kbInfo.RowKey                     = kbId;
                    kbInfo.PartitionKey               = StorageInfo.KBInfoTablePartitionKey;
                    kbInfo.RankerType                 = RankerTypes.AutoSuggestQuestion;
                    kbInfo.LastRefreshDateTime        = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    kbInfo.LastRefreshAttemptDateTime = new DateTime(1601, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                    await this.kbInfoHelper.InsertOrMergeKBInfo(kbInfo);
                }
                else
                {
                    return(this.Redirect("/Home"));
                }
            }

            if (!string.IsNullOrEmpty(kbInfo.KBId))
            {
                await this.knowledgeBaseRefreshHelper.RefreshKnowledgeBaseAsync(kbInfo);
            }

            return(this.Redirect("/Home"));
        }
コード例 #3
0
        /// <summary>
        /// Insert or merge KBInfo entity.
        /// </summary>
        /// <param name="kBInfo">Kb Info entity.</param>
        /// <returns><see cref="Task"/> that represents Insert or Merge function.</returns>
        public async Task InsertOrMergeKBInfo(KBInfo kBInfo)
        {
            await this.initializeTask.Value;

            TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(kBInfo);
            TableResult    insertOrMergeResult    = await this.cloudTable.ExecuteAsync(insertOrMergeOperation);

            if (insertOrMergeResult.HttpStatusCode != InsertSuccessResponseCode)
            {
                throw new Exception($"HTTP Error code - {insertOrMergeResult.HttpStatusCode}");
            }
        }
コード例 #4
0
        /// <summary>
        /// Refresh the data in the given knowledge base.
        /// </summary>
        /// <param name="kb">Knowledge base info</param>
        /// <param name="correlationId">Correlation id to use for logging</param>
        /// <returns>Tracking task</returns>
        public async Task RefreshKnowledgeBaseAsync(KBInfo kb, Guid?correlationId = null)
        {
            correlationId = correlationId ?? Guid.NewGuid();

            this.logProvider.LogInfo($"Starting refresh of knowledge base {kb.KBId}", correlationId: correlationId);
            this.logProvider.LogDebug($"Last successful refresh was on {kb.LastRefreshDateTime}", correlationId: correlationId);
            this.logProvider.LogDebug($"Last refresh attempt was on {kb.LastRefreshAttemptDateTime}, with status {kb.LastRefreshAttemptError ?? "success"}", correlationId: correlationId);

            Dictionary <string, Uri> blobInfoTemp = new Dictionary <string, Uri>();

            kb.LastRefreshAttemptDateTime = DateTime.UtcNow;

            try
            {
                // Update the KB with the current list contents
                ColumnInfo questionColumn = JsonConvert.DeserializeObject <ColumnInfo>(kb.QuestionField);
                await this.PopulateTemporaryBlobsWithListContentsAsync(kb, questionColumn, blobInfoTemp, correlationId.Value);

                await this.UpdateKnowledgeBaseAsync(kb.KBId, blobInfoTemp, JsonConvert.DeserializeObject <ColumnInfo>(kb.QuestionField).Name, correlationId.Value);

                this.logProvider.LogDebug($"Refresh of KB succeeded", correlationId: correlationId);

                // Record the successful update
                kb.LastRefreshDateTime     = DateTime.UtcNow;
                kb.LastRefreshAttemptError = string.Empty;
                await this.kbInfoHelper.InsertOrMergeKBInfo(kb);
            }
            catch (Exception ex)
            {
                this.logProvider.LogError($"Refresh of KB failed: {ex.Message}", ex, correlationId: correlationId);

                // Log refresh attempt
                kb.LastRefreshAttemptError = ex.ToString();
                await this.kbInfoHelper.InsertOrMergeKBInfo(kb);
            }
            finally
            {
                try
                {
                    // Delete the temporary blobs that were created
                    await this.DeleteTemporaryBlobsAsync(blobInfoTemp, correlationId.Value);
                }
                catch (Exception ex)
                {
                    this.logProvider.LogError($"Failed to delete temporary blobs: {ex.Message}", ex, correlationId: correlationId);
                }
            }

            this.logProvider.LogInfo($"Finished refreshing KB {kb.KBId}, with status {kb.LastRefreshAttemptError ?? "success"}", correlationId: correlationId);
        }
コード例 #5
0
        public async Task <ActionResult> ConfigureList(string id)
        {
            KBInfo kbInfo;

            if (string.IsNullOrEmpty(id))
            {
                kbInfo = new KBInfo();
            }
            else
            {
                kbInfo = await this.kbInfoHelper.GetKBInfo(id);
            }

            return(this.View(kbInfo));
        }
コード例 #6
0
        // Populate temporary blob files with the SharePoint list contents
        private async Task PopulateTemporaryBlobsWithListContentsAsync(KBInfo kb, ColumnInfo questionColumn, Dictionary <string, Uri> blobInfoTemp, Guid correlationId)
        {
            GetListContentsResponse listContents = null;

            do
            {
                listContents = await this.GetListContentsPageAsync(kb.SharePointListId, kb.AnswerFields, questionColumn.Name, kb.SharePointSiteId, listContents?.ODataNextLink ?? null);

                string blobName = $"{Guid.NewGuid()}.json";
                string blobUrl  = await this.blobHelper.UploadBlobAsync(JsonConvert.SerializeObject(listContents), blobName);

                blobInfoTemp.Add(blobName, new Uri(blobUrl));

                this.logProvider.LogDebug($"Fetched page of list contents, stored as {blobName}", correlationId: correlationId);
            }while (!string.IsNullOrEmpty(listContents.ODataNextLink));
        }