Ejemplo n.º 1
0
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            var reposConnectionString = CloudConfigurationManager.GetSetting("reposConnectionString");

            var repos = new Repository(reposConnectionString);

            while (!cancellationToken.IsCancellationRequested)
            {
                var msg = await _client.ReceiveAsync(TimeSpan.FromSeconds(5));

                if(msg != null)
                {
                    var json = (string) msg.Properties["json"];

                    var result = JsonConvert.DeserializeObject<PurchaseResult>(json);

                    var record = new AuditRecord
                    {
                        Id = Guid.NewGuid(),
                        RequestId = result.Request.Id,
                        RequestTimestamp = result.Request.Timestamp,
                        ResultId = result.Id,
                        ResultTimestamp = result.Timestamp,
                        Success = result.Success,
                        FailureReason = result.Success ? "<none>" : result.FailureReason.Value.ToString(),
                        JsonTickets = JsonConvert.SerializeObject(result.Request.DesiredTickets)
                    };

                    await repos.AddAuditRecord(record);
                }
            }
        }
Ejemplo n.º 2
0
 public Task AddAuditRecord(AuditRecord record)
 {
     _db.AuditRecords.Add(record);
     return _db.SaveChangesAsync();
 }