Skip to content

Commit fb83d12

Browse files
committed
request units sample
1 parent bfd5afd commit fb83d12

File tree

4 files changed

+189
-0
lines changed

4 files changed

+189
-0
lines changed

samples/request-units/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>

samples/request-units/Program.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
using Microsoft.Azure.Documents;
5+
using Microsoft.Azure.Documents.Client;
6+
using Microsoft.Azure.Documents.Linq;
7+
using Newtonsoft.Json;
8+
9+
namespace RequestUnits
10+
{
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
using (DocumentClient client = new DocumentClient(new Uri("https://FILLME.documents.azure.com:443/"), "FILLME",
16+
new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp, MaxConnectionLimit = 1000 }))
17+
{
18+
RunAsync(client).Wait();
19+
}
20+
}
21+
22+
private static async Task RunAsync(DocumentClient client)
23+
{
24+
// Get a 1KB document by ID
25+
ResourceResponse<Document> kbReadResponse = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri("db", "demo", "1kb-document"));
26+
Console.WriteLine("Read document completed with {0} RUs", kbReadResponse.RequestCharge);
27+
Console.ReadKey();
28+
29+
// Post a 1KB document
30+
Document document = kbReadResponse.Resource;
31+
document.Id = Guid.NewGuid().ToString();
32+
33+
ResourceResponse<Document> kbWriteResponse = await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("db", "demo"),
34+
document);
35+
Console.WriteLine("Create document completed with {0} RUs", kbWriteResponse.RequestCharge);
36+
Console.ReadKey();
37+
38+
document.Id = Guid.NewGuid().ToString();
39+
kbWriteResponse = await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("db", "demo"),
40+
document, new RequestOptions { IndexingDirective = IndexingDirective.Exclude });
41+
Console.WriteLine("Create document completed with {0} RUs", kbWriteResponse.RequestCharge);
42+
Console.ReadKey();
43+
44+
// Query for 100 1KB documents
45+
IDocumentQuery<Document> query = client.CreateDocumentQuery(
46+
UriFactory.CreateDocumentCollectionUri("db", "demo"),
47+
new FeedOptions { MaxItemCount = -1 }).Take(100).AsDocumentQuery();
48+
49+
FeedResponse<Document> queryResponse = await query.ExecuteNextAsync<Document>();
50+
Console.WriteLine("Query TOP 100 documents completed with {0} results and {1} RUs", queryResponse.Count, queryResponse.RequestCharge);
51+
Console.ReadKey();
52+
53+
// Query for 1000, query by index
54+
query = client.CreateDocumentQuery(
55+
UriFactory.CreateDocumentCollectionUri("db", "demo"),
56+
new FeedOptions { MaxItemCount = -1 }).Take(1000).AsDocumentQuery();
57+
58+
queryResponse = await query.ExecuteNextAsync<Document>();
59+
Console.WriteLine("Query TOP 1000 documents completed with {0} results and {1} RUs", queryResponse.Count, queryResponse.RequestCharge);
60+
Console.ReadKey();
61+
62+
// Query by filter (from index)
63+
IDocumentQuery<Family> secondQuery = client.CreateDocumentQuery<Family>(UriFactory.CreateDocumentCollectionUri("db", "demo"))
64+
.Where(f => f.Address.City == "redmond").AsDocumentQuery();
65+
66+
FeedResponse<Family> secondQueryResponse = await secondQuery.ExecuteNextAsync<Family>();
67+
Console.WriteLine("Query with filter completed with {0} results and {1} RUs", secondQueryResponse.Count, secondQueryResponse.RequestCharge);
68+
Console.ReadKey();
69+
70+
// Get a 16KB document by ID
71+
ResourceResponse<Document> multiKbReadResponse = await client.ReadDocumentAsync(UriFactory.CreateDocumentUri("db", "demo", "16kb-document"));
72+
Console.WriteLine("Read 16KB document completed with {0} RUs", multiKbReadResponse.RequestCharge);
73+
Console.ReadKey();
74+
}
75+
76+
public class Family
77+
{
78+
[JsonProperty("id")]
79+
public string Id { get; set; }
80+
81+
[JsonProperty("lastName")]
82+
public string LastName { get; set; }
83+
84+
[JsonProperty("address")]
85+
public Address Address { get; set; }
86+
}
87+
88+
public class Address
89+
{
90+
[JsonProperty("state")]
91+
public string State { get; set; }
92+
93+
[JsonProperty("county")]
94+
public string County { get; set; }
95+
96+
[JsonProperty("city")]
97+
public string City { get; set; }
98+
}
99+
}
100+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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>{86501036-7116-4FA4-BFF8-C3A3DCCA8D20}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>RequestUnits</RootNamespace>
11+
<AssemblyName>RequestUnits</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="Microsoft.Azure.Documents.Client, Version=1.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
39+
<HintPath>..\packages\Microsoft.Azure.DocumentDB.1.9.3\lib\net45\Microsoft.Azure.Documents.Client.dll</HintPath>
40+
<Private>True</Private>
41+
</Reference>
42+
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="System" />
47+
<Reference Include="System.Core" />
48+
<Reference Include="System.Xml.Linq" />
49+
<Reference Include="System.Data.DataSetExtensions" />
50+
<Reference Include="Microsoft.CSharp" />
51+
<Reference Include="System.Data" />
52+
<Reference Include="System.Net.Http" />
53+
<Reference Include="System.Xml" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<Compile Include="Program.cs" />
57+
<Compile Include="Properties\AssemblyInfo.cs" />
58+
</ItemGroup>
59+
<ItemGroup>
60+
<None Include="App.config" />
61+
<None Include="packages.config" />
62+
</ItemGroup>
63+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
64+
<Import Project="..\packages\Microsoft.Azure.DocumentDB.1.9.3\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\packages\Microsoft.Azure.DocumentDB.1.9.3\build\Microsoft.Azure.DocumentDB.targets')" />
65+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
66+
<PropertyGroup>
67+
<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>
68+
</PropertyGroup>
69+
<Error Condition="!Exists('..\packages\Microsoft.Azure.DocumentDB.1.9.3\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.DocumentDB.1.9.3\build\Microsoft.Azure.DocumentDB.targets'))" />
70+
</Target>
71+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
72+
Other similar extension points exist, see Microsoft.Common.targets.
73+
<Target Name="BeforeBuild">
74+
</Target>
75+
<Target Name="AfterBuild">
76+
</Target>
77+
-->
78+
</Project>

samples/request-units/packages.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.Azure.DocumentDB" version="1.9.3" targetFramework="net452" />
4+
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" />
5+
</packages>

0 commit comments

Comments
 (0)