- Using the plugin registration tool, register the following steps on your Azure Service Bus endpoint:
- Message: Retrieve
- Primary Entity: account
- Execution Mode: Asynchronous
- Click on Register New Step
- In Visual Studio, create a new console application called Packt.Xrm.ReadAudit.
- Add the following four NuGet packages:
- Microsoft.Azure.DocumentDB
- Windows.Azure.ServiceBus
- Newtonsoft.JSON
- Microsoft.CrmSdk.CoreAssemblies
- Add the following using statements:
using Microsoft.Azure.Documents.Client;
using Microsoft.ServiceBus.Messaging;
using Newtonsoft.Json.Linq;
using Microsoft.Xrm.Sdk;
- Add the following private constant variables:
private const string endpointUri = "https://.documents.azure.com:443/";
private const string primaryKey = "<Your Primary Key>";
private const string databaseName = "Dynamics365";
private const string collectionName = "Audit";
private const string connectionString = "Endpoint=sb://.servicebus.windows.net/;
SharedAccessKeyName=CrmQueue;SharedAccessKey=;EntityPath= ";
private const string queueName = "dynamics365queue";
private static DocumentClient docClient;
- Add the following code in your main method:
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
docClient = new DocumentClient(new Uri(endpointUri), primaryKey);
var dbUri = UriFactory.CreateDocumentCollectionUri(databaseName, collectionName);
client.OnMessage(message =>
{
var result = message.GetBody<RemoteExecutionContext>();
var readLog = $"{{userId:'{
result.InitiatingUserId}',entity:'{
result.PrimaryEntityName}',entityId:'{
result.PrimaryEntityId}'}}";
var parsedReadLog = JObject.Parse(readLog);
docClient.CreateDocumentAsync(dbUri, parsedReadLog).Wait();
}
);
Console.WriteLine("Press [Enter] to terminate");
Console.ReadLine();
client.Close();
- Run your console application.
- Retrieve an account record in Dynamics 365.
- Query your Cosmos DB in Azure for new entries.
..................Content has been hidden....................
You can't read the all page of ebook, please click
here login for view all page.