예제 #1
0
        public static void HandleDoUploadFile(FileTransferChunk command, Networking.Client client)
        {
            try
            {
                if (CanceledFileTransfers.ContainsKey(command.Id))
                {
                    return;
                }

                if (command.Chunk.Offset == 0 && File.Exists(command.FilePath))
                {
                    NativeMethods.DeleteFile(command.FilePath); // delete existing file
                }
                using (var destFile = new FileSplit(command.FilePath, FileAccess.Write))
                {
                    destFile.WriteChunk(command.Chunk);
                }
            }
            catch (Exception)
            {
                CanceledFileTransfers.Add(command.Id, "error");
                client.Send(new FileTransferCancel
                {
                    Id     = command.Id,
                    Reason = "Error writing file"
                });
            }
        }
예제 #2
0
 public static void HandleDoDownloadFileCancel(FileTransferCancel command, Networking.Client client)
 {
     if (!CanceledFileTransfers.ContainsKey(command.Id))
     {
         CanceledFileTransfers.Add(command.Id, "canceled");
         client.Send(new FileTransferCancel
         {
             Id     = command.Id,
             Reason = "Canceled"
         });
     }
 }
예제 #3
0
        public static void HandleDoDownloadFile(FileTransferRequest command, Networking.Client client)
        {
            new Thread(() =>
            {
                LimitThreads.WaitOne();
                try
                {
                    using (var srcFile = new FileSplit(command.RemotePath, FileAccess.Read))
                    {
                        foreach (var chunk in srcFile)
                        {
                            if (!client.Connected || CanceledFileTransfers.ContainsKey(command.Id))
                            {
                                break;
                            }

                            // blocking sending might not be required, needs further testing
                            client.SendBlocking(new FileTransferChunk
                            {
                                Id       = command.Id,
                                FilePath = command.RemotePath,
                                FileSize = srcFile.FileSize,
                                Chunk    = chunk
                            });
                        }
                    }
                }
                catch (Exception)
                {
                    CanceledFileTransfers.Add(command.Id, "error");
                    client.Send(new FileTransferCancel
                    {
                        Id     = command.Id,
                        Reason = "Error reading file"
                    });
                }
                LimitThreads.Release();
            }).Start();
        }