Exemplo n.º 1
0
        public static VirtualAsset CreateInstance(FileInfo file, bool cache, bool reload)
        {
            if (file == null || !file.Exists)
            {
                return(Empty);
            }

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                var hash = CryptoGenerator.GenString(CryptoHashType.MD5, file.FullName);

                VirtualAsset a;

                lock (_CacheLock)
                {
                    if (!AssetCache.TryGetValue(hash, out a))
                    {
                        a = Empty;
                    }
                }

                if (reload || IsNullOrEmpty(a))
                {
                    using (var img = new Bitmap(file.FullName, true))
                    {
                        a = new VirtualAsset(file, img);
                    }
                }

                if (IsNullOrEmpty(a))
                {
                    return Empty;
                }

                lock (_CacheLock)
                {
                    if (cache)
                    {
                        AssetCache[a.Hash] = a;
                    }
                    else
                    {
                        AssetCache.Remove(a.Hash);
                    }

                    if (AssetCache.Count > CacheCapacity)
                    {
                        AssetCache.Pop();
                    }
                }

                return a;
            }));
        }
Exemplo n.º 2
0
 public static bool IsNullOrEmpty(VirtualAsset asset)
 {
     return(asset == null || asset == Empty || asset.Hash == Empty.Hash || asset.Capacity == 0 || asset.Count == 0);
 }
Exemplo n.º 3
0
 public bool Equals(VirtualAsset other)
 {
     return(!ReferenceEquals(other, null) && Hash == other.Hash);
 }