Ejemplo n.º 1
0
        /// <summary>
        /// Handle & execute a command
        /// </summary>
        /// <param name="c"></param>
        /// <param name="client"></param>
        public static void Handle(Command c, TcpClient client)
        {
            switch (c.Type)
            {
            case CommandType.Transfer:
                Log.Command(c);

                foreach (string path in c.Files)
                {
                    Console.WriteLine(path);
                }

                break;

            case CommandType.Synchronize:


                break;

            case CommandType.RsyncStream:

                if (c.Stream.type == StreamType.Signature)
                {
                    // Display
                    Log.Command(c);
                    Log.Stream(c.Stream);

                    // Generate delta
                    MemoryStream deltaStream  = RsyncOps.GenerateDelta(c.Stream.stream, c.Stream.relativePath);
                    RsyncStream  rs           = new RsyncStream(StreamType.Delta, deltaStream, c.Stream.relativePath);
                    Command      replyCommand = new Command(CommandType.RsyncStream, c.Source.ToString());
                    replyCommand.AddStream(rs);

                    // Send delta back to source
                    CommandHandler.Send(replyCommand, client, c.Seq++);
                }
                else if (c.Stream.type == StreamType.Delta)
                {
                    // Display
                    Log.Command(c);
                    Log.Stream(c.Stream);

                    // Patch delta to file
                }
                else
                {
                    Log.Error(new Error(new Exception(), "Recieved unknown rsync stream type"));
                }

                break;

            default:
                Log.Command(c);
                break;
            }
        }
Ejemplo n.º 2
0
 public void AddStream(RsyncStream rs)
 {
     Stream = rs;
     Type   = CommandType.RsyncStream;
 }