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 CacheFileCookie ReadCookie(FileStream fs, long offset) { LinkedList <CacheFileCookie> linkedList = CacheFileCookieSerializer.ReadCookieList(fs, offset, 1); if (linkedList.First == null) { return(null); } return(linkedList.First.Value); }
internal static CacheFileCookie ReadLastCookie(FileStream fs) { LinkedList <CacheFileCookie> linkedList = CacheFileCookieSerializer.ReadCookieList(fs, -1L, -1); if (linkedList.Last == null) { return(null); } return(linkedList.Last.Value); }
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); }
internal static LinkedList <CacheFileCookie> ReadCookieList(FileStream fs) { return(CacheFileCookieSerializer.ReadCookieList(fs, -1L, -1)); }