public KinectFramesStore(KinectFramesStore toCopy) { // Constructor for creating a deep copy of another frame store frames = toCopy.frames; MaxFramesCount = toCopy.MaxFramesCount; frameIndex = 0; }
public void SerializeAndSaveFileChunk(string fileName, KinectFramesStore serializableData) { // Check that the specified file exists if (!DoesFileExist(fileName)) { throw new FileNotFoundException("Could not find the specified file"); } // Use a binary formatter and memory stream to first serialize the incoming // chunk. Then, use QuickLZ to compress this data before writing it into the // file BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { try { formatter.Serialize(memoryStream, serializableData); } catch (SerializationException) { throw new SerializationException("Error in serializing kinect data"); } // Reset the memory stream to its beginning and then compress the serialized object. // Level 1 gives a higher compression ration and Level 3 gives faster decompression memoryStream.Position = 0; byte[] compressedBytes = QuickLZ.compress(memoryStream.ToArray(), 3); // Append the chunk onto the file, also recording the size of the new chunk using the // stream position before and after the write so that it can be stored in the file info // object long startPosition, endPosition; using (FileStream fileStream = new FileStream(GetFullFilePath(fileName), FileMode.Append, FileAccess.Write)) { startPosition = fileStream.Position; try { fileStream.Write(compressedBytes, 0, compressedBytes.Length); } catch (IOException) { throw new IOException("Could not write chunk data to file"); } endPosition = fileStream.Position; } // Add a new chunk size to the file info object's internal list using the stream // position differences fileInfo.ChunkSizes.Add(endPosition - startPosition); } }