public Windows.Foundation.IAsyncOperationWithProgress <IBuffer, uint> ReadAsync(IBuffer buffer, uint count, InputStreamOptions options) { return(System.Runtime.InteropServices.WindowsRuntime.AsyncInfo.Run <IBuffer, uint>((token, progress) => { return Task.Run(() => { System.Diagnostics.Debug.WriteLine("ReadAsync for: " + count.ToString() + " bytes - Stream Size: " + internalStream.Size + " Stream position: " + internalStream.Position); // If first Read call if ((ReadDataIndex == 0) && (internalStream.Size > count)) { // First dummy read of the header inputStream = internalStream.GetInputStreamAt(wavHeaderLength); uint currentDataLength = (uint)(internalStream.Size - wavHeaderLength); if (currentDataLength > 0) { data.length = currentDataLength; var WAVHeaderBuffer = CreateWAVHeaderBuffer(data.length); if (WAVHeaderBuffer != null) { int headerLen = WAVHeaderBuffer.Length; if (count >= headerLen) { byte[] updatedBuffer = new byte[count]; WAVHeaderBuffer.CopyTo(updatedBuffer.AsBuffer()); if (count > headerLen) { //fill buffer inputStream.ReadAsync(updatedBuffer.AsBuffer((int)headerLen, (int)(count - headerLen)), (uint)(count - headerLen), options).AsTask().Wait(); } buffer = updatedBuffer.AsBuffer(); ReadDataIndex += buffer.Length; System.Diagnostics.Debug.WriteLine("ReadAsync return : " + buffer.Length.ToString() + " bytes - Stream Size: " + internalStream.Size + " Stream position: " + internalStream.Position); progress.Report((uint)buffer.Length); return updatedBuffer.AsBuffer(); } } } } else { inputStream.ReadAsync(buffer, count, options).AsTask().Wait(); ReadDataIndex += buffer.Length; System.Diagnostics.Debug.WriteLine("ReadAsync return : " + buffer.Length.ToString() + " bytes - Stream Size: " + internalStream.Size + " Stream position: " + internalStream.Position); progress.Report((uint)buffer.Length); return buffer; } return null; }); })); }
private SpeechToTextMainStream(ulong MaxSizeInBytes = 0, uint ThresholdDuration = 0, uint ThresholdLevel = 0) { tresholdDuration = ThresholdDuration; thresholdDurationInBytes = 0; thresholdLevel = ThresholdLevel; maxSize = MaxSizeInBytes; thresholdStart = 0; thresholdEnd = 0; audioStream = null; internalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); inputStream = internalStream.GetInputStreamAt(0); audioQueue = new ConcurrentQueue <SpeechToTextAudioStream>(); }
private SpeechToTextAudioStream( uint Channels, uint SamplesPerSec, uint AvgBytesPerSec, uint BlockAlign, uint BitsPerSample, ulong AudioStart) { nChannels = Channels; nSamplesPerSec = SamplesPerSec; nAvgBytesPerSec = AvgBytesPerSec; nBlockAlign = BlockAlign; wBitsPerSample = BitsPerSample; audioStart = AudioStart; internalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); inputStream = internalStream.GetInputStreamAt(0); }
private async void Sck_MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args) { //[email protected]("Message received " + args); if (args.MessageType == SocketMessageType.Utf8) { Windows.Storage.Streams.DataReader messageReader = args.GetDataReader(); messageReader.UnicodeEncoding = UnicodeEncoding.Utf8; string messageString = messageReader.ReadString(messageReader.UnconsumedBufferLength); com.codename1.io.websocket.WebSocket.messageReceived(id, messageString); } else { Windows.Storage.Streams.IInputStream readStream = args.GetDataStream(); byte[] readBuffer = new byte[4096]; try { while (true) { if (sender != sck) { return; } IBuffer res = await readStream.ReadAsync(readBuffer.AsBuffer(), (uint)readBuffer.Length, 0); if (res.Length == 0) { return; } byte[] resArr = new byte[res.Length]; res.CopyTo(resArr); com.codename1.io.websocket.WebSocket.messageReceived(1, resArr); } } catch (Exception ex) { com.codename1.io.websocket.WebSocket.errorReceived(id, ex.Message, ex.HResult); } } }
public bool Start() { try { StreamSocketListener listener = new StreamSocketListener(); listener.BindServiceNameAsync("80").AsTask(); listener.ConnectionReceived += async(sender, args) => { StringBuilder request = new StringBuilder(); using (Windows.Storage.Streams.IInputStream input = args.Socket.InputStream) { byte[] data = new byte[BufferSize]; Windows.Storage.Streams.IBuffer buffer = data.AsBuffer(); uint dataRead = BufferSize; while (dataRead == BufferSize) { await input.ReadAsync(buffer, BufferSize, InputStreamOptions.Partial); request.Append(Encoding.UTF8.GetString(data, 0, data.Length)); dataRead = buffer.Length; } //In the future, maybe we parse the HTTP request and serve different HTML pages for now we just always push index.html } using (IOutputStream output = args.Socket.OutputStream) { using (System.IO.Stream response = output.AsStreamForWrite()) { string page = ""; var folder = Windows.ApplicationModel.Package.Current.InstalledLocation; // acquire file var file = await folder.GetFileAsync("index.html"); var readFile = await Windows.Storage.FileIO.ReadLinesAsync(file); foreach (var line in readFile) { page += line; } byte[] bodyArray = Encoding.UTF8.GetBytes(page); var bodyStream = new MemoryStream(bodyArray); //iCount++; var header = "HTTP/1.1 200 OK\r\n" + $"Content-Length: {bodyStream.Length}\r\n" + "Connection: close\r\n\r\n"; byte[] headerArray = Encoding.UTF8.GetBytes(header); await response.WriteAsync(headerArray, 0, headerArray.Length); await bodyStream.CopyToAsync(response); await response.FlushAsync(); } } }; return(true); } catch (Exception e) { return(false); } }
public async Task setupSocket() { #if !UNITY_EDITOR tcpClient = new Windows.Networking.Sockets.StreamSocket(); tcpClient.Control.NoDelay = false; tcpClient.Control.KeepAlive = false; tcpClient.Control.OutboundBufferSizeInBytes = 1500; while (!connected) { try { textOut("Connecting to " + targetIP + " " + targetPort); await tcpClient.ConnectAsync(new HostName(targetIP), "" + targetPort); textOut("Connected!"); outputStream = tcpClient.OutputStream; inputStream = tcpClient.InputStream; writer = new DataWriter(outputStream); reader = new DataReader(inputStream); reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; reader.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian; reader.InputStreamOptions = InputStreamOptions.Partial; connected = true; while (connected) { await reader.LoadAsync(8192); if (reader.UnconsumedBufferLength > 4) { textOut("Reading...."); int incomingSize = reader.ReadInt32(); if (incomingSize > 0 && incomingSize < 100000) { //await reader.LoadAsync((uint)incomingSize);//preloads the buffer with the data which makes the following not needed. while (reader.UnconsumedBufferLength < incomingSize) { System.Threading.Tasks.Task.Delay(100).Wait(); await reader.LoadAsync(8192); } textOut("Getting new Line!"); int packetType = reader.ReadInt32(); float r = reader.ReadSingle(); float g = reader.ReadSingle(); float b = reader.ReadSingle(); float a = reader.ReadSingle(); int count = reader.ReadInt32();// this is actually just for padding... float sw = reader.ReadSingle(); float ew = reader.ReadSingle(); byte[] packet = new byte[incomingSize - 36]; //reader.ReadBytes(packet); if (packetType == 4 && packet.Length > 0) { lrStruct l = new lrStruct { r = r, g = g, b = b, a = a, pc = count, sw = sw, ew = ew, verts = new Vector3[count] }; textOut("" + count + " " + r + " " + g + " " + b + " " + a + " " + sw + " " + ew + "\n" + "Count Suggested Bytes:" + (count * 4 * 3) + " Preloaded Package Size:" + packet.Length); for (int i = 0; i < count; i++)//Dan Simplified this. Probably not bugged. { l.verts[i] = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); } incomingLineRenderers.Enqueue(l); textOut("Line Renderer Enqueued"); } if (packetType == 5) { undoLineRenderer = true; } } else { //TODO Handle it. } } } //outputStream = await udpClient.GetOutputStreamAsync(new HostName(targetIP), "" + targetPort); } catch (Exception e) { Debug.LogError(e.ToString()); connected = false; socketStarted = false; return; } } #endif }
private async void OpenButton_Click(object sender, RoutedEventArgs e) { // Open a text file. Windows.Storage.Pickers.FileOpenPicker open = new Windows.Storage.Pickers.FileOpenPicker(); open.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary; open.FileTypeFilter.Add(".rtf"); open.FileTypeFilter.Add(".txt"); open.FileTypeFilter.Add(".dat"); //open.FileTypeFilter.Add(".doc"); Windows.Storage.StorageFile file = await open.PickSingleFileAsync(); if (file != null) { vMV.File = file; try { editor.Document.SetText(TextSetOptions.None, string.Empty); if (file.FileType == ".rtf" || file.FileType == ".dat") { // using (Windows.Storage.Streams.IRandomAccessStream randAccStream = // await file.OpenAsync(Windows.Storage.FileAccessMode.Read)) // { Windows.Storage.Streams.IInputStream windowsRuntimeStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); // Load the file into the Document property of the RichEditBox. // Stream managedStream = windowsRuntimeStream.AsStreamForRead(bufferSize: 100920); editor.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, windowsRuntimeStream.AsStreamForRead(bufferSize: 100920).AsRandomAccessStream()); // } } else { // editor.Document.BatchDisplayUpdates(); editor.Document.SetText(Windows.UI.Text.TextSetOptions.UnicodeBidi, await FileIO.ReadTextAsync(file)); // editor.Document.ApplyDisplayUpdates(); /* var buffer = await Windows.Storage.FileIO.ReadBufferAsync(file); * using (var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(buffer)) * { * MessageDialog messageDialog = new MessageDialog("hhh"); * await messageDialog.ShowAsync(); * //string text = dataReader.ReadString(buffer.Length); * editor.Document.SetText(Windows.UI.Text.TextSetOptions.None, dataReader.ReadString(buffer.Length)); * } */ } } catch (Exception) { ContentDialog errorDialog = new ContentDialog() { Title = "Ошибка открытия файла", Content = "Sorry, I couldn't open the file.", PrimaryButtonText = "Okей" }; await errorDialog.ShowAsync(); } } }
public Windows.Foundation.IAsyncOperationWithProgress <uint, uint> WriteAsync(IBuffer buffer) { return(System.Runtime.InteropServices.WindowsRuntime.AsyncInfo.Run <uint, uint>((token, progress) => { return Task.Run(() => { // If it's the first WriteAsync in the stream // the buffer should contains the WAV Header if ((internalStream.Size == 0) && (wavHeaderLength == 0)) { WriteDataIndex = 0; // Check header byte[] array = buffer.ToArray(); wavHeaderLength = ParseAndGetWAVHeaderLength(array); internalStream.WriteAsync(buffer).AsTask().Wait(); WriteDataIndex += buffer.Length; progress.Report((uint)(buffer.Length)); return (uint)(buffer.Length); } else { if (internalStream.Position != internalStream.Size) { System.Diagnostics.Debug.WriteLine("Warning WriteAsync: " + internalStream.Position.ToString() + "/" + internalStream.Size.ToString()); } ulong index = internalStream.Size; uint byteToWrite = buffer.Length; // System.Diagnostics.Debug.WriteLine("WriteAsync: " + buffer.Length.ToString() + " at position: " + internalStream.Position); internalStream.WriteAsync(buffer.ToArray(0, (int)byteToWrite).AsBuffer()).AsTask().Wait(); WriteDataIndex += buffer.Length; var byteArray = buffer.ToArray(); if (byteArray.Length >= 2) { var amplitude = Decode(byteArray).Select(Math.Abs).Average(x => x); if (AudioLevel != null) { this.AudioLevel(this, amplitude); } // Currently the level is too low if (thresholdDurationInBytes > 0) { if (audioStream == null) { if (internalStream.Size > thresholdDurationInBytes) { var readStream = internalStream.GetInputStreamAt(internalStream.Size - thresholdDurationInBytes); byte[] readBuffer = new byte[thresholdDurationInBytes]; readStream.ReadAsync(readBuffer.AsBuffer(), (uint)thresholdDurationInBytes, InputStreamOptions.None).AsTask().Wait(); var level = Decode(readBuffer).Select(Math.Abs).Average(x => x); if (level > thresholdLevel) { System.Diagnostics.Debug.WriteLine("Audio Level sufficient to start recording"); thresholdStart = WriteDataIndex - thresholdDurationInBytes; audioStream = SpeechToTextAudioStream.Create(nChannels, nSamplesPerSec, nAvgBytesPerSec, nBlockAlign, wBitsPerSample, thresholdStart); var headerBuffer = CreateWAVHeaderBuffer(0); if ((audioStream != null) && (headerBuffer != null)) { audioStream.WriteAsync(headerBuffer.AsBuffer()).AsTask().Wait(); audioStream.WriteAsync(readBuffer.AsBuffer()).AsTask().Wait(); } } } } else { audioStream.WriteAsync(buffer.ToArray(0, (int)byteToWrite).AsBuffer()).AsTask().Wait(); var readStream = internalStream.GetInputStreamAt(internalStream.Size - thresholdDurationInBytes); byte[] readBuffer = new byte[thresholdDurationInBytes]; readStream.ReadAsync(readBuffer.AsBuffer(), (uint)thresholdDurationInBytes, InputStreamOptions.None).AsTask().Wait(); var level = Decode(readBuffer).Select(Math.Abs).Average(x => x); if (level < thresholdLevel) { System.Diagnostics.Debug.WriteLine("Audio Level lower enough to stop recording"); thresholdEnd = WriteDataIndex; audioStream.Seek(0); var headerBuffer = CreateWAVHeaderBuffer((uint)(thresholdEnd - thresholdStart)); if (headerBuffer != null) { audioStream.WriteAsync(headerBuffer.AsBuffer()).AsTask().Wait(); } if (audioQueue != null) { audioStream.endIndex = thresholdEnd; audioQueue.Enqueue(audioStream); } if (BufferReady != null) { this.BufferReady(this); if (audioStream != null) { audioStream = null; } thresholdStart = 0; thresholdEnd = 0; } } } } } if (maxSize > 0) { // check maxSize if ((internalStream.Size > maxSize) && (audioStream == null)) { lock (maxSizeLock) { byte[] headerBuffer = null; if (wavHeaderLength > 0) { // WAV header present headerBuffer = new byte[wavHeaderLength]; inputStream = internalStream.GetInputStreamAt(0); inputStream.ReadAsync(headerBuffer.AsBuffer(), (uint)wavHeaderLength, InputStreamOptions.None).AsTask().Wait(); } seekOffset += (internalStream.Size - wavHeaderLength); internalStream.Dispose(); inputStream.Dispose(); internalStream = new Windows.Storage.Streams.InMemoryRandomAccessStream(); if (headerBuffer != null) { internalStream.WriteAsync(headerBuffer.AsBuffer()).AsTask().Wait(); } inputStream = internalStream.GetInputStreamAt(0); } } } if (internalStream.Position == internalStream.Size) { WriteDataIndex += buffer.Length; } progress.Report((uint)buffer.Length); return (uint)buffer.Length; } }); })); }
public async void setupSocket() { #if !UNITY_EDITOR tcpClient = new Windows.Networking.Sockets.StreamSocket(); tcpClient.Control.NoDelay = false; tcpClient.Control.KeepAlive = false; tcpClient.Control.OutboundBufferSizeInBytes = 1500; while (!connected) { try { await tcpClient.ConnectAsync(new HostName(targetIP), "" + targetPort); outputStream = tcpClient.OutputStream; inputStream = tcpClient.InputStream; writer = new DataWriter(outputStream); reader = new DataReader(inputStream); reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; reader.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian; reader.InputStreamOptions = InputStreamOptions.Partial; connected = true; while (connected) { await reader.LoadAsync(8192); if (reader.UnconsumedBufferLength > 4) { int incomingSize = reader.ReadInt32(); if (incomingSize > 0 && incomingSize < 100000) { while (reader.UnconsumedBufferLength < incomingSize) { System.Threading.Tasks.Task.Delay(100).Wait(); await reader.LoadAsync(8192); } int packetType = reader.ReadInt32(); float r = reader.ReadSingle(); float g = reader.ReadSingle(); float b = reader.ReadSingle(); float a = reader.ReadSingle(); int count = reader.ReadInt32(); float sw = reader.ReadSingle(); float ew = reader.ReadSingle(); byte[] packet = new byte[incomingSize - 36];// this differs from spatialmapvuforia if (packetType == 4 && packet.Length > 0) { lrStruct l = new lrStruct { r = r, g = g, b = b, a = a, pc = count, sw = sw, ew = ew, verts = new Vector3[count] }; for (int i = 0; i < count; i++)//Dan Simplified this. Probably not bugged. { l.verts[i] = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); } incomingLineRenderers.Enqueue(l); } if (packetType == 5) { undoLineRenderer = true; } } else { //TODO Handle it. } } } } catch (Exception e) { Debug.LogError(e.ToString()); connected = false; socketStarted = false; doReconnect = true; return; } } doReconnect = true; #endif }
public async Task setupSocket() { //udpClient = new DatagramSocket(); //udpClient.Control.DontFragment = true; tcpClient = new Windows.Networking.Sockets.StreamSocket(); //tcpClient.Control.OutboundBufferSizeInBytes = 1500; tcpClient.Control.NoDelay = false; tcpClient.Control.KeepAlive = false; tcpClient.Control.OutboundBufferSizeInBytes = 1500; while (!connected) { try { //await udpClient.BindServiceNameAsync("" + targetPort); await tcpClient.ConnectAsync(new HostName(targetIP), "" + targetPort); outputStream = tcpClient.OutputStream; inputStream = tcpClient.InputStream; writer = new DataWriter(outputStream); reader = new DataReader(inputStream); reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; reader.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian; reader.InputStreamOptions = InputStreamOptions.Partial; connected = true; //incomingBuffer = new byte[0]; /* * while (connected) * { * * if(reader.UnconsumedBufferLength>4) * { * * int incomingSize = reader.ReadInt32(); * if(incomingSize>0&&incomingSize < 100000) * { * await reader.LoadAsync((uint)incomingSize);//preloads the buffer with the data which makes the following not needed. * * * * int packetType = reader.ReadInt32(); * float r = reader.ReadSingle(); * float g = reader.ReadSingle(); * float b = reader.ReadSingle(); * float a = reader.ReadSingle(); * int count = reader.ReadInt32();// this is actually just for padding... * float sw = reader.ReadSingle(); * float ew = reader.ReadSingle(); * byte[] packet = new byte[incomingSize-32]; * reader.ReadBytes(packet); * if(packetType==4&&packet.Length>0) * { * lrStruct l = new lrStruct(); * l.r = r; * l.g = g; * l.b = b; * l.a = a; * l.pc = count; * l.sw = sw; * l.ew = ew; * l.verts = new Vector3[count]; * for(int i = 0; i < count; i++)//Dan actually wrote this one from scratch, so might be bugged. * { * l.verts[i]=new Vector3(BitConverter.ToSingle(packet, i*12+0), BitConverter.ToSingle(packet, i * 12 + 4), * BitConverter.ToSingle(packet, i * 12 + 8)); * } * incomingLineRenderers.Enqueue(l); * } * if (packetType == 5) * undoLineRenderer = true; * * * } * else * { * //TODO Handle it. * } * * } * * } */ } catch (Exception e) { Debug.Log(e.ToString()); return; } } }
/* #if !UNITY_EDITOR * public async Task HandleSocket() * { * * if(!socketStarted&&targetIPReady&&!connected&&!startConnect&&tcpClient==null) * { * tcpClient = new Windows.Networking.Sockets.StreamSocket(); * tcpClient.Control.NoDelay = false; * tcpClient.Control.KeepAlive = false; * tcpClient.Control.OutboundBufferSizeInBytes = 1500; * startConnect=true; * await tcpClient.ConnectAsync(new HostName(targetIP), "" + targetPort); * outputStream = tcpClient.OutputStream; * inputStream = tcpClient.InputStream; * writer = new DataWriter(outputStream); * reader = new DataReader(inputStream); * reader.InputStreamOptions = InputStreamOptions.Partial; * reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; * reader.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian; * connected = true; * } * * if(connected&&reader.UnconsumedBufferLength>4) * { * lengthOfNextPacket=reader.ReadInt32(); * } * if(lengthOfNextPacket>0&&reader.UnconsumedBufferLength>lengthOfNextPacket) * { * int packetType = reader.ReadInt32(); * float r = reader.ReadSingle(); * float g = reader.ReadSingle(); * float b = reader.ReadSingle(); * float a = reader.ReadSingle(); * int count = reader.ReadInt32();// this is actually just for padding... * float sw = reader.ReadSingle(); * float ew = reader.ReadSingle(); * byte[] packet = new byte[lengthOfNextPacket-32]; * reader.ReadBytes(packet); * if(packetType==4&&packet.Length>0) * { * lrStruct l = new lrStruct(); * l.r = r; * l.g = g; * l.b = b; * l.a = a; * l.pc = count; * l.sw = sw; * l.ew = ew; * l.verts = new Vector3[count]; * for(int i = 0; i < count; i++)//Dan actually wrote this one from scratch, so might be bugged. * { * l.verts[i]=new Vector3(BitConverter.ToSingle(packet, i*12+0), BitConverter.ToSingle(packet, i * 12 + 4), * BitConverter.ToSingle(packet, i * 12 + 8)); * } * incomingLineRenderers.Enqueue(l); * } * if (packetType == 5) * undoLineRenderer = true; * lengthOfNextPacket=-1; * } * * * * * * } #endif */ #if !UNITY_EDITOR private async void _streamSocket_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args) { using (IInputStream inStream = args.Socket.InputStream) { reader = new DataReader(inStream); reader.InputStreamOptions = InputStreamOptions.Partial; outputStream = args.Socket.OutputStream; inputStream = inStream; writer = new DataWriter(outputStream); connected = true; while (connected) { await reader.LoadAsync(8192); if (reader.UnconsumedBufferLength > 4) { int incomingSize = reader.ReadInt32(); if (incomingSize > 0 && incomingSize < 100000) { await reader.LoadAsync((uint)incomingSize); //preloads the buffer with the data which makes the following not needed. int packetType = reader.ReadInt32(); float r = reader.ReadSingle(); float g = reader.ReadSingle(); float b = reader.ReadSingle(); float a = reader.ReadSingle(); int count = reader.ReadInt32();// this is actually just for padding... float sw = reader.ReadSingle(); float ew = reader.ReadSingle(); byte[] packet = new byte[incomingSize - 32]; reader.ReadBytes(packet); if (packetType == 4 && packet.Length > 0) { lrStruct l = new lrStruct(); l.r = r; l.g = g; l.b = b; l.a = a; l.pc = count; l.sw = sw; l.ew = ew; l.verts = new Vector3[count]; for (int i = 0; i < count; i++) //Dan actually wrote this one from scratch, so might be bugged. { l.verts[i] = new Vector3(BitConverter.ToSingle(packet, i * 12 + 0), BitConverter.ToSingle(packet, i * 12 + 4), BitConverter.ToSingle(packet, i * 12 + 8)); } incomingLineRenderers.Enqueue(l); } if (packetType == 5) { undoLineRenderer = true; } } else { //TODO Handle it. } } } } System.Diagnostics.Debug.WriteLine("Finished reading"); }