public virtual string Serialize(object value) { lock (_lock) { for (var i = 0; i < encoders.Count; i++) { try { ITypeEncoder encoder = encoders[i]; if (!encoder.IsSupport(value.GetType())) { continue; } return(encoder.Encode(value)); } catch (Exception) { } } } throw new NotSupportedException(string.Format("Unsupported type, this value \"{0}\" cannot be serialized", value)); }
public virtual object Deserialize(string input, Type type) { lock (_lock) { for (var i = 0; i < encoders.Count; i++) { try { ITypeEncoder encoder = encoders[i]; if (!encoder.IsSupport(type)) { continue; } return(encoder.Decode(type, input)); } catch (Exception) { } } } throw new NotSupportedException(string.Format("This value \"{0}\" cannot be converted to the type \"{1}\"", input, type.Name)); }
public virtual string Serialize(object value) { lock (_lock) { for (int i = 0; i < _encoders.Count; i++) { try { ITypeEncoder encoder = _encoders[i]; if (!encoder.IsSupport(value.GetType())) { continue; } return(encoder.Encode(value)); } catch (Exception e) { Log.Error(e); } } } throw new NotSupportedException($"Unsupported type, this value \"{value}\" cannot be serialized"); }
public WebMessageHandlerClient( HttpClient client, ITypeEncoder typeEncoder, ISerializerFactory factory) { this.client = client; this.typeEncoder = typeEncoder; this.factory = factory; }
/// <exception cref="ArgumentException"/> public HistoricalStorage( IServiceProvider provider, ITypeEncoder typeEncoder, IDiagnosticContext diagnosticContext) : base( provider.GetService <IValueConverter <TKey> >() ?? throw ImproperlyConfiguredException(typeof(TKey)), provider.GetService <IValueConverter <TValue> >() ?? throw ImproperlyConfiguredException(typeof(TValue)), provider.GetService <IHistoricalStorageProvider <TValue> >() ?? throw ImproperlyConfiguredException(typeof(TValue)), typeEncoder, diagnosticContext) =>
public virtual void RemoveTypeEncoder(ITypeEncoder encoder) { lock (_lock) { if (!_encoders.Contains(encoder)) { return; } _encoders.Remove(encoder); } }
/// <exception cref="ArgumentException"/> public PartitionedStorage( IServiceProvider provider, ITypeEncoder typeEncoder, IDiagnosticContext diagnosticContext) { this.keyType = typeEncoder.Encode(typeof(TKey)) ?? throw NotSupportedTypeException(typeof(TKey)); this.valueType = typeEncoder.Encode(typeof(TValue)) ?? throw NotSupportedTypeException(typeof(TValue)); this.backedStorage = provider.GetService <IPartitionedStorageProvider <TValue> >() ?? throw ImproperlyConfiguredException(); this.keyConverter = provider.GetService <IValueConverter <TKey> >() ?? throw ImproperlyConfiguredException(); this.valueConverter = provider.GetService <IValueConverter <TValue> >() ?? throw ImproperlyConfiguredException(); this.diagnosticContext = diagnosticContext; }
/// <summary/> public MongoRecordClient( ILogger <MongoRecordClient> logger, IOptionsMonitor <MongoHandlingServerOptions> options, ITypeEncoder typeEncoder, IMongoClientFactory clientFactory) { this.logger = logger; this.options = options; this.typeEncoder = typeEncoder; this.collection = clientFactory .GetDatabase(MongoOptionsNames.DefaultName) .GetCollection <MongoRecord>(MongoNames.MessageCollectionName); }
public virtual void AddTypeEncoder(ITypeEncoder encoder) { lock (_lock) { if (_encoders.Contains(encoder)) { return; } _encoders.Add(encoder); _encoders.Sort(_comparer); } }
/// <exception cref="NotSupportedException"/> protected Storage( IValueConverter <TKey> keyConverter, IValueConverter <TValue> valueConverter, IStorageProvider <TValue> backedStorage, ITypeEncoder typeEncoder, IDiagnosticContext diagnosticContext) { this.KeyType = typeEncoder.Encode(typeof(TKey)) ?? throw NotSupportedTypeException(typeof(TKey)); this.ValueType = typeEncoder.Encode(typeof(TValue)) ?? throw NotSupportedTypeException(typeof(TValue)); this.KeyConverter = keyConverter; this.ValueConverter = valueConverter; this.backedStorage = backedStorage; this.diagnosticContext = diagnosticContext; }
public MongoMessageHandlerProxy( ILogger <MongoMessageHandlerProxy <TMessage, TResponse> > logger, IOptions <MongoHandlingClientOptions> options, IDiagnosticContext context, ITypeEncoder typeEncoder, IMongoClientFactory clientFactory, ISystemClock clock, ExceptionModelConverter converter) { this.logger = logger; this.context = context; this.typeEncoder = typeEncoder; this.clock = clock; this.options = options.Value; this.collection = clientFactory .GetDatabase() .GetCollection <MongoRecord>(MongoNames.MessageCollectionName); this.converter = converter; }
public virtual string Serialize(object value) { lock (_lock) { for (int i = 0; i < encoders.Count; i++) { try { ITypeEncoder encoder = encoders[i]; if (!encoder.IsSupport(value.GetType())) { continue; } return(encoder.Encode(value)); } catch (Exception) { } } } throw new NotSupportedException(); }
public virtual object Deserialize(string input, Type type) { lock (_lock) { for (int i = 0; i < encoders.Count; i++) { try { ITypeEncoder encoder = encoders[i]; if (!encoder.IsSupport(type)) { continue; } return(encoder.Decode(type, input)); } catch (Exception) { } } } throw new NotSupportedException(); }
/// <summary/> public ExceptionModelConverter(ITypeEncoder typeEncoder, IOptions <MessagingClientOptions> options) { this.typeEncoder = typeEncoder; this.options = options; }
/// <summary/> public ExceptionJsonConverter(ITypeEncoder typeEncoder) => this.typeEncoder = typeEncoder;
/// <inheritdoc/> public MessageExceptionJsonConverter( ITypeEncoder typeEncoder, IOptions <MessagingClientOptions> clientOptions) : base(typeEncoder) => this.clientOptions = clientOptions;