private void AddRequestToHistory(IImageLoaderTask task) { AddRequestToHistory(task.Parameters.Path, task.GetKey()); AddRequestToHistory(task.Parameters.CustomCacheKey, task.GetKey()); AddRequestToHistory(task.Parameters.LoadingPlaceholderPath, task.GetKey(task.Parameters.LoadingPlaceholderPath)); AddRequestToHistory(task.Parameters.ErrorPlaceholderPath, task.GetKey(task.Parameters.ErrorPlaceholderPath)); }
private PendingTask GetPendingTaskIfValid(IImageLoaderTask task, bool rawKey) { ConcurrentDictionary <string, PendingTask> tasks; string key; if (rawKey) { tasks = _pendingTasksByRawKey; key = task.GetKey(raw: true); } else { tasks = _pendingTasks; key = task.GetKey(); } PendingTask alreadyRunningTaskForSameKey; if (tasks.TryGetValue(key, out alreadyRunningTaskForSameKey) && !alreadyRunningTaskForSameKey.ImageLoadingTask.IsCancelled) { return(alreadyRunningTaskForSameKey); } return(null); }
private void QueueAndGenerateImage(IImageLoaderTask task) { _logger.Debug(string.Format("Generating/retrieving image: {0}", task.GetKey())); var currentPendingTask = new PendingTask() { ImageLoadingTask = task }; PendingTask alreadyRunningTaskForSameKey = null; lock (_pauseWorkLock) { lock (_pendingTasksLock) { alreadyRunningTaskForSameKey = _pendingTasks.FirstOrDefault(t => t.ImageLoadingTask.GetKey() == task.GetKey() && (!t.ImageLoadingTask.IsCancelled)); if (alreadyRunningTaskForSameKey == null) { _pendingTasks.Add(currentPendingTask); } } } if (alreadyRunningTaskForSameKey == null || !currentPendingTask.ImageLoadingTask.CanUseMemoryCache()) { Run(currentPendingTask); } else { WaitForSimilarTask(currentPendingTask, alreadyRunningTaskForSameKey); } }
private void QueueAndGenerateImage(IImageLoaderTask task) { _logger.Debug(string.Format("Generating/retrieving image: {0}", task.GetKey())); int position = Interlocked.Increment(ref _currentPosition); var currentPendingTask = new PendingTask() { Position = position, ImageLoadingTask = task, FrameworkWrappingTask = CreateFrameworkTask(task) }; PendingTask alreadyRunningTaskForSameKey = null; lock (_pendingTasksLock) { alreadyRunningTaskForSameKey = FindSimilarPendingTask(task); if (alreadyRunningTaskForSameKey == null) { Interlocked.Increment(ref _statsTotalPending); _pendingTasks.Add(currentPendingTask); } else { alreadyRunningTaskForSameKey.Position = position; } } if (alreadyRunningTaskForSameKey == null || !currentPendingTask.ImageLoadingTask.CanUseMemoryCache()) { Run(currentPendingTask); } else { WaitForSimilarTask(currentPendingTask, alreadyRunningTaskForSameKey); } }
private PendingTask FindSimilarPendingTask(IImageLoaderTask task) { // At first check if the exact same items exists in pending tasks (exact same means same transformations, same downsample, ...) // Since it will be exactly the same it can be retrieved from memory cache string key = task.GetKey(raw: false); var alreadyRunningTaskForSameKey = _pendingTasks.FirstOrDefault(t => t.ImageLoadingTask.GetKey(raw: false) == key); return(alreadyRunningTaskForSameKey); }
private void QueueAndGenerateImage(IImageLoaderTask task) { _logger.Debug(string.Format("Generating/retrieving image: {0}", task.GetKey())); int position = Interlocked.Increment(ref _currentPosition); var currentPendingTask = new PendingTask() { Position = position, ImageLoadingTask = task }; var alreadyRunningTaskForSameKey = FindSimilarPendingTask(task); if (alreadyRunningTaskForSameKey == null) { if (!AddTaskToPendingTasks(currentPendingTask)) { return; } } else { alreadyRunningTaskForSameKey.Position = position; } if (alreadyRunningTaskForSameKey == null || !currentPendingTask.ImageLoadingTask.CanUseMemoryCache()) { Run(currentPendingTask); } else { WaitForSimilarTask(currentPendingTask, alreadyRunningTaskForSameKey); } }
public void RemovePendingTask(IImageLoaderTask task) { var key = task.GetKey(); PendingTask existingTask; _pendingTasks.TryRemove(key, out existingTask); }
private void QueueAndGenerateImage(IImageLoaderTask task) { _logger.Debug(string.Format("Generating/retrieving image: {0}", task.GetKey())); var currentPendingTask = new PendingTask() { ImageLoadingTask = task }; PendingTask alreadyRunningTaskForSameKey = null; lock (_pauseWorkLock) { lock (_pendingTasksLock) { alreadyRunningTaskForSameKey = _pendingTasks.FirstOrDefault(t => t.ImageLoadingTask.GetKey() == task.GetKey() && (!t.ImageLoadingTask.IsCancelled)); if (alreadyRunningTaskForSameKey == null) _pendingTasks.Add(currentPendingTask); } } if (alreadyRunningTaskForSameKey == null || !currentPendingTask.ImageLoadingTask.CanUseMemoryCache()) { Run(currentPendingTask); } else { WaitForSimilarTask(currentPendingTask, alreadyRunningTaskForSameKey); } }
private static void AddRequestToHistory(IImageLoaderTask task) { AddRequestToHistory(task.Parameters.Path, task.GetKey()); AddRequestToHistory(task.Parameters.CustomCacheKey, task.GetKey()); AddRequestToHistory(task.Parameters.LoadingPlaceholderPath, task.GetKey(task.Parameters.LoadingPlaceholderPath)); AddRequestToHistory(task.Parameters.ErrorPlaceholderPath, task.GetKey(task.Parameters.ErrorPlaceholderPath)); }
private PendingTask FindSimilarPendingTask(IImageLoaderTask task) { // At first check if the exact same items exists in pending tasks (exact same means same transformations, same downsample, ...) // Since it will be exactly the same it can be retrieved from memory cache string key = task.GetKey(raw: false); var alreadyRunningTaskForSameKey = _pendingTasks.FirstOrDefault(t => t.ImageLoadingTask.GetKey(raw: false) == key); return alreadyRunningTaskForSameKey; }