//[UnityTest, Order(3)]
        public IEnumerator TestAddDocument()
        {
            Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to AddDocument...");
            DocumentAccepted addDocumentResponse = null;

            using (FileStream fs = File.OpenRead(addDocumentFile))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    service.AddDocument(
                        callback: (DetailedResponse <DocumentAccepted> response, IBMError error) =>
                    {
                        Log.Debug("DiscoveryServiceV1IntegrationTests", "AddDocument result: {0}", response.Response);
                        addDocumentResponse = response.Result;
                        documentId          = addDocumentResponse.DocumentId;
                        Assert.IsNotNull(addDocumentResponse);
                        Assert.IsNotNull(documentId);
                        Assert.IsNull(error);
                    },
                        projectId: projectId,
                        collectionId: collectionId,
                        file: ms,
                        fileContentType: Utility.GetMimeType(Path.GetExtension(addDocumentFile)),
                        filename: Path.GetFileName(addDocumentFile)
                        );

                    while (addDocumentResponse == null)
                    {
                        yield return(null);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void AddDocument()
        {
            CloudPakForDataAuthenticator authenticator = new CloudPakForDataAuthenticator(
                url: "https://{cpd_cluster_host}{:port}",
                username: "******",
                password: "******"
                );

            DiscoveryService service = new DiscoveryService("2019-11-22", authenticator);

            service.SetServiceUrl("{https://{cpd_cluster_host}{:port}/discovery/{release}/instances/{instance_id}/api}");


            DetailedResponse <DocumentAccepted> result = null;

            using (FileStream fs = File.OpenRead("path/to/file.pdf"))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);

                    result = service.AddDocument(
                        projectId: "{project_id}",
                        collectionId: "{collection_id}",
                        file: ms,
                        filename: "example-file",
                        fileContentType: "application/pdf"
                        );
                }
            }

            Console.WriteLine(result.Response);
        }
        public void AddDocument()
        {
            IamAuthenticator authenticator = new IamAuthenticator(
                apikey: "{apikey}");

            DiscoveryService service = new DiscoveryService("2019-04-30", authenticator);

            service.SetServiceUrl("{serviceUrl}");

            DetailedResponse <DocumentAccepted> result;

            using (FileStream fs = File.OpenRead("{filePath}"))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    result = service.AddDocument(
                        environmentId: "{environmentId}",
                        collectionId: "{collectionId}",
                        file: ms,
                        filename: "{fileName}",
                        fileContentType: "{fileContentType}",
                        metadata: metadata
                        );

                    documentId = result.Result.DocumentId;
                }
            }

            Console.WriteLine(result.Response);
        }
Exemplo n.º 4
0
        public void AddDocument()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            DiscoveryService service = new DiscoveryService(versionDate, config);

            service.SetEndpoint(url);

            DetailedResponse <DocumentAccepted> result;

            using (FileStream fs = File.OpenRead(filepathToIngest))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    result = service.AddDocument(
                        environmentId: environmentId,
                        collectionId: collectionId,
                        file: ms,
                        filename: "watson_beats_jeopardy.html",
                        fileContentType: "text/html",
                        metadata: metadata
                        );

                    documentId = result.Result.DocumentId;
                }
            }

            Console.WriteLine(result.Response);
        }
        public void AddDocument_Success()
        {
            IClient  client  = Substitute.For <IClient>();
            IRequest request = Substitute.For <IRequest>();

            client.PostAsync(Arg.Any <string>())
            .Returns(request);

            DiscoveryService service = new DiscoveryService(client);
            var versionDate          = "versionDate";

            service.VersionDate = versionDate;

            var projectId             = "projectId";
            var collectionId          = "collectionId";
            var file                  = new MemoryStream();
            var filename              = "filename";
            var fileContentType       = "fileContentType";
            var metadata              = "metadata";
            var xWatsonDiscoveryForce = false;

            var result = service.AddDocument(projectId: projectId, collectionId: collectionId, file: file, filename: filename, fileContentType: fileContentType, metadata: metadata, xWatsonDiscoveryForce: xWatsonDiscoveryForce);

            request.Received().WithArgument("version", versionDate);
            client.Received().PostAsync($"{service.ServiceUrl}/v2/projects/{projectId}/collections/{collectionId}/documents");
        }
Exemplo n.º 6
0
        public void AddDocument()
        {
            TokenOptions tokenOptions = new TokenOptions()
            {
                IamApiKey  = apikey,
                ServiceUrl = url
            };

            DiscoveryService service = new DiscoveryService(tokenOptions, versionDate);

            DetailedResponse <DocumentAccepted> result;

            using (FileStream fs = File.OpenRead(filepathToIngest))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);
                    result = service.AddDocument(
                        environmentId: environmentId,
                        collectionId: collectionId,
                        file: ms,
                        filename: "watson_beats_jeopardy.html",
                        fileContentType: "text/html",
                        metadata: metadata
                        );

                    documentId = result.Result.DocumentId;
                }
            }

            Console.WriteLine(result.Response);
        }
        public void TestAddDeleteDocument()
        {
            DetailedResponse <DocumentAccepted> addDocumentResult = null;

            using (FileStream fs = File.OpenRead(filepathToIngest))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    fs.CopyTo(ms);

                    service.WithHeader("X-Watson-Test", "1");
                    addDocumentResult = service.AddDocument(
                        projectId: projectId,
                        collectionId: collectionId,
                        file: ms,
                        filename: "watson_beats_jeopardy.html",
                        fileContentType: "text/html",
                        metadata: metadata,
                        xWatsonDiscoveryForce: false
                        );
                }
            }

            Assert.IsNotNull(addDocumentResult.Result);
            Assert.IsNotNull(addDocumentResult.Result.DocumentId);
            Assert.IsNotNull(addDocumentResult.Result.Status);

            var documentId = addDocumentResult.Result.DocumentId;

            service.WithHeader("X-Watson-Test", "1");
            var deleteDocumentResult = service.DeleteDocument(
                projectId: projectId,
                collectionId: collectionId,
                documentId: documentId,
                xWatsonDiscoveryForce: false
                );

            Assert.IsNotNull(deleteDocumentResult.Result);
            Assert.IsNotNull(deleteDocumentResult.Result.DocumentId);
            Assert.IsNotNull(deleteDocumentResult.Result.Status);
        }
        private void AddDocument()
        {
            Console.WriteLine(string.Format("\nCalling AddDocument()..."));
            using (FileStream fs = File.OpenRead(_filepathToIngest))
            {
                var result = _discovery.AddDocument(_createdEnvironmentId, _createdCollectionId, _createdConfigurationId, fs as Stream, _metadata);

                if (result != null)
                {
                    Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
                    _createdDocumentId = result.DocumentId;
                }
                else
                {
                    Console.WriteLine("result is null.");
                }
            }
        }