Exemplo n.º 1
0
 private void radioTCPv5_CheckedChanged(object sender, EventArgs e)
 {
     if (radioTCPv5.Checked == true)
     {
         this.tf = new TransferFile(new TransferTCPv5());
         this.tf.attach(new ConsoleObserver());
         lblStatus.Text     = "Status: Selected TCPv5";
         tbFileName.Enabled = false;
     }
 }
Exemplo n.º 2
0
        // TODO:
        // add progress bar for file transfer


        public FileTransfer()
        {
            LoginForm loginForm = new LoginForm();
            var       result    = loginForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                string name = loginForm.Username;
                mPnrpManager = new PnrpManager();

                mPnrpThread = new Thread(delegate()
                {
                    mPnrpManager.registerPeerName(name);
                });
                mPnrpThread.Start();

                //--------------------------
                InitializeComponent();

                string currentDir = Directory.GetCurrentDirectory();
                tbSaveFolder.Text = currentDir;

                tbReceiveIP.Text   = getLocalIpAddress();
                tbReceivePort.Text = "8080";

                tbSendIP.Text   = getLocalIpAddress();
                tbSendPort.Text = "8080";

                // Set Transfer file protocol
                tf = new TransferFile(new TransferTCPv4());

                // attach IObservable interface to monitor
                tf.attach(new ConsoleObserver());
                lblStatus.Text     = "Status: Selected TCPv4";
                tbFileName.Enabled = false;

                // a notify icon in the corner
                FieldInfo iconField = typeof(Form).GetField("defaultIcon", BindingFlags.NonPublic | BindingFlags.Static);
                Icon      myIcon    = (Icon)iconField.GetValue(iconField);
                //notifyicon = notifyIcon1;
                notifyIcon1.Text    = "File Transfer App";
                notifyIcon1.Visible = true;
                //notifyicon.BalloonTipClicked += notifyicon_BalloonTipClicked;
                notifyIcon1.Icon = myIcon;

                // use events
                //FileTransferEvents.downloaded += FileTransferEvents_downloaded;
                FileTransferEvents.downloadComplete += FileTransferEvents_downloadComplete;
                FileTransferEvents.progress         += FileTransferEvents_progress;
                FileTransferEvents.speedChange      += FileTransferEvents_speedChange;
                FileTransferEvents.transferStarted  += FileTransferEvents_transferStarted;
            }
        }