Beispiel #1
0
        public static byte[] ReadAllBytes(string filename, FileInfoCache fileInfoCache)
        {
            var cacheName = CacheName.Normalize(filename);

            using (CreateLock(cacheName))
            {
                DateTime time = fileInfoCache != null?fileInfoCache.GetFileInfo(cacheName).LastWriteTimeUtc : new FileInfo(cacheName).LastWriteTimeUtc;

                lock (_cache)
                {
                    if (!_cache.TryGetValue(cacheName, out var bytes))
                    {
                        var b = File.ReadAllBytes(cacheName);
                        _cache.Add(cacheName, new CacheBlob <byte[]>(time, b));

                        return(b);
                    }
                    else if (bytes.CacheTime != time)
                    {
                        bytes.CacheTime = time;
                        return(bytes.Value = File.ReadAllBytes(cacheName));
                    }
                    else
                    {
                        return(bytes.Value);
                    }
                }
            }
        }
 public FileCacheInfoSerializer(
     Version dependencyVersion,
     FileInfoCache fileInfoCache)
 {
     _dependencyVersion = dependencyVersion;
     _fileInfoCache     = fileInfoCache;
 }
Beispiel #3
0
 public static Stream OpenRead(string filename, FileInfoCache fileInfoCache) =>
 new MemoryStream(ReadAllBytes(filename, fileInfoCache));
 public FileCacheInfoSerializer(
     Assembly dependency,
     FileInfoCache fileInfoCache)
     : this(dependency.GetName().Version, fileInfoCache)
 {
 }