Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
84e866a
fixes issue 95 - changed the CachingStrategy setter to set CacheEnabl…
Jan 14, 2014
a22b977
fixes issue 108
Jan 14, 2014
19564ad
Added a better fix for issue 108 which also takes adds and deletes in…
Jan 14, 2014
83a1cc3
Fixed accidental code change.
Jan 14, 2014
80a3ad9
Fixes #114 - Don't attempt to write to properties w/o a setter
Jan 20, 2014
ac921b5
Merge branch 'master' of https://github.com/DanPantry/SharpRepository…
Jan 20, 2014
c32ddfb
AzureTableRepository use InsertOrReplace
Jan 23, 2014
35657dd
Run aspects when add actually happens in batch mode
Jan 25, 2014
dc5bd5d
Added delete by multiple keys
Jan 25, 2014
83d7352
Added GetPrimaryKey
Jan 28, 2014
cbf5143
Lazy Load in EF test
Feb 25, 2014
d6c1284
Test CacheRepository adding multiple
Mar 24, 2014
caddb50
Removed new() restriction from EfRepository<>
ioann Mar 25, 2014
f72568b
Updated CacheRepositorySpike
Mar 25, 2014
773ad32
Azure blob configuration
Mar 27, 2014
8500165
Fix container setting from config
Mar 28, 2014
cc0864b
Merge pull request #125 from ioann/remove-new-restriction-from-ef-repo
jtreuting Mar 29, 2014
89b9553
Azure Blob: Catch Get 404 and return NULL
Mar 30, 2014
f9e6a49
Merge branch 'develop' of https://github.com/SharpRepository/SharpRep…
Mar 30, 2014
9420ab2
Include FetchStrategy include paths in ToString for Specification
Apr 10, 2014
332f488
GetMany and GetManyAsDictionary
Apr 10, 2014
7309270
Updated AzureStorage nuget package for AzureBlobRepository
Apr 17, 2014
28e4b2d
Update Redis caching provider NuGet packages to latest
Oct 17, 2014
92d3a4c
Changed from ServiceStack to StackExchange.Redis
Oct 17, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using SharpRepository.Repository;
using SharpRepository.Repository.Configuration;

