public async Task Execute(Experiment experiment, DocumentClient client, DocumentCollection collection, Uri documentCollectionUri, int taskId, ConfigurationOptions options) { var cancellationTokenService = new CancellationTokenSource(); try { cancellationTokenService.CancelAfter(2500); Order order = Order.NewOrder(); ResourceResponse <Document> response = await client.CreateDocumentAsync(documentCollectionUri, order, new RequestOptions() { }, false, cancellationTokenService.Token); if (options.Record) { Console.WriteLine("Order: {0}", JsonConvert.SerializeObject(order)); } experiment.IncrementOperationCount(); experiment.UpdateRequestUnits(taskId, response.RequestCharge); } catch (Exception e) { Trace.TraceError("Failed to write. Exception was {0}", e); if (e is DocumentClientException) { DocumentClientException de = (DocumentClientException)e; if (de.StatusCode == HttpStatusCode.Forbidden) { experiment.IncrementOperationCount(); } } } }
public async Task Execute(Experiment experiment, DocumentClient client, DocumentCollection collection, Uri documentCollectionUri, int taskId, ConfigurationOptions options) { try { ResourceResponse <DocumentCollection> response = await client.ReadDocumentCollectionAsync(collection.SelfLink, new RequestOptions() { }); experiment.IncrementOperationCount(); experiment.UpdateRequestUnits(taskId, response.RequestCharge); } catch (Exception e) { Trace.TraceError("Failed to read {0}. Exception was {1}", collection.SelfLink, e); if (e is DocumentClientException) { DocumentClientException de = (DocumentClientException)e; if (de.StatusCode == HttpStatusCode.Forbidden) { experiment.IncrementOperationCount(); } } } }
/// <summary> /// Initializes a new instance of the <see cref="T:MsLearnCosmosDB.Experiment"/> class. /// </summary> /// <param name="client">Client.</param> /// <param name="collection">Collection.</param> /// <param name="documentCollectionUri">Document collection URI.</param> /// <param name="options">Configured options</param> public Experiment(DocumentClient client, DocumentCollection collection, Uri documentCollectionUri, ConfigurationOptions options) { this.client = client; this.collection = collection; this.DocumentCollectionUri = documentCollectionUri; this.Options = options; this.OperationCount = 0; }