public override Task <HoroscopResponse> ShowSign(HoroscopRequest request, ServerCallContext context)
        {
            var Birthday = DateTime.Parse(request.Date);

            string sign = "";

            string[] dates = File.ReadAllLines(@"../../PeriodSign.txt");

            for (int index = 0; index < dates.Length; index = index + 3)
            {
                sign = dates[index];
                var StartPeriod  = DateTime.Parse(dates[index + 1]);
                var FinishPeriod = DateTime.Parse(dates[index + 2]);

                if ((Birthday.Month == StartPeriod.Month && Birthday.Day >= StartPeriod.Day) || (Birthday.Month == FinishPeriod.Month && Birthday.Day <= FinishPeriod.Day))
                {
                    break;
                }
            }

            return(Task.FromResult(new HoroscopResponse()
            {
                Sign = sign
            }));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            const string Host = "localhost";
            const int    Port = 16842;

            var channel = new Channel($"{Host}:{Port}", ChannelCredentials.Insecure);
            var request = new HoroscopRequest();

            do
            {
                Console.WriteLine("Enter your Birthday: ");
                request.Date = Console.ReadLine();
            } while (isValid(request.Date) == false);

            //var client = new HoroscopService.HoroscopServiceClient(channel);
            //var respone = client.ShowSign(request);
            //Console.WriteLine("Your Zodiac Sign is {0} ", respone.Sign);

            //----------------------Bonus

            var Birthday = DateTime.Parse(request.Date);

            switch (wichSeasone(Birthday))
            {
            case 1:
                var SpringRequest = new SpringRequest();
                var Springclient  = new SpringService.SpringServiceClient(channel);

                SpringRequest.Date = request.Date;
                var respone1 = Springclient.getZodiacSign(SpringRequest);
                Console.WriteLine("Your Zodiac Sign is {0} ", respone1.Sign);
                break;

            case 2:
                var SummerRequest = new SummerRequest();
                var Summerclient  = new SummerService.SummerServiceClient(channel);

                SummerRequest.Date = request.Date;
                var respone3 = Summerclient.getZodiacSign(SummerRequest);
                Console.WriteLine("Your Zodiac Sign is {0} ", respone3.Sign);
                break;

            case 3:
                var AutumnRequest = new AutumnRequest();
                var Autumnclient  = new AutumnService.AutumnServiceClient(channel);

                AutumnRequest.Date = request.Date;
                var respone2 = Autumnclient.getZodiacSign(AutumnRequest);
                Console.WriteLine("Your Zodiac Sign is {0} ", respone2.Sign);
                break;

            case 4:
                var WinterRequest = new WinterRequest();
                var Winterclient  = new WinterService.WinterServiceClient(channel);

                WinterRequest.Date = request.Date;
                var respone4 = Winterclient.getZodiacSign(WinterRequest);
                Console.WriteLine("Your Zodiac Sign is {0} ", respone4.Sign);
                break;
            }

            // Shutdown
            channel.ShutdownAsync().Wait();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }