Skip to content

Commit d13e959

Browse files
author
Jeff Treuting
committed
Fixed an issue with loading the caching strategy from configuraiton
It wasn't updating the QueryManager so it was using the NoCachingStrategy even when the CachingStrategy got updated, the QueryManager didn't. Changed exceptions in configuraiton loading to ConfigurationErrorsException instead of ArgumentException. Added web.config transformation files but haven't got them working yet when creating a new nuget package, that comes next.
1 parent aa22d61 commit d13e959

8 files changed

Lines changed: 66 additions & 32 deletions

File tree

SharpRepository.Ef5Repository/Ef5ConfigRepositoryFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Configuration;
23
using System.Data.Entity;
34
using SharpRepository.Repository;
45
using SharpRepository.Repository.Configuration;
@@ -17,7 +18,7 @@ public override IRepository<T, TKey> GetInstance<T, TKey>()
1718
// check for required parameters
1819
if (String.IsNullOrEmpty(RepositoryElement["connectionString"]))
1920
{
20-
throw new ArgumentException("connectionString parameter is required for the Ef5Repository in the configuration file");
21+
throw new ConfigurationErrorsException("The connectionString attribute is required in order to use the Ef5Repository via the configuration file.");
2122
}
2223

2324
Type dbContextType = null;

SharpRepository.EfRepository/EfConfigRepositoryFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Configuration;
23
using System.Data.Entity;
34
using SharpRepository.Repository;
45
using SharpRepository.Repository.Configuration;
@@ -17,7 +18,7 @@ public override IRepository<T, TKey> GetInstance<T, TKey>()
1718
// check for required parameters
1819
if (String.IsNullOrEmpty(RepositoryElement["connectionString"]))
1920
{
20-
throw new ArgumentException("connectionString parameter is required for the EfRepository in the configuration file");
21+
throw new ConfigurationErrorsException("The connectionString attribute is required in order to use the EfRepository via the configuration file.");
2122
}
2223

2324
Type dbContextType = null;

SharpRepository.Repository/Caching/TimeoutConfigCachingStrategyFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Configuration;
23
using SharpRepository.Repository.Configuration;
34

45
namespace SharpRepository.Repository.Caching
@@ -15,7 +16,8 @@ public override ICachingStrategy<T, TKey> GetInstance<T, TKey>()
1516
int timeout;
1617
if (!Int32.TryParse(CachingStrategyElement["timeout"], out timeout))
1718
{
18-
throw new ArgumentException("timeout");
19+
20+
throw new ConfigurationErrorsException("The timeout attribute is required in order to use the TimeoutCachingStrategy via the configuration file.");
1921
}
2022

2123
return new TimeoutCachingStrategy<T, TKey>(timeout);

SharpRepository.Repository/RepositoryBase.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract partial class RepositoryBase<T, TKey> : IRepository<T, TKey> whe
1818
private ICachingStrategy<T, TKey> _cachingStrategy;
1919

2020
// the query manager uses the caching strategy to determine if it should check the cache or run the query
21-
private readonly QueryManager<T, TKey> _queryManager;
21+
private QueryManager<T, TKey> _queryManager;
2222

2323
// just the type name, used to find the primary key if it is [TypeName]Id
2424
private readonly string _typeName;
@@ -44,15 +44,18 @@ protected RepositoryBase(ICachingStrategy<T, TKey> cachingStrategy = null)
4444
throw new InvalidOperationException("The repository type and the primary key type can not be the same.");
4545
}
4646

47-
_cachingStrategy = cachingStrategy ?? new NoCachingStrategy<T, TKey>();
47+
CachingStrategy = cachingStrategy ?? new NoCachingStrategy<T, TKey>();
4848
_typeName = typeof (T).Name;
49-
_queryManager = new QueryManager<T, TKey>(_cachingStrategy);
5049
}
5150

5251
public ICachingStrategy<T, TKey> CachingStrategy
5352
{
5453
get { return _cachingStrategy; }
55-
set { _cachingStrategy = value ?? new NoCachingStrategy<T, TKey>(); }
54+
set
55+
{
56+
_cachingStrategy = value ?? new NoCachingStrategy<T, TKey>();
57+
_queryManager = new QueryManager<T, TKey>(_cachingStrategy);
58+
}
5659
}
5760

5861
public abstract IQueryable<T> AsQueryable();

SharpRepository.Repository/RepositoryFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public static class RepositoryFactory
3737

