<commit_before>﻿using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FFImageLoading.Cache;
using FFImageLoading.Helpers;
using FFImageLoading.Extensions;
using FFImageLoading.DataResolver;
using System.Threading;

#if SILVERLIGHT
using System.Windows.Controls;
using System.Windows.Media.Imaging;
#else
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
#endif

namespace FFImageLoading.Work
{
    public class ImageLoaderTask : ImageLoaderTaskBase
    {
        private static readonly SemaphoreSlim _decodingLock = new SemaphoreSlim(1, 1);
        internal readonly ITarget<WriteableBitmap, ImageLoaderTask> _target;

        public ImageLoaderTask(IDownloadCache downloadCache, IMainThreadDispatcher mainThreadDispatcher, IMiniLogger miniLogger, TaskParameter parameters, ITarget<WriteableBitmap, ImageLoaderTask> target, bool clearCacheOnOutOfMemory)
            : base(mainThreadDispatcher, miniLogger, parameters, downloadCache, false, clearCacheOnOutOfMemory)
        {
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            _target = target;

            DownloadCache = downloadCache;
        }

        public override bool UsesSameNativeControl(IImageLoaderTask task)
        {
            return _target.UsesSameNativeControl((ImageLoaderTask)task);
        }

        public override async Task<bool> PrepareAndTryLoadingFromCacheAsync()
        {
			if (CanUseMemoryCache())
			{
	            var cacheResult = await TryLoadingFromCacheAsync().ConfigureAwait(false);
	            if (cacheResult == CacheResult.Found || cacheResult == CacheResult.ErrorOccured) // If image is loaded from cache there is nothing to do here anymore, if something weird happened with the cache... error callback has already been called, let's just leave
	                return true; // stop processing if loaded from cache OR if loading from cached raised an exception
			}

            await LoadPlaceHolderAsync(Parameters.LoadingPlaceholderPath, Parameters.LoadingPlaceholderSource, true).ConfigureAwait(false);
            return false;
        }

        protected override async Task<GenerateResult> TryGeneratingImageAsync()
        {
            WithLoadingResult<WriteableBitmap> imageWithResult;
            WriteableBitmap image = null;

            try
            {
                imageWithResult = await RetrieveImageAsync(Parameters.Path, Parameters.Source, false).ConfigureAwait(false);
                image = imageWithResult.Item;
            }
            catch (Exception ex)<commit_msg>Windows build issue fix<commit_after>﻿using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FFImageLoading.Cache;
using FFImageLoading.Helpers;
using FFImageLoading.Extensions;
using FFImageLoading.DataResolver;
using System.Threading;

#if SILVERLIGHT
using System.Windows.Controls;
using System.Windows.Media.Imaging;
#else
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
#endif

namespace FFImageLoading.Work
{
    public class ImageLoaderTask : ImageLoaderTaskBase
    {
        private static readonly SemaphoreSlim _decodingLock = new SemaphoreSlim(1, 1);
        internal readonly ITarget<WriteableBitmap, ImageLoaderTask> _target;

        public ImageLoaderTask(IDownloadCache downloadCache, IMainThreadDispatcher mainThreadDispatcher, IMiniLogger miniLogger, TaskParameter parameters, ITarget<WriteableBitmap, ImageLoaderTask> target, bool clearCacheOnOutOfMemory)
            : base(mainThreadDispatcher, miniLogger, parameters, downloadCache, false, clearCacheOnOutOfMemory)
        {
            if (target == null)
                throw new ArgumentNullException(nameof(target));

            _target = target;
        }

        public override bool UsesSameNativeControl(IImageLoaderTask task)
        {
            return _target.UsesSameNativeControl((ImageLoaderTask)task);
        }

        public override async Task<bool> PrepareAndTryLoadingFromCacheAsync()
        {
			if (CanUseMemoryCache())
			{
	            var cacheResult = await TryLoadingFromCacheAsync().ConfigureAwait(false);
	            if (cacheResult == CacheResult.Found || cacheResult == CacheResult.ErrorOccured) // If image is loaded from cache there is nothing to do here anymore, if something weird happened with the cache... error callback has already been called, let's just leave
	                return true; // stop processing if loaded from cache OR if loading from cached raised an exception
			}

            await LoadPlaceHolderAsync(Parameters.LoadingPlaceholderPath, Parameters.LoadingPlaceholderSource, true).ConfigureAwait(false);
            return false;
        }

        protected override async Task<GenerateResult> TryGeneratingImageAsync()
        {
            WithLoadingResult<WriteableBitmap> imageWithResult;
            WriteableBitmap image = null;

            try
            {
                imageWithResult = await RetrieveImageAsync(Parameters.Path, Parameters.Source, false).ConfigureAwait(false);
                image = imageWithResult.Item;
            }
            catch (Exception ex)
{'fraction_non_alphanumeric': 0.06751543209876543, 'fraction_numerical': 0.0007716049382716049, 'mean_word_length': 3.229200652528548, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6642545', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1260, 'n_words': 348}