public SQLiteSimpleCache(ISQLitePlatform platform, SQLiteConnectionString connection, IByteSerializer defaultSerializer)
     : base(platform, connection)
 {
     this.CreateTable <SQliteCacheTable>();
     this.serializer      = defaultSerializer;
     this.asyncConnection = new SQLiteAsyncConnection(() => this);
 }
Exemplo n.º 2
0
    public static ArrayPoolBufferWriter <byte> Write(this IByteSerializer serializer, object?value, Type type)
    {
        var bufferWriter = new ArrayPoolBufferWriter <byte>();

        serializer.Write(bufferWriter, value);
        return(bufferWriter);
    }
Exemplo n.º 3
0
    public static ArrayPoolBufferWriter <byte> Write <T>(this IByteSerializer <T> serializer, T value)
    {
        var bufferWriter = new ArrayPoolBufferWriter <byte>();

        serializer.Write(bufferWriter, value);
        return(bufferWriter);
    }
Exemplo n.º 4
0
    public static Channel <T> WithByteSerializer <T>(
        this Channel <ReadOnlyMemory <byte> > downstreamChannel,
        IByteSerializer <T> serializer,
        BoundedChannelOptions?channelOptions = null,
        CancellationToken cancellationToken  = default)
    {
        channelOptions ??= new BoundedChannelOptions(16)
        {
            FullMode     = BoundedChannelFullMode.Wait,
            SingleReader = true,
            SingleWriter = true,
            AllowSynchronousContinuations = true,
        };
        var pair = ChannelPair.CreateTwisted(
            Channel.CreateBounded <T>(channelOptions),
            Channel.CreateBounded <T>(channelOptions));

        downstreamChannel.Connect(pair.Channel1,
                                  serializer.Read,
                                  Write,
                                  ChannelCompletionMode.Full,
                                  cancellationToken);
        return(pair.Channel2);

        ReadOnlyMemory <byte> Write(T value)
        {
            using var bufferWriter = serializer.Write(value);
            return(bufferWriter.WrittenMemory.ToArray());
        }
    }
 public static IBlobSerializer AsBlobSerializer(this IByteSerializer serializer)
 {
     return(new BlobSerializerDelegate(
                serializer.SerializeToBytes,
                (data, type) => serializer.Deserialize(data, type),
                serializer.CanDeserialize));
 }
Exemplo n.º 6
0
        public static bool CanSerializeBytes <T>(this IByteSerializer serializer, T item)
        {
            var text = serializer.SerializeToBytes(item);

            var obj = serializer.Deserialize <T>(text);

            return(obj.Equals(item));
        }
