Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new Zodiac.ZodiacClient(channel);

            bool enterAnotherDate = true;

            char[] wrongDelimiters = { ' ', '.', '-' };

            do
            {
                string responseToEnterAnotherDate;

                Console.Write("Type in your birthdate in the format: MM/DD/YYYY\n");
                string dateString = Console.ReadLine();
                if (dateString.IndexOfAny(wrongDelimiters) == -1)
                {
                    DateTime date;

                    if (DateTime.TryParse(dateString, out date))
                    {
                        var zodiacToBeFound = new ClientZodiac()
                        {
                            ZodiacDate = Timestamp.FromDateTimeOffset(date)
                        };
                        var response = await client.FindZodiacAsync(new ZodiacRequest { Zodiac = zodiacToBeFound });

                        Console.WriteLine("Your zodiac is: " + response.ZodiacName);

                        enterAnotherDate = false;
                    }
                    else
                    {
                        Console.WriteLine("You have entered an incorrect date. Would you like to try again? Yes or No");
                        responseToEnterAnotherDate = Console.ReadLine();

                        if (responseToEnterAnotherDate != "Yes")
                        {
                            enterAnotherDate = false;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("You used some other delimiters besides '/'. Would you like to try again? Yes or No");
                    responseToEnterAnotherDate = Console.ReadLine();

                    if (responseToEnterAnotherDate != "Yes")
                    {
                        enterAnotherDate = false;
                    }
                }
            } while (enterAnotherDate);
        }
Ejemplo n.º 2
0
        public string CalculateZodiac(ClientZodiac zodiac)
        {
            //Console.WriteLine(zodiac.ZodiacDate.ToDateTime().Day);
            string line;

            try
            {
                StreamReader sr = new StreamReader(filePath);
                line = sr.ReadLine();
                while (line != null)
                {
                    string[] broken_line = line.Split(' ');

                    string zodiacName = broken_line[0];

                    string zodiacStartMonth = broken_line[1];
                    string zodiacStartDay   = broken_line[2];

                    string zodiacEndMonth = broken_line[3];
                    string zodiacEndDay   = broken_line[4];

                    if (zodiac.ZodiacDate.ToDateTime().Month == Convert.ToInt32(zodiacStartMonth) || zodiac.ZodiacDate.ToDateTime().Month == Convert.ToInt32(zodiacEndMonth))
                    {
                        if (zodiac.ZodiacDate.ToDateTime().Day + 1 >= Convert.ToInt32(zodiacStartDay) || zodiac.ZodiacDate.ToDateTime().Day + 1 <= Convert.ToInt32(zodiacEndDay))
                        {
                            return(zodiacName);
                        }
                    }

                    line = sr.ReadLine();
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
            finally
            {
                Console.WriteLine("Executing finally block.");
            }

            return("No zodiac name found for the introduced date");
        }