Skip to content

Commit b4bb556

Browse files
author
Jeff Treuting
committed
Merged AOP branch
This brings in aspects on entities that hook into the lifecycle of a repository as well as azure table and azure blob repositories (still in beta)
1 parent 67d6801 commit b4bb556

File tree

124 files changed

+452127
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+452127
-212
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using SharpRepository.Repository.Caching;
2+
3+
namespace SharpRepository.AzureBlobRepository
4+
{
5+
public class AzureBlobRepository<T, TKey> : AzureBlobRepositoryBase<T, TKey> where T: class, new()
6+
{
7+
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = true, ICachingStrategy<T, TKey> cachingStrategy = null)
8+
: base(connectionString, containerName, createIfNotExists, cachingStrategy)
9+
{
10+
11+
}
12+
}
13+
14+
public class AzureBlobRepository<T> : AzureBlobRepositoryBase<T, string> where T : class, new()
15+
{
16+
public AzureBlobRepository(string connectionString, string containerName = null, bool createIfNotExists = true, ICachingStrategy<T, string> cachingStrategy = null)
17+
: base(connectionString, containerName, createIfNotExists, cachingStrategy)
18+
{
19+
20+
}
21+
}
22+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Text;
5+
using Microsoft.WindowsAzure.Storage.Blob;
6+
using Newtonsoft.Json;
7+
using SharpRepository.Repository;
8+
using SharpRepository.Repository.Caching;
9+
using SharpRepository.Repository.FetchStrategies;
10+
11+
namespace SharpRepository.AzureBlobRepository
12+
{
13+
public class AzureBlobRepositoryBase<T, TKey> : LinqRepositoryBase<T, TKey> where T: class, new()
14+
{
15+
protected CloudBlobClient BlobClient { get; private set; }
16+
protected CloudBlobContainer BlobContainer { get; private set; }
17+
protected string ContainerName { get; private set; }
18+
19+
internal AzureBlobRepositoryBase(string connectionString, string containerName, bool createIfNotExists,
20+
ICachingStrategy<T, TKey> cachingStrategy = null)
21+
: base(cachingStrategy)
22+
{
23+
var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connectionString);
24+
25+
ContainerName = TypeName.ToLower();
26+
27+
if (!String.IsNullOrEmpty(containerName))
28+
{
29+
ContainerName = containerName;
30+
}
31+
32+
BlobClient = storageAccount.CreateCloudBlobClient();
33+
BlobContainer = BlobClient.GetContainerReference(ContainerName);
34+
35+
if (createIfNotExists)
36+
{
37+
BlobContainer.CreateIfNotExists();
38+
}
39+
}
40+
41+
protected override T GetQuery(TKey key)
42+
{
43+
var blob = BlobContainer.GetBlockBlobReference(key.ToString());
44+
45+
return blob == null ? null : JsonConvert.DeserializeObject<T>(blob.DownloadText());
46+
}
47+
48+
protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = null)
49+
{
50+
throw new NotImplementedException();
51+
}
52+
53+
private CloudBlockBlob GetBlobReference(T entity)
54+
{
55+
TKey key;
56+
GetPrimaryKey(entity, out key);
57+
58+
return BlobContainer.GetBlockBlobReference(key.ToString());
59+
}
60+
61+
protected override void AddItem(T entity)
62+
{
63+
var blob = GetBlobReference(entity);
64+
blob.UploadText(JsonConvert.SerializeObject(entity));
65+
}
66+
67+
protected override void DeleteItem(T entity)
68+
{
69+
var blob = GetBlobReference(entity);
70+
blob.DeleteIfExists();
71+
}
72+
73+
protected override void UpdateItem(T entity)
74+
{
75+
var blob = GetBlobReference(entity);
76+
blob.UploadText(JsonConvert.SerializeObject(entity));
77+
}
78+
79+
protected override void SaveChanges()
80+
{
81+
82+
}
83+
84+
public override void Dispose()
85+
{
86+
87+
}
88+
}
89+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SharpRepository.AzureBlobRepository")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SharpRepository.AzureBlobRepository")]
13+
[assembly: AssemblyCopyright("Copyright © 2013")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("65284fa9-8790-403c-8242-9a3081a48a2b")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{F766CC4F-B69C-444C-A89F-01E2E8B172A8}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>SharpRepository.AzureBlobRepository</RootNamespace>
11+
<AssemblyName>SharpRepository.AzureBlobRepository</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<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>
36+
</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>
39+
</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>
43+
<Reference Include="Microsoft.WindowsAzure.Storage, Version=2.1.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
44+
<SpecificVersion>False</SpecificVersion>
45+
<HintPath>..\packages\WindowsAzure.Storage.2.1.0.4\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
46+
</Reference>
47+
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
48+
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
49+
</Reference>
50+
<Reference Include="System" />
51+
<Reference Include="System.Core" />
52+
<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>
55+
</Reference>
56+
<Reference Include="System.Xml.Linq" />
57+
<Reference Include="System.Data.DataSetExtensions" />
58+
<Reference Include="Microsoft.CSharp" />
59+
<Reference Include="System.Data" />
60+
<Reference Include="System.Xml" />
61+
</ItemGroup>
62+
<ItemGroup>
63+
<Compile Include="AzureBlobRepository.cs" />
64+
<Compile Include="AzureBlobRepositoryBase.cs" />
65+
<Compile Include="Properties\AssemblyInfo.cs" />
66+
</ItemGroup>
67+
<ItemGroup>
68+
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj">
69+
<Project>{710dee79-25ce-4f68-b8b1-d08a135ad154}</Project>
70+
<Name>SharpRepository.Repository</Name>
71+
</ProjectReference>
72+
</ItemGroup>
73+
<ItemGroup>
74+
<None Include="packages.config" />
75+
</ItemGroup>
76+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
77+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
78+
Other similar extension points exist, see Microsoft.Common.targets.
79+
<Target Name="BeforeBuild">
80+
</Target>
81+
<Target Name="AfterBuild">
82+
</Target>
83+
-->
84+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<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" />
6+
<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" />
9+
</packages>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Microsoft.WindowsAzure.Storage.Table;
2+
using SharpRepository.Repository.Caching;
3+
4+
namespace SharpRepository.AzureTableRepository
5+
{
6+
public class AzureTableRepository<T> : AzureTableRepositoryBase<T> where T : class, ITableEntity, new()
7+
{
8+
public AzureTableRepository(string connectionString, string tableName = null, bool createIfNotExists = true, ICompoundKeyCachingStrategy<T, string, string> cachingStrategy = null)
9+
: base(connectionString, tableName, createIfNotExists, cachingStrategy)
10+
{
11+
}
12+
}
13+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Linq;
3+
using System.Reflection;
4+
using Microsoft.WindowsAzure.Storage.Table;
5+
using SharpRepository.Repository;
6+
using SharpRepository.Repository.Caching;
7+
using SharpRepository.Repository.FetchStrategies;
8+
9+
namespace SharpRepository.AzureTableRepository
10+
{
11+
public class AzureTableRepositoryBase<T> : LinqCompoundKeyRepositoryBase<T, string, string> where T : class, ITableEntity, new()
12+
{
13+
protected CloudTableClient TableClient { get; private set; }
14+
protected CloudTable Table { get; private set; }
15+
protected string TableName { get; private set; }
16+
17+
internal AzureTableRepositoryBase(string connectionString, string tableName, bool createIfNotExists, ICompoundKeyCachingStrategy<T, string, string> cachingStrategy = null)
18+
: base(cachingStrategy)
19+
{
20+
var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connectionString);
21+
22+
TableName = TypeName;
23+
24+
if (!String.IsNullOrEmpty(tableName))
25+
{
26+
TableName = tableName;
27+
}
28+
29+
TableClient = storageAccount.CreateCloudTableClient();
30+
Table = TableClient.GetTableReference(TableName);
31+
32+
if (createIfNotExists)
33+
{
34+
Table.CreateIfNotExists();
35+
}
36+
}
37+
38+
protected override T GetQuery(string key, string key2)
39+
{
40+
var result = Table.Execute(TableOperation.Retrieve<T>(key, key2));
41+
return result.Result as T;
42+
}
43+
44+
protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = null)
45+
{
46+
throw new NotImplementedException();
47+
}
48+
49+
protected override void AddItem(T entity)
50+
{
51+
Table.Execute(TableOperation.Insert(entity));
52+
}
53+
54+
// TODO: override Add(IEnumerable<T> entities) to use the TableSet.Add(entities) isntead of looping ourselves and having AddItem() called multiple times
55+
56+
protected override void DeleteItem(T entity)
57+
{
58+
Table.Execute(TableOperation.Delete(entity));
59+
}
60+
61+
protected override void UpdateItem(T entity)
62+
{
63+
Table.Execute(TableOperation.Replace(entity));
64+
}
65+
66+
protected override void SaveChanges()
67+
{
68+
69+
}
70+
71+
protected override PropertyInfo[] GetPrimaryKeyPropertyInfo()
72+
{
73+
var type = typeof(T);
74+
75+
var partitionKey = type.GetProperty("PartitionKey") ;
76+
var rowKey = type.GetProperty("RowKey");
77+
78+
if (partitionKey != null && rowKey != null)
79+
{
80+
return new [] { partitionKey, rowKey};
81+
}
82+
83+
return base.GetPrimaryKeyPropertyInfo();
84+
}
85+
86+
public override void Dispose()
87+
{
88+
89+
}
90+
}
91+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SharpRepository.AzureTableRepository")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SharpRepository.AzureTableRepository")]
13+
[assembly: AssemblyCopyright("Copyright © 2013")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("72bbdf66-ceb1-463c-840e-07d8a128e356")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)