Example #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;
            }
        }
        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;
            }
        }
Example #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;
            }
        }
Example #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;
            }
        }