예제 #1
0
        public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
        {
            var unprotectedBytes = _byteConverter.ToBytes(value);
            var protectedBytes   = _dataProtector.Protect(unprotectedBytes);
            var cipherText       = Convert.ToBase64String(protectedBytes);

            writer.WriteStringValue(cipherText);
        }
        public string ToCipherText(T value, JsonSerializer serializer = null)
        {
            var unprotectedBytes = _byteConverter.ToBytes(value);
            var protectedBytes   = _dataProtector.Protect(unprotectedBytes);
            var cipherText       = Convert.ToBase64String(protectedBytes);

            return(cipherText);
        }
예제 #3
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            T[] bbuf = new T[count];
            int read = _base.Read(bbuf, offset, count);

            buffer = _converter.ToBytes(bbuf);

            return(read);
        }
예제 #4
0
 /// <summary>
 /// Execute an asynchronous continuation of Serialize->Send for an event.
 /// </summary>
 public Task PublishAsync(IEvent Event)
 {
     return(Task.Run(
                () =>
     {
         try
         {
             return _converter.ToBytes(Event);
         }
         catch (Exception ex)
         {
             _logger.LogError(ex, $"Error converting {Event} to bytes.");
             throw;
         }
     })
            .ContinueWith(t => _model.BasicPublish(_config.Exchange, _config.Routing, null, t.Result), TaskContinuationOptions.NotOnFaulted));
 }