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) { OnErrorFrame?.Invoke(this, fileInfo, frameIndex, null); } if (storedFrame != null && frame.Timestamp != storedFrame.Timestamp) { OnErrorFrame?.Invoke(this, fileInfo, frameIndex, storedFrame); } if (frameIndex % ChunkSize == ChunkSize - 1) { OnChunkLoaded?.Invoke(this, currentChunkNumber, currentChunkBytes); OnChunkStored?.Invoke(this, currentChunkNumber, currentChunkBytes); currentChunkNumber++; currentChunkBytes = 0; } frameIndex++; } device.Close(); }
private async Task StoreChunk(IDataStreamer <FrameKey, FrameData> dataStreamer, KeyValuePair <FrameKey, FrameData>[] frameArray, int currentChunkNumber, int currentChunkBytes) { await dataStreamer.AddData(frameArray); OnChunkStored?.Invoke(this, currentChunkNumber, currentChunkBytes); }
private void StoreChunk(FrameCache packetCache, KeyValuePair <FrameKey, FrameData>[] frameArray, int count, int currentChunkNumber, int currentChunkBytes) { packetCache.PutAll(frameArray.Take(count)); OnChunkStored?.Invoke(this, currentChunkNumber, currentChunkBytes); }