public void FileUpload(FileInfo file, string filename,SoftwareRepositoryService.RepositoryServiceClient client) { FileStream fs = null; try { bool firsttime = true; fs = File.Open(file.FullName, FileMode.Open, FileAccess.Read); int bytesRead = 0; //int count = 0; while (true) { long BlockSize = 5000; long Remainder = (int)(fs.Length - fs.Position); if (Remainder == 0) break; long size = Math.Min(BlockSize, Remainder); byte[] block = new byte[size]; bytesRead = fs.Read(block, 0, block.Length); client.UploadPackages(filename, block, firsttime); firsttime = false; } fs.Close(); return; } catch { if (fs != null) fs.Close(); return; } }
public void DownloadPackages(string fname,string dpath,SoftwareRepositoryService.RepositoryServiceClient client) { try { FileStream fs = new FileStream(dpath + "\\" + fname.Split('-')[0], FileMode.Create, FileAccess.Write); client.InitiateDownload(fname); byte[] block; while (true) { block = client.DownloadPackage(); if (block == null) break; fs.Write(block, 0, block.Length); } client.CloseDownload(); fs.Close(); } catch { return; } }