Skip to content

Commit f3487c3

Browse files
committed
Merge pull request Azure#115 from arramac/master
Update samples for partitioned collections
2 parents 287acaf + 973f446 commit f3487c3

40 files changed

+1215
-931
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
55
</startup>
66
<appSettings file="appSettings.config"/>
7-
</configuration>
7+
</configuration>

samples/code-samples/CollectionManagement/CollectionManagement.csproj

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>DocumentDB.Samples.CollectionManagement</RootNamespace>
1111
<AssemblyName>DocumentDB.Samples.CollectionManagement</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14-
<SccProjectName>SAK</SccProjectName>
15-
<SccLocalPath>SAK</SccLocalPath>
16-
<SccAuxPath>SAK</SccAuxPath>
17-
<SccProvider>SAK</SccProvider>
14+
<SccProjectName>
15+
</SccProjectName>
16+
<SccLocalPath>
17+
</SccLocalPath>
18+
<SccAuxPath>
19+
</SccAuxPath>
20+
<SccProvider>
21+
</SccProvider>
1822
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
23+
<TargetFrameworkProfile />
24+
<NuGetPackageImportStamp>
25+
</NuGetPackageImportStamp>
1926
</PropertyGroup>
2027
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2128
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -37,12 +44,12 @@
3744
<WarningLevel>4</WarningLevel>
3845
</PropertyGroup>
3946
<ItemGroup>
40-
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
41-
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.5.1\lib\net40\Microsoft.Azure.Documents.Client.dll</HintPath>
47+
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.6.1\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
4249
<Private>True</Private>
4350
</Reference>
44-
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
45-
<HintPath>..\packages\Newtonsoft.Json.5.0.7\lib\net45\Newtonsoft.Json.dll</HintPath>
51+
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
4653
<Private>True</Private>
4754
</Reference>
4855
<Reference Include="System" />
@@ -56,17 +63,27 @@
5663
</ItemGroup>
5764
<ItemGroup>
5865
<Compile Include="Program.cs" />
59-
<Compile Include="Properties\AssemblyInfo.cs" />
6066
</ItemGroup>
6167
<ItemGroup>
6268
<None Include="..\appSettings.config">
6369
<Link>appSettings.config</Link>
6470
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
71+
<SubType>Designer</SubType>
6572
</None>
6673
<None Include="App.config" />
6774
<None Include="packages.config" />
6875
</ItemGroup>
76+
<ItemGroup>
77+
<Folder Include="Properties\" />
78+
</ItemGroup>
6979
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
80+
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.6.1\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.6.1\build\Microsoft.Azure.DocumentDB.targets')" />
81+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
82+
<PropertyGroup>
83+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
84+
</PropertyGroup>
85+
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.6.1\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.6.1\build\Microsoft.Azure.DocumentDB.targets'))" />
86+
</Target>
7087
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7188
Other similar extension points exist, see Microsoft.Common.targets.
7289
<Target Name="BeforeBuild">

samples/code-samples/CollectionManagement/Program.cs

Lines changed: 130 additions & 115 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.DocumentDB" version="1.5.1" targetFramework="net45" />
4-
<package id="Newtonsoft.Json" version="5.0.7" targetFramework="net45" />
3+
<package id="Microsoft.Azure.DocumentDB" version="1.6.1" targetFramework="net451" />
4+
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net451" />
55
</packages>

samples/code-samples/DatabaseManagement/DatabaseManagement.csproj

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@
1111
<AssemblyName>DocumentDB.Samples.DatabaseManagement</AssemblyName>
1212
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14-
<SccProjectName>SAK</SccProjectName>
15-
<SccLocalPath>SAK</SccLocalPath>
16-
<SccAuxPath>SAK</SccAuxPath>
17-
<SccProvider>SAK</SccProvider>
14+
<SccProjectName>
15+
</SccProjectName>
16+
<SccLocalPath>
17+
</SccLocalPath>
18+
<SccAuxPath>
19+
</SccAuxPath>
20+
<SccProvider>
21+
</SccProvider>
1822
<TargetFrameworkProfile />
1923
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
24+
<NuGetPackageImportStamp>
25+
</NuGetPackageImportStamp>
2026
</PropertyGroup>
2127
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2228
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -38,12 +44,12 @@
3844
<WarningLevel>4</WarningLevel>
3945
</PropertyGroup>
4046
<ItemGroup>
41-
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
42-
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.5.1\lib\net40\Microsoft.Azure.Documents.Client.dll</HintPath>
47+
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
48+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.6.1\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
4349
<Private>True</Private>
4450
</Reference>
45-
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
46-
<HintPath>..\packages\Newtonsoft.Json.5.0.7\lib\net45\Newtonsoft.Json.dll</HintPath>
51+
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
4753
<Private>True</Private>
4854
</Reference>
4955
<Reference Include="System" />
@@ -57,7 +63,6 @@
5763
</ItemGroup>
5864
<ItemGroup>
5965
<Compile Include="Program.cs" />
60-
<Compile Include="Properties\AssemblyInfo.cs" />
6166
</ItemGroup>
6267
<ItemGroup>
6368
<None Include="..\appSettings.config">
@@ -70,7 +75,17 @@
7075
</None>
7176
<None Include="packages.config" />
7277
</ItemGroup>
78+
<ItemGroup>
79+
<Folder Include="Properties\" />
80+
</ItemGroup>
7381
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
82+
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.6.1\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.6.1\build\Microsoft.Azure.DocumentDB.targets')" />
83+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
84+
<PropertyGroup>
85+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
86+
</PropertyGroup>
87+
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.6.1\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.6.1\build\Microsoft.Azure.DocumentDB.targets'))" />
88+
</Target>
7489
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7590
Other similar extension points exist, see Microsoft.Common.targets.
7691
<Target Name="BeforeBuild">

