示例#1
0
        public void Execute(string accessToken, string baseUrl, HttpClient httpClient)
        {
            Console.Write("Unestite text:\n");
            var input  = Console.ReadLine();
            var client = new WordCounterAPIClient();

            var phraseCreateDto = new PhraseCreateDto {
                Text = input
            };

            var result = client.CallClientCreatePhraseAsync(accessToken, baseUrl, httpClient, phraseCreateDto).Result;

            if (result == null)
            {
                Console.Write("Neuspešno cuvanje!:\n");
            }
            else
            {
                Console.Write("Uspesno sacuvan text:\n");
                Console.WriteLine("-----------");
                Console.WriteLine("ID\t\tText");
                Console.WriteLine("-----------");
                Console.WriteLine("{0}\t\t{1}", result.Id, result.Text);
            }

            Console.ReadLine();
        }
        public void Execute(string accessToken, string baseUrl, HttpClient httpClient)
        {
            Console.Write("Izaberite broj reda za brisanje:\n");
            var client  = new WordCounterAPIClient();
            var phrases = client.CallClientGetPhrasesAsync(accessToken, baseUrl, httpClient).Result;

            if (phrases != null)
            {
                Console.WriteLine("-----------");
                Console.WriteLine("ID\t\tText");
                Console.WriteLine("-----------");
                foreach (var phrase in phrases)
                {
                    Console.WriteLine("{0}\t\t{1}", phrase.Id, phrase.Text);
                }

                string id = Console.ReadLine();

                var br = client.CallClientDeleteByIdAsync(accessToken, baseUrl, httpClient, id).Result;

                if (br)
                {
                    Console.WriteLine("Red je uspesno obrisan. Pritisnie bilo koje dugme za nastavak", br);
                }
                Console.ReadLine();
            }
        }
示例#3
0
        public async Task RunAsync()
        {
            var authenticationResult = await AuthenticateAsync();
            if (!string.IsNullOrEmpty(authenticationResult.AccessToken))
            {
                var baseAddress = _config.GetValue<string>("BaseAddress");
                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", authenticationResult.AccessToken);

                WordCounterAPIClient wordCounterAPIClient = new WordCounterAPIClient(baseAddress, httpClient);

                //var responseMessage = await httpClient.GetAsync(baseAddress);

               

                var responseMessage = await wordCounterAPIClient.GetPhraseByIdAsync(1).GetAwaiter().ToString;

                if (responseMessage.IsSuccessStatusCode
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    string jsonResponse = await responseMessage.Content.ReadAsStringAsync();
                    Console.WriteLine(jsonResponse);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"Failed to call Web API: {responseMessage.StatusCode}");
                    string jsonResponse = await responseMessage.Content.ReadAsStringAsync();
                    Console.WriteLine($"Content: {jsonResponse}");
                }
                Console.ResetColor();
            }
        }
示例#4
0
        public void Execute(string accessToken, string baseUrl, HttpClient httpClient)
        {
            Console.WriteLine("Izaberite red iz baze:");
            var client  = new WordCounterAPIClient();
            var phrases = client.CallClientGetPhrasesAsync(accessToken, baseUrl, httpClient).Result;

            if (phrases != null)
            {
                Console.WriteLine("-----------");
                Console.WriteLine("ID\t\tText");
                Console.WriteLine("-----------");
                foreach (var phrase in phrases)
                {
                    Console.WriteLine("{0}\t\t{1}", phrase.Id, phrase.Text);
                }

                string id = Console.ReadLine();

                var text = client.CallClientGetPhraseByIdAsync(accessToken, baseUrl, httpClient, id).Result;

                var br = client.CallClientWordCountAsync(accessToken, baseUrl, httpClient, text.Text).Result;

                Console.WriteLine("Broj reci je:{0}", br);
                Console.ReadLine();
            }
        }
        public void Execute(string accessToken, string baseUrl, HttpClient httpClient)
        {
            Console.WriteLine("Unesite text:\n");
            var text = Console.ReadLine();

            var client = new WordCounterAPIClient();

            var result = client.CallClientWordCountAsync(accessToken, baseUrl, httpClient, text);


            if (!string.IsNullOrEmpty(result.Result))
            {
                Console.WriteLine("Broj reci je:{0}", result.Result);
            }
            Console.ReadLine();
        }
示例#6
0
        public void Execute(string accessToken, string baseUrl, HttpClient httpClient)
        {
            Console.WriteLine("Unesite putanju do txt fajla:\n");
            var path = Console.ReadLine();

            try
            {
                var text = System.IO.File.ReadAllText(path);

                var client = new WordCounterAPIClient();
                var result = client.CallClientWordCountAsync(accessToken, baseUrl, httpClient, text).Result;

                if (!string.IsNullOrEmpty(result))
                {
                    Console.WriteLine("Broj reci je:{0}", result);
                }
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Log.Logger.Error("Greška pri ucitavanju fajla: {0}", ex.Message);
                Console.ReadLine();
            }
        }