Ejemplo n.º 1
0
        private void InitializeIfNeeded(Configuration userDefinedConfig = null)
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializeLock)
            {
                if (_initialized)
                {
                    return;
                }

                if (userDefinedConfig == null)
                {
                    userDefinedConfig = new Configuration();
                }

                var logger = new MiniLoggerWrapper(userDefinedConfig.Logger ?? new MiniLogger(), userDefinedConfig.VerboseLogging);
                userDefinedConfig.Logger = logger;

                var md5Helper = userDefinedConfig.MD5Helper ?? new MD5Helper();
                userDefinedConfig.MD5Helper = md5Helper;

                var httpClient = userDefinedConfig.HttpClient ?? new HttpClient(new HttpClientHandler()
                {
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                });

                if (userDefinedConfig.HttpReadTimeout > 0)
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(userDefinedConfig.HttpReadTimeout);
                }
                userDefinedConfig.HttpClient = httpClient;

                var scheduler = userDefinedConfig.Scheduler ?? new WorkScheduler(userDefinedConfig, PlatformPerformance.Create());
                userDefinedConfig.Scheduler = scheduler;

                if (string.IsNullOrWhiteSpace(userDefinedConfig.DiskCachePath))
                {
                    var diskCache = userDefinedConfig.DiskCache ?? SimpleDiskCache.CreateCache("FFSimpleDiskCache", userDefinedConfig);
                    userDefinedConfig.DiskCache = diskCache;
                }
                else
                {
                    var diskCache = userDefinedConfig.DiskCache ?? new SimpleDiskCache(userDefinedConfig.DiskCachePath, userDefinedConfig);
                    userDefinedConfig.DiskCache = diskCache;
                }

                var downloadCache = userDefinedConfig.DownloadCache ?? new DownloadCache(userDefinedConfig);
                userDefinedConfig.DownloadCache = downloadCache;

                Config = userDefinedConfig;

                _initialized = true;
            }
        }
Ejemplo n.º 2
0
        private void InitializeIfNeeded(Configuration userDefinedConfig = null)
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializeLock)
            {
                if (_initialized)
                {
                    return;
                }

                if (userDefinedConfig == null)
                {
                    userDefinedConfig = new Configuration();
                }

                var logger = new MiniLoggerWrapper(userDefinedConfig.Logger ?? new MiniLogger(), userDefinedConfig.VerboseLogging);
                userDefinedConfig.Logger = logger;

                var md5Helper = userDefinedConfig.MD5Helper ?? new MD5Helper();
                userDefinedConfig.MD5Helper = md5Helper;

                var httpClient = userDefinedConfig.HttpClient ?? new HttpClient();

                if (userDefinedConfig.HttpReadTimeout > 0)
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(userDefinedConfig.HttpReadTimeout);
                }
                userDefinedConfig.HttpClient = httpClient;

                var scheduler = userDefinedConfig.Scheduler ?? new WorkScheduler(userDefinedConfig, new PlatformPerformance());
                userDefinedConfig.Scheduler = scheduler;

                var diskCache = userDefinedConfig.DiskCache ?? SimpleDiskCache.CreateCache("FFSimpleDiskCache", userDefinedConfig);
                userDefinedConfig.DiskCache = diskCache;

                var downloadCache = userDefinedConfig.DownloadCache ?? new DownloadCache(userDefinedConfig);
                userDefinedConfig.DownloadCache = downloadCache;

                Config = userDefinedConfig;

                _initialized = true;
            }
        }
