public async Task UploadPackageAsync(RequestPackage package) { if (package == null) throw new ArgumentNullException("package"); var method = UpdateMethod.UploadPackage; var context = method.ToString(); this.LogRequest(context); await this.TransferHandler.WriteAsync(this.Id, (byte)method); var data = Utilities.Concat(package.Header.NetworkBuffer, package.Data); this.LogRequest(data, context); await this.TransferHandler.WriteAsync(data); }
private async Task SavePackageAsync(ClientPlatform platform, RequestPackage package) { using (var fs = File.OpenWrite(_paths[(int)platform])) { var buffer = MemoryPool.Get80KBuffer(); try { using (var ms = new MemoryStream(package.Data)) { int readBytes; while ((readBytes = ms.Read(buffer, 0, buffer.Length)) != 0) { await fs.WriteAsync(buffer, 0, readBytes); } } } finally { MemoryPool.Return80KBuffer(buffer); } } await this.SavePackageConfigAsync(); }
private async Task UploadPackageAsync(ITransferHandler handler) { using (var ms = new MemoryStream(await handler.ReadAsync())) { var header = new RequestHeader().Setup(ms); var packageBytes = new byte[ms.Length - ms.Position]; await ms.ReadAsync(packageBytes, 0, packageBytes.Length); var package = new RequestPackage(header, packageBytes); _packages[(int)package.Header.ClientPlatform] = package; await this.SavePackageAsync(package.Header.ClientPlatform, package); } }