Permalink
Browse files

cleanup before pushing 0.1

  • Loading branch information...
1 parent 55aaf69 commit 5ab38640f21c89c4b4b684bc78e8d4ab917ae44a @craiggwilson committed Sep 1, 2012
View
@@ -8,6 +8,7 @@ TestResults
# Nuget
packages
+NuGet.config
# NCrunch
*.ncrunch*
View
@@ -13,19 +13,20 @@
<description>"OData provider backed by MongoDB"</description>
<tags>mongodb mongo odata wcf</tags>
<dependencies>
- <dependency id="FluentAssertions"/>
- <dependency id="Microsoft.Data.Edm"/>
- <dependency id="Microsoft.Data.OData"/>
- <dependency id="Microsoft.Data.Services"/>
- <dependency id="Microsoft.Data.Services.Client"/>
- <dependency id="mongocsharpdriver"/>
- <dependency id="NUnit"/>
- <dependency id="System.Spatial"/>
+ <dependency id="FluentAssertions" version="1.7.1.1" />
+ <dependency id="Microsoft.Data.Edm" version="5.0.2" />
+ <dependency id="Microsoft.Data.OData" version="5.0.2" />
+ <dependency id="Microsoft.Data.Services" version="5.0.2" />
+ <dependency id="Microsoft.Data.Services.Client" version="5.0.2" />
+ <dependency id="mongocsharpdriver" version="1.6"/>
+ <dependency id="NUnit" version="2.6.1"/>
+ <dependency id="System.Spatial" version="5.0.2"/>
</dependencies>
</metadata>
<files>
<file src="artifacts\build\MongoDB.OData.dll" target="lib\4.0" />
<file src="artifacts\build\MongoDB.OData.xml" target="lib\4.0" />
<file src="artifacts\build\MongoDB.OData.pdb" target="lib\4.0" />
+ <file src="src\**\*.cs" target="src" />
</files>
</package>
View
@@ -1,4 +1,65 @@
mongo-dotnet-odata
==================
-An OData Provider for MongoDB
+An OData Provider for MongoDB. Requires OData version 3 for support of mongodb arrays.
+
+Getting Started
+---------------
+
+It's extremely easy to get an odata service up and running with mongodb. Below are a few simple steps:
+
+1. Using nuget, simply pull down the [MongoDB.OData](http://www.nuget.org/packages/MongoDB.OData) package.
+2. Create a class that you want to be your OData container name.
+
+ [MongoDatabase("hr")]
+ public class Sample
+ {
+ [MongoCollection("people")]
+ public MongoCollection<Person> People { get; set; }
+
+ [MongoCollection("users")]
+ public MongoCollection<User> Users { get; set; }
+ }
+
+3. Create a WCF Data Service
+4. Inherit from `MongoDataService<T>` and implement the abstract methods. Also, like any other WCF data service, you need to configure the entity.
+
+ public class SampleService : MongoDataService<Sample>
+ {
+ // This method is called only once to initialize service-wide policies.
+ public static void InitializeService(DataServiceConfiguration config)
+ {
+ // MongoDataService<T> has a method that pre-configures some stuff for you...
+ Configure(config);
+
+ // Set these as necessary
+ config.SetEntitySetAccessRule("*", EntitySetRights.All);
+ config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
+ }
+
+ protected override MongoServer CreateMongoServer()
+ {
+ // use whatever your connection string is. if you don't know how to form a
+ // mongodb connection string, please refer to the mongodb documentation at
+ // http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Connectionstrings.
+ return MongoServer.Create();
+ }
+ }
+
+5. That's it. You can see the [samples](https://github.com/craiggwilson/mongo-dotnet-odata/tree/master/src/MongoDB.OData.SampleHost) for working examples.
+
+Supported Features
+------------------
+
+- Queries
+ - OData Entity Types - MongoDB Documents
+ - OData Complex Types - MongoDB Embedded Documents
+ - OData Collections - MongoDB Arrays
+- OData Service Operations
+
+Future Development
+------------------
+- Projections
+- Spatial Literals
+- Updating
+- ObjectId translation
View
@@ -1,22 +1,22 @@
Properties {
$base_dir = Split-Path $psake.build_script_file
- $artifacts_dir = "$base_dir\artifacts\"
- $build_dir = "$artifacts_dir\build\"
- $package_dir = "$artifacts_dir\packages\"
- $src_dir = "$base_dir\src\"
- $tools_dir = "$base_dir\tools\"
- $nuget_file = "$tools_dir\nuget\nuget.exe"
- $nunit_file = "$tools_dir\nunit\nunit-console.exe"
+ $artifacts_dir = "$base_dir\artifacts"
+ $build_dir = "$artifacts_dir\build"
+ $package_dir = "$artifacts_dir\packages"
+ $src_dir = "$base_dir\src"
+ $tools_dir = "$base_dir\tools"
$sln_file = "$base_dir\MongoDB.OData.sln"
$asm_file = "$src_dir\GlobalAssemblyInfo.cs"
$nuspec_file = "$base_dir\MongoDB.OData.nuspec"
- $version = "0.1.0.0"
- $sem_version = "0.1"
+ $nuget_tool = "$tools_dir\nuget\nuget.exe"
+
+ $version = "0.1.1.0"
+ $sem_version = "0.1.1"
$config = "Release"
}
-$framework = '4.0'
+Framework("4.0")
include .\psake_ext.ps1
@@ -49,8 +49,12 @@ Task Build -Depends Init {
Exec { msbuild "$sln_file" /t:Build /p:Configuration=Release /v:quiet /p:OutDir=$build_dir }
}
-task Package -depends Build {
+task Package -Depends Build {
mkdir -p $package_dir
- & $nuget_file pack $nuspec_file -o $package_dir -Version $sem_version -Symbols -BasePath $base_dir
+ &$nuget_tool pack $nuspec_file -o $package_dir -Version $sem_version -Symbols -BasePath $base_dir
+}
+
+task Publish -Depends Package {
+ &$nuget_tool push "$package_dir\MongoDB.OData.$sem_version.nupkg"
}
Binary file not shown.
@@ -2,11 +2,24 @@
namespace MongoDB.OData
{
+ /// <summary>
+ /// Defines the mongodb collection to use.
+ /// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public class MongoCollectionAttribute : Attribute
{
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>
+ /// The name.
+ /// </value>
public string Name { get; private set; }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MongoCollectionAttribute" /> class.
+ /// </summary>
+ /// <param name="name">The name.</param>
public MongoCollectionAttribute(string name)
{
Name = name;
@@ -7,18 +7,33 @@
namespace MongoDB.OData
{
- public abstract class MongoDataService<T> : DataService<TypedDataSource>, IServiceProvider
+ /// <summary>
+ /// Base class for creating a WCF Data Service to connect to MongoDB.
+ /// </summary>
+ /// <typeparam name="TDataContext">The type of the data context.</typeparam>
+ public abstract class MongoDataService<TDataContext> : DataService<TypedDataSource>, IServiceProvider
{
private static object _metadataLock = new object();
private static TypedMetadata _metadata;
+ /// <summary>
+ /// Some basic configuration that should be used.
+ /// </summary>
+ /// <param name="config">The config.</param>
protected static void Configure(DataServiceConfiguration config)
{
config.DataServiceBehavior.AcceptProjectionRequests = false;
config.DataServiceBehavior.AcceptSpatialLiteralsInQuery = false;
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
+ /// <summary>
+ /// Gets the service object of the specified type.
+ /// </summary>
+ /// <param name="serviceType">An object that specifies the type of service object to get.</param>
+ /// <returns>
+ /// A service object of type <paramref name="serviceType" />.-or- null if there is no service object of type <paramref name="serviceType" />.
+ /// </returns>
public object GetService(Type serviceType)
{
if (serviceType == typeof(IDataServiceMetadataProvider))
@@ -35,6 +50,10 @@ public object GetService(Type serviceType)
}
}
+ /// <summary>
+ /// Creates the data source.
+ /// </summary>
+ /// <returns></returns>
protected sealed override TypedDataSource CreateDataSource()
{
var server = CreateMongoServer();
@@ -44,40 +63,50 @@ protected sealed override TypedDataSource CreateDataSource()
return dataSource;
}
- protected virtual T CreateDataContext(MongoServer server)
+ /// <summary>
+ /// Creates the data context.
+ /// </summary>
+ /// <param name="server">The server.</param>
+ /// <returns>An instance of the data context.</returns>
+ /// <exception cref="System.InvalidOperationException"></exception>
+ protected virtual TDataContext CreateDataContext(MongoServer server)
{
- var ctor = typeof(T).GetConstructor(new[] { typeof(MongoServer) });
+ var ctor = typeof(TDataContext).GetConstructor(new[] { typeof(MongoServer) });
if (ctor != null)
{
- return (T)ctor.Invoke(new[] { server });
+ return (TDataContext)ctor.Invoke(new[] { server });
}
- ctor = typeof(T).GetConstructor(Type.EmptyTypes);
+ ctor = typeof(TDataContext).GetConstructor(Type.EmptyTypes);
if (ctor != null)
{
- return (T)ctor.Invoke(new object[0]);
+ return (TDataContext)ctor.Invoke(new object[0]);
}
- throw new InvalidOperationException(string.Format("Either overload the CreateDataContext(MongoServer) method or ensure that {0} has an empty ctor or a ctor that take a single MongoServer parameter.", typeof(T)));
+ throw new InvalidOperationException(string.Format("Either overload the CreateDataContext(MongoServer) method or ensure that {0} has an empty ctor or a ctor that take a single MongoServer parameter.", typeof(TDataContext)));
}
+ /// <summary>
+ /// Creates the mongo server.
+ /// </summary>
+ /// <returns>An instance of the MongoServer used for connecting to the mongodb servers.</returns>
protected abstract MongoServer CreateMongoServer();
private TypedMetadata GetMetadata()
{
- //if (_metadataProvider == null)
- //{
- // lock (_metadataLock)
- // {
- // if (_metadataProvider == null)
- // {
- var builder = new TypedMetadataBuilder<T>();
- _metadata = builder.BuildMetadata();
- // }
- // }
- //}
+ if (_metadata == null)
+ {
+ lock (_metadataLock)
+ {
+ if (_metadata == null)
+ {
+ var builder = new TypedMetadataBuilder<TDataContext>();
+ _metadata = builder.BuildMetadata();
+ }
+ }
+ }
return _metadata;
}
@@ -90,7 +119,7 @@ private TypedQueryProvider GetQueryProvider()
private void InitializeDataContext(TypedDataSource dataSource)
{
var metadata = GetMetadata();
- foreach(var resourceSet in metadata.ResourceSets)
+ foreach (var resourceSet in metadata.ResourceSets)
{
var annotation = (TypedResourceSetAnnotation)resourceSet.CustomState;
annotation.SetDataContext(dataSource);
@@ -2,11 +2,24 @@
namespace MongoDB.OData
{
+ /// <summary>
+ /// Defines the mongodb database to use.
+ /// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public class MongoDatabaseAttribute : Attribute
{
+ /// <summary>
+ /// Gets the name.
+ /// </summary>
+ /// <value>
+ /// The name.
+ /// </value>
public string Name { get; private set; }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MongoDatabaseAttribute" /> class.
+ /// </summary>
+ /// <param name="name">The name.</param>
public MongoDatabaseAttribute(string name)
{
Name = name;
@@ -2,12 +2,33 @@
namespace MongoDB.OData.Typed
{
+ /// <summary>
+ /// A data source that includes both the MongoServer needed to connect to MongoDB as well
+ /// as the defining DataContext provided by the user.
+ /// </summary>
public sealed class TypedDataSource
{
+ /// <summary>
+ /// Gets the data context.
+ /// </summary>
+ /// <value>
+ /// The data context.
+ /// </value>
public object DataContext { get; private set; }
+ /// <summary>
+ /// Gets the server.
+ /// </summary>
+ /// <value>
+ /// The server.
+ /// </value>
public MongoServer Server { get; private set; }
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TypedDataSource" /> class.
+ /// </summary>
+ /// <param name="server">The server.</param>
+ /// <param name="dataContext">The data context.</param>
public TypedDataSource(MongoServer server, object dataContext)
{
Server = server;
@@ -516,9 +516,9 @@ private static string GetResourceTypeName(Type type)
return type.Name;
}
- protected static T GetSingleAttribute<T>(MemberInfo member) where T : Attribute
+ private static TAttribute GetSingleAttribute<TAttribute>(MemberInfo member) where TAttribute : Attribute
{
- return (T)member.GetCustomAttributes(typeof(T), false).SingleOrDefault();
+ return (TAttribute)member.GetCustomAttributes(typeof(TAttribute), false).SingleOrDefault();
}
}
}
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <solution>
- <add key="disableSourceControlIntegration" value="true" />
- </solution>
-</configuration>
View
Binary file not shown.

0 comments on commit 5ab3864

Please sign in to comment.