Skip to content

Commit 1b22cac

Browse files
authored
Merge pull request Azure#337 from arramac/master
Add multimodel, upgrade SDK version
2 parents 88f7ec8 + 2d84290 commit 1b22cac

File tree

11 files changed

+524
-5
lines changed

11 files changed

+524
-5
lines changed

samples/MultiModel/App.config

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
5+
</startup>
6+
<runtime>
7+
<gcServer enabled="true" />
8+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
9+
<dependentAssembly>
10+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
11+
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
12+
</dependentAssembly>
13+
</assemblyBinding>
14+
</runtime>
15+
<appSettings>
16+
<add key="EndPointUrl" value="https://FILLME.documents.azure.com:443/" />
17+
<add key="AuthorizationKey" value="FILLME" />
18+
19+
<add key="DatabaseName" value="db" />
20+
<add key="CollectionName" value="demo" />
21+
22+
<add key="CollectionThroughput" value="10000" />
23+
<add key="ShouldCleanupOnStart" value="false" />
24+
<add key="ShouldCleanupOnFinish" value="false" />
25+
26+
<!-- determined by the tool -->
27+
<add key="DegreeOfParallelism" value="-1" />
28+
<add key="NumberOfDocumentsToInsert" value="1000000" />
29+
30+
<add key="CollectionPartitionKey" value="/partitionKey" />
31+
<add key="DocumentTemplateFile" value="Player.json" />
32+
</appSettings>
33+
<system.diagnostics>
34+
<trace autoflush="false" indentsize="4">
35+
<listeners>
36+
<add name="configConsoleListener" type="System.Diagnostics.ConsoleTraceListener" />
37+
</listeners>
38+
</trace>
39+
</system.diagnostics>
40+
</configuration>

samples/MultiModel/County.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+

2+
namespace DocumentDB.Sample.MultiModel
3+
{
4+
using Newtonsoft.Json;
5+
6+
internal sealed class County
7+
{
8+
[JsonProperty(PropertyName = "id")]
9+
public string Name { get; set; }
10+
11+
[JsonProperty(PropertyName = "label")]
12+
public string Label { get; set; }
13+
14+
public int Population { get; set; }
15+
16+
public string State { get; set; }
17+
18+
public string Seat { get; set; }
19+
}
20+
}

samples/MultiModel/DocumentModel.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+

2+
namespace DocumentDB.Sample.MultiModel
3+
{
4+
using Microsoft.Azure.Documents.Client;
5+
using Microsoft.Azure.Documents.Linq;
6+
using System;
7+
using System.Threading.Tasks;
8+
9+
internal sealed class DocumentModel
10+
{
11+
private readonly DocumentClient client;
12+
private readonly Uri collectionLink;
13+
14+
public DocumentModel(DocumentClient client, Uri collectionLink)
15+
{
16+
this.client = client;
17+
this.collectionLink = collectionLink;
18+
}
19+
20+
public async Task InsertCountyDataAsync()
21+
{
22+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "King", Population = 1931249, Seat = "Seattle", State = "WA" });
23+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Pierce", Population = 795225, Seat = "Tacoma", State = "WA" });
24+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Snohomish", Population = 713335, Seat = "Everett", State = "WA" });
25+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Spokane", Population = 421221, Seat = "Spokane", State = "WA" });
26+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Lewis", Population = 75455, Seat = "Chehalis", State = "WA" });
27+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Cowlitz", Population = 102410, Seat = "Kelso", State = "WA" });
28+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Clark", Population = 425363, Seat = "Vancouver", State = "WA" });
29+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Skamania", Population = 11066, Seat = "Stevenson", State = "WA" });
30+
31+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Baker", Population = 16510, Seat = "Baker City", State = "OR" });
32+
await this.client.CreateDocumentAsync(this.collectionLink, new County() { Name = "Multinomah", Population = 790670, Seat = "Portland", State = "OR" });
33+
}
34+
35+
public async Task QueryCountyAsync()
36+
{
37+
// 1. Query For Highest Population County
38+
var query = this.client.CreateDocumentQuery<County>(this.collectionLink,
39+
"SELECT TOP 1 * FROM root r ORDER BY r.Population DESC").AsDocumentQuery();
40+
41+
while (query.HasMoreResults)
42+
{
43+
foreach (County county in await query.ExecuteNextAsync())
44+
{
45+
Console.WriteLine("County with the Max Population - {0}", county.Name);
46+
}
47+
}
48+
49+
// 2. Query the county name where seat = Seattle
50+
query = this.client.CreateDocumentQuery<County>(this.collectionLink,
51+
"SELECT * FROM root r WHERE r.Seat='Everett'").AsDocumentQuery();
52+
53+
while (query.HasMoreResults)
54+
{
55+
foreach (County county in await query.ExecuteNextAsync())
56+
{
57+
Console.WriteLine("County with the Everett Seat - {0}", county.Name);
58+
}
59+
}
60+
}
61+
}
62+
}

