示例#1
0
        private static void addNewDoor(DoorServiceClient client)
        {
            Console.Write("Enter new door label: ");
            var label = Console.ReadLine();

            if (client.addNewDoor(label))
            {
                Console.WriteLine("Door was added");
                return;
            }
            Console.WriteLine("Nope");
        }
示例#2
0
 private static void printDoor(DoorServiceClient client)
 {
     Console.Write("Enter door id: ");
     if (long.TryParse(Console.ReadLine(), out long id))
     {
         var door = client.getDoor(id);
         if (door != null)
         {
             Console.WriteLine(door.ToString());
             return;
         }
     }
     Console.WriteLine("Nope");
 }
示例#3
0
 private static void changeLable(DoorServiceClient client)
 {
     Console.Write("Enter door id: ");
     if (long.TryParse(Console.ReadLine(), out long id))
     {
         Console.Write("Enter new label: ");
         var label = Console.ReadLine();
         if (client.updateDoorLabel(id, label))
         {
             Console.WriteLine("Label was updated");
             return;
         }
     }
     Console.WriteLine("Nope");
 }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        async Task InitAsync()
        {
            try
            {
                this.client = new DoorServiceClient(new InstanceContext(this), "TcpBinding");
                this.client.Open();

                await this.client.LoginAsync(System.Environment.MachineName + GetExtraName());
            }
            catch (Exception ex)
            {
                model.AddLog(new LogData {
                    AppName = "ERROR", Info = $"Communication error: {ex}"
                });
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            using (var client = new DoorServiceClient()) {
                printInstruction();
                printAllDoors(client);

                while (true)
                {
                    Console.Write("Input: ");
                    var input = Console.ReadKey().KeyChar;
                    Console.WriteLine();
                    switch (input)
                    {
                    case '1': printAllDoors(client); break;

                    case '2': executeSingleObjectAction((x) => client.openDoor(x), "Door is opened"); break;

                    case '3': executeSingleObjectAction((x) => client.closeDoor(x), "Door is closed"); break;

                    case '4': executeSingleObjectAction((x) => client.lockDoor(x), "Door is locked"); break;

                    case '5': executeSingleObjectAction((x) => client.lockDoor(x), "Door is unlocked"); break;

                    case '6': printDoor(client); break;

                    case '7': addNewDoor(client); break;

                    case '8': changeLable(client); break;

                    case '9': executeSingleObjectAction((x) => client.removeDoor(x), "Door is removed"); break;

                    case '0': printInstruction(); break;

                    default:
                        break;
                    }
                }
            }
        }
示例#6
0
 private static void printAllDoors(DoorServiceClient client)
 {
     Console.WriteLine(new String('-', 60));
     client.getAllDoors().ToList().ForEach(x => Console.WriteLine(x.ToString()));
     Console.WriteLine(new String('-', 60));
 }