internal static void ReadPreCookies(FileStream fs, long offset, int pageSize, LinkedList <CacheFileCookie> cookieList, int capacity) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); CacheFileCookieSerializer.SetOffsetAndPageSize(fs, binaryFormatter, offset, ref pageSize); for (int i = 0; i < pageSize; i++) { long position = fs.Position; if (position == fs.Length) { return; } CacheFileCookie cacheFileCookie = (CacheFileCookie)binaryFormatter.Deserialize(fs); cacheFileCookie.NextCookieOffset = fs.Position; cookieList.AddFirst(cacheFileCookie); if (cookieList.Count > capacity) { cookieList.RemoveLast(); } if (cacheFileCookie.PreCookieOffset < 0L) { return; } fs.Seek(cacheFileCookie.PreCookieOffset, SeekOrigin.Begin); } }
internal static void WriteCookieToFile(FileStream cookieFileStream, CacheFileCookie cookie, CacheFileCookie preCookie) { BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); if (cookieFileStream.Length == 0L) { binaryFormatter.Serialize(cookieFileStream, 0); } cookie.PreCookieOffset = preCookie.CookieOffset; cookie.CookieOffset = cookieFileStream.Position; binaryFormatter.Serialize(cookieFileStream, cookie); cookieFileStream.SetLength(cookieFileStream.Position); }
internal static LinkedList <CacheFileCookie> ReadCookieList(FileStream fs, long offset, int pageSize) { LinkedList <CacheFileCookie> linkedList = new LinkedList <CacheFileCookie>(); BinaryFormatter binaryFormatter = ExchangeBinaryFormatterFactory.CreateBinaryFormatter(null); CacheFileCookieSerializer.SetOffsetAndPageSize(fs, binaryFormatter, offset, ref pageSize); for (int i = 0; i < pageSize; i++) { long position = fs.Position; if (position == fs.Length) { break; } CacheFileCookie cacheFileCookie = (CacheFileCookie)binaryFormatter.Deserialize(fs); cacheFileCookie.NextCookieOffset = fs.Position; linkedList.AddLast(cacheFileCookie); } return(linkedList); }