Exemplo n.º 7
0
        public static IBlobSerializer AsBlobSerializer(this IByteSerializer serializer)
        {
            var gm = typeof(IByteSerializer).GetTypeInfo().GetDeclaredMethod("Deserialize");

            return(new BlobSerializerDelegate(
                       obj => serializer.SerializeToBytes(obj),
                       (data, type) => gm.MakeGenericMethod(type).Invoke(serializer, new[] { data }),
                       serializer.CanDeserialize));
        }
 public RequestCachingBehavior(IDistributedCache cache, IByteSerializer byteSerializer,
                               ILogger <TResponse> logger, IOptionsSnapshot <RequestCacheConfiguration> options,
                               IDateTimeService dateTimeService)
 {
     _options         = options ?? throw new ArgumentNullException(nameof(options));
     _dateTimeService = dateTimeService ?? throw new ArgumentNullException(nameof(dateTimeService));
     _cache           = cache ?? throw new ArgumentNullException(nameof(cache));
     _byteSerializer  = byteSerializer ?? throw new ArgumentNullException(nameof(byteSerializer));
     _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Exemplo n.º 9
0
        public ZyreBackplane(CrossStitchCore core, BackplaneConfiguration config = null, IByteSerializer byteSerializer = null)
        {
            _core           = core;
            _config         = config ?? BackplaneConfiguration.GetDefault();
            _byteSerializer = byteSerializer ?? new JsonByteSerializer();

            // TODO: Need to expose more zyre options in the config, including broadcast port, broadcast interface,
            // and beacon interval.

            _zyre               = new NetMQ.Zyre.Zyre(core.NodeId);
            _zyre.EnterEvent   += ZyreEnterEvent;
            _zyre.StopEvent    += ZyreStopEvent;
            _zyre.ExitEvent    += ZyreExitEvent;
            _zyre.EvasiveEvent += ZyreEvasiveEvent;
            _zyre.JoinEvent    += ZyreJoinEvent;
            _zyre.LeaveEvent   += ZyreLeaveEvent;
            _zyre.WhisperEvent += ZyreWhisperEvent;
            _zyre.ShoutEvent   += ZyreShoutEvent;
        }
Exemplo n.º 10
0
 public CastingByteSerializer(IByteSerializer untypedSerializer, Type serializedType)
 {
     UntypedSerializer = untypedSerializer;
     SerializedType    = serializedType;
 }
 private static bool CanDeserialize(this IByteSerializer serializer, Type type)
 {
     return(true);
 }
Exemplo n.º 12
0
 public NetMqMessageMapper(IByteSerializer byteSerializer)
 {
     _byteSerializer = byteSerializer;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Extend base serializer with additional messages
 /// </summary>
 public Generic <T> Add(IByteSerializer <T> additionalSerializer)
 {
     _serializers.Add(additionalSerializer);
     return(this);
 }
Exemplo n.º 14
0
 public PracticalTest(IByteSerializer serializer)
 {
     _byteSerializer = serializer;
 }
Exemplo n.º 15
0
 public static T Read <T>(this IByteSerializer serializer, ReadOnlyMemory <byte> data)
 => (T)serializer.Read(data, typeof(T)) !;
 public ConcurrentSessionContextManager()
 {
     _byteSerializer  = new BinaryFormatterByteSerializer();
     _sessionContexts = new ConcurrentDictionary <Guid, SessionContext>();
 }
Exemplo n.º 17
0
 public ObjectEncryptor(IEncrypting encrypting, IByteSerializer byteSerializer)
 {
     _encrypting     = encrypting;
     _byteSerializer = byteSerializer;
 }
Exemplo n.º 18
0
 public static ArrayPoolBufferWriter <byte> Write <T>(this IByteSerializer serializer, T value)
 // ReSharper disable once HeapView.PossibleBoxingAllocation
 => serializer.Write(value, typeof(T));
Exemplo n.º 19
0
 /// <summary>
 /// Initialize merged serializer with a minimum of one target
 /// </summary>
 /// <param name="core">Serializer for the core protocol specification</param>
 internal Generic(IByteSerializer <T> core)
 {
     _serializers.Add(core);
 }
Exemplo n.º 20
0
 public static IByteSerializer NewAsymmetric(IByteSerializer reader, IByteSerializer writer)
 => new AsymmetricByteSerializer(reader, writer);
Exemplo n.º 21
0
 public AsymmetricByteSerializer(IByteSerializer reader, IByteSerializer writer)
 {
     Reader = reader;
     Writer = writer;
 }
 public CacheService(ICacheProvider cacheProvider, IByteSerializer byteSerializer)
 {
     _byteSerializer = byteSerializer;
     _lazyCache      = new AsyncLazy <IDatabase>(cacheProvider.Get);
 }
Exemplo n.º 23
0
 public RequestCachingBehavior(IDistributedCache cache, IByteSerializer byteSerializer, ILogger <TResponse> logger)
 {
     this.cache          = cache ?? throw new ArgumentNullException(nameof(cache));
     this.byteSerializer = byteSerializer ?? throw new ArgumentNullException(nameof(byteSerializer));
     this.logger         = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Extension method to extend a serializer with additional serializers for type support
 /// </summary>
 /// <typeparam name="T">Type of header</typeparam>
 /// <param name="coreSerializer">Current serializer</param>
 /// <param name="extension">Additional serializer</param>
 /// <returns>Merged instance</returns>
 public static IByteSerializer <T> Extend <T>(this IByteSerializer <T> coreSerializer, IByteSerializer <T> extension)
     where T : IBinaryHeader, new()
 {
     return((coreSerializer as Generic <T> ?? new Generic <T>(coreSerializer)).Add(extension));
 }