Skip to content

Commit

Permalink
Default configurations on packages
Browse files Browse the repository at this point in the history
Factory for AzureTable
Factory for CouchDb
Factory for AppFabric cache
Factory for WindowsAzure cache
  • Loading branch information
omarpiani committed Nov 2, 2017
1 parent 629568c commit b356c74
Show file tree
Hide file tree
Showing 67 changed files with 722 additions and 470 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard1.3</TargetFrameworks>
<Product>SharpRepository for AzureBlob</Product>
<Authors>Ben Griswold, Jeff Treuting</Authors>
<Description>SharpRepository is a generic repository</Description>
<Product>SharpRepository for AzureBlob</Product>
<Authors>Ben Griswold, Jeff Treuting</Authors>
<Description>SharpRepository is a generic repository, AzureBlob implementation</Description>
<Summary>Written in C#, includes support for various relational, document and object databases including Entity Framework, RavenDB, MongoDB, CouchDB and Db4o. SharpRepository includes Xml and InMemory repository implementations as well. SharpRepository offers built-in caching options for AppFabric, memcached and the standard System.Runtime.Caching. SharpRepository also supports Specifications, FetchStrategies, Batches and Traits!</Summary>
<PackageId>SharpRepository.AzureBlobRepository</PackageId>
<PackageId>SharpRepository.AzureBlobRepository</PackageId>
<PackageVersion>2.0.1-alpha3</PackageVersion>
<PackageReleaseNotes>2.0.1-alpha3: configurable via appsettings.json</PackageReleaseNotes>
<PackageTags>SharpRepository Repository Azure Blob</PackageTags>
<PackageIconUrl>https://user-images.githubusercontent.com/6349515/28491142-7b6350c4-6eeb-11e7-9c5b-e3b8ef1e73b8.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/SharpRepository/SharpRepository</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/SharpRepository/SharpRepository/master/license.txt</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>2.0.1-alpha3: configurable via appsettings.json</PackageReleaseNotes>
<PackageTags>SharpRepository Repository Azure Blob</PackageTags>
<PackageIconUrl>https://user-images.githubusercontent.com/6349515/28491142-7b6350c4-6eeb-11e7-9c5b-e3b8ef1e73b8.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/SharpRepository/SharpRepository</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/SharpRepository/SharpRepository/master/license.txt</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/SharpRepository/SharpRepository.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>2.0.1-alpha3</Version>
<FileVersion>2.0.1.0</FileVersion>
<RepositoryType>git</RepositoryType>
<Version>2.0.1-alpha3</Version>
</PropertyGroup>
<ItemGroup>
<Content Include="repository.azureBlob.json">
<Pack>true</Pack>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj" />
</ItemGroup>
Expand Down
13 changes: 13 additions & 0 deletions SharpRepository.AzureBlobRepository/repository.azureBlob.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"sharpRepository": {
"repositories": {
"default": "azureBlob",
"azureBlob": {
"factory": "SharpRepository.AzureBlobRepository.AzureBlobConfigRepositoryFactory, SharpRepository.AzureBlobRepository",
"connectionString": "connectionStringOrName",
"container": "containerName",
"createIfNotExists": "true"
}
}
}
}
11 changes: 0 additions & 11 deletions SharpRepository.AzureDocumentDb/App.config

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netstandard1.5</TargetFrameworks>
<Product>SharpRepository for AzureDocumentDb</Product>
<Authors>Ben Griswold, Jeff Treuting</Authors>
<Description>SharpRepository is a generic repository</Description>
<Description>SharpRepository is a generic repository, Azure DocumentDb implementation</Description>
<Summary>Written in C#, includes support for various relational, document and object databases including Entity Framework, RavenDB, MongoDB, CouchDB and Db4o. SharpRepository includes Xml and InMemory repository implementations as well. SharpRepository offers built-in caching options for AppFabric, memcached and the standard System.Runtime.Caching. SharpRepository also supports Specifications, FetchStrategies, Batches and Traits!</Summary>
<PackageId>SharpRepository.AzureDocumentDbRepository</PackageId>
<PackageVersion>2.0.1-alpha3</PackageVersion>
Expand All @@ -16,8 +16,13 @@
<RepositoryUrl>https://github.com/SharpRepository/SharpRepository.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>2.0.1-alpha3</Version>
<FileVersion>2.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="repository.azureDocumentDb.json">
<Pack>true</Pack>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj" />
</ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions SharpRepository.AzureDocumentDb/repository.azureDocumentDb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"sharpRepository": {
"repositories": {
"default": "azureDocumentDb",
"azureDocumentDb": {
"factory": "SharpRepository.AzureDocumentDbRepository.DocumentDbConfigRepositoryFactory, SharpRepository.AzureDocumentDbRepository",
"endpointUrl": "https://example.com:443/",
"authorizationKey": "DocumentDBSample",
"databaseId": "Entertainment",
"collectionId": "Games",
"createIfNotExists": "true"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using SharpRepository.Repository;
using SharpRepository.Repository.Configuration;
using Microsoft.WindowsAzure.Storage.Table;

namespace SharpRepository.AzureTableRepository
{
public class AzureTableConfigRepositoryFactory : ConfigRepositoryFactory
{
public AzureTableConfigRepositoryFactory(IRepositoryConfiguration config)
: base(config)
{
}

public override IRepository<T> GetInstance<T>()
{
throw new NotImplementedException();
}

public override IRepository<T, TKey> GetInstance<T, TKey>()
{
throw new NotImplementedException("azure table only implements ICompoundKeyRepository<T, string, string> using GetAzureTableInstanc");
}

public override ICompoundKeyRepository<T> GetCompoundKeyInstance<T>()
{
throw new NotImplementedException("azure table only implements ICompoundKeyRepository<T, string, string> using GetAzureTableInstance");
}

public override ICompoundKeyRepository<T, TKey, TKey2, TKey3> GetInstance<T, TKey, TKey2, TKey3>()
{
throw new NotImplementedException("azure table only implements ICompoundKeyRepository<T, TKey, TKey2>");
}

public override ICompoundKeyRepository<T, TKey, TKey2> GetInstance<T, TKey, TKey2>()
{
Boolean.TryParse(RepositoryConfiguration["createIfNotExists"], out bool createIfNotExists);

return new AzureTableRepository<T, TKey, TKey2>(RepositoryConfiguration["connectionString"], RepositoryConfiguration["tableName"], createIfNotExists);
}
}
}
15 changes: 13 additions & 2 deletions SharpRepository.AzureTableRepository/AzureTableRepository.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
using Microsoft.WindowsAzure.Storage.Table;
using SharpRepository.Repository.Caching;
using System;
using System.Linq;
using System.Reflection;

namespace SharpRepository.AzureTableRepository
{
public class AzureTableRepository<T> : AzureTableRepositoryBase<T> where T : class, ITableEntity, new()
public class AzureTableRepository<T,TKey, TKey2> : AzureTableRepositoryBase<T, TKey, TKey2> where T : class, new()
{
public AzureTableRepository(string connectionString, string tableName = null, bool createIfNotExists = true, ICompoundKeyCachingStrategy<T, string, string> cachingStrategy = null)
public AzureTableRepository(string connectionString, string tableName = null, bool createIfNotExists = true, ICompoundKeyCachingStrategy<T, TKey, TKey2> cachingStrategy = null)
: base(connectionString, tableName, createIfNotExists, cachingStrategy)
{
if (typeof(TKey) != typeof(string) && typeof(TKey2) != typeof(string))
{
throw new Exception("Type of keys TKey and TKey2 musts be string");
}

if (!typeof(T).GetTypeInfo().GetInterfaces().Contains(typeof(ITableEntity))) {
throw new Exception("Type of T must implement ITableEntity");
}
}
}
}
21 changes: 11 additions & 10 deletions SharpRepository.AzureTableRepository/AzureTableRepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

namespace SharpRepository.AzureTableRepository
{
public class AzureTableRepositoryBase<T> : LinqCompoundKeyRepositoryBase<T, string, string> where T : class, ITableEntity, new()
public class AzureTableRepositoryBase<T,TKey,TKey2> : LinqCompoundKeyRepositoryBase<T, TKey, TKey2> where T : class, new()
{
protected CloudTableClient TableClient { get; private set; }
protected CloudTable Table { get; private set; }
protected string TableName { get; private set; }

internal AzureTableRepositoryBase(string connectionString, string tableName, bool createIfNotExists, ICompoundKeyCachingStrategy<T, string, string> cachingStrategy = null)
internal AzureTableRepositoryBase(string connectionString, string tableName, bool createIfNotExists, ICompoundKeyCachingStrategy<T, TKey, TKey2> cachingStrategy = null)
: base(cachingStrategy)
{
var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(connectionString);
Expand All @@ -35,10 +35,13 @@ internal AzureTableRepositoryBase(string connectionString, string tableName, boo
}
}

protected override T GetQuery(string key, string key2)
protected override T GetQuery(TKey key, TKey2 key2)
{
var result = Table.ExecuteAsync(TableOperation.Retrieve<T>(key, key2)).Result;
return result.Result as T;
//TODO: Evaluate if this query without generic type works
var operation = TableOperation.Retrieve(key.ToString(), key2.ToString());

var result = Table.ExecuteAsync(operation).Result;
return result.Result as T;
}

protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = null)
Expand All @@ -48,24 +51,23 @@ protected override IQueryable<T> BaseQuery(IFetchStrategy<T> fetchStrategy = nul

protected override void AddItem(T entity)
{
Table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
Table.ExecuteAsync(TableOperation.InsertOrReplace((ITableEntity)entity));
}

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

protected override void DeleteItem(T entity)
{
Table.ExecuteAsync(TableOperation.Delete(entity));
Table.ExecuteAsync(TableOperation.Delete((ITableEntity)entity));
}

protected override void UpdateItem(T entity)
{
Table.ExecuteAsync(TableOperation.Replace(entity));
Table.ExecuteAsync(TableOperation.Replace((ITableEntity)entity));
}

protected override void SaveChanges()
{

}

protected override PropertyInfo[] GetPrimaryKeyPropertyInfo()
Expand All @@ -85,7 +87,6 @@ protected override PropertyInfo[] GetPrimaryKeyPropertyInfo()

public override void Dispose()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using SharpRepository.Repository.Configuration;

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

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

public AzureTableRepositoryConfiguration(string name, string connectionString, string tableName, bool createIfNotExists = false, string cachingStrategy = null, string cachingProvider = null)
: base(name)
{
ConnectionString = connectionString;
TableName = tableName;
CreateIfNotExists = createIfNotExists;
CachingStrategy = cachingStrategy;
CachingProvider = cachingProvider;
Factory = typeof(AzureTableConfigRepositoryFactory);
}

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

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

public bool CreateIfNotExists
{
set { Attributes["createIfNotExists"] = value.ToString(); }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>netstandard1.5</TargetFrameworks>
<Product>SharpRepository for AzureTable</Product>
<Authors>Ben Griswold, Jeff Treuting</Authors>
<Description>SharpRepository is a generic repository</Description>
<Product>SharpRepository for AzureTable</Product>
<Authors>Ben Griswold, Jeff Treuting</Authors>
<Description>SharpRepository is a generic repository, Azure Table implementation</Description>
<Summary>Written in C#, includes support for various relational, document and object databases including Entity Framework, RavenDB, MongoDB, CouchDB and Db4o. SharpRepository includes Xml and InMemory repository implementations as well. SharpRepository offers built-in caching options for AppFabric, memcached and the standard System.Runtime.Caching. SharpRepository also supports Specifications, FetchStrategies, Batches and Traits!</Summary>
<PackageId>SharpRepository.AzureBlobRepository</PackageId>
<PackageId>SharpRepository.AzureTableRepository</PackageId>
<PackageVersion>2.0.1-alpha3</PackageVersion>
<PackageReleaseNotes>2.0.1-alpha3: configurable via appsettings.json</PackageReleaseNotes>
<PackageTags>SharpRepository Repository Azure Table</PackageTags>
<PackageIconUrl>https://user-images.githubusercontent.com/6349515/28491142-7b6350c4-6eeb-11e7-9c5b-e3b8ef1e73b8.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/SharpRepository/SharpRepository</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/SharpRepository/SharpRepository/master/license.txt</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<PackageReleaseNotes>2.0.1-alpha3: configurable via appsettings.json</PackageReleaseNotes>
<PackageTags>SharpRepository Repository Azure Table</PackageTags>
<PackageIconUrl>https://user-images.githubusercontent.com/6349515/28491142-7b6350c4-6eeb-11e7-9c5b-e3b8ef1e73b8.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/SharpRepository/SharpRepository</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/SharpRepository/SharpRepository/master/license.txt</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/SharpRepository/SharpRepository.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>2.0.1-alpha3</Version>
<RepositoryType>git</RepositoryType>
<Version>2.0.1-alpha3</Version>
</PropertyGroup>
<ItemGroup>
<Content Include="repository.azureTable.json">
<Pack>true</Pack>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="2.3.2" />
<PackageReference Include="WindowsAzure.Storage" Version="8.4.0" />
Expand All @@ -26,7 +32,4 @@
<ItemGroup>
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions SharpRepository.AzureTableRepository/repository.azureTable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"sharpRepository": {
"repositories": {
"default": "azureTable",
"azureTable": {
"factory": "SharpRepository.AzureTable.AzureTableConfigRepositoryFactory, SharpRepository.AzureTable",
"connectionString": "ArzureTableConnectionString",
"tableName": "tableName"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netstandard1.3</TargetFrameworks>
<Product>SharpRepository for a Cache Repository</Product>
<Authors>Ben Griswold, Jeff Treuting</Authors>
<Description>SharpRepository is a generic repository</Description>
<Description>SharpRepository is a generic repository, SharpRepository Cache Provider implementation</Description>
<Summary>Written in C#, includes support for various relational, document and object databases including Entity Framework, RavenDB, MongoDB, CouchDB and Db4o. SharpRepository includes Xml and InMemory repository implementations as well. SharpRepository offers built-in caching options for AppFabric, memcached and the standard System.Runtime.Caching. SharpRepository also supports Specifications, FetchStrategies, Batches and Traits!</Summary>
<PackageId>SharpRepository.CouchDbRepository</PackageId>
<PackageVersion>2.0.1-alpha3</PackageVersion>
Expand All @@ -17,6 +17,12 @@
<RepositoryType>git</RepositoryType>
<Version>2.0.1-alpha3</Version>
</PropertyGroup>
<ItemGroup>
<Content Include="repository.cache.json">
<Pack>true</Pack>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
Expand Down

This file was deleted.

Loading

0 comments on commit b356c74

Please sign in to comment.