Browse Source

Refactoring

Former-commit-id: 5d2f2a7e593a0c61238c7d3673fa76f5c7156e63
pull/17/head
JimBobSquarePants 13 years ago
parent
commit
edcf3a7469
  1. 6
      src/ImageProcessor.Web/Caching/CachedImage.cs
  2. 15
      src/ImageProcessor.Web/Caching/DiskCache.cs
  3. 3
      src/ImageProcessor.Web/Caching/PersistantDictionary.cs
  4. 9
      src/ImageProcessor.Web/Caching/SQLContext.cs
  5. 4
      src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs
  6. 6
      src/ImageProcessor.sln
  7. 6
      src/ImageProcessor.vsmdi
  8. 2
      src/Test/Test/Views/Home/Index.cshtml

6
src/ImageProcessor.Web/Caching/CachedImage.cs

@ -22,8 +22,8 @@ namespace ImageProcessor.Web.Caching
/// <param name="path"> /// <param name="path">
/// The value of the cached image. /// The value of the cached image.
/// </param> /// </param>
/// <param name="naxAge"> /// <param name="maxAge">
/// The maximum age in days cached image. /// The max age of the cached image.
/// </param> /// </param>
/// <param name="lastWriteTimeUtc"> /// <param name="lastWriteTimeUtc">
/// The last write time of the cached image. /// The last write time of the cached image.
@ -45,7 +45,7 @@ namespace ImageProcessor.Web.Caching
public string Path { get; set; } public string Path { get; set; }
/// <summary> /// <summary>
/// The maximum age of the cached image in days. /// Gets or sets the maximum age of the cached image in days.
/// </summary> /// </summary>
public int MaxAge { get; set; } public int MaxAge { get; set; }

15
src/ImageProcessor.Web/Caching/DiskCache.cs

@ -147,7 +147,7 @@ namespace ImageProcessor.Web.Caching
{ {
if (PersistantDictionary.Instance.TryGetValue(key, out cachedImage)) if (PersistantDictionary.Instance.TryGetValue(key, out cachedImage))
{ {
// Can't check the last write time so Check to see if the cached image is set to expire // Can't check the last write time so check to see if the cached image is set to expire
// or if the max age is different. // or if the max age is different.
if (cachedImage.ExpiresUtc < DateTime.UtcNow.AddDays(-MaxFileCachedDuration) if (cachedImage.ExpiresUtc < DateTime.UtcNow.AddDays(-MaxFileCachedDuration)
|| cachedImage.MaxAge != MaxFileCachedDuration) || cachedImage.MaxAge != MaxFileCachedDuration)
@ -161,11 +161,9 @@ namespace ImageProcessor.Web.Caching
return false; return false;
} }
else
{ // Nothing in the cache so we should return true.
// Nothing in the cache so we should return true. return true;
return true;
}
} }
FileInfo imageFileInfo = new FileInfo(imagePath); FileInfo imageFileInfo = new FileInfo(imagePath);
@ -271,10 +269,11 @@ namespace ImageProcessor.Web.Caching
groupCount -= 1; groupCount -= 1;
} }
} }
catch (Exception) catch (Exception ex)
{ {
// Do Nothing, skip to the next. // Do Nothing, skip to the next.
// TODO: Should we handle this? // TODO: Should we handle this?
throw ex;
continue; continue;
} }
} }

3
src/ImageProcessor.Web/Caching/PersistantDictionary.cs

@ -141,8 +141,9 @@ namespace ImageProcessor.Web.Caching
return SQLContext.AddImage(key, cachedImage); return SQLContext.AddImage(key, cachedImage);
} }
catch (Exception) catch (Exception ex)
{ {
throw ex;
return false; return false;
} }
} }

9
src/ImageProcessor.Web/Caching/SQLContext.cs

