public FileTransferInfo(FileTransfer.Modes mode, string key, string userKey, string userName, string address, string fileName, string fileSize) { Mode = mode; Key = key; UserKey = userKey; UserName = userName; Address = address; FileName = fileName; FileSize = fileSize; }
/// <summary> /// Send the TcpClient obtained when a connection is established to the correct /// File Transfer control. /// </summary> /// <param name="tcpClient"></param> /// <param name="key"></param> /// <param name="mode"></param> private void SetTcpClient(TcpClient tcpClient, string key, FileTransfer.Modes mode) { // Find the File Transfer control with the matching key and transfer mode. // Set the supplied TcpClient as the control's Tcp Client. foreach (FileTransferControl fileTransferControl in fileTransferList) { if (fileTransferControl.Key.Equals(key) && fileTransferControl.Mode == mode) { fileTransferControl.SetTcpClient(tcpClient); break; } } }
/// <summary> /// Add a new File Transfer control to the form. A connection is established between /// the client and server. Depending on the transfer mode, the local machine acts as /// a server or a client. /// </summary> /// <param name="mode">The transfer mode. Can be Send or Receive.</param> /// <param name="remoteUserName">Remote user's name.</param> /// <param name="remoteAddress">IP address of remote user.</param> /// <param name="key">Unique key for this file transfer.</param> /// <param name="fileName">Name of file to be sent/received.</param> /// <param name="fileSize">Size of the file.</param> public void AddFileTransfer(FileTransfer.Modes mode, string remoteUserName, string remoteAddress, string key, string fileName, string fileSize) { // Create a new File Transfer control and set its properties. FileTransferControl fileTransferControl = null; try { fileTransferControl = new FileTransferControl(mode, key, bAutoReceiveFile); fileTransferControl.UserName = remoteUserName; fileTransferControl.FileName = fileName; fileTransferControl.FileSize = long.Parse(fileSize); // This will force the system to create a handle for the control. IntPtr dummy = fileTransferControl.Handle; fileTransferControl.Selected += new FileTransferControl.SelectedEventHandler(FileTransferControl_Selected); fileTransferControl.MouseClick += new FileTransferControl.MouseClickEventHandler(FileTransferControl_MouseClick); fileTransferControl.Notify += new FileTransferControl.NotifyEventhandler(FileTransferControl_Notify); fileTransferControl.LayoutChanged += new FileTransferControl.LayoutChangedEventHandler(FileTransferControl_LayoutChanged); fileTransferControl.InitControl(); // Add the control to the top of the File transfer list. fileTransferList.Insert(0, fileTransferControl); if (mode == FileTransfer.Modes.Send) { ShowWindow(false, false); BeginAccept(key); } else { ShowWindow(bFileToForeground, false); BeginConnect(key, remoteAddress); } // Update the panel's controls. PopulateTransferList(0); // Set the UI theme. SetTheme(Properties.Settings.Default.UseThemes, Properties.Settings.Default.ThemeFile); // Make the new control the selected control. SelectControl(fileTransferControl); } catch (Exception ex) { fileTransferControl.Dispose(); } }
public FileTransferControl(FileTransfer.Modes mode, string key, bool autoReceive) { this.key = key; this.mode = mode; this.bAutoReceive = autoReceive; this.bCancelTransfer = false; this.isSelected = false; InitializeComponent(); InitUI(); foreach (Control control in tableLayoutPanel.Controls) { control.MouseDown += new MouseEventHandler(FileTransferControl_MouseDown); control.MouseClick += new MouseEventHandler(FileTransferControl_MouseClick); if (control is Label) { control.MouseDoubleClick += new MouseEventHandler(FileTransferControl_MouseDoubleClick); } } }