private async Task ProcessFile(IIgnite client, FileInfo fileInfo, FastPcapFileReaderDevice device) { device.Open(); var frameKeyProvider = new FrameKeyProvider(); var cache = CacheFactory.GetOrCreateFrameCache(client, FrameCacheName ?? fileInfo.Name); using (var dataStreamer = client.GetDataStreamer <FrameKey, FrameData>(cache.Name)) { var frameIndex = 0; var frameArray = new KeyValuePair <FrameKey, FrameData> [ChunkSize]; var cacheStoreTask = Task.CompletedTask; var currentChunkBytes = 0; var currentChunkNumber = 0; RawCapture rawCapture = null; while ((rawCapture = device.GetNextPacket()) != null) { currentChunkBytes += rawCapture.Data.Length + 4 * sizeof(int); var frame = new FrameData { LinkLayer = (LinkLayerType)rawCapture.LinkLayerType, Timestamp = rawCapture.Timeval.ToUnixTimeMilliseconds(), Data = rawCapture.Data }; var frameKey = new FrameKey(frameIndex, frameKeyProvider.GetKeyHash(frame)); frameArray[frameIndex % ChunkSize] = KeyValuePair.Create(frameKey, frame); // Is CHUNK full? if (frameIndex % ChunkSize == ChunkSize - 1) { OnChunkLoaded?.Invoke(this, currentChunkNumber, currentChunkBytes); cacheStoreTask = cacheStoreTask.ContinueWith(CreateStoreAction(dataStreamer, frameArray, ChunkSize, currentChunkNumber, currentChunkBytes)); currentChunkNumber++; currentChunkBytes = 0; } frameIndex++; } OnChunkLoaded?.Invoke(this, currentChunkNumber, currentChunkBytes); cacheStoreTask = cacheStoreTask.ContinueWith(CreateStoreAction(dataStreamer, frameArray, frameIndex % ChunkSize, currentChunkNumber, currentChunkBytes)); await cacheStoreTask; dataStreamer.Flush(); //dataStreamer.Close(false); // HACK: causes Exception in JVM.DLL } device.Close(); }
private async Task ProcessFile(IIgnite client, FileInfo fileInfo, FastPcapFileReaderDevice device) { device.Open(); var frameKeyProvider = new FrameKeyProvider(); var cache = CacheFactory.GetOrCreateFrameCache(client, FrameCacheName ?? fileInfo.Name); RawCapture rawCapture = null; var frameIndex = 0; var currentChunkBytes = 0; var currentChunkNumber = 0; while ((rawCapture = device.GetNextPacket()) != null) { currentChunkBytes += rawCapture.Data.Length + 4 * sizeof(int); var frame = new FrameData { LinkLayer = (LinkLayerType)rawCapture.LinkLayerType, Timestamp = rawCapture.Timeval.ToUnixTimeMilliseconds(), Data = rawCapture.Data }; var frameKey = new FrameKey(frameIndex, frameKeyProvider.GetKeyHash(frame)); var storedFrame = await cache.GetAsync(frameKey); if (storedFrame == null) { OnErrorFrameOccured(fileInfo, frameIndex, null); } if (storedFrame != null && frame.Timestamp != storedFrame.Timestamp) { OnErrorFrameOccured(fileInfo, frameIndex, storedFrame); } if (frameIndex % ChunkSize == ChunkSize - 1) { OnChunkLoaded(currentChunkNumber, currentChunkBytes); OnChunkStored(currentChunkNumber, currentChunkBytes); currentChunkNumber++; currentChunkBytes = 0; } frameIndex++; } device.Close(); }