public bool AnalyzeCommand(RS485Packet packet) { VooProtocol protocol = new VooProtocol(packet.current, packet.source, packet.destination, packet.RawData); if (protocol.isFound) { switch (protocol.CurrentPacket.Key) { case VooProtocol.Commands.SERVER_HELP: RS485VooEvents.Instance.OutputData(VooConfiguration.Help); break; case VooProtocol.Commands.SERVER_EXIT: RS485VooEvents.Instance.TerminateMachine(RS485Constants.Machine.ServerAndClient); break; case VooProtocol.Commands.SERVER_ADD_AUTH: RS485VooEvents.Instance.RegisterUser(protocol); break; case VooProtocol.Commands.SERVER_REMOVE_AUTH: RS485VooEvents.Instance.UnRegisterUser(protocol); break; case VooProtocol.Commands.SERVER_CREATE_APPLICATION: RS485VooEvents.Instance.CreateApplication(protocol); break; case VooProtocol.Commands.SERVER_REMOVE_APPLICATION: RS485VooEvents.Instance.RemoveApplication(protocol); break; case VooProtocol.Commands.CLIENT_BEGIN_SESSION: RS485VooEvents.Instance.BeginSession(protocol); break; case VooProtocol.Commands.CLIENT_END_SESSION: RS485VooEvents.Instance.EndSession(protocol); break; case VooProtocol.Commands.CLIENT_CD: RS485VooEvents.Instance.ExecuteCommand(protocol); break; case VooProtocol.Commands.CLIENT_DIR: RS485VooEvents.Instance.ExecuteCommand(protocol); break; case VooProtocol.Commands.CLIENT_FETCH: RS485VooEvents.Instance.Fetch(protocol); break; case VooProtocol.Commands.CLIENT_PUSH: RS485VooEvents.Instance.Push(protocol); break; case VooProtocol.Commands.CLIENT_AUTH: RS485VooEvents.Instance.LoginUser(protocol); break; case VooProtocol.Commands.CLIENT_PUSH_DATA: break; default: // TODO: Output information about error of protocol data. // RS485VooEvents.Instance.Error("You have error in protocol parser."); // It's for other messages not for implementation protocol. RS485VooEvents.Instance.ReceiveData(protocol); break; } } else { RS485VooEvents.Instance.ReceiveData(protocol); } return true; }
protected void LoginUser(VooProtocol protocol) { Console.WriteLine("Application: LoginUser(VooProtocol protocol)"); currentUser = FindUser(protocol.Get("username"), protocol.Get("password"), true); if (currentUser != null) { Console.WriteLine("Application: LoginUser -> username = '******', password = '******'", currentUser.UserName, currentUser.Password); } else { Console.WriteLine("Application: LoginUser -> User can't be found."); } }
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); }
protected void ExecuteCommand(VooProtocol protocol) { Console.WriteLine("Application: ExecuteCommand(VooProtocol protocol)"); String result = String.Empty; switch (protocol.CurrentPacket.Key) { case VooProtocol.Commands.CLIENT_CD: String temp = protocol.Get("folder"); if (temp == "..") { if (application.Split('\\').Length > 1) { application = application.Substring(0, application.LastIndexOf('\\') + 1); } } else { application = Path.Combine(application, temp); } RS485VooEvents.Instance.SendPackets(new RS485PacketManager( new RS485_dll.Voodoo.Libraries.RS485Library.RS485Terminal.InputData(RS485Packet.PriorityEnum.Highest, DirAction(application), protocol.Destination, protocol.Source, protocol.Destination), 64)); break; case VooProtocol.Commands.CLIENT_DIR: RS485VooEvents.Instance.SendPackets(new RS485PacketManager( new RS485_dll.Voodoo.Libraries.RS485Library.RS485Terminal.InputData(RS485Packet.PriorityEnum.Highest, DirAction(Path.Combine(application, protocol.Get("application"))), protocol.Destination, protocol.Source, protocol.Destination), 64)); break; } RS485VooEvents.Instance.OutputData(result); }
public void BeginSession(VooProtocol protocol) { BeginSessionDelegate local = BeginSessionEvent; if (local != null) { local(protocol); } }
public void CreateApplication(VooProtocol protocol) { Console.WriteLine("Application: CreateApplication(VooProtocol protocol)"); application = protocol.Get("application"); Console.WriteLine("Application: CreateApplication -> application = '{0}'", application); }
private VooFile FindFile(VooProtocol protocol, List<VooFile> files) { VooFile result = null; foreach (VooFile file in files) { if (file.IsParent(protocol.Source, protocol.Destination)) { result = file; break; } } return result; }
protected void RemoveApplication(VooProtocol protocol) { Console.WriteLine("Application: RemoveApplication(VooProtocol protocol)"); application = String.Empty; Console.WriteLine("Application: RemoveApplication -> application = '{0}'", protocol.Get("application")); }
public void ReceiveData(VooProtocol protocol) { ReceiveDataDelegate local = ReceiveDataEvent; if (local != null) { local(protocol); } }
public void Push(VooProtocol protocol) { PushDelegate local = PushEvent; if (local != null) { local(protocol); } }
public void LoginUser(VooProtocol protocol) { LoginUserDelegate local = LoginUserEvent; if (local != null) { local(protocol); } }
public void Fetch(VooProtocol protocol) { FetchDelegate local = FetchEvent; if (local != null) { local(protocol); } }
public void ExecuteCommand(VooProtocol protocol) { ExecuteCommandDelegate local = ExecuteCommandEvent; if (local != null) { local(protocol); } }
public void EndSession(VooProtocol protocol) { EndSessionDelegate local = EndSessionEvent; if (local != null) { local(protocol); } }
public void CreateApplication(VooProtocol protocol) { CreateApplicationDelegate local = CreateApplicationEvent; if (local != null) { local(protocol); } }
protected void Push(VooProtocol protocol) { Console.WriteLine("Application: Push(VooProtocol protocol)"); VooFile file = new VooFile(protocol.Source, protocol.Destination, protocol.Get("from"), protocol.Get("to"), Convert.ToInt64(protocol.Get("size"))); Console.WriteLine("Application: Push from = '{0}', to = '{1}', size = '{2}'", file.From, file.To, file.Size); pushes.Add(file); }
protected void RegisterUser(VooProtocol protocol) { Console.WriteLine("Application: RegisterUser(VooProtocol protocol)"); User user = new User(protocol.Get("username"), protocol.Get("password")); Console.WriteLine("Application: RegisterUser -> username = '******', password = '******'", user.UserName, user.Password); users.Add(user); }
public void RemoveApplication(VooProtocol protocol) { RemoveApplicationDelegate local = RemoveApplicationEvent; if (local != null) { local(protocol); } }
protected void UnRegisterUser(VooProtocol protocol) { Console.WriteLine("Application: UnRegisterUser(VooProtocol protocol)"); User user = FindUser(protocol.Get("username"), protocol.Get("password"), true); if (user != null) { Console.WriteLine("Application: UnRegisterUser -> username = '******', password = '******'", user.UserName, user.Password); users.Remove(user); Console.WriteLine("Application: UnRegisterUser -> Done."); } }
public void UnRegisterUser(VooProtocol protocol) { UnRegisterUserDelegate local = UnRegisterUserEvent; if (local != null) { local(protocol); } }
private VooFile FindPushes(VooProtocol protocol) { return FindFile(protocol, pushes); }
protected void BeginSession(VooProtocol protocol) { Console.WriteLine("Application: BeginSession(VooProtocol protocol)"); machine = protocol.Get("machine"); Console.WriteLine("Application: BeginSession -> machine is {0}.", machine); // Store last machine. if (currentUser != null && !String.IsNullOrEmpty(machine)) { sessions.Add(machine); Console.WriteLine("Application: BeginSession -> Add machine('{0}') to session.", machine); Console.WriteLine("Application: BeginSession -> Done.", machine); } }
public void ReceiveData(VooProtocol protocol) { // Console.WriteLine("Application: ReceiveData(VooProtocol protocol)"); VooFile file = FindPushes(protocol); if (file != null) { if (file.Collect(protocol.RawData)) { Console.WriteLine("Application ReceiveData -> file is downloaded."); pushes.Remove(file); } } else { Console.WriteLine(protocol.RawData); } }
protected void EndSession(VooProtocol protocol) { Console.WriteLine("Application: EndSession(VooProtocol protocol)"); machine = protocol.Get("machine"); Console.WriteLine("Application: EndSession -> Remove machine('{0}') from sessions.", machine); if (!String.IsNullOrEmpty(machine) && sessions.Count > 0) { sessions.Remove(machine); machine = null; Console.WriteLine("Application: EndSession -> Done.", machine); } }