Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string credentials = string.Empty;

            try
            {
                credentials = Utility.SimpleGet(
                    Environment.GetEnvironmentVariable("VCAP_URL"),
                    Environment.GetEnvironmentVariable("VCAP_USERNAME"),
                    Environment.GetEnvironmentVariable("VCAP_PASSWORD")).Result;
            }
            catch (Exception e)
            {
                Console.WriteLine(string.Format("Failed to get credentials: {0}", e.Message));
            }

            Task.WaitAll();

            var vcapServices = JObject.Parse(credentials);
            var _url         = vcapServices["language_translator"]["url"];
            var _username    = vcapServices["language_translator"]["username"];
            var _password    = vcapServices["language_translator"]["password"];

            LanguageTranslatorServiceExample _languageTranslatorExample = new LanguageTranslatorServiceExample(_url.ToString(), _username.ToString(), _password.ToString());

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string _username = "******";
            string _password = "******";

            LanguageTranslatorServiceExample _languageTranslatorExample = new LanguageTranslatorServiceExample(_username, _password);

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var environmentVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
            var fileContent         = File.ReadAllText(environmentVariable);
            var vcapServices        = JObject.Parse(fileContent);
            var _username           = vcapServices["language_translator"][0]["credentials"]["username"];
            var _password           = vcapServices["language_translator"][0]["credentials"]["password"];

            LanguageTranslatorServiceExample _languageTranslatorExample = new LanguageTranslatorServiceExample(_username.ToString(), _password.ToString());

            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string credentials = string.Empty;

            #region Get Credentials
            string _endpoint = string.Empty;
            string _username = string.Empty;
            string _password = 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("language-translator-sdk")[0].Credentials;
                    _endpoint = credential.Url;
                    _username = credential.Username;
                    _password = credential.Password;
                }
                else
                {
                    Console.WriteLine("Credentials file does not exist. Please define credentials.");
                    _username = "";
                    _password = "";
                    _endpoint = "";
                }
            }
            #endregion

            LanguageTranslatorServiceExample _languageTranslatorExample = new LanguageTranslatorServiceExample(_endpoint, _username, _password);
            Console.ReadKey();
        }