Skip to content

Commit cd33c15

Browse files
committed
Merge branch 'develop' into get-includes
Conflicts: SharpRepository.Repository/ConfigurationBasedRepository.cs SharpRepository.Repository/ICrudRepository.cs
2 parents 35b6c89 + cfc7908 commit cd33c15

394 files changed

Lines changed: 499908 additions & 8411 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using SharpRepository.Repository;
3+
using SharpRepository.Repository.Configuration;
4+
5+
namespace SharpRepository.AzureBlobRepository
6+
{
7+
public class AzureBlobConfigRepositoryFactory : ConfigRepositoryFactory
8+
{
9+
public AzureBlobConfigRepositoryFactory(IRepositoryConfiguration config)
10+
: base(config)
11+
{
12+
}
13+
14+
public override IRepository<T> GetInstance<T>()
15+
{
16+
throw new NotImplementedException("AzureBlobRepository does not support using IRepository<T> directly to reference a IRepository<T, string>");
17+
}
18+
19+
public override IRepository<T, TKey> GetInstance<T, TKey>()
20+
{
21+
var createIfNotExists = false;
22+
Boolean.TryParse(RepositoryConfiguration["createIfNotExists"], out createIfNotExists);
23+
24+
return new AzureBlobRepository<T, TKey>(RepositoryConfiguration["connectionString"], RepositoryConfiguration["container"], createIfNotExists);
25+
}
26+
27+
public override ICompoundKeyRepository<T, TKey, TKey2> GetInstance<T, TKey, TKey2>()
28+
{
29+
throw new NotImplementedException();
30+
}
31+
}
32+
}

