Exemplo n.º 1
0
 private void button2_Click(object sender, EventArgs e)
 {
     byte [] bytete = new byte[5];
     for (int i = 0; i < bytete.Length; i++)
     {
         bytete[i] = byte.Parse(i + 5 + "");
     }
     //发送验证结果
     SetDeviceEp((IPEndPoint)dataTransmitter.LocalEndPoint);
     dataTransmitter.Send(bytete);
 }
Exemplo n.º 2
0
        private static void RunDesignPattern_Adapter()
        {
            Console.WriteLine("Start (7) Run Design Pattern - Adapter");
            var description =
                "Adapter(轉接器模式)" + "\n" +
                "目的:將兩個以上不同的介面統一成一個介面,讓User更輕鬆維護。" + "\n" +
                "實際情境中,可能出現架構上已經設計兩套Library在專案中,突然需求需要第三個Library,這時候Adapter模式下只需要將共用介面引用至第三個Library中開發完交付給User,User只有修改new出第三套Libraray所產生的Instance就大功告成了。";

            Console.WriteLine(description);
            Console.WriteLine("------------------------------------------------------------------------");

            // Example 1
            //Lib_1
            ICommunication Tunnel = new UdpCommunication();

            //Lib_2
            //ICommunication Tunnel = new TcpCommunication();
            //Lib_3
            //ICommunication Tunnel = new MqttCommunication();

            try
            {
                Tunnel.Connect("192.168.243.1", 3254);
                byte[] sendBuffer = GetSendBuffer();
                Tunnel.Send(sendBuffer);

                byte[] receiveBuffer = Tunnel.Receive();
                Tunnel.Disconnect();
                Console.WriteLine(GetReceiveString(receiveBuffer));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            // Example 2
            var a = new Adapter1();

            a.Main();

            Console.WriteLine("Done. 請按任意鍵繼續");
            Console.ReadLine();
        }