Esempio n. 1
0
        public static CalendarDate ConvertToCalendarDate(string date)
        {
            CalendarDate newDate = new CalendarDate();
            int          month   = 0;
            int          day     = 0;
            int          year    = 0;
            int          i       = 0;

            while (!date[i].Equals('/'))
            {
                month = month * 10 + (int)Char.GetNumericValue(date[i]);
                i++;
            }
            i++;
            while (!date[i].Equals('/'))
            {
                day = day * 10 + (int)Char.GetNumericValue(date[i]);
                i++;
            }
            i++;
            while (i < date.Length)
            {
                year = year * 10 + (int)Char.GetNumericValue(date[i]);
                i++;
            }
            newDate.Year  = year;
            newDate.Month = month;
            newDate.Day   = day;
            return(newDate);
        }
Esempio n. 2
0
        public static bool Validation(CalendarDate date)
        {
            if (date.Month > 12 || date.Month <= 0)
            {
                Console.WriteLine("There are only 12 months");
                return(false);
            }

            if (date.Day <= 0)
            {
                Console.WriteLine("Wrong input!");
                return(false);
            }

            if (date.Month == 1)
            {
                if (date.Day > 31)
                {
                    Console.WriteLine("January has only 31 days");
                    return(false);
                }
            }
            if (date.Month == 2)
            {
                if ((date.Year % 4 == 0 && date.Year % 100 != 0) || date.Year % 400 == 0)
                {
                    if (date.Day > 29)
                    {
                        Console.WriteLine("This February has only 29 days");
                        return(false);
                    }
                }
                else if (date.Day > 28)
                {
                    Console.WriteLine("This February has only 28 days");
                    return(false);
                }
            }
            if (date.Month == 3)
            {
                if (date.Day > 31)
                {
                    Console.WriteLine("March has only 31 days");
                    return(false);
                }
            }
            if (date.Month == 4)
            {
                if (date.Day > 30)
                {
                    Console.WriteLine("April has only 30 days");
                    return(false);
                }
            }
            if (date.Month == 5)
            {
                if (date.Day > 31)
                {
                    Console.WriteLine("May has only 31 days");
                    return(false);
                }
            }
            if (date.Month == 6)
            {
                if (date.Day > 30)
                {
                    Console.WriteLine("June has only 30 days");
                    return(false);
                }
            }
            if (date.Month == 7)
            {
                if (date.Day > 31)
                {
                    Console.WriteLine("July has only 31 days");
                    return(false);
                }
            }
            if (date.Month == 8)
            {
                if (date.Day > 31)
                {
                    Console.WriteLine("August has only 31 days");
                    return(false);
                }
            }
            if (date.Month == 9)
            {
                if (date.Day > 30)
                {
                    Console.WriteLine("September has only 30 days");
                    return(false);
                }
            }
            if (date.Month == 10)
            {
                if (date.Day > 31)
                {
                    Console.WriteLine("October has only 31 days");
                    return(false);
                }
            }
            if (date.Month == 11)
            {
                if (date.Day > 30)
                {
                    Console.WriteLine("November has only 30 days");
                    return(false);
                }
            }
            if (date.Month == 12)
            {
                if (date.Day > 31)
                {
                    Console.WriteLine("December has only 30 days");
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        static async Task Main(string[] args)
        {
            string date;

            do
            {
                Console.WriteLine("Enter a date: ");
                date = Console.ReadLine();
                if (dateValid(date))
                {
                    CalendarDate newDate = CalendarDate.ConvertToCalendarDate(date);

                    if (CalendarDate.Validation(newDate))
                    {
                        if (newDate.Month == 1 || newDate.Month == 2 || newDate.Month == 12)
                        {
                            using var channel = GrpcChannel.ForAddress("https://localhost:7580");
                            var client = new Winter.WinterClient(channel);
                            var reply  = client.WinterSign(
                                new WinterRequest {
                                Date = date
                            });
                            Console.WriteLine("Your sign is: " + reply.ZodiacSign);
                        }
                        else if (newDate.Month == 3 || newDate.Month == 4 || newDate.Month == 5)
                        {
                            using var channel = GrpcChannel.ForAddress("https://localhost:7580");
                            var client = new Spring.SpringClient(channel);
                            var reply  = client.SpringSign(
                                new SpringRequest {
                                Date = date
                            });
                            Console.WriteLine("Your sign is: " + reply.ZodiacSign);
                        }
                        else if (newDate.Month == 6 || newDate.Month == 7 || newDate.Month == 8)
                        {
                            using var channel = GrpcChannel.ForAddress("https://localhost:7580");
                            var client = new Summer.SummerClient(channel);
                            var reply  = client.SummerSign(
                                new SummerRequest {
                                Date = date
                            });
                            Console.WriteLine("Your sign is: " + reply.ZodiacSign);
                        }
                        else
                        {
                            using var channel = GrpcChannel.ForAddress("https://localhost:7580");
                            var client = new Autumn.AutumnClient(channel);
                            var reply  = client.AutumnSign(
                                new AutumnRequest {
                                Date = date
                            });
                            Console.WriteLine("Your sign is: " + reply.ZodiacSign);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Wrong input!");
                }
            } while (!dateValid(date));
        }