Ejemplo n.º 3
0
        private void InitializeIfNeeded(Configuration userDefinedConfig = null)
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializeLock)
            {
                if (_initialized)
                {
                    return;
                }

                if (userDefinedConfig == null)
                {
                    userDefinedConfig = new Configuration();
                }

                var httpClient = userDefinedConfig.HttpClient ?? new HttpClient();

                if (userDefinedConfig.HttpReadTimeout > 0)
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(userDefinedConfig.HttpReadTimeout);
                }

                var logger        = userDefinedConfig.Logger ?? new MiniLogger();
                var scheduler     = userDefinedConfig.Scheduler ?? new WorkScheduler(logger);
                var diskCache     = userDefinedConfig.DiskCache ?? SimpleDiskCache.CreateCache("FFSimpleDiskCache");
                var downloadCache = userDefinedConfig.DownloadCache ?? new DownloadCache(httpClient, diskCache);

                userDefinedConfig.HttpClient    = httpClient;
                userDefinedConfig.Scheduler     = scheduler;
                userDefinedConfig.Logger        = logger;
                userDefinedConfig.DiskCache     = diskCache;
                userDefinedConfig.DownloadCache = downloadCache;

                Config = userDefinedConfig;

                _initialized = true;
            }
        }
Ejemplo n.º 4
0
        private void InitializeIfNeeded(Configuration userDefinedConfig = null)
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializeLock)
            {
                if (_initialized)
                {
                    return;
                }

                if (userDefinedConfig == null)
                {
                    userDefinedConfig = new Configuration();
                }

                var logger = new MiniLoggerWrapper(userDefinedConfig.Logger ?? new MiniLogger(), userDefinedConfig.VerboseLogging);
                userDefinedConfig.Logger = logger;

                var md5Helper = userDefinedConfig.MD5Helper ?? new MD5Helper();
                userDefinedConfig.MD5Helper = md5Helper;

                var httpClient = userDefinedConfig.HttpClient ?? new HttpClient(new HttpClientHandler()
                {
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                });

                if (userDefinedConfig.HttpReadTimeout > 0)
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(userDefinedConfig.HttpReadTimeout);
                }
                userDefinedConfig.HttpClient = httpClient;

                var scheduler = userDefinedConfig.Scheduler ?? new WorkScheduler(userDefinedConfig, PlatformPerformance.Create(userDefinedConfig.VerbosePerformanceLogging));
                userDefinedConfig.Scheduler = scheduler;

                if (string.IsNullOrWhiteSpace(userDefinedConfig.DiskCachePath))
                {
                    var diskCache = userDefinedConfig.DiskCache ?? SimpleDiskCache.CreateCache("FFSimpleDiskCache", userDefinedConfig);
                    userDefinedConfig.DiskCache = diskCache;
                }
                else
                {
                    var diskCache = userDefinedConfig.DiskCache ?? new SimpleDiskCache(userDefinedConfig.DiskCachePath, userDefinedConfig);
                    userDefinedConfig.DiskCache = diskCache;
                }

                var downloadCache = userDefinedConfig.DownloadCache ?? new DownloadCache(userDefinedConfig);
                userDefinedConfig.DownloadCache = downloadCache;

#if WINDOWS
                // To resolve this Windows issues: https://github.com/luberda-molinet/FFImageLoading/issues/439
                userDefinedConfig.ExecuteCallbacksOnUIThread = true;
#endif

                Config = userDefinedConfig;

                _initialized = true;
            }
        }
Ejemplo n.º 5
0
 public void SetUp()
 {
     cache = new SimpleDiskCache(SpecialPathPolicy.For <SimpleDiskCacheTest>().GetTempDirectory().FullName);
     cache.Purge();
 }
Ejemplo n.º 6
0
        public void GroupsThrowIfKeyIsNull()
        {
            SimpleDiskCache cache = new SimpleDiskCache("foo");

            Assert.Throws <ArgumentNullException>(delegate { GC.KeepAlive(cache.Groups[null]); });
        }
Ejemplo n.º 7
0
        public void ShouldUseTheFullPathOfTheCacheDirectory()
        {
            SimpleDiskCache cache = new SimpleDiskCache("foo");

            Assert.AreEqual(cache.CacheDirectoryPath, Path.GetFullPath("foo"));
        }