Exemple #1
0
        public void ExportAndImport()
        {
            QuestionAnsweringProjectsClient client = Client;
            string exportedProjectName             = CreateTestProjectName();

            CreateProject(exportedProjectName);

            #region Snippet:QuestionAnsweringProjectsClient_ExportProject
            Operation <BinaryData> exportOperation = client.Export(waitForCompletion: true, exportedProjectName, format: "json");

            // retrieve export operation response, and extract url of exported file
            JsonDocument operationValueJson = JsonDocument.Parse(exportOperation.Value);
            string       exportedFileUrl    = operationValueJson.RootElement.GetProperty("resultUrl").ToString();
            #endregion

            Assert.True(exportOperation.HasCompleted);
            Assert.True(!String.IsNullOrEmpty(exportedFileUrl));

            #region Snippet:QuestionAnsweringProjectsClient_ImportProject
            // Set import project name and request content
            string importedProjectName = "{ProjectNameToBeImported}";
#if !SNIPPET
            importedProjectName = "importedProject";
#endif
            RequestContent importRequestContent = RequestContent.Create(new
            {
                Metadata = new
                {
                    ProjectName          = "NewProjectForExport",
                    Description          = "This is the description for a test project",
                    Language             = "en",
                    DefaultAnswer        = "No answer found for your question.",
                    MultilingualResource = false,
                    CreatedDateTime      = "2021-11-25T09=35=33Z",
                    LastModifiedDateTime = "2021-11-25T09=35=33Z",
                    Settings             = new
                    {
                        DefaultAnswer = "No answer found for your question."
                    }
                }
            });

            Operation <BinaryData> importOperation = client.Import(waitForCompletion: true, importedProjectName, importRequestContent, format: "json");

            Console.WriteLine($"Operation status: {importOperation.GetRawResponse().Status}");
            #endregion

            Assert.True(importOperation.HasCompleted);
            Assert.AreEqual(200, importOperation.GetRawResponse().Status);

            #region Snippet:QuestionAnsweringProjectsClient_GetProjectDetails
            Response projectDetails = client.GetProjectDetails(importedProjectName);

            Console.WriteLine(projectDetails.Content);
            #endregion

            Assert.AreEqual(200, projectDetails.Status);

            DeleteProject(importedProjectName);
        }
        private async Task Language_QnA_MigrationGuide_Authoring()
        {
            #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateClient
            Uri endpoint = new Uri("{LanguageQnaEndpoint}");
            AzureKeyCredential credential = new AzureKeyCredential("{ApiKey}");

            QuestionAnsweringProjectsClient client = new QuestionAnsweringProjectsClient(endpoint, credential);
            #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateClient

            #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateProject
            string         newProjectName         = "{ProjectName}";
            RequestContent creationRequestContent = RequestContent.Create(
                new {
                description          = "This is the description for a test project",
                language             = "en",
                multilingualResource = false,
                settings             = new
                {
                    defaultAnswer = "No answer found for your question."
                }
            }
                );

            Response creationResponse = await client.CreateProjectAsync(newProjectName, creationRequestContent);

            #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_CreateProject

            #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_UpdateKnowledgeSource
            string         sourceUri = "{SourceURI}";
            RequestContent updateSourcesRequestContent = RequestContent.Create(
                new[] {
                new {
                    op    = "add",
                    value = new
                    {
                        displayName          = "MicrosoftFAQ",
                        source               = sourceUri,
                        sourceUri            = sourceUri,
                        sourceKind           = "url",
                        contentStructureKind = "unstructured",
                        refresh              = false
                    }
                }
            });

            Operation <BinaryData> updateSourcesOperation = await client.UpdateSourcesAsync(WaitUntil.Completed, "{ProjectName}", updateSourcesRequestContent);

            #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_UpdateKnowledgeSource

            #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_UpdateQnas
            RequestContent updateQnasRequestContent = RequestContent.Create(
                new[] {
                new {
                    op    = "add",
                    value = new
                    {
                        questions = new[]
                        {
                            "What is the easiest way to use Azure services in my .NET project?"
                        },
                        answer = "Refer to the Azure SDKs"
                    }
                }
            });

            Operation <BinaryData> updateQnasOperation = await client.UpdateQnasAsync(WaitUntil.Completed, "{ProjectName}", updateQnasRequestContent);

            #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_UpdateQnas

            #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_ExportProject
            Operation <BinaryData> exportOperation = client.Export(WaitUntil.Completed, "{ProjectName}", "{ExportFormat}");
            #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_ExportProject

            #region Snippet:Language_QnA_Maker_Snippets_MigrationGuide_DeleteProject
            Operation <BinaryData> deletionOperation = await client.DeleteProjectAsync(WaitUntil.Completed, "{ProjectName}");

            #endregion Snippet:Language_QnA_Maker_Snippets_MigrationGuide_DeleteProject
        }