Skip to content

Commit

Permalink
IDataServiceQueryProvider implementation seems good.
Browse files Browse the repository at this point in the history
  • Loading branch information
craiggwilson committed Aug 28, 2012
1 parent 17e5f0a commit 2675198
Show file tree
Hide file tree
Showing 35 changed files with 941 additions and 150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@ obj
*.user *.user
*.suo *.suo
*.cache *.cache
TestResults


# Nuget # Nuget
packages packages
Expand Down
36 changes: 30 additions & 6 deletions MongoDB.OData.sln
@@ -1,18 +1,22 @@


Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2010 # Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData", "src\MongoDB.OData\MongoDB.OData.csproj", "{FE1AD69A-98AB-4F2D-88C9-B7B449191912}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.SampleHost", "src\MongoDB.OData.SampleHost\MongoDB.OData.SampleHost.csproj", "{D9B7A239-9F4E-4E55-838D-4766EBEA5672}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C6F8D4C8-3816-48F4-A278-88D6CF8776B7}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C6F8D4C8-3816-48F4-A278-88D6CF8776B7}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore .gitignore = .gitignore
README.md = README.md README.md = README.md
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData", "src\MongoDB.OData\MongoDB.OData.csproj", "{FE1AD69A-98AB-4F2D-88C9-B7B449191912}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.SampleHost", "src\MongoDB.OData.SampleHost\MongoDB.OData.SampleHost.csproj", "{D9B7A239-9F4E-4E55-838D-4766EBEA5672}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.SampleModels", "src\MongoDB.OData.SampleModels\MongoDB.OData.SampleModels.csproj", "{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.SampleModels", "src\MongoDB.OData.SampleModels\MongoDB.OData.SampleModels.csproj", "{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.IntegrationTests", "src\MongoDB.OData.IntegrationTests\MongoDB.OData.IntegrationTests.csproj", "{628EAB24-C5B8-47C4-B634-EECA4089BDA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.OData.UnitTests", "src\MongoDB.OData.UnitTests\MongoDB.OData.UnitTests.csproj", "{079AA188-5BA0-437F-AAA2-3F4681393A15}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -53,6 +57,26 @@ Global
{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|Mixed Platforms.Build.0 = Release|Any CPU {59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|x86.ActiveCfg = Release|Any CPU {59DA97A0-8CD9-461C-9EA5-1AE45D34A1A7}.Release|x86.ActiveCfg = Release|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Debug|x86.ActiveCfg = Debug|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|Any CPU.Build.0 = Release|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{628EAB24-C5B8-47C4-B634-EECA4089BDA4}.Release|x86.ActiveCfg = Release|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Debug|x86.ActiveCfg = Debug|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|Any CPU.Build.0 = Release|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{079AA188-5BA0-437F-AAA2-3F4681393A15}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
Expand Down
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{628EAB24-C5B8-47C4-B634-EECA4089BDA4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MongoDB.OData.IntegrationTests</RootNamespace>
<AssemblyName>MongoDB.OData.IntegrationTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</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>
</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.Data.Edm, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.Data.Edm.5.0.1\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.Data.OData.5.0.1\lib\net40\Microsoft.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Services, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.Data.Services.5.0.1\lib\net40\Microsoft.Data.Services.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Services.Client, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.Data.Services.Client.5.0.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson">
<HintPath>..\..\packages\mongocsharpdriver.1.5\lib\net35\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Driver">
<HintPath>..\..\packages\mongocsharpdriver.1.5\lib\net35\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Spatial, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\System.Spatial.5.0.1\lib\net40\System.Spatial.dll</HintPath>
</Reference>
<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="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\tools\NuGet\nuget.targets" />
<!-- 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>
36 changes: 36 additions & 0 deletions src/MongoDB.OData.IntegrationTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MongoDB.OData.IntegrationTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("MongoDB.OData.IntegrationTests")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("db1ce51c-c044-4790-8820-ae9c423ae9c3")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
9 changes: 9 additions & 0 deletions src/MongoDB.OData.IntegrationTests/packages.config
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Data.Edm" version="5.0.1" />
<package id="Microsoft.Data.OData" version="5.0.1" />
<package id="Microsoft.Data.Services" version="5.0.1" />
<package id="Microsoft.Data.Services.Client" version="5.0.1" />
<package id="mongocsharpdriver" version="1.5" />
<package id="System.Spatial" version="5.0.1" />
</packages>
@@ -1,3 +1,3 @@
 


<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service="MongoDB.OData.SampleHost.Sample" %> <%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service="MongoDB.OData.SampleHost.BlogApi" %>
Expand Up @@ -6,37 +6,36 @@
using System.ServiceModel.Web; using System.ServiceModel.Web;
using System.Web; using System.Web;
using MongoDB.Driver; using MongoDB.Driver;
using MongoDB.OData.SampleModels; using MongoDB.OData.SampleModels.Blog;


namespace MongoDB.OData.SampleHost namespace MongoDB.OData.SampleHost
{ {
public class Sample : TypedMongoDataService public class BlogApi : TypedMongoDataService
{ {
// This method is called only once to initialize service-wide policies. // This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config) public static void InitializeService(DataServiceConfiguration config)
{ {
TypedMongoDataService.Configure(config); TypedMongoDataService.Configure(config);

config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.UseVerboseErrors = true; config.UseVerboseErrors = true;
} }


protected override void BuildMetadata(TypedMongoDataServiceMetadata metadata) protected override void BuildMetadata(TypedMongoDataServiceMetadataBuilder builder)
{ {
metadata.SetContainer("MongoDB.Samples", "Blog"); builder.SetContainer("MongoDB.Samples", "BlogApi");
metadata.AddResourceSet<Blog>("Blogs", "odata", "blogs"); builder.AddResourceSet<Blog>("Blogs", "odata_blogs", "blogs");
metadata.AddResourceSet<Post>("Posts", "odata", "posts"); builder.AddResourceSet<Post>("Posts", "odata_blogs", "posts");
metadata.AddResourceSet<User>("Users", "odata", "users"); builder.AddResourceSet<User>("Users", "odata_blogs", "users");
} }


protected override MongoServer CreateDataSource() protected override MongoServer CreateDataSource()
{ {
var server = MongoServer.Create(); var server = MongoServer.Create();


//create data if none exists... //create data if none exists...
var db = server.GetDatabase("odata"); var db = server.GetDatabase("odata_blogs");
var userCollection = db.GetCollection<User>("users"); var userCollection = db.GetCollection<User>("users");
var blogCollection = db.GetCollection<Blog>("blogs"); var blogCollection = db.GetCollection<BlogApi>("blogs");
var postsCollection = db.GetCollection<Post>("posts"); var postsCollection = db.GetCollection<Post>("posts");


if (userCollection.Count() > 0) if (userCollection.Count() > 0)
Expand Down
3 changes: 3 additions & 0 deletions src/MongoDB.OData.SampleHost/HumanResourcesApi.svc
@@ -0,0 +1,3 @@


<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service="MongoDB.OData.SampleHost.HumanResourcesApi" %>
103 changes: 103 additions & 0 deletions src/MongoDB.OData.SampleHost/HumanResourcesApi.svc.cs
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.OData.SampleModels.HumanResources;

namespace MongoDB.OData.SampleHost
{
public class HumanResourcesApi : TypedMongoDataService
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
TypedMongoDataService.Configure(config);
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.UseVerboseErrors = true;
}

protected override void BuildMetadata(TypedMongoDataServiceMetadataBuilder builder)
{
if (!BsonClassMap.IsClassMapRegistered(typeof(Person)))
{
BsonClassMap.RegisterClassMap<Person>(cm =>
{
cm.AutoMap();
cm.SetIsRootClass(true);
cm.AddKnownType(typeof(Employee));
cm.AddKnownType(typeof(Manager));
cm.AddKnownType(typeof(Contractor));
});
}

builder.SetContainer("MongoDB.Samples", "HumanResources");
builder.AddResourceSet<Person>("People", "odata_hr", "people");
}

protected override MongoServer CreateDataSource()
{
var server = MongoServer.Create();

//create data if none exists...
var db = server.GetDatabase("odata_hr");

var people = db.GetCollection<Person>("people");

if (people.Count() > 0)
{
return server;
}

var employee1 = new Employee
{
Id = "Employee1",
HireDate = new DateTime(2005, 1, 1),
Name = new Name { First = "Jack", Last = "McJack" },
Salary = 1200
};

var employee2 = new Employee
{
Id = "Employee2",
HireDate = new DateTime(2007, 1, 1),
Name = new Name { First = "Jane", Last = "McJane" },
Salary = 1300
};

var contractor1 = new Contractor
{
Id = "Contractor1",
HireDate = new DateTime(2010, 1, 1),
Name = new Name { First = "Joe", Last = "McJoe" },
Salary = 300,
Address = "123 Main ST.",
};

var manager1 = new Manager
{
Id = "Manager1",
HireDate = new DateTime(2000, 1, 1),
Name = new Name { First = "Jim", Last = "McJim" },
Salary = 2000,
Employees = new List<PersonRef>
{
new PersonRef { Id = employee1.Id, Name = employee1.Name },
new PersonRef { Id = employee2.Id, Name = employee2.Name },
new PersonRef { Id = contractor1.Id, Name = contractor1.Name },
}
};

people.Save(employee1);
people.Save(employee2);
people.Save(contractor1);
people.Save(manager1);

return server;
}
}
}

0 comments on commit 2675198

Please sign in to comment.