示例#1
0
 public ClientSession(Socket socket, MonoDebugServer server)
 {
     Server = server;
     if (socket != null)
     {
         remoteEndpoint = ((IPEndPoint)socket.RemoteEndPoint).Address;
     }
     RootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "MonoToolsServer");
     if (remoteEndpoint != null)
     {
         RootPath = Path.Combine(RootPath, remoteEndpoint.ToString());
     }
     communication          = new TcpCommunication(socket, CanCompress, Roles.Server, IsLocal, Password, RootPath);
     communication.Progress = progress => {
         const int Width = 60;
         Console.CursorLeft = 0;
         var n         = (int)(Width * progress + 0.5);
         var p         = ((int)(progress * 100 + 0.5)).ToString() + "%";
         var t         = (Width - p.Length) / 2;
         var backColor = Console.BackgroundColor;
         for (int i = 0; i < Width; i++)
         {
             Console.BackgroundColor = i < n ? ConsoleColor.DarkGreen : ConsoleColor.DarkGray;
             Console.Write((i < t || i >= t + p.Length) ? ' ' : p[i - t]);
         }
         Console.BackgroundColor = backColor;
     };
 }
示例#2
0
 public void SetSecurityToken(TcpCommunication con)
 {
     if (con.Role == Roles.Client && !string.IsNullOrEmpty(con.Password))
     {
         SecurityToken = Cryptography.Encrypt((((IPEndPoint)con.socket.LocalEndPoint).Address).ToString(), con.Password);
     }
 }
示例#3
0
        public void Send(TcpCommunication connection)
        {
            RelativePaths();
            con    = connection;
            mode   = StreamModes.Write;
            stream = connection.Stream;
            var w = connection.writer;

            System.Diagnostics.Debugger.Log(1, "", " ");
            long position = 0;

            foreach (var file in EnumerateFiles())
            {
                if (!string.IsNullOrEmpty(file.Name))
                {
                    w.Write(file.Name);
                    var comp = NeedsCompression(connection, file.Name);
                    w.Write(comp);
                    w.Write((Int64)file.Content.Length);
                    Stream writer;
                    if (comp)
                    {
                        writer = new DeflateStream(stream, CompressionLevel.Fastest, true);
                    }
                    else
                    {
                        writer = stream;
                    }
                    file.Content.CopyTo(writer, pos => Progress(((double)(position + pos)) / TotalSize));
                    position += file.Content.Length;
                }
            }
            w.Write("");
        }
示例#4
0
 public void Send(TcpCommunication con)
 {
     if (!IsLocal)
     {
         Files.Progress = con.Progress;
         Files.Send(con);
     }
 }
示例#5
0
 public void Receive(TcpCommunication con)
 {
     if (!IsLocal)
     {
         MonoDebugServer.logger.Info("Receiving content:");
         RootPath       = con.RootPath;
         Files.Progress = con.Progress;
         Files.Receive(con);
     }
     else
     {
         RootPath = LocalPath;
     }
     WorkingDirectory = WorkingDirectory ?? RootPath;
     AbsolutePaths();
 }
示例#6
0
 public bool CheckSecurityToken(TcpCommunication con)
 {
     if (con.Role == Roles.Server && !string.IsNullOrEmpty(con.Password))
     {
         if (string.IsNullOrEmpty(SecurityToken))
         {
             return(false);
         }
         try {
             var ip = Cryptography.Decrypt(SecurityToken, con.Password);
             return(ip == ((IPEndPoint)con.socket.RemoteEndPoint).Address.ToString());
         } catch {
             return(false);
         }
     }
     return(true);
 }
示例#7
0
        public void Receive(TcpCommunication connection)
        {
            ClearRoot();
            AbsolutePaths();
            con    = connection;
            stream = connection.Stream;
            long position = 0;

            foreach (var file in EnumerateFiles())               // save files contents
            {
                var path = Path.Combine(RootPath, file.Name);
                var dir  = Path.GetDirectoryName(path);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                using (var w = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) {
                    file.Content.CopyTo(w, pos => Progress(((double)(position + pos)) / TotalSize));
                    position += w.Length;
                }
            }
            Console.WriteLine();
        }
示例#8
0
 bool NeedsCompression(TcpCommunication connection, string file)
 {
     return(connection.Compressed && Compressed.Contains(Path.GetExtension(file)));
 }