3838
private static SharpRepositorySection GetConfiguration(string sectionName)
3939
{
40-
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
41-
var section = config.GetSection(sectionName) as SharpRepositorySection;
40+
var section = ConfigurationManager.GetSection(sectionName) as SharpRepositorySection;
4241
if (section == null)
4342
throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
4443

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<sharpRepository>
2+
<repositories>
3+
<repository name="inMemory" factory="SharpRepository.InMemoryRepository.InMemoryConfigRepositoryFactory, SharpRepository.InMemoryRepository" />
4+
</repositories>
5+
</sharpRepository>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<configuration>
2+
<configSections>
3+
<section name="sharpRepository" type="SharpRepository.Repository.Configuration.SharpRepositorySection, SharpRepository.Repository"/>
4+
</configSections>
5+
</configuration>
6+
<sharpRepository>
7+
<repositories>
8+
</repositories>
9+
<cachingProviders default="inMemoryProvider">
10+
<cachingProvider name="inMemoryProvider" factory="SharpRepository.Repository.Caching.InMemoryConfigCachingProviderFactory, SharpRepository.Repository"/>
11+
</cachingProviders>
12+
<cachingStrategies>
13+
<cachingStrategy name="standardCachingStrategy" factory="SharpRepository.Repository.Caching.StandardConfigCachingStrategyFactory, SharpRepository.Repository" generational="true" writeThrough="false"/>
14+
<cachingStrategy name="timeoutCachingStrategy" factory="SharpRepository.Repository.Caching.TimeoutConfigCachingStrategyFactory, SharpRepository.Repository" timeout="300"/>
15+
<cachingStrategy name="noCaching" factory="SharpRepository.Repository.Caching.NoCachingConfigCachingStrategyFactory, SharpRepository.Repository"/>
16+
</cachingStrategies>
17+
</sharpRepository>

nuget/nuget-build.ps1

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,39 @@ $new_notes = Read-Host "Any release notes?"
1919

2020
Write-Host ""
2121

22-
$directories = Get-Directory $(Get-Location), "SharpRepository.*" -recurse
23-
22+
$directories = Get-Directory $(Get-Location), "SharpRepository.*"
23+
$uniqueDirectories = @()
2424
foreach($directory in $directories)
2525
{
2626
$dir_fullname = $directory.fullname
27-
28-
Write-Host "Processing " $dir_fullname
29-
30-
$template_path = ($directory.fullname + "\" + $directory + ".nuspec.template")
31-
$nuspec_path = ($directory.fullname + "\" + $directory + ".nuspec")
32-
33-
# update the version number
34-
((Get-Content $template_path) -creplace $version_holder, ("<version>" + $new_version + "</version>")) | Set-Content $nuspec_path
35-
((Get-Content $nuspec_path) -creplace $notes_holder, ("<releaseNotes>" + $new_notes + "</releaseNotes>")) | Set-Content $nuspec_path
36-
37-
# copy the nuspec file over to the main project directory because I only know how to create the nuget package from that diretory, but that's just me i think :)
38-
Copy-Item $nuspec_path "..\$directory\$directory.nuspec"
39-
40-
# build the nuget package
41-
#& "C\NuGet\nuget.exe pack ..\$directory\$directory.csproj -Prop Configuration=Release"
42-
Invoke-Expression "& `"nuget.exe`" pack ..\$directory\$directory.csproj -Prop Configuration=Release"
43-
44-
# move the nuget package back to the nuget directories
45-
Move-Item "$cur_directory\$directory.$new_version.nupkg" "$dir_fullname\$directory.$new_version.nupkg"
4627

47-
# delete the nuspec file from the project directory
48-
Remove-Item "..\$directory\$directory.nuspec"
28+
if (!($uniqueDirectories -contains $dir_fullname) )
29+
{
30+
Write-Host "Processing " $dir_fullname
31+
32+
$template_path = ($directory.fullname + "\" + $directory + ".nuspec.template")
33+
$nuspec_path = ($directory.fullname + "\" + $directory + ".nuspec")
34+
35+
# update the version number
36+
((Get-Content $template_path) -creplace $version_holder, ("<version>" + $new_version + "</version>")) | Set-Content $nuspec_path
37+
((Get-Content $nuspec_path) -creplace $notes_holder, ("<releaseNotes>" + $new_notes + "</releaseNotes>")) | Set-Content $nuspec_path
38+
39+
# copy the nuspec file over to the main project directory because I only know how to create the nuget package from that diretory, but that's just me i think :)
40+
Copy-Item $nuspec_path "..\$directory\$directory.nuspec"
41+
42+
# build the nuget package
43+
#& "C\NuGet\nuget.exe pack ..\$directory\$directory.csproj -Prop Configuration=Release"
44+
Invoke-Expression "& `"nuget.exe`" pack ..\$directory\$directory.csproj -Prop Configuration=Release"
45+
46+
# move the nuget package back to the nuget directories
47+
Move-Item "$cur_directory\$directory.$new_version.nupkg" "$dir_fullname\$directory.$new_version.nupkg"
48+
49+
# delete the nuspec file from the project directory
50+
Remove-Item "..\$directory\$directory.nuspec"
51+
52+
# add the full path to the list of already processed directories, this is because the array for this loop has dups
53+
$uniqueDirectories += $directory.fullname
54+
}
4955
}
5056

5157
Read-Host -prompt "Finished. Press Enter key to exit"

0 commit comments

Comments
 (0)