Example #1
0
        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));
        }
Example #2
0
        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));
        }
Example #3
0
        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;
 }
Example #5
0
 /// <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) =>
Example #6
0
        public virtual void RemoveTypeEncoder(ITypeEncoder encoder)
        {
            lock (_lock)
            {
                if (!_encoders.Contains(encoder))
                {
                    return;
                }

                _encoders.Remove(encoder);
            }
        }
Example #7
0
 /// <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);
 }
Example #9
0
        public virtual void AddTypeEncoder(ITypeEncoder encoder)
        {
            lock (_lock)
            {
                if (_encoders.Contains(encoder))
                {
                    return;
                }

                _encoders.Add(encoder);
                _encoders.Sort(_comparer);
            }
        }
Example #10
0
 /// <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;
 }
Example #12
0
        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();
        }
Example #13
0
        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;
Example #16
0
 /// <inheritdoc/>
 public MessageExceptionJsonConverter(
     ITypeEncoder typeEncoder,
     IOptions <MessagingClientOptions> clientOptions)
     : base(typeEncoder) =>
     this.clientOptions = clientOptions;