本文整理汇总了C#中Microsoft.Azure.Documents.Client.DocumentClient.OpenAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentClient.OpenAsync方法的具体用法?C# DocumentClient.OpenAsync怎么用?C# DocumentClient.OpenAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Documents.Client.DocumentClient
的用法示例。
在下文中一共展示了DocumentClient.OpenAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDocumentClient
public DocumentClient GetDocumentClient()
{
if (_documentClient != null) return _documentClient;
_documentClient = new DocumentClient(new Uri(_endpointUrl), _authorizationKey);
_documentClient.OpenAsync().Wait();
return _documentClient;
}
示例2: TestConnection
/// <summary>
/// Tests the DocumentDB connection.
/// </summary>
/// <param name="connectionString">DocumentDB connection string to use to connect to the account.</param>
/// <param name="connectionMode">DocumentDB connectio mode to use when testing the connection.</param>
/// <returns>Task that represents asynchronous connection operation.</returns>
public async Task TestConnection(string connectionString, DocumentDbConnectionMode? connectionMode)
{
if (String.IsNullOrEmpty(connectionString))
throw Errors.ConnectionStringMissing();
var parsed = DocumentDbConnectionStringBuilder.Parse(connectionString);
if (String.IsNullOrEmpty(parsed.AccountEndpoint))
throw Errors.AccountEndpointMissing();
if (String.IsNullOrEmpty(parsed.AccountKey))
throw Errors.AccountKeyMissing();
if (String.IsNullOrEmpty(parsed.Database))
throw Errors.DatabaseNameMissing();
var connectionPolicy = DocumentDbClientHelper.ApplyConnectionMode(new ConnectionPolicy(), connectionMode);
using (var client = new DocumentClient(new Uri(parsed.AccountEndpoint), parsed.AccountKey, connectionPolicy))
{
await client.OpenAsync();
}
}
示例3: sp2
private static async Task sp2(DocumentCollection dc, DocumentClient client, Database database)
{
DocumentCollection dc2 = client.CreateDocumentCollectionQuery(database.SelfLink)
.Where(c => c.Id == "LMSCollection1444075919174")
.AsEnumerable()
.FirstOrDefault();
await client.OpenAsync();
//await _iDbService.CollectionTransfer(client, dc2, dc);
var mn=await client.ReadDatabaseAsync(database.SelfLink);
/* await client.CreateDocumentAsync(dc.SelfLink, new CurrentCollection
{
id = "CurrentCollection",
name=dc.Id
});*/
/* var resolver = _iDbService.GetResolver(client, dc);
foreach (var d in resolver.PartitionMap)
{
Console.WriteLine(d.Value);
Offer offer = client.CreateOfferQuery()
.Where(r => r.ResourceLink == d.Value)
.AsEnumerable()
.SingleOrDefault();
}*/
/* HashPartitionResolver hashResolver = new HashPartitionResolver(
u => ((PostMessage) u).Path.District,
new string[] {dc.SelfLink, dc2.SelfLink});
client.PartitionResolvers[database.SelfLink] = hashResolver;*/
var rangeResolver = _iDbService.GetResolver(client);
client.PartitionResolvers[database.SelfLink] = rangeResolver;
var created = await _iDbService.InitResolver("");
while (true)
{
var re2 = await _iDbService.UpdateResolver(dc2);
var p = re2;
await Task.Delay(TimeSpan.FromSeconds(4));
}
var z1 = rangeResolver.GetPartitionKey(new PostMessage
{
Type = "Post",
Info = new Info
{
user = "tzk",
uid = "1210808",
message = "java",
timestamp = 7
},
Path = new PostPath
{
District = "tst-azhang"
}
});
//search global
IQueryable<PostMessage> query = client.CreateDocumentQuery<PostMessage>(database.SelfLink)
.Where(u => u.Info.timestamp>1);
var now = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
//search on partition
var t1 = DateTime.Now;
var query2 = client.CreateDocumentQuery<PostMessage>(database.SelfLink, new FeedOptions
{
MaxItemCount = 1200
}, now);
var query3 = client.CreateDocumentQuery<PostMessage>(dc2.SelfLink).AsDocumentQuery();
var t2 = DateTime.Now;
Console.WriteLine(t2-t1);
//.Where(u => u.Path.District=="tst-azhang");
foreach (PostMessage a in query2)
{
Console.WriteLine(a.Info.timestamp);
}
/* double totalRequestCharge = 0;
while (query3.HasMoreResults)
{
FeedResponse<dynamic> queryResponse = await query3.ExecuteNextAsync<dynamic>();
Console.WriteLine("Query batch consumed {0} request units {1} doc", queryResponse.RequestCharge, queryResponse.Count);
totalRequestCharge += queryResponse.RequestCharge;
}
Console.WriteLine(DateTime.Now - t2);
Console.WriteLine("Query consumed {0} request units in total", totalRequestCharge);*/
//.........这里部分代码省略.........