@ -129,8 +129,9 @@ namespace ImageProcessor.Web.Caching
return true; return true;
} }
catch (Exception) catch (Exception ex)
{ {
throw ex;
return false; return false;
} }
} }
@ -167,8 +168,9 @@ namespace ImageProcessor.Web.Caching
return true; return true;
} }
catch (Exception) catch (Exception ex)
{ {
throw ex;
return false; return false;
} }
} }
@ -211,8 +213,9 @@ namespace ImageProcessor.Web.Caching
return dictionary; return dictionary;
} }
catch (Exception) catch (Exception ex)
{ {
throw ex;
return new Dictionary<string, CachedImage>(); return new Dictionary<string, CachedImage>();
} }
} }

4
src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs

@ -139,7 +139,7 @@ namespace ImageProcessor.Web.HttpModules
.AutoProcess().Save(cachedPath); .AutoProcess().Save(cachedPath);
// Ensure that the LastWriteTime property of the source and cached file match. // Ensure that the LastWriteTime property of the source and cached file match.
DateTime dateTime = DiskCache.SetCachedLastWriteTime(path, cachedPath, isRemote); DateTime dateTime = DiskCache.SetCachedLastWriteTime(path, cachedPath, true);
// Add to the cache. // Add to the cache.
DiskCache.AddImageToCache(cachedPath, dateTime); DiskCache.AddImageToCache(cachedPath, dateTime);
@ -158,7 +158,7 @@ namespace ImageProcessor.Web.HttpModules
imageFactory.Load(fullPath).AutoProcess().Save(cachedPath); imageFactory.Load(fullPath).AutoProcess().Save(cachedPath);
// Ensure that the LastWriteTime property of the source and cached file match. // Ensure that the LastWriteTime property of the source and cached file match.
DateTime dateTime = DiskCache.SetCachedLastWriteTime(path, cachedPath, isRemote); DateTime dateTime = DiskCache.SetCachedLastWriteTime(path, cachedPath, false);
// Add to the cache. // Add to the cache.
DiskCache.AddImageToCache(cachedPath, dateTime); DiskCache.AddImageToCache(cachedPath, dateTime);

6
src/ImageProcessor.sln

@ -1,6 +1,6 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Web # Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor", "ImageProcessor\ImageProcessor.csproj", "{3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessor", "ImageProcessor\ImageProcessor.csproj", "{3B5DD734-FB7A-487D-8CE6-55E7AF9AEA7E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test\Test.csproj", "{30327C08-7574-4D7E-AC95-6A58753C6855}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test\Test.csproj", "{30327C08-7574-4D7E-AC95-6A58753C6855}"
@ -13,10 +13,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Tests", "Web.Test\Web.T
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C427A497-74DC-49B1-8420-D6E68354F29B}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C427A497-74DC-49B1-8420-D6E68354F29B}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
ImageProcessor.vsmdi = ImageProcessor.vsmdi
Local.testsettings = Local.testsettings Local.testsettings = Local.testsettings
EndProjectSection EndProjectSection
EndProject EndProject
Global Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = ImageProcessor.vsmdi
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
All|Any CPU = All|Any CPU All|Any CPU = All|Any CPU
All|Mixed Platforms = All|Mixed Platforms All|Mixed Platforms = All|Mixed Platforms

6
src/ImageProcessor.vsmdi

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
<RunConfiguration id="7707ff8b-37f7-4192-88cc-339cb7fc8874" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</TestList>
</TestLists>

2
src/Test/Test/Views/Home/Index.cshtml

@ -90,7 +90,7 @@
</div> </div>
<div class="clmn2"> <div class="clmn2">
<h2>Remote</h2> <h2>Remote</h2>
<img src="/remote.axd?http://images.mymovies.net/images/film/cin/500x377/fid11707.jpg?width=300" /> @* <img src="/remote.axd?http://images.mymovies.net/images/film/cin/500x377/fid11707.jpg?width=300" />*@
</div> </div>
</div> </div>
</section> </section>

Loading…
Cancel
Save