コード例 #1
0
ファイル: CatFact.cs プロジェクト: strawberries73/UtilityBelt
        public void Run()
        {
            string       content = string.Empty;
            string       catUrl  = "https://cat-fact.herokuapp.com/facts/random";
            CatFactModel catFact = new CatFactModel();

            try
            {
                using (var wc = GetWebClient())
                {
                    content = wc.DownloadString(catUrl);
                }
                catFact = JsonSerializer.Deserialize <CatFactModel>(content);
            }
            catch
            {
                Console.WriteLine("Got no result or couldn't convert to a cat fact");
                return;
            }

            Console.WriteLine();
            if (catFact.Status != null && catFact.Status.Verified)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            Console.WriteLine(catFact.Text);
            Console.WriteLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: M0RG4N01/UtilityBelt
 static void CatFact()
 {
     string content = string.Empty;
     string catUrl = "https://cat-fact.herokuapp.com/facts/random";
     using (var wc = new WebClient())
     {
         content = wc.DownloadString(catUrl);
     }
     CatFactModel catFact = JsonSerializer.Deserialize<CatFactModel>(content);
     Console.WriteLine();
     if (catFact.Status != null && catFact.Status.Verified)
         Console.ForegroundColor = ConsoleColor.Yellow;
     else
         Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine(catFact.Text);
     Console.WriteLine();
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: gupta-sandeep/UtilityBelt
        private static void CatFact()
        {
            logger.LogInformation($"User Choice : {nameof(CatFact)}");
            string content = string.Empty;
            string catUrl  = "https://cat-fact.herokuapp.com/facts/random";

            using (var wc = new WebClient())
            {
                content = wc.DownloadString(catUrl);
            }
            CatFactModel catFact = JsonSerializer.Deserialize <CatFactModel>(content);

            Console.WriteLine();
            if (catFact.Status != null && catFact.Status.Verified)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            Console.WriteLine(catFact.Text);
            Console.WriteLine();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: jperazas208/UtilityBelt
        static void CatFact()
        {
            string     content = string.Empty;
            string     catUrl  = "https://cat-fact.herokuapp.com/facts/random";
            WebRequest catReq  = WebRequest.Create(catUrl);

            using (WebResponse wr = catReq.GetResponse())
                using (Stream receiveStream = wr.GetResponseStream())
                    using (StreamReader sReader = new StreamReader(receiveStream, Encoding.UTF8))
                        content = sReader.ReadToEnd();
            CatFactModel catFact = JsonSerializer.Deserialize <CatFactModel>(content);

            Console.WriteLine("");
            if (catFact.status.verified)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            Console.WriteLine(catFact.text);
            Console.WriteLine("");
        }