consolidate internal interfaces

This commit is contained in:
Luke Pulverenti
2016-10-31 00:28:23 -04:00
parent 0579f245e4
commit 3bf72b71b3
28 changed files with 114 additions and 301 deletions

View File

@@ -780,40 +780,38 @@ namespace Emby.Drawing
// All enhanced images are saved as png to allow transparency
var enhancedImagePath = GetCachePath(EnhancedImageCachePath, cacheGuid + ".png");
var semaphore = GetLock(enhancedImagePath);
await semaphore.WaitAsync().ConfigureAwait(false);
// Check again in case of contention
if (_fileSystem.FileExists(enhancedImagePath))
{
semaphore.Release();
return enhancedImagePath;
}
var imageProcessingLockTaken = false;
_fileSystem.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
var tmpPath = Path.Combine(_appPaths.TempDirectory, Path.ChangeExtension(Guid.NewGuid().ToString(), Path.GetExtension(enhancedImagePath)));
_fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath));
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
try
{
_fileSystem.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
await ExecuteImageEnhancers(supportedEnhancers, originalImagePath, tmpPath, item, imageType, imageIndex).ConfigureAwait(false);
await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false);
imageProcessingLockTaken = true;
await ExecuteImageEnhancers(supportedEnhancers, originalImagePath, enhancedImagePath, item, imageType, imageIndex).ConfigureAwait(false);
try
{
File.Copy(tmpPath, enhancedImagePath, true);
}
catch
{
}
}
finally
{
if (imageProcessingLockTaken)
{
_imageProcessingSemaphore.Release();
}
semaphore.Release();
_imageProcessingSemaphore.Release();
}
return enhancedImagePath;
return tmpPath;
}
/// <summary>
@@ -838,21 +836,6 @@ namespace Emby.Drawing
}
}
/// <summary>
/// The _semaphoreLocks
/// </summary>
private readonly ConcurrentDictionary<string, SemaphoreSlim> _semaphoreLocks = new ConcurrentDictionary<string, SemaphoreSlim>();
/// <summary>
/// Gets the lock.
/// </summary>
/// <param name="filename">The filename.</param>
/// <returns>System.Object.</returns>
private SemaphoreSlim GetLock(string filename)
{
return _semaphoreLocks.GetOrAdd(filename, key => new SemaphoreSlim(1, 1));
}
/// <summary>
/// Gets the cache path.
/// </summary>