本文整理汇总了C#中Microsoft.Azure.Documents.Client.DocumentClient.DeleteDocumentAsync方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentClient.DeleteDocumentAsync方法的具体用法?C# DocumentClient.DeleteDocumentAsync怎么用?C# DocumentClient.DeleteDocumentAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Azure.Documents.Client.DocumentClient
的用法示例。
在下文中一共展示了DocumentClient.DeleteDocumentAsync方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static int Main(string[] args)
{
Options options = new Options();
if (!CommandLine.Parser.Default.ParseArguments(args, options))
{
Console.WriteLine("Invalid arguments");
return 1;
}
using (DocumentClient client = new DocumentClient(
new Uri(options.Endpoint),
options.AuthKey,
new ConnectionPolicy { ConnectionMode = ConnectionMode.Direct, ConnectionProtocol = Protocol.Tcp }))
{
Database database = client.CreateDatabaseQuery().Where(d => d.Id == options.Database).AsEnumerable().FirstOrDefault();
if (database == null)
{
Console.WriteLine("Cannot find database " + options.Database);
return 2;
}
List<DocumentCollection> collections = client.ReadDocumentCollectionFeedAsync(database.SelfLink).Result.ToList();
int minimumRequiredCollections = Math.Max(options.NewCollections, options.CurrentCollections);
if (collections.Count < minimumRequiredCollections)
{
Console.WriteLine("At least {0} collections must be pre-created", minimumRequiredCollections);
return 3;
}
Console.WriteLine("Current distribution of documents across collections:");
LogDocumentCountsPerCollection(client, database).Wait();
Console.WriteLine();
HashPartitionResolver currentPartitionResolver = new HashPartitionResolver(options.PartitionKeyName, collections.Take(options.CurrentCollections).Select(c => c.SelfLink));
HashPartitionResolver nextPartitionResolver = new HashPartitionResolver(options.PartitionKeyName, collections.Take(options.NewCollections).Select(c => c.SelfLink));
int numberOfMovedDocuments = 0;
Parallel.ForEach(currentPartitionResolver.CollectionLinks, collectionLink =>
{
ResourceFeedReader<Document> feedReader = client.CreateDocumentFeedReader(collectionLink, new FeedOptions { MaxItemCount = -1 });
while (feedReader.HasMoreResults)
{
foreach (Document document in DocumentClientHelper.ExecuteWithRetryAsync<FeedResponse<Document>>(() => feedReader.ExecuteNextAsync()).Result)
{
object partitionKey = nextPartitionResolver.GetPartitionKey(document);
string newCollectionLink = nextPartitionResolver.ResolveForCreate(partitionKey);
if (newCollectionLink != collectionLink)
{
int count = Interlocked.Increment(ref numberOfMovedDocuments);
DocumentClientHelper.ExecuteWithRetryAsync(() => client.DeleteDocumentAsync(document.SelfLink)).Wait();
DocumentClientHelper.ExecuteWithRetryAsync(() => client.CreateDocumentAsync(newCollectionLink, document)).Wait();
if (count % 100 == 0)
{
Console.WriteLine("Moved {0} documents between partitions", numberOfMovedDocuments);
}
}
}
}
});
Console.WriteLine();
Console.WriteLine("Moved {0} documents between partitions.", numberOfMovedDocuments);
Console.WriteLine();
Console.WriteLine("Current distribution of documents across collections:");
LogDocumentCountsPerCollection(client, database).Wait();
Console.WriteLine();
}
return 0;
}
示例2: TransferDc
private static async Task TransferDc(DocumentCollection oldDc, DocumentCollection newDc, DocumentClient client,
Database database, Hashtable newList)
{
foreach (DictionaryEntry dis in newList)
{
var tempDis = dis;
var items =
from d in client.CreateDocumentQuery<PostMessage>(oldDc.DocumentsLink)
where d.Type == "Post" && d.Path.District == tempDis.Key.ToString()
select d;
foreach (var item in items)
{
try
{
await client.DeleteDocumentAsync(item._self);
}
catch (Exception)
{
Thread.Sleep(200);
client.DeleteDocumentAsync(item._self).Wait();
}
try
{
await client.CreateDocumentAsync(newDc.DocumentsLink, item);
}
catch (Exception)
{
Thread.Sleep(200);
client.CreateDocumentAsync(newDc.DocumentsLink, item).Wait();
}
}
}
}
示例3: SaveDisList
private static async Task SaveDisList(Hashtable newList, Hashtable oldList,
DocumentCollection origin, DocumentCollection oldDc,
DocumentCollection newDc, DocumentClient client)
{
var t = (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
var allow = new DcAllocate
{
Type = "DisList",
DcName = newDc.Id,
DcSelfLink = newDc.SelfLink,
District = new List<string>()
};
foreach (DictionaryEntry i in newList)
{
allow.District.Add(i.Key.ToString());
}
await client.CreateDocumentAsync(origin.DocumentsLink, allow);
var ds =
from d in client.CreateDocumentQuery<DcAllocate>(origin.DocumentsLink)
where d.Type == "DisList" && d.DcName == oldDc.Id
select d;
var l = ds.ToList().FirstOrDefault();
if (l != null) await client.DeleteDocumentAsync(l._self);
var allow2 = new DcAllocate
{
Type = "DisList",
DcName = oldDc.Id,
DcSelfLink = oldDc.SelfLink,
District = new List<string>(),
};
foreach (DictionaryEntry i in oldList)
{
allow2.District.Add(i.Key.ToString());
}
await client.CreateDocumentAsync(origin.DocumentsLink, allow2);
}
示例4: DeleteAll
private static async Task DeleteAll(DocumentClient client, Database database,
DocumentCollection documentCollection)
{
IEnumerable<DocumentCollection> dz = client.CreateDocumentCollectionQuery(database.SelfLink)
.AsEnumerable();
foreach (var z in dz)
{
var families =
from f in client.CreateDocumentQuery(z.DocumentsLink)
select f;
foreach (var family in families)
{
dynamic d = JsonConvert.DeserializeObject(family.ToString());
//Console.WriteLine(d.Path.school);
try
{
//var res = await client.DeleteDocumentAsync(family.SelfLink);
var family1 = family;
var response = await _iDbService.ExecuteWithRetries(5, () => client.DeleteDocumentAsync(family1.SelfLink));
}
catch (DocumentClientException e)
{
/* if (e.RetryAfter.TotalMilliseconds>0)
{
Console.WriteLine(e.RetryAfter.TotalMilliseconds);
Thread.Sleep((int) e.RetryAfter.TotalMilliseconds);
client.DeleteDocumentAsync(family.SelfLink).Wait();
}
else
{*/
Console.WriteLine(e.Message);
// }
}
Console.WriteLine(family.SelfLink);
}
}
}
示例5: DeleteCourse
private static async Task DeleteCourse(Guid guid, DocumentCollection documentCollection)
{
DocumentClient documentClient = new DocumentClient(new Uri("https://schooltest.documents.azure.com:443/"),
"Of414DnEibhmqeSTB0pKShdQtR6dxxfXP8uT93pggxoumKthJGzuECCUJZ27Pqf846VUkFfOrraMTQ74PZaywA==");
Course course = documentClient.CreateDocumentQuery<Course>(documentCollection.DocumentsLink,
new SqlQuerySpec(string.Format("SELECT * FROM c WHERE c.CourseId = '{0}'", guid))).AsEnumerable().FirstOrDefault();
if (course == null)
return;
await documentClient.DeleteDocumentAsync(course.SelfLink);
}
示例6: DeleteFamily
public static Task DeleteFamily(DocumentClient client, DocumentCollection collection, string needle)
{
var family = GetFamily(client, collection, needle);
dynamic doc = GetDocumentById(client, collection,family.id);
var task = client.DeleteDocumentAsync(doc.SelfLink);
return task;
}