Ejemplo n.º 1
0
        private async Task <IEnumerable <FAQEntry> > GetKnowledgeBaseContents(bool forceDownload)
        {
            IEnumerable <FAQEntry> faqs = _memoryCache.Get <IEnumerable <FAQEntry> >(Constants.KNOWLEDGE_BASE_CONTENTS_CACHE_KEY);

            // Not in cache or force to renew
            if (faqs == null || forceDownload)
            {
                // Retrieve knoledge base contents from reomte server
                var contentsModel = await _knowledgeBaseService.DownloadKnowledgeBaseContents(_settings.QnAMaker.SubscriptionKey, _settings.QnAMaker.KnowledgeBaseId, KnowledgeBaseEnum.Environment.Test.GetStringValue());

                if (contentsModel == null)
                {
                    return(null);
                }

                faqs = contentsModel.QnaDocuments.SelectMany(c => c.Questions, (c, ques) => new FAQEntry {
                    Id = c.Id, Answer = c.Answer, Question = ques, Source = c.Source
                });
                MemoryCacheEntryOptions options = new MemoryCacheEntryOptions
                {
                    Priority = CacheItemPriority.NeverRemove
                };
                _memoryCache.Set(Constants.KNOWLEDGE_BASE_CONTENTS_CACHE_KEY, faqs, options);
            }

            return(faqs);
        }
Ejemplo n.º 2
0
        private async Task PreGetknowledgeBaseContetns()
        {
            IEnumerable <FAQEntry> faqs = _memoryCache.Get <IEnumerable <FAQEntry> >(Constants.KNOWLEDGE_BASE_CONTENTS_CACHE_KEY);

            if (faqs == null)
            {
                // Retrieve knoledge base contents
                var contentsModel = await _knowledgeBaseService.DownloadKnowledgeBaseContents(_settings.QnAMaker.SubscriptionKey, _settings.QnAMaker.KnowledgeBaseId, KnowledgeBaseEnum.Environment.Test.GetStringValue());

                faqs = contentsModel.QnaDocuments.SelectMany(c => c.Questions, (c, ques) => new FAQEntry {
                    Id = c.Id, Answer = c.Answer, Question = ques, Source = c.Source
                });
                MemoryCacheEntryOptions options = new MemoryCacheEntryOptions
                {
                    Priority = CacheItemPriority.NeverRemove
                };
                _memoryCache.Set(Constants.KNOWLEDGE_BASE_CONTENTS_CACHE_KEY, faqs, options);
                Debug.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}->%PreGetknowledgeBaseContetns completed%");
            }
        }