namespace SharpRepository.AzureBlobRepository
{
public class AzureBlobConfigRepositoryFactory : ConfigRepositoryFactory
{
public AzureBlobConfigRepositoryFactory(IRepositoryConfiguration config)
: base(config)
{
}

public override IRepository<T> GetInstance<T>()
{
throw new NotImplementedException("AzureBlobRepository does not support using IRepository<T> directly to reference a IRepository<T, string>");
}

public override IRepository<T, TKey> GetInstance<T, TKey>()
{
var createIfNotExists = false;
Boolean.TryParse(RepositoryConfiguration["createIfNotExists"], out createIfNotExists);

return new AzureBlobRepository<T, TKey>(RepositoryConfiguration["connectionString"], RepositoryConfiguration["container"], createIfNotExists);
}

public override ICompoundKeyRepository<T, TKey, TKey2> GetInstance<T, TKey, TKey2>()
{
throw new NotImplementedException();
}
}
}
4 changes: 2 additions & 2 deletions SharpRepository.AzureBlobRepository/AzureBlobRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SharpRepository.AzureBlobRepository
{
public class AzureBlobRepository<T, TKey> : AzureBlobRepositoryBase<T, TKey> where T: class, new()
{
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = true, ICachingStrategy<T, TKey> cachingStrategy = null)
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = false, ICachingStrategy<T, TKey> cachingStrategy = null)
: base(connectionString, containerName, createIfNotExists, cachingStrategy)
{

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

public class AzureBlobRepository<T> : AzureBlobRepositoryBase<T, string> where T : class, new()
{
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = true, ICachingStrategy<T, string> cachingStrategy = null)
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = false, ICachingStrategy<T, string> cachingStrategy = null)
: base(connectionString, containerName, createIfNotExists, cachingStrategy)
{

Expand Down
34 changes: 26 additions & 8 deletions SharpRepository.AzureBlobRepository/AzureBlobRepositoryBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json;
using SharpRepository.Repository;
Expand Down Expand Up @@ -30,13 +31,12 @@ internal AzureBlobRepositoryBase(string connectionString, string containerName,

CreateIfNotExists = createIfNotExists;
BlobClient = storageAccount.CreateCloudBlobClient();
SetContainer(containerName);
SetContainer();
}

protected void SetContainer(string containerName)
protected void SetContainer()
{
ContainerName = containerName;
BlobContainer = BlobClient.GetContainerReference(containerName);
BlobContainer = BlobClient.GetContainerReference(ContainerName);

if (CreateIfNotExists)
{
Expand All @@ -46,9 +46,23 @@ protected void SetContainer(string containerName)

protected override T GetQuery(TKey key)
{
var blob = BlobContainer.GetBlockBlobReference(key.ToString());
try
{
var blob = BlobContainer.GetBlockBlobReference(key.ToString());

return blob == null ? null : JsonConvert.DeserializeObject<T>(blob.DownloadText());
}
catch (StorageException storageException)
{
// check for 404 and return null in that case only, let others bubble up
if (storageException.RequestInformation.HttpStatusCode == 404)
{
return null;
}

return blob == null ? null : JsonConvert.DeserializeObject<T>(blob.DownloadText());
throw;
}

}

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

protected override void AddItem(T entity)
{
var blob = GetBlobReference(entity);
blob.UploadText(JsonConvert.SerializeObject(entity));
AddOrUpdateItem(entity);
}

protected override void DeleteItem(T entity)
Expand All @@ -77,6 +90,11 @@ protected override void DeleteItem(T entity)
}

protected override void UpdateItem(T entity)
{
AddOrUpdateItem(entity);
}

private void AddOrUpdateItem(T entity)
{
var blob = GetBlobReference(entity);
blob.UploadText(JsonConvert.SerializeObject(entity));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using SharpRepository.Repository.Configuration;

namespace SharpRepository.AzureBlobRepository
{
public class AzureBlobRepositoryConfiguration : RepositoryConfiguration
{
public AzureBlobRepositoryConfiguration(string name) : this(name, null, null)
{
}

public AzureBlobRepositoryConfiguration(string name, string connectionString)
: this(name, connectionString, null)
{
}

public AzureBlobRepositoryConfiguration(string name, string connectionString, string container, bool createIfNotExists = false, string cachingStrategy = null, string cachingProvider = null)
: base(name)
{
ConnectionString = connectionString;
Container = container;
CreateIfNotExists = createIfNotExists;
CachingStrategy = cachingStrategy;
CachingProvider = cachingProvider;
Factory = typeof(AzureBlobConfigRepositoryFactory);
}

public string ConnectionString
{
set { Attributes["connectionString"] = value; }
}

public string Container
{
set { Attributes["container"] = String.IsNullOrEmpty(value) ? null : value; }
}

public bool CreateIfNotExists
{
set { Attributes["createIfNotExists"] = value.ToString(); }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,34 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Data.Edm, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
<Reference Include="Microsoft.Data.Edm, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Data.Edm.5.6.1\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
<Reference Include="Microsoft.Data.OData, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Data.OData.5.6.1\lib\net40\Microsoft.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath>
<Reference Include="Microsoft.Data.Services.Client, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Microsoft.Data.Services.Client.5.6.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=2.1.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.2.0.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=3.1.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\WindowsAzure.Storage.2.1.0.4\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
<HintPath>..\packages\WindowsAzure.Storage.3.1.0.1\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Services.Client" />
<Reference Include="System.Spatial, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll</HintPath>
<Reference Include="System.Spatial, Version=5.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.Spatial.5.6.1\lib\net40\System.Spatial.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -62,6 +69,8 @@
<ItemGroup>
<Compile Include="AzureBlobRepository.cs" />
<Compile Include="AzureBlobRepositoryBase.cs" />
<Compile Include="AzureBlobConfigRepositoryFactory.cs" />
<Compile Include="AzureBlobRepositoryConfiguration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -71,6 +80,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
19 changes: 19 additions & 0 deletions SharpRepository.AzureBlobRepository/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.1.0" newVersion="5.6.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
11 changes: 6 additions & 5 deletions SharpRepository.AzureBlobRepository/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Data.Edm" version="5.2.0" targetFramework="net40" />
<package id="Microsoft.Data.OData" version="5.2.0" targetFramework="net40" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="1.8.0.0" targetFramework="net40" />
<package id="Microsoft.Data.Edm" version="5.6.1" targetFramework="net40" />
<package id="Microsoft.Data.OData" version="5.6.1" targetFramework="net40" />
<package id="Microsoft.Data.Services.Client" version="5.6.1" targetFramework="net40" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net40" />
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net40" />
<package id="System.Spatial" version="5.2.0" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="2.1.0.4" targetFramework="net40" />
<package id="System.Spatial" version="5.6.1" targetFramework="net40" />
<package id="WindowsAzure.Storage" version="3.1.0.1" targetFramework="net40" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = nul

protected override void AddItem(T entity)
{
Table.Execute(TableOperation.Insert(entity));
Table.Execute(TableOperation.InsertOrReplace(entity));
}

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