samples/MultiModel/GraphModel.cs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+

2+
namespace DocumentDB.Sample.MultiModel
3+
{
4+
using Microsoft.Azure.Documents;
5+
using Microsoft.Azure.Documents.Client;
6+
using Microsoft.Azure.Documents.Linq;
7+
using Microsoft.Azure.Graphs;
8+
using System;
9+
using System.Threading.Tasks;
10+
11+
class GraphModel
12+
{
13+
private readonly DocumentClient client;
14+
private readonly DocumentCollection collection;
15+
16+
private GraphConnection graphConnection;
17+
private GraphCommand graphCommand;
18+
19+
public GraphModel(DocumentClient client, DocumentCollection collection)
20+
{
21+
this.client = client;
22+
this.collection = collection;
23+
this.graphConnection = new GraphConnection(client, collection);
24+
this.graphCommand = new GraphCommand(this.graphConnection);
25+
}
26+
27+
public async Task AddNodesAsync()
28+
{
29+
string[] edgeQueries = new string[]
30+
{
31+
//Adams
32+
"g.AddV('county').Property('name', 'Adams').Property('id', 'Adams').Property('Population', 18728).Property('Seat', 'Ritzville')",
33+
34+
//Grant
35+
"g.AddV('county').Property('name', 'Grant').Property('id', 'Grant').Property('Population', 89120).Property('Seat', 'Ephrata')",
36+
};
37+
38+
foreach (string edgeQuery in edgeQueries)
39+
{
40+
Console.WriteLine("Query : " + edgeQuery);
41+
IDocumentQuery<dynamic> query = this.client.CreateGremlinQuery(this.collection, edgeQuery);
42+
while (query.HasMoreResults)
43+
{
44+
await query.ExecuteNextAsync();
45+
}
46+
}
47+
}
48+
49+
public async Task AddEdgesAsync()
50+
{
51+
string[] edgeQueries = new string[]
52+
{
53+
// King -> Pierce
54+
"g.V('King').AddE('neighbor').Property('inter-state', 'false').To(g.V('Pierce'))",
55+
56+
// King -> Snohomish
57+
"g.V('King').AddE('neighbor').Property('inter-state', 'false').To(g.V('Snohomish'))",
58+
59+
// Pierce -> Lewis
60+
"g.V('Pierce').AddE('neighbor').Property('inter-state', 'false').To(g.V('Lewis'))",
61+
62+
// Lewis -> Cowlitz
63+
"g.V('Lewis').AddE('neighbor').Property('inter-state', 'false').To(g.V('Cowlitz'))",
64+
65+
// Cowlitz -> Clark
66+
"g.V('Cowlitz').AddE('neighbor').Property('inter-state', 'false').To(g.V('Clark'))",
67+
68+
// Lewis -> Skamania
69+
"g.V('Lewis').AddE('neighbor').Property('inter-state', 'false').To(g.V('Skamania'))",
70+
71+
// Skamania -> Clark
72+
"g.V('Skamania').AddE('neighbor').Property('inter-state', 'false').To(g.V('Clark'))",
73+
74+
// Clark -> Multinomah
75+
"g.V('Clark').AddE('neighbor').Property('inter-state', 'true').To(g.V('Multinomah'))",
76+
77+
// Adams -> Grant
78+
"g.V('Adams').AddE('neighbor').Property('inter-state', 'false').To(g.V('Grant'))"
79+
};
80+
81+
foreach (string edgeQuery in edgeQueries)
82+
{
83+
Console.WriteLine("Query : " + edgeQuery);
84+
IDocumentQuery<dynamic> query = this.client.CreateGremlinQuery(this.collection, edgeQuery);
85+
while (query.HasMoreResults)
86+
{
87+
await query.ExecuteNextAsync();
88+
}
89+
}
90+
}
91+
92+
93+
public async Task QueryAsync()
94+
{
95+
string[] queries = new string[]
96+
{
97+
// 1. All neighbors of King county
98+
"g.V('King').out()",
99+
100+
//2. All neighbors of Clark where inter-state = false (connecting between states)
101+
"g.V('Clark').outE().has('inter-state', 'true')",
102+
103+
//3. Find the path from King County till Multinomah -- DFS (King->Pierce->Lewis->Cowlitz->Clark->Multinomah)
104+
"g.V('King').repeat(out()).until(hasId('Multinomah')).path().limit(1)"
105+
};
106+
107+
foreach (string queryText in queries)
108+
{
109+
Console.WriteLine("Query : " + queryText);
110+
111+
IDocumentQuery<dynamic> query = this.client.CreateGremlinQuery(this.collection, queryText);
112+
while (query.HasMoreResults)
113+
{
114+
foreach (var resultStep in await query.ExecuteNextAsync())
115+
{
116+
Console.WriteLine(" Path : " + resultStep.ToString());
117+
}
118+
}
119+
}
120+
}
121+
}
122+
}

