Example #1
0
 /// <summary>
 /// Use always this method to create a new command
 /// </summary>
 /// <param name="id"></param>
 /// <param name="username"></param>
 /// <param name="typ"></param>
 /// <param name="filename"></param>
 /// <param name="parameter"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public Command createCommand(int id, string username, int typ, string filename, string parameter, string data)
 {
     Command nCommand = new Command();
     nCommand.Id = id;
     nCommand.Username = markSpecialCharacters(username);
     nCommand.Typ = typ;
     nCommand.Filename = markSpecialCharacters(filename);
     nCommand.Parameter = markSpecialCharacters(parameter);
     nCommand.Data = markSpecialCharacters(data);
     return nCommand;
 }
Example #2
0
 /// <summary>
 /// Use this method to extract commands.
 /// Be careful by using this method.. if you want to send this extracted command.. you have to mark all characters..
 /// </summary>
 /// <param name="strCommand"></param>
 /// <returns></returns>
 public Command extractCommandFromStr(String strCommand)
 {
     char[] splitsCharacters = new char[] { ';', '{', '}' };
     Command nCommand = new Command();
     String[] commandParts = strCommand.Split(splitsCharacters);
     if(commandParts == null ||commandParts.Length < COMMAND_PARTS || commandParts.Length > COMMAND_PARTS)
     {
         return null;
     }
     try {
         for (int i = 0; i < commandParts.Length; i++)
         {
             switch (i)
             {
                 case 0:
                     //ID
                     nCommand.Id = Int32.Parse(commandParts[i].Substring(1, commandParts.Length));
                     break;
                 case 1:
                     //USERNAME
                     nCommand.Username = commandParts[i];
                     nCommand.Username = unmarkSpecialCharacters(nCommand.Username);
                     break;
                 case 2:
                     //TYP
                     nCommand.Typ = Int32.Parse(commandParts[i]);
                     break;
                 case 3:
                     //FILENAME
                     nCommand.Filename = commandParts[i];
                     nCommand.Filename = unmarkSpecialCharacters(nCommand.Filename);
                     break;
                 case 4:
                     //PARAMETER
                     nCommand.Parameter = commandParts[i];
                     nCommand.Parameter = unmarkSpecialCharacters(nCommand.Parameter);
                     break;
                 case 5:
                     //DATA
                     nCommand.Data = commandParts[i].Substring(0, commandParts.Length - 1);
                     nCommand.Data = unmarkSpecialCharacters(nCommand.Data);
                     break;
             }
         }
     }
     catch(Exception ex)
     {
         return null;
     }
     return nCommand;
 }
Example #3
0
 /// <summary>
 /// This method sends the response of the request command
 /// </summary>
 /// <param name="ResponseCommand"></param>
 public void sendResponseCommand(Command ResponseCommand)
 {
     CommandFactory cmdFactory = new CommandFactory();
     //To be sure that cmd is really marked..
     ResponseCommand = cmdFactory.markAllSpecialCharacters(ResponseCommand);
     this.server.Server.Send(Encoding.ASCII.GetBytes(ResponseCommand.toString()));
 }
Example #4
0
 public Command markAllSpecialCharacters(Command cmd)
 {
     cmd.Username = markSpecialCharacters(cmd.Username);
     cmd.Filename = markSpecialCharacters(cmd.Filename);
     cmd.Parameter = markSpecialCharacters(cmd.Parameter);
     cmd.Data = markSpecialCharacters(cmd.Data);
     return cmd;
 }