本文整理汇总了C#中Microsoft.Azure.Documents.Client.DocumentClient类的典型用法代码示例。如果您正苦于以下问题:C# DocumentClient类的具体用法?C# DocumentClient怎么用?C# DocumentClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentClient类属于Microsoft.Azure.Documents.Client命名空间,在下文中一共展示了DocumentClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDocumentClient
public DocumentClient GetDocumentClient()
{
if (_documentClient != null) return _documentClient;
_documentClient = new DocumentClient(new Uri(_endpointUrl), _authorizationKey);
_documentClient.OpenAsync().Wait();
return _documentClient;
}
示例2: InitializeHashResolver
/// <summary>
/// Initialize a HashPartitionResolver.
/// </summary>
/// <param name="partitionKeyPropertyName">The property name to be used as the partition Key.</param>
/// <param name="client">The DocumentDB client instance to use.</param>
/// <param name="database">The database to run the samples on.</param>
/// <param name="collectionNames">The names of collections used.</param>
/// <returns>The created HashPartitionResolver.</returns>
public static async Task<HashPartitionResolver> InitializeHashResolver(string partitionKeyPropertyName, DocumentClient client, Database database, string[] collectionNames)
{
// Set local to input.
string[] CollectionNames = collectionNames;
int numCollectionNames = CollectionNames.Length;
// Create array of DocumentCollections.
DocumentCollection[] collections = new DocumentCollection[numCollectionNames];
// Create string array of Self Links to Collections.
string[] selfLinks = new string[numCollectionNames];
//Create some collections to partition data.
for (int i = 0; i < numCollectionNames; i++)
{
collections[i] = await DocumentClientHelper.GetCollectionAsync(client, database, CollectionNames[i]);
selfLinks[i] = collections[i].SelfLink;
}
// Join Self Link Array into a comma separated string.
string selfLinkString = String.Join(", ", selfLinks);
//Initialize a partition resolver that users hashing, and register with DocumentClient.
//Uses User Id for PartitionKeyPropertyName, could also be TenantId, or any other variable.
HashPartitionResolver hashResolver = new HashPartitionResolver(partitionKeyPropertyName, new[] { selfLinkString });
client.PartitionResolvers[database.SelfLink] = hashResolver;
return hashResolver;
}
示例3: DatabaseNode
public DatabaseNode(DocumentClient localclient, Database db)
{
Text = db.Id;
Tag = db;
_client = localclient;
ImageKey = "SystemFeed";
SelectedImageKey = "SystemFeed";
Nodes.Add(new UsersNode(_client));
MenuItem myMenuItem3 = new MenuItem("Read Database");
myMenuItem3.Click += new EventHandler(myMenuItemReadDatabase_Click);
_contextMenu.MenuItems.Add(myMenuItem3);
MenuItem myMenuItem = new MenuItem("Delete Database");
myMenuItem.Click += new EventHandler(myMenuItemDeleteDatabase_Click);
_contextMenu.MenuItems.Add(myMenuItem);
_contextMenu.MenuItems.Add("-");
MenuItem myMenuItem2 = new MenuItem("Create DocumentCollection");
myMenuItem2.Click += new EventHandler(myMenuItemAddDocumentCollection_Click);
_contextMenu.MenuItems.Add(myMenuItem2);
MenuItem myMenuItem4 = new MenuItem("Refresh DocumentCollections Feed");
myMenuItem4.Click += new EventHandler((sender, e) => Refresh(true));
_contextMenu.MenuItems.Add(myMenuItem4);
}
示例4: AzureDocumentDBSink
public AzureDocumentDBSink(Uri endpointUri, string authorizationKey, string databaseName, string collectionName, IFormatProvider formatProvider)
{
_formatProvider = formatProvider;
_client = new DocumentClient(endpointUri, authorizationKey);
Task.WaitAll(new []{CreateDatabaseIfNotExistsAsync(databaseName)});
Task.WaitAll(new []{CreateCollectionIfNotExistsAsync(collectionName)});
}
示例5: Main
public static void Main(string[] args)
{
try
{
//Instantiate a new DocumentClient instance
using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey, connectionPolicy))
{
//Get, or Create, a reference to Database
database = GetOrCreateDatabaseAsync(databaseId).Result;
//Do operations on Collections
RunCollectionDemo().Wait();
}
}
catch (DocumentClientException de)
{
Exception baseException = de.GetBaseException();
Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
}
catch (Exception e)
{
Exception baseException = e.GetBaseException();
Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
}
finally
{
Console.WriteLine("End of demo, press any key to exit.");
Console.ReadKey();
}
}
示例6: CreateDocumentCollection
private static void CreateDocumentCollection(DocumentClient documentClient)
{
// Create the database if it doesn't exist.
try
{
documentClient.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName))
.GetAwaiter()
.GetResult();
}
catch (DocumentClientException de)
{
// If the document collection does not exist, create it
if (de.StatusCode == HttpStatusCode.NotFound)
{
var collectionInfo = new DocumentCollection
{
Id = CollectionName,
IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 })
};
documentClient.CreateDocumentCollectionAsync(
UriFactory.CreateDatabaseUri(DatabaseName),
collectionInfo,
new RequestOptions { OfferThroughput = 400 }).GetAwaiter().GetResult();
}
else
{
throw;
}
}
}
示例7: Main
public static void Main(string[] args)
{
try
{
//Get a single instance of Document client and reuse this for all the samples
//This is the recommended approach for DocumentClient as opposed to new'ing up new instances each time
using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
{
//ensure the database & collection exist before running samples
Init();
RunDocumentsDemo().Wait();
//Clean-up environment
Cleanup();
}
}
catch (DocumentClientException de)
{
Exception baseException = de.GetBaseException();
Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
}
catch (Exception e)
{
Exception baseException = e.GetBaseException();
Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
}
finally
{
Console.WriteLine("\nEnd of demo, press any key to exit.");
Console.ReadKey();
}
}
示例8: DatabaseAccountNode
public DatabaseAccountNode(string endpointName, DocumentClient client)
{
this.accountEndpoint = endpointName;
this.Text = endpointName;
if (string.Compare(endpointName, Constants.LocalEmulatorEndpoint, true) == 0)
{
this.Text = "devEmulator";
}
this.ImageKey = "DatabaseAccount";
this.SelectedImageKey = "DatabaseAccount";
this.client = client;
this.Tag = "This represents the DatabaseAccount. Right click to add Database";
this.loadindNode = new TreeNode(TreeNodeConstants.LoadingNode);
this.Nodes.Add(this.loadindNode);
MenuItem myMenuItem = new MenuItem("Add Database");
myMenuItem.Click += new EventHandler(myMenuItemAddDatabase_Click);
this.contextMenu.MenuItems.Add(myMenuItem);
MenuItem myMenuItem1 = new MenuItem("Refresh Databases feed");
myMenuItem1.Click += new EventHandler((sender, e) => Refresh(true));
this.contextMenu.MenuItems.Add(myMenuItem1);
this.contextMenu.MenuItems.Add("-");
MenuItem myMenuItem2 = new MenuItem("Remove setting");
myMenuItem2.Click += new EventHandler(myMenuItemRemoveDatabaseAccount_Click);
this.contextMenu.MenuItems.Add(myMenuItem2);
MenuItem myMenuItem3 = new MenuItem("Change setting");
myMenuItem3.Click += new EventHandler(myMenuItemChangeSetting_Click);
this.contextMenu.MenuItems.Add(myMenuItem3);
}
示例9: FindDocumentCollection
static DocumentCollection FindDocumentCollection(DocumentClient client, Database database, string name)
{
return client.CreateDocumentCollectionQuery(database.SelfLink)
.Where(x => x.Id == name)
.ToList()
.SingleOrDefault();
}
示例10: UpdateDcAll
public static async Task UpdateDcAll(string endpointUrl, string authorizationKey)
{
DocumentClient client = new DocumentClient(new Uri(endpointUrl), authorizationKey);
var database = await DocumentDB.GetDB(client);
IEnumerable<DocumentCollection> dz = client.CreateDocumentCollectionQuery(database.SelfLink)
.AsEnumerable();
DocumentCollection origin = client.CreateDocumentCollectionQuery(database.SelfLink)
.Where(c => c.Id == "LMSCollection")
.AsEnumerable()
.FirstOrDefault();
//search collection
var ds =
from d in client.CreateDocumentQuery<DcAllocate>(origin.DocumentsLink)
where d.Type == "DisList"
select d;
foreach (var d in ds)
{
if (d.District.Contains("tst-azhang14"))
{
Console.WriteLine(d.DcName);
}
}
/* foreach (var x in dz)
{
Console.WriteLine(x.Id + x.DocumentsLink);
await UpdateDc(x, client, database, origin);
}*/
}
示例11: InitClient
void InitClient()
{
var endpoint = new Uri(this.Config["DocDb:endpoint"]);
var authKey = this.Config["DocDb:authkey"];
var connectionPolicy = GetConnectionPolicy();
Client = new DocumentClient(endpoint, authKey, connectionPolicy);
}
示例12: FindDatabase
static Database FindDatabase(DocumentClient client, string name)
{
return client.CreateDatabaseQuery()
.Where(x => x.Id == name)
.ToList()
.SingleOrDefault();
}
示例13: GetStartedDemo
public async Task GetStartedDemo()
{
try
{
var items = DataHelper.GetRealEstateT(int.Parse(DateTime.UtcNow.ToString("yyyyMMdd"))).Select(x => JsonHelper.Deserialize<RealEstateObj>(x.Data));
this.client = new DocumentClient(new Uri(EndpointUri), PrimaryKey);
await this.CreateDatabaseIfNotExists("fresdb");
await this.CreateDocumentCollectionIfNotExists("fresdb", "frescollection");
foreach (var item in items)
{
await this.CreateRealEstate("fresdb", "frescollection", item);
}
}
catch (DocumentClientException de)
{
Exception baseException = de.GetBaseException();
Console.WriteLine("{0} error occurred: {1}, Message: {2}", de.StatusCode, de.Message, baseException.Message);
}
catch (Exception e)
{
Exception baseException = e.GetBaseException();
Console.WriteLine("Error: {0}, Message: {1}", e.Message, baseException.Message);
}
finally
{
Console.WriteLine("End of demo, press any key to exit.");
Console.ReadKey();
}
}
示例14: DocumentDBDataProvider
public DocumentDBDataProvider(string endpoint, string authorizationKey, string databaseId = "ojibwe")
{
Client = new DocumentClient(new Uri(endpoint), authorizationKey);
_databaseId = databaseId;
if(!Initialize())
throw new ApplicationException("Could not initialize DataProvider");
}
示例15: DeleteDatabase
protected static void DeleteDatabase()
{
using (var client = new DocumentClient(new Uri(UnitTestsConfig.EndPoint), UnitTestsConfig.AuthorizationKey))
{
DatabaseService.DeleteDatabase(client, UnitTestsConfig.Database).Wait();
}
}