Exemplo n.º 1
0
        public void ReciveNewFile(Socket reciveConnection, string fileTransferId, bool viaServer)
        {
            if(viaServer)
            {
                byte [] byteBuffer = Encoding.UTF8.GetBytes("FILE_TRANSFER_ID " + fileTransferId + "\n\r");
                reciveConnection.Send(byteBuffer, 0, byteBuffer.Length, SocketFlags.None);
            }

            ReciveFile reciveFile = new ReciveFile(reciveConnection, fileTransferId);
            reciveFile.SendFileChangeEvent += new DGP_Messenger.ReciveFile.SendFileStatus(reciveFile_SendFileChangeEvent);

            this.Invoke(new NewActivityDelegate(this.NewActivity), new object [] { reciveFile});
            //	this.NewActivity(reciveFile);
        }
Exemplo n.º 2
0
        private void linkLabel_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                LinkLabel lb = sender as LinkLabel;
                Activity  ac = listBox1.Items[i] as Activity;

                if (LinkLabel.ReferenceEquals(lb, ac.linkLabel))
                {
                    if (ac.TransferState == TransferStatus.CONFIRM_RECIVE)
                    {
                        FileInfo fi = null;
                        try
                        {
                            bool gotFile = true;
                            do
                            {
                                saveFileDialog.FileName = ac.fileTransfer.FileName;
                                DialogResult fileDialogResult = saveFileDialog.ShowDialog(this);

                                if (fileDialogResult == DialogResult.OK)
                                {
                                    fi = new FileInfo(saveFileDialog.FileName);
                                    if (fi.Exists)
                                    {
                                        bool canContinue;
                                        if (fi.Length < ac.fileTransfer.FileSize)
                                        {
                                            canContinue = true;
                                        }
                                        else
                                        {
                                            canContinue = false;
                                        }

                                        ResumeDownloadDialog rs     = new ResumeDownloadDialog(fi.Name, canContinue);
                                        DialogResult         result = rs.ShowDialog();

                                        /*MessageBox.Show("Filen " + fi.Name + " finns redan. Men har inte blivit helt nerladdad!\n"+
                                         *      "Vill du försöka fortsätta nerladdningen där den slutade sist? \n" +
                                         *      "Om inte så kommer nerladdningen börja om från början och filen kommer skrivas över!",
                                         *      "File Prompt", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);*/

                                        if (result == DialogResult.OK)
                                        {
                                            ReciveFile rc = (ReciveFile)ac.fileTransfer;
                                            rc.ResumeTransfer(fi.FullName, fi.Length);
                                        }
                                        else if (result == DialogResult.Abort)
                                        {
                                            fi.Delete();
                                            MessageBox.Show("File Deleted");

                                            ReciveFile rc = (ReciveFile)ac.fileTransfer;
                                            rc.StartTransfer(fi.FullName);
                                        }
                                        else if (result == DialogResult.Cancel)
                                        {
                                            //MessageBox.Show("Leta ny fil");
                                            gotFile = false;
                                        }
                                    }
                                    else
                                    {
                                        ReciveFile rc = (ReciveFile)ac.fileTransfer;
                                        rc.StartTransfer(saveFileDialog.FileName);
                                    }
                                }
                                else if (fileDialogResult == DialogResult.Cancel)
                                {
                                    /// Didnt get the file, but do nothing
                                    gotFile = true;
                                }
                            }while(gotFile != true);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Transfer Error");
                            if (ac != null)
                            {
                                ac.fileTransfer.close();
                            }
                        }

                        /*finally
                         * {
                         *
                         * }*/
                    }
                    else if (ac.TransferState != TransferStatus.FILE_RECIVING)
                    {
                        listBox1.Items.Remove(ac);
                        listBox1.Controls.Remove(lb);
                    }
                    else
                    {
                        ac.fileTransfer.close();
                        lb.Text = "Ta Bort";
                    }
                    listBox1.Refresh();
                }
            }
        }