private void Read(string filePath, IWriteQueue <ByteBlock> queue, Func <BinaryReader, long, ByteBlock> reading) { try { var count = 0; using (BinaryReader binaryReader = new BinaryReader(File.OpenRead(filePath))) { while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length) { if (_zipController.IsCancelled) { throw new AbortedOperationException($"Read file {filePath}"); } var dataBlock = reading(binaryReader, count); queue.Enqueue(dataBlock); count++; } } } catch (Exception ex) { LoggerProvider.Logger().Error($"Error. Read the file: {ex.Message}"); } }
public WhiteboxProfilingModule(IWriteQueue client) { if (client == null) { throw new ArgumentNullException("client"); } _client = client; }
public void ReadOriginalFile(string sourceFile, IWriteQueue <ByteBlock> queue, int byteBlockSize) { ByteBlock reading(BinaryReader binaryReader, long count) { var remainingFileSize = binaryReader.BaseStream.Length - binaryReader.BaseStream.Position; var bytesRead = remainingFileSize <= byteBlockSize ? (int)remainingFileSize : byteBlockSize; var lastBuffer = new byte[bytesRead]; binaryReader.Read(lastBuffer, 0, bytesRead); return(new ByteBlock(count, lastBuffer)); } Read(sourceFile, queue, reading); }
public NamedPipesWriteQueue() { _clientStream = new NamedPipeClientStream(Constants.ThisMachineServerName, Constants.PipeName, PipeDirection.Out); _timer = new Timer(WriteToQueue); _initTime = DateTime.Now; var inProcQueue = new InProcQueue(); _readQueue = inProcQueue; _writeQueue = inProcQueue; Trace("Starting up."); ResetTimer(); }
public void ReadCompressedFile(string sourceFile, IWriteQueue <ByteBlock> queue) { ByteBlock reading(BinaryReader binaryReader, long count) { byte[] lengthBuffer = new byte[8]; binaryReader.Read(lengthBuffer, 0, lengthBuffer.Length); var blockLength = BitConverter.ToInt32(lengthBuffer, 4); byte[] compressedData = new byte[blockLength]; lengthBuffer.CopyTo(compressedData, 0); binaryReader.Read(compressedData, 8, blockLength - 8); int dataSize = BitConverter.ToInt32(compressedData, blockLength - 4); return(new CompressedByteBlock(count, compressedData, dataSize)); }; Read(sourceFile, queue, reading); }
void WriteToQueue(object state) { try { if (!_clientStream.IsConnected) { _clientStream.Connect((int)_connectionRetryInterval.TotalMilliseconds); } object message; while (_readQueue.TryDequeue(out message)) { var ms = new MemoryStream(); _formatter.Serialize(ms, message); var bytes = ms.ToArray(); _clientStream.Write(bytes, 0, bytes.Length); _clientStream.Flush(); } ResetTimer(); } catch (TimeoutException timeoutException) { Trace("Could not connect to profiler: {0}", timeoutException.Message); if (DateTime.Now - _initTime < _giveUpInterval) { ResetTimer(); } else { Trace("Connection attempt threshold exceeded; detaching event queue and giving up."); var nullQueue = new NullQueue(); _readQueue = nullQueue; _writeQueue = nullQueue; Dispose(); } } catch (Exception exception) { Trace("Error communicating with profiler, giving up: {0}", exception.Message); } }
void WriteToQueue(object state) { try { if (!_clientStream.IsConnected) _clientStream.Connect((int)_connectionRetryInterval.TotalMilliseconds); object message; while (_readQueue.TryDequeue(out message)) { var ms = new MemoryStream(); _formatter.Serialize(ms, message); var bytes = ms.ToArray(); _clientStream.Write(bytes, 0, bytes.Length); _clientStream.Flush(); } ResetTimer(); } catch (TimeoutException timeoutException) { Trace("Could not connect to profiler: {0}", timeoutException.Message); if (DateTime.Now - _initTime < _giveUpInterval) { ResetTimer(); } else { Trace("Connection attempt threshold exceeded; detaching event queue and giving up."); var nullQueue = new NullQueue(); _readQueue = nullQueue; _writeQueue = nullQueue; Dispose(); } } catch (Exception exception) { Trace("Error communicating with profiler, giving up: {0}", exception.Message); } }
public WhiteboxProfilingModule(IWriteQueue client) { if (client == null) throw new ArgumentNullException("client"); _client = client; }