samples/code-samples/DatabaseManagement/Program.cs

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,18 @@
3333
public class Program
3434
{
3535
//Read config
36-
private static readonly string databaseId = ConfigurationManager.AppSettings["DatabaseId"];
36+
private static readonly string databaseName = ConfigurationManager.AppSettings["DatabaseId"];
3737
private static readonly string endpointUrl = ConfigurationManager.AppSettings["EndPointUrl"];
3838
private static readonly string authorizationKey = ConfigurationManager.AppSettings["AuthorizationKey"];
3939
private static readonly ConnectionPolicy connectionPolicy = new ConnectionPolicy { UserAgentSuffix = " samples-net/3" };
4040

41-
//Reusable instance of DocumentClient which represents the connection to a DocumentDB endpoint
4241
private static DocumentClient client;
4342

4443
public static void Main(string[] args)
4544
{
4645
try
4746
{
48-
//Connect to DocumentDB
49-
//Setup a single instance of DocumentClient that is reused throughout the application
47+
// Setup a single instance of DocumentClient that is reused throughout the application
5048
using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
5149
{
5250
RunDatabaseDemo().Wait();
@@ -69,54 +67,42 @@ public static void Main(string[] args)
6967
}
7068
}
7169

70+
/// <summary>
71+
/// Run basic database metadata operations as a console app.
72+
/// </summary>
73+
/// <returns></returns>
7274
private static async Task RunDatabaseDemo()
7375
{
74-
//********************************************************************************************************
75-
// 1 - Query for a Database
76-
//
77-
// Note: we are using query here instead of ReadDatabaseAsync because we're checking if something exists
78-
// the ReadDatabaseAsync method expects the resource to be there, if its not we will get an error
79-
// instead of an empty
80-
//********************************************************************************************************
81-
Database database = client.CreateDatabaseQuery().Where(db => db.Id == databaseId).AsEnumerable().FirstOrDefault();
82-
Console.WriteLine("1. Query for a database returned: {0}", database==null?"no results":database.Id);
76+
await CreateDatabaseIfNotExists();
8377

84-
//check if a database was returned
85-
if (database==null)
86-
{
87-
//**************************
88-
// 2 - Create a Database
89-
//**************************
90-
database = await client.CreateDatabaseAsync(new Database { Id = databaseId });
91-
Console.WriteLine("\n2. Created Database: id - {0} and selfLink - {1}", database.Id, database.SelfLink);
92-
}
93-
94-
//*********************************************************************************
95-
// 3 - Get a single database
96-
// Note: that we don't need to use the SelfLink of a Database anymore
97-
// the links for a resource are now comprised of their Id properties
98-
// using UriFactory will give you the correct URI for a resource
99-
//
100-
// SelfLink will still work if you're already using this
101-
//********************************************************************************
102-
database = await client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(databaseId));
78+
Database database = await client.ReadDatabaseAsync(UriFactory.CreateDatabaseUri(databaseName));
10379
Console.WriteLine("\n3. Read a database resource: {0}", database);
10480

105-
//***************************************
106-
// 4 - List all databases for an account
107-
//***************************************
108-
var databases = await client.ReadDatabaseFeedAsync();
10981
Console.WriteLine("\n4. Reading all databases resources for an account");
110-
foreach (var db in databases)
82+
foreach (var db in await client.ReadDatabaseFeedAsync())
11183
{
112-
Console.WriteLine(db);
84+
Console.WriteLine(db);
11385
}
11486

115-
//*************************************
116-
// 5 - Delete a Database using its Id
117-
//*************************************
118-
await client.DeleteDatabaseAsync(UriFactory.CreateDatabaseUri(databaseId));
87+
await client.DeleteDatabaseAsync(UriFactory.CreateDatabaseUri(databaseName));
11988
Console.WriteLine("\n5. Database {0} deleted.", database.Id);
120-
}
89+
}
90+
91+
/// <summary>
92+
/// Create a database if it doesn't exist.
93+
/// </summary>
94+
/// <returns></returns>
95+
private static async Task CreateDatabaseIfNotExists()
96+
{
97+
Database database = client.CreateDatabaseQuery().Where(db => db.Id == databaseName).AsEnumerable().FirstOrDefault();
98+
Console.WriteLine("1. Query for a database returned: {0}", database == null ? "no results" : database.Id);
99+
100+
//check if a database was returned
101+
if (database == null)
102+
{
103+
database = await client.CreateDatabaseAsync(new Database { Id = databaseName });
104+
Console.WriteLine("\n2. Created Database: id - {0}", database.Id);
105+
}
106+
}
121107
}
122108
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Azure.DocumentDB" version="1.5.1" targetFramework="net451" />
4-
<package id="Newtonsoft.Json" version="5.0.7" targetFramework="net451" />
3+
<package id="Microsoft.Azure.DocumentDB" version="1.6.1" targetFramework="net451" />
4+
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net451" />
55
</packages>

