コード例 #1
0
 // read the document, modify it, call update method on modified document
 public static async void ModifyDatesDocument(UpdateDates update)
 {
     Console.WriteLine("modifying: update dates document");
     Trace.TraceInformation("worker role:modifying: update dates document");
     Database database = GetDatabase(DatabaseId).Result;
     DocumentCollection collection = GetCollection(database, CollectionId).Result;
     await UpdateDocument(collection, update);
     Console.WriteLine("new update date: " + update.lastUpdate.ToString() + " new updated to date: " + update.updatedTo.ToString());
     Trace.TraceInformation("worker role: new update date: " + update.lastUpdate.ToString() + " new updated to date: " + update.updatedTo.ToString());
     Console.WriteLine("update dates document modified");
 }
コード例 #2
0
 // change the dates document
 public static void AlterUpdateDates()
 {
     UpdateDates update = new UpdateDates();
     update.lastUpdate = dateTimeLastUpdated;
     update.updatedTo = dateTimeUpdatedTo;
     update.id = "update_dates";
     if (update.updatedTo.Month == 12 && update.updatedTo.Day == 31) // if 31st december push to 1st january
     {
         update.updatedTo = update.updatedTo.AddDays(1);
     }
     DatabaseDates.ModifyDatesDocument(update);
 }
コード例 #3
0
        // create the update dates document
        public static async void CreateDatesDocument()
        {
            var queryDone = false;
            UpdateDates update = new UpdateDates();
            update.id = "update_dates";
            update.lastUpdate = DateTime.Now;
            update.updatedTo = DateTime.Now;
            while (!queryDone)
            {
                try
                {
                    Console.WriteLine("creating document for the update dates document");
                    Database database = GetDatabase(DatabaseId).Result;
                    DocumentCollection collection = GetCollection(database, CollectionId).Result;
                    await client.CreateDocumentAsync(collection.SelfLink, update);
                    Console.WriteLine("update dates document created");
                    queryDone = true;
                }
                catch (DocumentClientException documentClientException)
                {
                    var statusCode = (int)documentClientException.StatusCode;
                    if (statusCode == 429 || statusCode == 503)
                        Thread.Sleep(documentClientException.RetryAfter);
                    else
                        throw;
                }
                catch (AggregateException aggregateException)
                {
                    if (aggregateException.InnerException.GetType() == typeof(DocumentClientException))
                    {

                        var docExcep = aggregateException.InnerException as DocumentClientException;
                        var statusCode = (int)docExcep.StatusCode;
                        if (statusCode == 429 || statusCode == 503)
                            Thread.Sleep(docExcep.RetryAfter);
                        else
                            throw;
                    }
                }
            }
        }
コード例 #4
0
 // update a modified document
 public static async Task<Document> UpdateDocument(DocumentCollection coll, UpdateDates record)
 {
     return await client.UpsertDocumentAsync(coll.SelfLink, record);
 }