private void button1_Click(object sender, EventArgs e)
 {
     if (dataGridView1.Rows.Count > 0 && IsValidIP(textBox1.Text) && textBox2.Text.Length > 0)
     {
         TransferNamespace.FilesTransfer transfer = new TransferNamespace.FilesTransfer() { Action = FileTransferring.TransferNamespace.Action.Invite };
         transfer.Files = new List<TransferNamespace.Transfer>();
         foreach (DataRow i in files.Rows)
         {
             if (((EDataType)i["Type"]) == EDataType.Folder)
             {
                 if (!Directory.Exists((string)i["Path"])) continue;
                 DirectoryInfo dir = new DirectoryInfo((string)i["Path"]);
                 string root = dir.Parent.FullName;
                 string name = dir.Name;
                 transfer.Files.AddRange(RecurseFolder(root, @"\" + name));
             }
             else
             {
                 if (!File.Exists((string)i["Path"])) continue;
                 FileInfo file = new FileInfo((string)i["Path"]);
                 TransferNamespace.Transfer t = new TransferNamespace.Transfer();
                 t.Catalog = "<root>";
                 t.Id = Guid.NewGuid().ToString() + Guid.NewGuid().ToString();
                 t.Name = file.Name;
                 t.FullPath = file.FullName;
                 t.Length = file.Length;
                 transfer.Files.Add(t);
             }
         }
         transfer.Name = textBox2.Text;
         TransferNamespace.TransferClient client = new FileTransferring.TransferNamespace.TransferClient(HelpClass.ConfigureEndpoint(), new EndpointAddress("net.tcp://" + textBox1.Text + ":7634/ClientTransferring/tcp"));
         try
         {
             client.Open();
         }
         catch { MessageBox.Show("Can not connect to the remote address!"); }
         FileProgressForm progress = new FileProgressForm(client,0);
         progress.BeginSend(transfer);
         try
         {
             progress.Show(this);
         }
         catch { }
     }
 }
Пример #2
0
 public IEnumerable<object> SendQuery(string ip, FilesTransfer transfer, int sport)
 {
     int port = 0;
     switch (transfer.Action)
     {
         case Action.Invite:
             {
                 port = HelpClass.GetAvailablePort();
                     ThreadStart start = delegate
                     {
                         form = new FileProgressForm(null, port);
                         form.sport = sport;
                         form.Show();
                         form.GetThread = new Thread(new ParameterizedThreadStart(form.GetInvoke));
                         form.GetThread.Start(transfer);
                     };
                     HelpClass.Form.BeginInvoke(start);
                     break;
             }
         default:
             {
                 return new List<object>() { (int)InviteRusult.Busy, 0 };
             }
     }
     return new List<object>() { (int)InviteRusult.Ok, port };
 }