samples/code-samples/DocumentDB.Samples.sln

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
99
EndProjectSection
1010
EndProject
1111
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CollectionManagement", "CollectionManagement\CollectionManagement.csproj", "{F244DE0C-FC94-4D96-AECF-C92BBBAA6627}"
12+
ProjectSection(ProjectDependencies) = postProject
13+
{16C11979-9B7C-4F35-BCD1-CAC434D79467} = {16C11979-9B7C-4F35-BCD1-CAC434D79467}
14+
EndProjectSection
1215
EndProject
1316
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentManagement", "DocumentManagement\DocumentManagement.csproj", "{CF8BEC3A-2791-4C56-B036-60CB5AE9367A}"
1417
EndProject
1518
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{16C11979-9B7C-4F35-BCD1-CAC434D79467}"
1619
EndProject
1720
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserManagement", "UserManagement\UserManagement.csproj", "{82B1A5F3-6BDE-4A70-9F3A-17ECEDEA64F1}"
21+
ProjectSection(ProjectDependencies) = postProject
22+
{16C11979-9B7C-4F35-BCD1-CAC434D79467} = {16C11979-9B7C-4F35-BCD1-CAC434D79467}
23+
EndProjectSection
1824
EndProject
1925
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IndexManagement", "IndexManagement\IndexManagement.csproj", "{35C7BBEB-B390-42F2-A301-15CE198CE79B}"
2026
EndProject
2127
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerSideScripts", "ServerSideScripts\ServerSideScripts.csproj", "{FF2F469C-8A1C-4B9C-A83A-0D4712FFCBC9}"
22-
EndProject
23-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Partitioning", "Partitioning\Partitioning.csproj", "{7910DE01-5D2F-4E3F-AEBE-26CFFD9A50A9}"
28+
ProjectSection(ProjectDependencies) = postProject
29+
{16C11979-9B7C-4F35-BCD1-CAC434D79467} = {16C11979-9B7C-4F35-BCD1-CAC434D79467}
30+
EndProjectSection
2431
EndProject
2532
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseManagement", "DatabaseManagement\DatabaseManagement.csproj", "{2F473ECB-3265-462B-B8F4-D5286883D12A}"
33+
ProjectSection(ProjectDependencies) = postProject
34+
{16C11979-9B7C-4F35-BCD1-CAC434D79467} = {16C11979-9B7C-4F35-BCD1-CAC434D79467}
35+
EndProjectSection
2636
EndProject
2737
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Queries", "Queries\Queries.csproj", "{6B5021ED-8B3A-4E38-92DB-612C4ECDC580}"
2838
EndProject
@@ -58,10 +68,6 @@ Global
5868
{FF2F469C-8A1C-4B9C-A83A-0D4712FFCBC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
5969
{FF2F469C-8A1C-4B9C-A83A-0D4712FFCBC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
6070
{FF2F469C-8A1C-4B9C-A83A-0D4712FFCBC9}.Release|Any CPU.Build.0 = Release|Any CPU
61-
{7910DE01-5D2F-4E3F-AEBE-26CFFD9A50A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62-
{7910DE01-5D2F-4E3F-AEBE-26CFFD9A50A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
63-
{7910DE01-5D2F-4E3F-AEBE-26CFFD9A50A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
64-
{7910DE01-5D2F-4E3F-AEBE-26CFFD9A50A9}.Release|Any CPU.Build.0 = Release|Any CPU
6571
{2F473ECB-3265-462B-B8F4-D5286883D12A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6672
{2F473ECB-3265-462B-B8F4-D5286883D12A}.Debug|Any CPU.Build.0 = Debug|Any CPU
6773
{2F473ECB-3265-462B-B8F4-D5286883D12A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
55
</startup>
66
<appSettings file="appSettings.config"/>
7-
</configuration>
7+
</configuration>

0 commit comments

Comments
 (0)