コード例 #1
0
        public void TestGetServiceProperties()
        {
            var apikey             = "bogus-apikey";
            var tempVcapCredential = new Dictionary <string, List <VcapCredential> >();
            var vcapCredential     = new VcapCredential()
            {
                Credentials = new Credential()
                {
                    ApiKey = apikey
                }
            };

            tempVcapCredential.Add("assistant", new List <VcapCredential>()
            {
                vcapCredential
            });

            var vcapString = JsonConvert.SerializeObject(tempVcapCredential);

            Environment.SetEnvironmentVariable("VCAP_SERVICES", vcapString);
            Assert.IsNotNull(Environment.GetEnvironmentVariable("VCAP_SERVICES"));

            var serviceProperties = CredentialUtils.GetServiceProperties("assistant");

            Assert.IsNotNull(serviceProperties);
        }
コード例 #2
0
        protected IBMService(string serviceName, IAuthenticator authenticator, WebProxy webProxy = null)
        {
            ServiceName = serviceName;

            this.authenticator = authenticator ?? throw new ArgumentNullException(ErrorMessageNoAuthenticator);

            Client = new IBMHttpClient(webProxy);

            // Try to retrieve the service URL from either a credential file, environment, or VCAP_SERVICES.
            Dictionary <string, string> props = CredentialUtils.GetServiceProperties(serviceName);

            props.TryGetValue(PropNameServiceUrl, out string serviceUrl);
            if (!string.IsNullOrEmpty(serviceUrl))
            {
                SetServiceUrl(serviceUrl);
            }

            // Check to see if "disable ssl" was set in the service properties.
            bool disableSsl = false;

            props.TryGetValue(PropNameServiceDisableSslVerification, out string tempDisableSsl);
            if (!string.IsNullOrEmpty(tempDisableSsl))
            {
                bool.TryParse(tempDisableSsl, out disableSsl);
            }

            DisableSslVerification(disableSsl);
        }
コード例 #3
0
        public void Setup()
        {
            service = new AssistantService(versionDate);
            var creds = CredentialUtils.GetServiceProperties("assistant");

            creds.TryGetValue("ASSISTANT_ID", out assistantId);
        }
        public void Setup()
        {
            service = new VisualRecognitionService(versionDate);
            var creds = CredentialUtils.GetServiceProperties("visual_recognition");

            creds.TryGetValue("COLLECTION_ID", out collectionId);
            service.Client.BaseClient.Timeout = TimeSpan.FromMinutes(120);
        }
コード例 #5
0
        public void Setup()
        {
            //Authenticator discoveryAuthenticator = new BearerTokenAuthenticator(bearerToken: bearerToken);
            //service = new DiscoveryService(versionDate: versionDate, authenticator: discoveryAuthenticator);
            //service.SetServiceUrl(serviceUrl: serviceUrl);
            //service.DisableSslVerification(true);
            service = new DiscoveryService(versionDate);
            var creds = CredentialUtils.GetServiceProperties("discovery");

            creds.TryGetValue("PROJECT_ID", out projectId);
            creds.TryGetValue("COLLECTION_ID", out collectionId);
        }
コード例 #6
0
        public BaseService(Authenticator authenticator, string serviceId)
        {
            ServiceId = serviceId;

            Authenticator = authenticator ?? throw new ArgumentNullException(ErrorMessageNoAuthenticator);
            // Try to retrieve the service URL from either a credential file, environment, or VCAP_SERVICES.
            Dictionary <string, string> props = CredentialUtils.GetServiceProperties(serviceId);

            props.TryGetValue(PropNameServiceUrl, out string url);
            if (!string.IsNullOrEmpty(url))
            {
                SetServiceUrl(url);
            }
        }
コード例 #7
0
        public void Setup()
        {
            var creds = CredentialUtils.GetServiceProperties("assistant");

            creds.TryGetValue("WORKSPACE_ID", out workspaceId);
            service = new AssistantService(versionDate);


#if DELETE_DOTNET_WORKSPACES
            service.WithHeader("X-Watson-Test", "1");
            var           workspaces       = service.ListWorkspaces();
            List <string> dotnet_workpaces = new List <string>();

            foreach (Workspace workspace in workspaces.Workspaces)
            {
                if (workspace.Name == createdWorkspaceName)
                {
                    dotnet_workpaces.Add(workspace.WorkspaceId);
                }
            }

            foreach (string workspaceId in dotnet_workpaces)
            {
                try
                {
                    var getWorkspaceResult = GetWorkspace(
                        workspaceId: workspaceId
                        );
                    if (getWorkspaceResult != null)
                    {
                        DeleteWorkspace(
                            workspaceId: workspaceId
                            );
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("error: {0}", e.Message);
                }
            }
#endif
        }