using System;
using System.Threading;
using GatewayAPI;

namespace WCF_duplex_client
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            using (GatewayClientAPI gca = new GatewayClientAPI())
            {
                gca.NewMessage += new GatewayMessageHandler(gca_NewMessage);
                gca.NewCall += new GatewayCallHandler(gca_NewCall);
                bool end = false;
                while (!end)
                {
                    if (gca.IsConnected)
                    {
                        switch (Console.ReadLine())
                        {
                            case "end":
                                end = true;
                                break;
                            case "info":
                                string[] result = gca.GetGatewayInformation();
                                if (result != null)
                                {
                                    foreach (string item in result)
                                    {
                                        Console.WriteLine(item);
                                    }
                                }
                                break;
                            case "signal":
                                Console.WriteLine(gca.GetSignalStatus());
                                break;
                            case "ring":
                                Console.WriteLine(gca.RingThePhone("776316948", true));
                                break;
                            default:
                                if (gca.Test())
                                    Console.WriteLine("OK");
                                else
                                    Console.WriteLine("ERROR");
                                break;
                        }
                    }
                    Thread.Sleep(200);
                }
            }

        }

        static void gca_NewCall(string phone, DateTime incommingTime)
        {
            Console.WriteLine("New call: " + phone);
        }

        static void gca_NewMessage(string message, string phone, DateTime incommingTime)
        {
            Console.WriteLine("New message: " + message + " " + phone);
        }
    }
}
