public DocumentClient GetDocumentClient() { if (_documentClient != null) return _documentClient; _documentClient = new DocumentClient(new Uri(_endpointUrl), _authorizationKey); _documentClient.OpenAsync().Wait(); return _documentClient; }
/// <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; }
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); }
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)}); }
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); }
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; } } }
private async Task<DocumentClient> GetDocumentDbClient() { var client = new DocumentClient(new Uri(_endPointUrl), _authorizationKKry); var database = client.CreateDatabaseQuery(). Where(db => db.Id == DocumentDbId).AsEnumerable().FirstOrDefault(); if (database == null) { database = await client.CreateDatabaseAsync( new Database { Id = DocumentDbId }); } DocumentCollection = client.CreateDocumentCollectionQuery ("dbs/" + database.Id).Where(c => c.Id == _collectionId).AsEnumerable().FirstOrDefault(); if (DocumentCollection == null) { DocumentCollection = await client.CreateDocumentCollectionAsync("dbs/" + DocumentDbId, new DocumentCollection { Id = _collectionId }); } return client; }
public VenueMetaDataRepository(string endpointUri, string authorizationKey) { EndpointUri = new Uri(endpointUri); AuthorizationKey = authorizationKey; _documentClient = new DocumentClient(EndpointUri, AuthorizationKey); }
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(); } }
//new add private static async Task GetStart() { var client = new DocumentClient(new Uri(EndpointURL), AuthorizationKey); database = client.CreateDatabaseQuery().Where(d => d.Id == "ppweict").AsEnumerable().FirstOrDefault(); collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == "Exam_Pool").AsEnumerable().FirstOrDefault(); var EfDs = client.CreateDocumentQuery(collection.DocumentsLink, "SELECT * FROM Exam_pool f WHERE f.verify = \"true\" "); foreach (exam_pool EfD in EfDs) { Console.WriteLine(EfD); exams.Add(new exam_pool { id = EfD.id, exam_catrgory = EfD.exam_catrgory, exam_level = EfD.exam_level, questions = EfD.questions, answer_A = EfD.answer_A, answer_B = EfD.answer_B, answer_C = EfD.answer_C, answer_D = EfD.answer_D, answer_E = EfD.answer_E, C_answer = EfD.C_answer, exam_link = EfD.exam_link, lang = EfD.lang, verify = EfD.verify, }); } }
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); }*/ }
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(); } }
static Database FindDatabase(DocumentClient client, string name) { return client.CreateDatabaseQuery() .Where(x => x.Id == name) .ToList() .SingleOrDefault(); }
static DocumentCollection FindDocumentCollection(DocumentClient client, Database database, string name) { return client.CreateDocumentCollectionQuery(database.SelfLink) .Where(x => x.Id == name) .ToList() .SingleOrDefault(); }
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); }
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(); } }
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"); }
protected static void DeleteDatabase() { using (var client = new DocumentClient(new Uri(UnitTestsConfig.EndPoint), UnitTestsConfig.AuthorizationKey)) { DatabaseService.DeleteDatabase(client, UnitTestsConfig.Database).Wait(); } }
public DatabaseAccountNode(string endpointName, DocumentClient client) { this.accountEndpoint = endpointName; this.Text = endpointName; this.ImageKey = "DatabaseAccount"; this.SelectedImageKey = "DatabaseAccount"; this.client = client; this.Tag = "This represents the DatabaseAccount. Right click to add Database"; this.Nodes.Add(new OffersNode(this.client)); MenuItem myMenuItem = new MenuItem("Create 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); MenuItem myMenuItem4 = new MenuItem("Query Database"); myMenuItem4.Click += new EventHandler(myMenuItemQueryDatabase_Click); this.contextMenu.MenuItems.Add(myMenuItem4); 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); }
public DocumentDBDataReader() { var dict = new Dictionary<HighchartsHelper.DocumentTypes, IEnumerable<Document>>(); _documentClient = new DocumentClient(new Uri(ConfigurationManager.AppSettings["DocumentServiceEndpoint"]), ConfigurationManager.AppSettings["DocumentKey"]); _database = _documentClient.CreateDatabaseQuery().Where(db => db.Id == ConfigurationManager.AppSettings["DocumentDatabase"]).AsEnumerable().FirstOrDefault(); if (_database == null) throw new ApplicationException("Error: DocumentDB database does not exist"); // Check to verify a document collection with the id=FamilyCollection does not exist _documentCollection = _documentClient.CreateDocumentCollectionQuery(_database.CollectionsLink).Where(c => c.Id == ConfigurationManager.AppSettings["DocumentCollection"]).AsEnumerable().FirstOrDefault(); if (_documentCollection == null) throw new ApplicationException("Error: DocumentDB collection does not exist"); try { _documentClient.CreateUserDefinedFunctionAsync(_documentCollection.SelfLink, new UserDefinedFunction { Id = "ISDEFINED", Body = @"function ISDEFINED(doc, prop) { return doc[prop] !== undefined; }" }); } catch (Exception) { //fail silently for now.. } }
public static void Main(string[] args) { try { // Setup a single instance of DocumentClient that is reused throughout the application using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey)) { RunDatabaseDemo().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(); } }
public static void Main(string[] args) { try { //Get a Document client using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey)) { RunDemoAsync(databaseId, collectionId).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(); } }
public VenueMetaDataRepository() { EndpointUri = new Uri(WingtipTicketApp.Config.DocumentDbUri); AuthorizationKey = WingtipTicketApp.Config.DocumentDbKey; _documentClient = new DocumentClient(EndpointUri, AuthorizationKey); }
private static DocumentCollection GetDocumentCollection(DocumentClient client, Database database, string collectionId) { return client.CreateDocumentCollectionQuery(database.SelfLink) .Where(c => c.Id == collectionId) .AsEnumerable() .SingleOrDefault(); }
private static async Task<DocumentCollection> CreateDocumentCollection(DocumentClient client, Database database, string collectionId) { var collectionSpec = new DocumentCollection { Id = collectionId }; var requestOptions = new RequestOptions { OfferType = "S1" }; return await client.CreateDocumentCollectionAsync(database.SelfLink, collectionSpec, requestOptions); }
public SpotRepository() { string endpoint = ConfigurationManager.AppSettings["endpoint"]; string authKey = ConfigurationManager.AppSettings["authKey"]; Uri endpointUri = new Uri(endpoint); client = new DocumentClient(endpointUri, authKey); }
/// <summary> /// Main method for the sample. /// </summary> /// <param name="args">command line arguments.</param> public static void Main(string[] args) { try { using (var client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey, ConnectionPolicy)) { var program = new Program(client); program.RunAsync().Wait(); Console.WriteLine("Samples completed successfully."); } } #if !DEBUG catch (Exception e) { // If the Exception is a DocumentClientException, the "StatusCode" value might help identity // the source of the problem. Console.WriteLine("Samples failed with exception:{0}", e); } #endif finally { Console.WriteLine("End of samples, press any key to exit."); Console.ReadKey(); } }
static void Main(string[] args) { _client = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey); var database = CreateDatabase("erp"); var collection = CreateCollection(database, "customers"); }
public static async Task<HttpStatusCode> CreateCollection(DocumentClient client, Database database, string collectionName) { var result = await client.CreateDocumentCollectionAsync(database.CollectionsLink, new DocumentCollection { Id = collectionName }); return result.StatusCode; }
public Dichotomy(string endpointUrl, string authorizationKey) { _client = new DocumentClient(new Uri(endpointUrl), authorizationKey); _database = _client.CreateDatabaseQuery().Where(db => db.SelfLink == ConfigurationManager.AppSettings["DBSelfLink"]) .AsEnumerable().FirstOrDefault(); _iDbService = new DbService(); }
protected virtual void Dispose(bool disposing) { if (disposing && _database != null) { _database.Dispose(); _database = null; } }
public DocumentClient() { string settingKey = Constant.AppSettingKey.AzureDatabaseDocument; string[] accountCredentials = AppSetting.GetValue(settingKey, true); string accountEndpoint = accountCredentials[0]; string accountKey = accountCredentials[1]; _databaseId = accountCredentials[2]; _database = new DocClient(new Uri(accountEndpoint), accountKey); }
private static Database GetDatabase(Microsoft.Azure.Documents.Client.DocumentClient client) { // Check to verify a database with the id=LoggingDocumentsDB does not exist var database = client.CreateDatabaseQuery().Where(db => db.Id == "LoggingDocumentsDB").AsEnumerable().FirstOrDefault(); if (database == null) { database = client.CreateDatabaseAsync(new Database { Id = "LoggingDocumentsDB" }).Result; } return(database); }
private static DocumentCollection GetCollection(Microsoft.Azure.Documents.Client.DocumentClient client, Database database) { // Create a document collection. var documentCollection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == "LogEntries").ToArray().FirstOrDefault(); if (documentCollection == null) { // Create the document collection. documentCollection = client.CreateDocumentCollectionAsync(database.SelfLink, new DocumentCollection { Id = "LogEntries" }).Result; } return(documentCollection); }
public DocumentDBService(DBSetting dbSetting) { _dbSetting = dbSetting; _cosmosDBClient = new Microsoft.Azure.Documents.Client.DocumentClient(new Uri(_dbSetting.EndPointURL), _dbSetting.Key); }