samples/MultiModel/MultiModel.csproj

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.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>{5DCE9060-4D96-45C8-985E-D310BB4433A9}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>MultiModel</RootNamespace>
11+
<AssemblyName>MultiModel</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Microsoft.Azure.Documents.Client">
37+
<HintPath>References\Microsoft.Azure.Documents.Client.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Microsoft.Azure.Graphs">
40+
<HintPath>References\Microsoft.Azure.Graphs.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
43+
<HintPath>packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="System" />
47+
<Reference Include="System.configuration" />
48+
<Reference Include="System.Core" />
49+
<Reference Include="System.Xml.Linq" />
50+
<Reference Include="System.Data.DataSetExtensions" />
51+
<Reference Include="Microsoft.CSharp" />
52+
<Reference Include="System.Data" />
53+
<Reference Include="System.Net.Http" />
54+
<Reference Include="System.Xml" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<Compile Include="County.cs" />
58+
<Compile Include="DocumentModel.cs" />
59+
<Compile Include="GraphModel.cs" />
60+
<Compile Include="Program.cs" />
61+
<Compile Include="Properties\AssemblyInfo.cs" />
62+
</ItemGroup>
63+
<ItemGroup>
64+
<None Include="App.config" />
65+
<None Include="packages.config" />
66+
</ItemGroup>
67+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
68+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
69+
Other similar extension points exist, see Microsoft.Common.targets.
70+
<Target Name="BeforeBuild">
71+
</Target>
72+
<Target Name="AfterBuild">
73+
</Target>
74+
-->
75+
</Project>

samples/MultiModel/MultiModel.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiModel", "MultiModel.csproj", "{5DCE9060-4D96-45C8-985E-D310BB4433A9}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{5DCE9060-4D96-45C8-985E-D310BB4433A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5DCE9060-4D96-45C8-985E-D310BB4433A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5DCE9060-4D96-45C8-985E-D310BB4433A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5DCE9060-4D96-45C8-985E-D310BB4433A9}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

0 commit comments

Comments
 (0)