using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using GatewayAPI;

namespace WCF_duplex_server
{
    class Program
    {
        static void Main(string[] args)
        {
            ServerControl.ClientConnected += new GatewayServerOnlineHandler(ServerControl_ClientCountChange);
            ServerControl.ClientDisconnected += new GatewayServerOnlineHandler(ServerControl_ClientCountChange);
            ServerControl.IncommingCall += new GatewayCallHandler(ServerControl_IncommingCall);
            ServerControl.OutgoingCall += new GatewayCallHandler(ServerControl_OutgoingCall);
            ServerControl.IncommingMessage += new GatewayMessageHandler(ServerControl_IncommingMessage);
            ServerControl.OutgoingMessage += new GatewayMessageHandler(ServerControl_OutgoingMessage);

            using (GatewayServerAPI server = new GatewayServerAPI())
            {
                Console.WriteLine("Server is loaded");
                bool end = false;
                while (!end)
                {
                    Console.ReadLine();
                }
            }
        }

        static void ServerControl_OutgoingMessage(string message, string phone, DateTime incommingTime)
        {
            Console.WriteLine("OutgoingMessage");
        }

        static void ServerControl_IncommingMessage(string message, string phone, DateTime incommingTime)
        {
            Console.WriteLine("IncommingMessage");
        }

        static void ServerControl_OutgoingCall(string phone, DateTime incommingTime)
        {
            Console.WriteLine("OutgoingCall");
        }

        static void ServerControl_IncommingCall(string phone, DateTime incommingTime)
        {
            Console.WriteLine("IncommingCall");
        }

        static void ServerControl_ClientCountChange(int onlineClientCount)
        {
            Console.WriteLine("Online clients count: " + onlineClientCount.ToString());
        }
    }
}
