protected void SendPackets(RS485PacketManager manager)
 {
     lock (RS485Events.synchronized)
     {
         Managers.Add(manager);
     }
 }
 private void AddUserAction()
 {
     if (session != null)
     {
         Console.WriteLine("username: "******"password: "******"Please input session information.");
     }
 }
        private void SetSessionAction()
        {
            RS485PacketManager manager;
            if (session != null)
            {
                // Send request to remove new session.
                manager = new RS485PacketManager(
                    new InputData(RS485Packet.PriorityEnum.High, VooProtocol.CreateEndSessionCommand(session), session.Source, session.Destination, session.Source),
                    32);
                lock (RS485Events.synchronized)
                {

                    Managers.Add(manager);
                }
            }
            Console.Write("Destination = ");
            String destination = Console.ReadLine().Trim();
            // Console.Write("Entry application = ");
            // application = Console.ReadLine().Trim();
            application = @"C:\";
            session = new Session(source, destination);
            // Send request to begin new session.
            manager = new RS485PacketManager(
                   new InputData(RS485Packet.PriorityEnum.High, VooProtocol.CreateBeginSessionCommand(session), session.Source, session.Destination, session.Source),
                   32);
            RS485Packet packet = new RS485Packet(session.Source, session.Source, session.Destination, RS485Packet.PriorityEnum.High,
                                        RS485Packet.CommandEnum.Data, VooProtocol.CreateCApplicationCommand(application));
            manager.Packets.Add(packet);
               //     lock (RS485Events.synchronized)
            {
                Managers.Add(manager);
            }
        }
 // TODO: Using this method you can perform low protocol level
 //  commands such as '/auth --username="******" --password="******"'
 //  and so on.
 private void TerminalAction()
 {
     if (session != null)
     {
         Console.Write(">");
         String command = Console.ReadLine();
         RS485PacketManager manager = new RS485PacketManager(
             new InputData(RS485Packet.PriorityEnum.High, command, session.Source, session.Destination, session.Source),
             32);
       //  lock (RS485Events.synchronized)
         {
             Managers.Add(manager);
         }
     }
     else
     {
         Console.WriteLine("Please input session information.");
     }
 }
 private void FetchFileAction()
 {
     if (session != null)
     {
         Console.Write("Download: ");
         String from = Console.ReadLine();
         Console.Write("To: ");
         String to = Console.ReadLine();
         RS485PacketManager manager = new RS485PacketManager(
             new InputData(RS485Packet.PriorityEnum.High,
                 VooProtocol.CreateFetchCommand(session.ToString(), from, to),
                 session.Source, session.Destination, session.Source),
             32);
        // lock (RS485Events.synchronized)
         {
             Managers.Add(manager);
         }
     }
     else
     {
         Console.WriteLine("Please input session information.");
     }
 }
 private void SendFileAction()
 {
     if (session != null)
     {
         // TODO: Create custom packets for sending files.
         Console.Write("Push: ");
         String from = Console.ReadLine();
         Console.Write("To: ");
         String to = Console.ReadLine();
         if (File.Exists(from))
         {
             VooFile file = new VooFile(session.Source, session.Destination, from, to);
             Console.WriteLine("Application: SendFileAction() -> read file('{0}')", from);
             file.ReadToEnd();
             // lock (RS485Events.synchronized)
             {
                 RS485PacketManager manager = new RS485PacketManager(
                     new RS485_dll.Voodoo.Libraries.RS485Library.RS485Terminal.InputData(
                         RS485Packet.PriorityEnum.High, file.Data,
                         session.Source, session.Destination, session.Source),
                     32);
                 RS485Packet packet = new RS485Packet(session.Source, session.Source, session.Destination, RS485Packet.PriorityEnum.High,
                     RS485Packet.CommandEnum.Data, VooProtocol.CreatePushCommand(session.ToString(), from, to, Convert.ToString(file.Data.Length)));
                 manager.Packets.Insert(0, packet);
                 Managers.Add(manager);
             }
         }
         else
         {
             Console.WriteLine("File doesn't exist.");
         }
     }
     else
     {
         Console.WriteLine("Please input session information.");
     }
 }
 private InputData ChatAction()
 {
     if (session != null)
     {
         Console.WriteLine("Data:");
         String data = Console.ReadLine();
         RS485PacketManager manager = new RS485PacketManager(
                     new RS485_dll.Voodoo.Libraries.RS485Library.RS485Terminal.InputData(
                         RS485Packet.PriorityEnum.High, data,
                         session.Source, session.Destination, session.Source),
                     32);
         // lock (RS485Events.synchronized)
         {
             Managers.Add(manager);
         }
     }
     else
     {
         Console.WriteLine("Please input session information.");
     }
     return null;
 }
 private void AuthUserAction()
 {
     if (user.IsValid())
     {
         RS485PacketManager manager = new RS485PacketManager(
            new InputData(RS485Packet.PriorityEnum.High, VooProtocol.CreateAuthUser(user.UserName, user.Password), session.Source, session.Destination, session.Source),
            32);
         lock (RS485Events.synchronized)
         {
             Managers.Add(manager);
         }
     }
 }
 protected void Fetch(VooProtocol protocol)
 {
     Console.WriteLine("Application: Fetch(VooProtocol protocol)");
     Console.WriteLine("Application: Fetch -> from = '{0}', to = '{1}'",
         protocol.Get("from"), protocol.Get("to"));
     VooFile file = new VooFile(protocol.Source, protocol.Destination,
         protocol.Get("from"), protocol.Get("to"));
     fetches.Add(file);
     Console.WriteLine("Application: Fetch -> read data");
     file.ReadToEnd();
     RS485PacketManager manager = new RS485PacketManager(new RS485_dll.Voodoo.Libraries.RS485Library.RS485Terminal.InputData(RS485Packet.PriorityEnum.Highest,
         file.Data, protocol.Destination, protocol.Source, protocol.Destination), 32);
     RS485Packet packet = new RS485Packet(protocol.Destination, protocol.Destination, protocol.Source,
         RS485Packet.PriorityEnum.Highest, RS485Packet.CommandEnum.Data, protocol.CreatePushCommand());
     manager.Packets.Insert(0, packet);
     Console.WriteLine("Application: Call send packets.");
     RS485VooEvents.Instance.SendPackets(manager);
 }
        public void Run()
        {
            RS485PacketManager manager = new RS485PacketManager(
                new RS485_dll.Voodoo.Libraries.RS485Library.RS485Terminal.InputData(RS485Packet.PriorityEnum.Highest,
                   "aaaaaaaaaaaaaaaaaaaaaaaab", "1", "2", "1"), 8, true);
            List<RS485Packet> packets = manager.Packets;

            // Push command
            Test3();
            // CR Session
            /*
            Test1();
            // CR Application
            Test2();
            // CR Authentication

            // Fetch command
            Test4();
            // Dir
            Test5();
            // Cd
            Test6();
            //
            Test7();
            // Dir
            Test8();
            // Cd
            Test9();
            */
        }
 public void SendPackets(RS485PacketManager manager)
 {
     SendPacketsDelegate local = SendPacketsEvent;
     if (local != null)
     {
         local(manager);
     }
 }