Exemple #1
0
        public static void Main(string[] args)
        {
            string credentials = string.Empty;

            #region Get Credentials
            string _endpoint    = string.Empty;
            string _username    = string.Empty;
            string _password    = string.Empty;
            string _workspaceID = string.Empty;

            if (string.IsNullOrEmpty(credentials))
            {
                var    parentDirectory     = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.Parent.FullName;
                string credentialsFilepath = parentDirectory + Path.DirectorySeparatorChar + "sdk-credentials" + Path.DirectorySeparatorChar + "credentials.json";
                if (File.Exists(credentialsFilepath))
                {
                    try
                    {
                        credentials = File.ReadAllText(credentialsFilepath);
                        credentials = Utility.AddTopLevelObjectToJson(credentials, "VCAP_SERVICES");
                    }
                    catch (Exception e)
                    {
                        throw new Exception(string.Format("Failed to load credentials: {0}", e.Message));
                    }

                    VcapCredentials vcapCredentials = JsonConvert.DeserializeObject <VcapCredentials>(credentials);
                    var             vcapServices    = JObject.Parse(credentials);

                    Credential credential = vcapCredentials.GetCredentialByname("conversation-sdk")[0].Credentials;
                    _endpoint    = credential.Url;
                    _username    = credential.Username;
                    _password    = credential.Password;
                    _workspaceID = credential.WorkspaceId;
                }
                else
                {
                    Console.WriteLine("Credentials file does not exist. Please define credentials.");
                    _username    = "";
                    _password    = "";
                    _endpoint    = "";
                    _workspaceID = "";
                }
            }
            #endregion

            //  Uncomment to run the service example.
            ConversationServiceExample _conversationExample = new ConversationServiceExample(_endpoint, _username, _password, _workspaceID);

            //  Uncomment to run the context example.
            ConversationContextExample _converationContextExample = new ConversationContextExample(_endpoint, _username, _password, _workspaceID);

            Console.ReadKey();
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            var environmentVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
            var fileContent         = File.ReadAllText(environmentVariable);
            var vcapServices        = JObject.Parse(fileContent);
            var _username           = vcapServices["conversation"][0]["credentials"]["username"];
            var _password           = vcapServices["conversation"][0]["credentials"]["password"];
            var _workspaceID        = vcapServices["conversation"][0]["credentials"]["workspaceId"];

            ConversationServiceExample _conversationExample = new ConversationServiceExample(_username.ToString(), _password.ToString(), _workspaceID.ToString());

            Console.ReadKey();
        }