Exemplo n.º 1
0
 public EventCacheEntry(BackgroundCommandEvent commandEvent, IBackgroundCommandSerializer serializer)
 {
     EventStatus    = commandEvent.Status.ToString();
     EventTimestamp = commandEvent.Timestamp;
     Command        = serializer.SerializeAsync(commandEvent.Command).Result;
     if (commandEvent.Exception != null)
     {
         try
         {
             Exception = JsonConvert.SerializeObject(commandEvent.Exception);
         }
         catch (Exception ex)
         {
             Exception = ex.ToString();
         }
     }
 }
 public EventTableEntity(BackgroundCommandEvent commandEvent, IBackgroundCommandSerializer serializer)
 {
     PartitionKey   = commandEvent.Command.Id;
     RowKey         = BackgroundCommandIdGenerator.Generate();
     EventStatus    = commandEvent.Status.ToString();
     EventTimestamp = commandEvent.Timestamp;
     Command        = serializer.SerializeAsync(commandEvent.Command).Result;
     if (commandEvent.Exception != null)
     {
         try
         {
             Exception = JsonConvert.SerializeObject(commandEvent.Exception);
         }
         catch (Exception ex)
         {
             Exception = ex.ToString();
         }
     }
 }
        /// <inheritdoc />
        public async Task DispatchAsync(IBackgroundCommand command, CancellationToken cancellationToken = default)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            try
            {
                var options = _options.Value;
                await _queue.AddMessageAsync(
                    new CloudQueueMessage(await _serializer.SerializeAsync(command)),
                    timeToLive : options.TimeToLive,
                    initialVisibilityDelay : options.InitialVisibilityDelay,
                    options : options.QueueRequestOptions,
                    operationContext : options.OperationContextBuilder != null?options.OperationContextBuilder(command) : null,
                    cancellationToken);
            }
            catch (Exception ex)
            {
                throw new BackgroundProcessingException($"Error while enqueueing command {command}: {ex.Message}", ex);
            }
        }