示例#1
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                return;
            }
            client = new ServiceChatClient(new System.ServiceModel.InstanceContext(new Program()));
            id     = client.Connect(args[0]);



            while (true)
            {
                PrintMenu();
                Console.WriteLine("Input option");
                char key = Console.ReadKey().KeyChar;
                Console.WriteLine();
                switch (key)
                {
                case 'w':
                {
                    int    receiverId;
                    string mes;
                    lock (locker)
                    {
                        Console.WriteLine("Write receiver Id");
                        if (!Int32.TryParse(Console.ReadLine(), out receiverId))
                        {
                            Console.WriteLine("Wrong input!");
                            continue;
                        }
                        Console.WriteLine("Write message");
                        mes = Console.ReadLine();
                    }
                    client.SendMsg(mes, receiverId, id);
                }; break;

                case 'u':
                {
                    Console.WriteLine("Users ID: ");
                    var usersId = client.GetServerUsers();
                    for (int i = 0; i < usersId.Length; i++)
                    {
                        Console.Write(usersId[i] + " ");
                    }
                    Console.WriteLine();
                }; break;

                case 'i':
                {
                    Console.WriteLine("Your data:\n" +
                                      $"\tID - {id}\n" +
                                      $"\tNickName - {args[0]}"
                                      );
                }; break;

                case 'e':
                {
                    client.Disconnect(id);
                    Console.WriteLine("Disconnect...");
                    return;
                }

                default:
                {
                    Console.WriteLine("Wrong command!");
                    continue;
                }
                }
            }
        }