本文整理汇总了C#中DocumentCollection类的典型用法代码示例。如果您正苦于以下问题:C# DocumentCollection类的具体用法?C# DocumentCollection怎么用?C# DocumentCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DocumentCollection类属于命名空间,在下文中一共展示了DocumentCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDocumentCollectionIfNotExists
private static async Task CreateDocumentCollectionIfNotExists(string databaseName, string collectionName)
{
try
{
await Client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName));
}
catch (DocumentClientException de)
{
// If the document collection does not exist, create a new collection
if (de.StatusCode == HttpStatusCode.NotFound)
{
DocumentCollection collectionInfo = new DocumentCollection();
collectionInfo.Id = collectionName;
// Configure collections for maximum query flexibility including string range queries.
collectionInfo.IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 });
// Here we create a collection with 400 RU/s.
await Client.CreateDocumentCollectionAsync(
UriFactory.CreateDatabaseUri(databaseName),
collectionInfo,
new RequestOptions { OfferThroughput = 400 });
}
else
{
throw;
}
}
}
示例2: DocumentDBDataReader
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..
}
}
示例3: GetDocumentDbClient
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;
}
示例4: CollectionTransfer
public async Task CollectionTransfer(DocumentCollection dc1, DocumentCollection dc2)
{
var sp = await _iDBoperation.GetStoreProcedure(dc1.SelfLink, "BatchDelete");
var sp2 = await _iDBoperation.GetStoreProcedure(dc1.SelfLink, "BatchInsert");
var docs = _iDBoperation.GetDocumentByType(dc1.DocumentsLink, "Post");
var l = docs.ToList();
var cur = 0;
int maxDoc = 400;
while (cur < l.Count)
{
var s = new List<dynamic>();
for (var i = cur; i < l.Count; i++)
{
if (s.Count < maxDoc)
{
s.Add(l[i]);
}
}
var n = await BatchTransfer(sp2.SelfLink, sp.SelfLink, s);
//Console.WriteLine(n + "----" + l.Count);
cur = cur + n;
}
}
示例5: 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;
}
示例6: GetStart
//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,
});
}
}
示例7: FetchAll
public DocumentCollection FetchAll()
{
DocumentCollection coll = new DocumentCollection();
Query qry = new Query(Document.Schema);
coll.LoadAndCloseReader(qry.ExecuteReader());
return coll;
}
示例8: CreateDocumentCollection
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);
}
示例9: 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;
}
}
}
示例10: GetUpdateResolver
private static RangePartitionResolver<long> GetUpdateResolver(RangePartitionResolver<long> oldResolver,
DocumentCollection newDc)
{
var map = new Dictionary<Range<long>, string>();
var vs = oldResolver.PartitionMap;
if (vs.Count > 1)
{
foreach (var v in vs)
{
if (map.Count < vs.Count - 1)
{
map.Add(new Range<long>(v.Key.Low, v.Key.High), v.Value);
}
}
}
//Check Resolver
var now = (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
if (now < vs.LastOrDefault().Key.Low || now > vs.LastOrDefault().Key.High) return null;
map.Add(new Range<long>(vs.LastOrDefault().Key.Low, now), vs.LastOrDefault().Value);
map.Add(new Range<long>(now + 1, vs.LastOrDefault().Key.High), newDc.SelfLink);
return new RangePartitionResolver<long>(
u => ((PostMessage) u).Info.timestamp,
map);
}
示例11: CreateCollection
private async Task CreateCollection(string collectionId)
{
collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == collectionId).ToArray().FirstOrDefault();
if (null == collection)
{
collection = await client.CreateDocumentCollectionAsync(database.SelfLink, new DocumentCollection { Id = collectionId });
}
}
示例12: GoOnVacation
public async static Task GoOnVacation(DocumentClient client, DocumentCollection collection, string jeffersons, bool left)
{
var family = GetFamily(client, collection, jeffersons);
dynamic doc = GetDocumentById(client, collection,family.id);
Family f = doc;
f.IsHome = false;
var task = await client.ReplaceDocumentAsync(doc.SelfLink, f);
}
示例13: UpdateCurrentCollection
public async Task UpdateCurrentCollection(DocumentCollection newDc)
{
await _iDBoperation.DeleteDocById("CurrentCollection");
var doc = new CurrentCollection
{
id = "CurrentCollection",
name = newDc.Id
};
await _iDBoperation.CreateDocument(doc);
}
示例14: GetCollection
public async Task<DocumentCollection> GetCollection()
{
if (_documentCollection == null)
{
var db = await GetDatabase();
_documentCollection = await GetCollection(_config["DocumentCollection"], db);
}
return _documentCollection;
}
示例15: UsersController
static UsersController()
{
var address = CloudConfigurationManager.GetSetting("DocumentDbEndpointAddress");
var authorizationKey = CloudConfigurationManager.GetSetting("DocumentDbAuthorizationKey");
Client = new DocumentClient(new Uri(address), authorizationKey);
var database = GetOrCreateDatabase(Client, "CloudCampDb");
DocumentCollection = GetOrCreateCollection(Client, database.SelfLink, "Users");
}