-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting in place the first stab at a DocumentDB implementation #531
- Loading branch information
Showing
10 changed files
with
589 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{8DB73E9B-8AE1-4341-8DF8-469C578A150D}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Bifrost.DocumentDB</RootNamespace> | ||
<AssemblyName>Bifrost.DocumentDB</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\Solutions\</SolutionDir> | ||
<RestorePackages>true</RestorePackages> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<DocumentationFile>bin\Debug\Bifrost.DocumentDB.XML</DocumentationFile> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.Azure.Documents.Client"> | ||
<HintPath>..\Solutions\packages\Microsoft.Azure.Documents.Client.0.9.0-preview\lib\net40\Microsoft.Azure.Documents.Client.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\Solutions\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Entities\ConfigurationExtensions.cs" /> | ||
<Compile Include="Entities\EntityContextConnection.cs" /> | ||
<Compile Include="Entities\EntityContext.cs" /> | ||
<Compile Include="Entities\EntityContextConfiguration.cs" /> | ||
<Compile Include="Events\ConfigurationExtensions.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Read\QueryProvider.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Bifrost\Bifrost.csproj"> | ||
<Project>{fb310720-cd89-44b6-bd54-7861f65d8466}</Project> | ||
<Name>Bifrost</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> | ||
</Target> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
86 changes: 86 additions & 0 deletions
86
Source/Bifrost.DocumentDB/Entities/ConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#region License | ||
// | ||
// Copyright (c) 2008-2014, Dolittle (http://www.dolittle.com) | ||
// | ||
// Licensed under the MIT License (http://opensource.org/licenses/MIT) | ||
// | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the license at | ||
// | ||
// http://github.com/dolittle/Bifrost/blob/master/MIT-LICENSE.txt | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#endregion | ||
using System; | ||
using Bifrost.Configuration; | ||
using Bifrost.DocumentDB.Entities; | ||
|
||
namespace Bifrost.Configuration | ||
{ | ||
/// <summary> | ||
/// Extensions for configuration | ||
/// </summary> | ||
public static partial class ConfigurationExtensions | ||
{ | ||
/// <summary> | ||
/// Configures <see cref="IHaveStorage">storage</see> to use a DocumentDB | ||
/// </summary> | ||
/// <param name="storage"><see cref="IHaveStorage">Storage</see> to configure</param> | ||
/// <param name="callback">Chained callback for configuring the specifics</param> | ||
/// <returns>Chained <see cref="IConfigure"/> for fluent configuration</returns> | ||
public static IConfigure UsingDocumentDB(this IHaveStorage storage, Action<EntityContextConfiguration> callback) | ||
{ | ||
var configuration = new EntityContextConfiguration(); | ||
callback(configuration); | ||
|
||
var connection = new EntityContextConnection(configuration); | ||
configuration.Connection = connection; | ||
|
||
storage.EntityContextConfiguration = configuration; | ||
|
||
return Configure.Instance; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Configure the Url endpoint for the database server | ||
/// </summary> | ||
/// <param name="configuration"><see cref="EntityContextConfiguration"/> to configure</param> | ||
/// <param name="url"></param> | ||
/// <returns>Chained <see cref="EntityContextConfiguration"/> to configure</returns> | ||
public static EntityContextConfiguration WithUrl(this EntityContextConfiguration configuration, string url) | ||
{ | ||
configuration.Url = url; | ||
return configuration; | ||
} | ||
|
||
/// <summary> | ||
/// Configure the default database by its databaseId | ||
/// </summary> | ||
/// <param name="configuration"><see cref="EntityContextConfiguration"/> to configure</param> | ||
/// <param name="databaseId">Database id to connect to</param> | ||
/// <returns>Chained <see cref="EntityContextConfiguration"/> to configure</returns> | ||
public static EntityContextConfiguration WithDefaultDatabase(this EntityContextConfiguration configuration, string databaseId) | ||
{ | ||
configuration.DatabaseId = databaseId; | ||
return configuration; | ||
} | ||
|
||
/// <summary> | ||
/// Configure the authorization key to use | ||
/// </summary> | ||
/// <param name="configuration"><see cref="EntityContextConfiguration"/> to configure</param> | ||
/// <param name="authorizationKey">Authorization key to use</param> | ||
/// <returns>Chained <see cref="EntityContextConfiguration"/> to configure</returns> | ||
public static EntityContextConfiguration UsingAuthorizationKey(this EntityContextConfiguration configuration, string authorizationKey) | ||
{ | ||
configuration.AuthorizationKey = authorizationKey; | ||
return configuration; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#region License | ||
// | ||
// Copyright (c) 2008-2014, Dolittle (http://www.dolittle.com) | ||
// | ||
// Licensed under the MIT License (http://opensource.org/licenses/MIT) | ||
// | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the license at | ||
// | ||
// http://github.com/dolittle/Bifrost/blob/master/MIT-LICENSE.txt | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#endregion | ||
using System; | ||
using System.Linq; | ||
using Bifrost.Entities; | ||
using Microsoft.Azure.Documents; | ||
using Microsoft.Azure.Documents.Linq; | ||
|
||
namespace Bifrost.DocumentDB.Entities | ||
{ | ||
/// <summary> | ||
/// Represents an implementation of <see cref="IEntityContext{T}"/> specifically for DocumentDB | ||
/// </summary> | ||
/// <typeparam name="T">Type of entity</typeparam> | ||
public class EntityContext<T> : IEntityContext<T> | ||
{ | ||
EntityContextConnection _connection; | ||
DocumentCollection _collection; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="EntityContext{T}"/> | ||
/// </summary> | ||
/// <param name="connection"></param> | ||
public EntityContext(EntityContextConnection connection) | ||
{ | ||
_connection = connection; | ||
_collection = connection.GetCollectionFor<T>(); | ||
} | ||
|
||
#pragma warning disable 1591 // Xml Comments | ||
public IQueryable<T> Entities | ||
{ | ||
get | ||
{ | ||
var queryable = _connection.Client.CreateDocumentQuery<T>(_collection.DocumentsLink); | ||
return queryable; | ||
} | ||
} | ||
|
||
public void Attach(T entity) | ||
{ | ||
} | ||
|
||
public void Insert(T entity) | ||
{ | ||
_connection.Client.CreateDocumentAsync(_collection.DocumentsLink, entity); | ||
} | ||
|
||
public void Update(T entity) | ||
{ | ||
_connection.Client.ReplaceDocumentAsync(_collection.DocumentsLink, entity); | ||
} | ||
|
||
public void Delete(T entity) | ||
{ | ||
|
||
} | ||
|
||
public void Save(T entity) | ||
{ | ||
_connection.Client.ReplaceDocumentAsync(_collection.DocumentsLink, entity); | ||
} | ||
|
||
public void Commit() | ||
{ | ||
} | ||
|
||
public T GetById<TProperty>(TProperty id) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public void DeleteById<TProperty>(TProperty id) | ||
{ | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
#pragma warning restore 1591 // Xml Comments | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Source/Bifrost.DocumentDB/Entities/EntityContextConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#region License | ||
// | ||
// Copyright (c) 2008-2014, Dolittle (http://www.dolittle.com) | ||
// | ||
// Licensed under the MIT License (http://opensource.org/licenses/MIT) | ||
// | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the license at | ||
// | ||
// http://github.com/dolittle/Bifrost/blob/master/MIT-LICENSE.txt | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#endregion | ||
using System; | ||
using Bifrost.Configuration; | ||
using Bifrost.Entities; | ||
|
||
namespace Bifrost.DocumentDB.Entities | ||
{ | ||
/// <summary> | ||
/// Implements the <see cref="IEntityContextConfiguration"/> specific for the DocumentDB support | ||
/// </summary> | ||
public class EntityContextConfiguration : IEntityContextConfiguration | ||
{ | ||
/// <summary> | ||
/// Gets or sets the url endpoint for the database server | ||
/// </summary> | ||
public string Url { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the database id | ||
/// </summary> | ||
public string DatabaseId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the authorization key | ||
/// </summary> | ||
public string AuthorizationKey { get; set; } | ||
|
||
|
||
#pragma warning disable 1591 // Xml Comments | ||
public Type EntityContextType { get { return typeof(EntityContext<>); } } | ||
|
||
public IEntityContextConnection Connection { get; set; } | ||
#pragma warning restore 1591 // Xml Comments | ||
} | ||
} |
Oops, something went wrong.