public void LoadBlock(MyAbstractMemoryBlock memoryBlock, string globalDataFolder) { int length = m_buffer.Length; SizeT size = memoryBlock.GetSize(); while (size > length) { length *= 2; } if (length != m_buffer.Length) { m_buffer = new byte[length]; } try { string filePath = ResolveFilePath(memoryBlock, globalDataFolder); long fileSize = new FileInfo(filePath).Length; if (fileSize != size) { throw new InvalidDataException("Different size of a stored memory block (" + fileSize + " B != " + size + " B)"); } using (var reader = new BinaryReader(File.OpenRead(filePath))) { reader.Read(m_buffer, 0, size); } memoryBlock.Fill(m_buffer); } catch (Exception e) { MyLog.WARNING.WriteLine("Memory block loading failed (node: {0} (id: {1}), block: {2}): {3}", memoryBlock.Owner.Name, memoryBlock.Owner.Id, memoryBlock.Name, e.Message); } }
public void LoadBlock(MyAbstractMemoryBlock memoryBlock, string globalDataFolder) { int length = buffer.Length; SizeT size = memoryBlock.GetSize(); while (size > length) { length *= 2; } if (length != buffer.Length) { buffer = new byte[length]; } try { string filePath = ResolveFilePath(memoryBlock, globalDataFolder); long fileSize = new FileInfo(filePath).Length; if (fileSize != size) { throw new InvalidDataException("Different size of a stored memory block (" + fileSize + " B != " + size + " B)"); } BinaryReader reader = new BinaryReader(File.OpenRead(filePath)); reader.Read(buffer, 0, size); reader.Close(); memoryBlock.Fill(buffer); } catch (Exception e) { MyLog.WARNING.WriteLine("Memory block loading failed (" + memoryBlock.Owner.Name + "." + memoryBlock.Name + "): " + e.Message); } }