SharpRepository.AzureBlobRepository/AzureBlobRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace SharpRepository.AzureBlobRepository
44
{
55
public class AzureBlobRepository<T, TKey> : AzureBlobRepositoryBase<T, TKey> where T: class, new()
66
{
7-
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = true, ICachingStrategy<T, TKey> cachingStrategy = null)
7+
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = false, ICachingStrategy<T, TKey> cachingStrategy = null)
88
: base(connectionString, containerName, createIfNotExists, cachingStrategy)
99
{
1010

@@ -13,7 +13,7 @@ public AzureBlobRepository(string connectionString, string containerName = null,
1313

1414
public class AzureBlobRepository<T> : AzureBlobRepositoryBase<T, string> where T : class, new()
1515
{
16-
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = true, ICachingStrategy<T, string> cachingStrategy = null)
16+
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = false, ICachingStrategy<T, string> cachingStrategy = null)
1717
: base(connectionString, containerName, createIfNotExists, cachingStrategy)
1818
{
1919

SharpRepository.AzureBlobRepository/AzureBlobRepositoryBase.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using Microsoft.WindowsAzure.Storage;
34
using Microsoft.WindowsAzure.Storage.Blob;
45
using Newtonsoft.Json;
56
using SharpRepository.Repository;
@@ -30,13 +31,12 @@ internal AzureBlobRepositoryBase(string connectionString, string containerName,
3031

3132
CreateIfNotExists = createIfNotExists;
3233
BlobClient = storageAccount.CreateCloudBlobClient();
33-
SetContainer(containerName);
34+
SetContainer();
3435
}
3536

36-
protected void SetContainer(string containerName)
37+
protected void SetContainer()
3738
{
38-
ContainerName = containerName;
39-
BlobContainer = BlobClient.GetContainerReference(containerName);
39+
BlobContainer = BlobClient.GetContainerReference(ContainerName);
4040

4141
if (CreateIfNotExists)
4242
{
@@ -46,9 +46,23 @@ protected void SetContainer(string containerName)
4646

4747
protected override T GetQuery(TKey key, IFetchStrategy<T> fetchStrategy)
4848
{
49-
var blob = BlobContainer.GetBlockBlobReference(key.ToString());
49+
try
50+
{
51+
var blob = BlobContainer.GetBlockBlobReference(key.ToString());
52+
53+
return blob == null ? null : JsonConvert.DeserializeObject<T>(blob.DownloadText());
54+
}
55+
catch (StorageException storageException)
56+
{
57+
// check for 404 and return null in that case only, let others bubble up
58+
if (storageException.RequestInformation.HttpStatusCode == 404)
59+
{
60+
return null;
61+
}
5062

51-
return blob == null ? null : JsonConvert.DeserializeObject<T>(blob.DownloadText());
63+
throw;
64+
}
65+
5266
}
5367

5468
protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = null)
@@ -66,8 +80,7 @@ private CloudBlockBlob GetBlobReference(T entity)
6680

6781
protected override void AddItem(T entity)
6882
{
69-
var blob = GetBlobReference(entity);
70-
blob.UploadText(JsonConvert.SerializeObject(entity));
83+
AddOrUpdateItem(entity);
7184
}
7285

7386
protected override void DeleteItem(T entity)
@@ -77,6 +90,11 @@ protected override void DeleteItem(T entity)
7790
}
7891

7992
protected override void UpdateItem(T entity)
93+
{
94+
AddOrUpdateItem(entity);
95+
}
96+
97+
private void AddOrUpdateItem(T entity)
8098
{
8199
var blob = GetBlobReference(entity);
82100
blob.UploadText(JsonConvert.SerializeObject(entity));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using SharpRepository.Repository.Configuration;
3+
4+
namespace SharpRepository.AzureBlobRepository
5+
{
6+
public class AzureBlobRepositoryConfiguration : RepositoryConfiguration
7+
{
8+
public AzureBlobRepositoryConfiguration(string name) : this(name, null, null)
9+
{
10+
}
11+
12+
public AzureBlobRepositoryConfiguration(string name, string connectionString)
13+
: this(name, connectionString, null)
14+
{
15+
}
16+
17+
public AzureBlobRepositoryConfiguration(string name, string connectionString, string container, bool createIfNotExists = false, string cachingStrategy = null, string cachingProvider = null)
18+
: base(name)
19+
{
20+
ConnectionString = connectionString;
21+
Container = container;
22+
CreateIfNotExists = createIfNotExists;
23+
CachingStrategy = cachingStrategy;
24+
CachingProvider = cachingProvider;
25+
Factory = typeof(AzureBlobConfigRepositoryFactory);
26+
}
27+
28+
public string ConnectionString
29+
{
30+
set { Attributes["connectionString"] = value; }
31+
}
32+
33+
public string Container
34+
{
35+
set { Attributes["container"] = String.IsNullOrEmpty(value) ? null : value; }
36+
}
37+
38+
public bool CreateIfNotExists
39+
{
40+
set { Attributes["createIfNotExists"] = value.ToString(); }
41+
}
42+
}
43+
}

SharpRepository.AzureBlobRepository/SharpRepository.AzureBlobRepository.csproj

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,34 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34-
<Reference Include="Microsoft.Data.Edm, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
35-
<HintPath>..\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
34+
<Reference Include="Microsoft.Data.Edm, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
35+
<SpecificVersion>False</SpecificVersion>
36+
<HintPath>..\packages\Microsoft.Data.Edm.5.6.1\lib\net40\Microsoft.Data.Edm.dll</HintPath>
3637
</Reference>
37-
<Reference Include="Microsoft.Data.OData, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
38-
<HintPath>..\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
38+
<Reference Include="Microsoft.Data.OData, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
39+
<SpecificVersion>False</SpecificVersion>
40+
<HintPath>..\packages\Microsoft.Data.OData.5.6.1\lib\net40\Microsoft.Data.OData.dll</HintPath>
3941
</Reference>
40-
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
42+
<Reference Include="Microsoft.Data.Services.Client, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43+
<SpecificVersion>False</SpecificVersion>
44+
<HintPath>..\packages\Microsoft.Data.Services.Client.5.6.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
4245
</Reference>
43-
<Reference Include="Microsoft.WindowsAzure.Storage, Version=2.1.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46+
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
48+
</Reference>
49+
<Reference Include="Microsoft.WindowsAzure.Storage, Version=3.1.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4450
<SpecificVersion>False</SpecificVersion>
45-
<HintPath>..\packages\WindowsAzure.Storage.2.1.0.4\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
51+
<HintPath>..\packages\WindowsAzure.Storage.3.1.0.1\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
4652
</Reference>
4753
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
4854
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
4955
</Reference>
5056
<Reference Include="System" />
5157
<Reference Include="System.Core" />
5258
<Reference Include="System.Data.Services.Client" />
53-
<Reference Include="System.Spatial, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
54-
<HintPath>..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll</HintPath>
59+
<Reference Include="System.Spatial, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
60+
<SpecificVersion>False</SpecificVersion>
61+
<HintPath>..\packages\System.Spatial.5.6.1\lib\net40\System.Spatial.dll</HintPath>
5562
</Reference>
5663
<Reference Include="System.Xml.Linq" />
5764
<Reference Include="System.Data.DataSetExtensions" />
@@ -62,6 +69,8 @@
6269
<ItemGroup>
6370
<Compile Include="AzureBlobRepository.cs" />
6471
<Compile Include="AzureBlobRepositoryBase.cs" />
72+
<Compile Include="AzureBlobConfigRepositoryFactory.cs" />
73+
<Compile Include="AzureBlobRepositoryConfiguration.cs" />
6574
<Compile Include="Properties\AssemblyInfo.cs" />
6675
</ItemGroup>
6776
<ItemGroup>
@@ -71,6 +80,7 @@
7180
</ProjectReference>
7281
</ItemGroup>
7382
<ItemGroup>
83+
<None Include="app.config" />
7484
<None Include="packages.config" />
7585
</ItemGroup>
7686
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
8+
</dependentAssembly>
9+
<dependentAssembly>
10+
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
11+
<bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
12+
</dependentAssembly>
13+
<dependentAssembly>
14+
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
15+
<bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
16+
</dependentAssembly>
17+
</assemblyBinding>
18+
</runtime>
19+
</configuration>
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Data.Edm" version="5.2.0" targetFramework="net40" />
4-
<package id="Microsoft.Data.OData" version="5.2.0" targetFramework="net40" />
5-
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="1.8.0.0" targetFramework="net40" />
3+
<package id="Microsoft.Data.Edm" version="5.6.1" targetFramework="net40" />
4+
<package id="Microsoft.Data.OData" version="5.6.1" targetFramework="net40" />
5+
<package id="Microsoft.Data.Services.Client" version="5.6.1" targetFramework="net40" />
6+
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net40" />
67
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net40" />
7-
<package id="System.Spatial" version="5.2.0" targetFramework="net40" />
8-
<package id="WindowsAzure.Storage" version="2.1.0.4" targetFramework="net40" />
8+
<package id="System.Spatial" version="5.6.1" targetFramework="net40" />
9+
<package id="WindowsAzure.Storage" version="3.1.0.1" targetFramework="net40" />
910
</packages>

SharpRepository.AzureTableRepository/AzureTableRepositoryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = nul
4848

4949
protected override void AddItem(T entity)
5050
{
51-
Table.Execute(TableOperation.Insert(entity));
51+
Table.Execute(TableOperation.InsertOrReplace(entity));
5252
}
5353

5454
// TODO: override Add(IEnumerable<T> entities) to use the TableSet.Add(entities) isntead of looping ourselves and having AddItem() called multiple times

0 commit comments

Comments
 (0)