Esempio n. 1
0
        public IImage GetImage(IBaseContext context, GEDCOMIndividualRecord iRec)
        {
            if (context == null || iRec == null)
            {
                return(null);
            }

            IImage result = null;

            // get multimedia UID
            string imageUID = context.GetPrimaryBitmapUID(iRec);

            // portrait doesn't define for individual
            if (string.IsNullOrEmpty(imageUID))
            {
                return(null);
            }

            string cachedFile = GetCachedFilename(imageUID);

            // check in-memory cache
            if (fMemoryCache.TryGetValue(cachedFile, out result))
            {
                return(result);
            }

            // in-memory cache doesn't contain image
            // check cache folder by multimedia UID
            if (File.Exists(cachedFile))
            {
                result = AppHost.GfxProvider.LoadImage(cachedFile);
            }

            // if cache doesn't contain the image, then load and save it to cache
            if (result == null)
            {
                result = context.GetPrimaryBitmap(iRec, -1, -1, true);

                // save image to cache
                if (result != null)
                {
                    AppHost.GfxProvider.SaveImage(result, cachedFile);
                }
            }

            // put new image from disk's cache or storage to memory cache
            if (result != null)
            {
                fMemoryCache.Add(cachedFile, result);
            }

            // return result image
            return(result);
        }