static void Main(string[] args) { Console.ReadLine(); Console.WriteLine(@"Upload video"); using (var client = new TcpClient(@"127.0.0.1", 11111)) { var handler = new TransferHandler(client.GetStream(), new byte[16 * 1024]); //var config = new LogConfig(new RequestHeader(ClientPlatform.WinMobile, new Version(0, 0, 0, 0), string.Empty, string.Empty), Category.Logs, @"C:\Temp\"); //new LogsClientHandler(2, handler).ConfigureAsync(config).Wait(); var path = @"C:\Users\bg900343\Desktop\DEV-B318.wmv"; var clientFile = new ClientFile(Path.GetFileName(path), File.ReadAllBytes(path)); var requestHeader = new RequestHeader(ClientPlatform.WinMobile, new Version(0, 0, 0, 0), string.Empty, string.Empty); new LogsClientHandler(2, handler).UploadFilesAsync(requestHeader, new List<ClientFile> { clientFile }).Wait(); handler.CloseAsync().Wait(); } Console.WriteLine(@"Done"); Console.ReadLine(); }
private async void UploadTapped(object sender, TappedRoutedEventArgs e) { var btn = (sender as Button); if (btn != null) { var ctx = btn.DataContext as LogCategoryViewModel; if (ctx != null) { btn.IsEnabled = false; try { var picker = new FileOpenPicker(); picker.FileTypeFilter.Add(@".wmv"); var file = await picker.PickSingleFileAsync(); if (file != null) { var fileSize = (await file.GetBasicPropertiesAsync()).Size; var data = new byte[fileSize]; var buffer = new byte[16 * 1024]; using (var ms = new MemoryStream(data)) { using (var s = (await file.OpenReadAsync()).AsStreamForRead()) { int readBytes; while ((readBytes = await s.ReadAsync(buffer, 0, buffer.Length)) != 0) { await ms.WriteAsync(buffer, 0, readBytes); } } } var clientFile = new ClientFile(file.Name, data); using (var socket = new StreamSocket()) { await socket.ConnectAsync(new HostName(@"127.0.0.1"), @"11111"); var handler = new WinRtTransferHandler(socket); var requestHeader = new RequestHeader(ctx.Platform, new Version(0, 0, 0, 0), string.Empty, string.Empty); await new LogsClientHandler(2, handler).UploadFilesAsync(requestHeader, new List<ClientFile> { clientFile }); await handler.CloseAsync(); } } } catch (Exception ex) { } finally { btn.IsEnabled = true; } } } }
public async Task<bool> UploadDatabaseAsync(RequestHeader header, ClientFile database) { if (header == null) throw new ArgumentNullException("header"); if (database == null) throw new ArgumentNullException("database"); return await Upload(header, new[] { database }, LogMethod.UploadDatabase); }