Exemplo n.º 1
0
        public Messenger(
            Transporter channel,
            SerializerFactory serializerFactory,
            DeserializerFactory deserializerFactory,
            MessageTypeInfo[] outputMessages,
            MessageTypeInfo[] inputMessages)
        {
            _channel               = channel;
            _channel.OnReceive    += _channel_OnReceive;
            _channel.OnDisconnect += (c, e) => ChannelIsDisconnected?.Invoke(this, e);


            var outputSayMessageSerializes = new Dictionary <int, ISerializer>();

            foreach (var messageSayInfo in outputMessages)
            {
                var serializer    = serializerFactory.Create(messageSayInfo.ArgumentTypes);
                var hasReturnType = messageSayInfo.ReturnType != typeof(void);

                outputSayMessageSerializes.Add(messageSayInfo.MessageId, serializer);
                if (hasReturnType)
                {
                    _inputSayMessageDeserializeInfos.Add(
                        -messageSayInfo.MessageId,
                        InputMessageDeserializeInfo.CreateForAnswer(
                            deserializerFactory.Create(messageSayInfo.ReturnType)));
                }
            }
            foreach (var messageSayInfo in inputMessages)
            {
                var hasReturnType = messageSayInfo.ReturnType != typeof(void);
                var deserializer  = deserializerFactory.Create(messageSayInfo.ArgumentTypes);
                _inputSayMessageDeserializeInfos.Add(
                    messageSayInfo.MessageId,
                    InputMessageDeserializeInfo.CreateForAsk(messageSayInfo.ArgumentTypes.Length, hasReturnType,
                                                             deserializer));

                if (hasReturnType)
                {
                    outputSayMessageSerializes.Add(-messageSayInfo.MessageId,
                                                   serializerFactory.Create(messageSayInfo.ReturnType));
                }
            }
            _inputSayMessageDeserializeInfos.Add(Messenger.ExceptionMessageTypeId,
                                                 InputMessageDeserializeInfo.CreateForExceptionHandling());

            _sender = new Sender(_channel, outputSayMessageSerializes);
        }
Exemplo n.º 2
0
 public async Task <T> QuerySingleAsync <T>(RequestContext context)
 {
     return(await ExecuteWrapAsync(async (dbSession) =>
     {
         var dataReader = await CommandExecuter.ExecuteReaderAsync(dbSession, context);
         var deser = DeserializerFactory.Create();
         return await deser.ToSingleAsync <T>(context, dataReader);
     }, context));
 }
Exemplo n.º 3
0
 public T QuerySingle <T>(RequestContext context)
 {
     return(ExecuteWrap((dbSession) =>
     {
         var dataReader = CommandExecuter.ExecuteReader(dbSession, context);
         var deser = DeserializerFactory.Create();
         return deser.ToSingle <T>(context, dataReader);
     }, context));
 }
Exemplo n.º 4
0
        public SmartSqlMapper(SmartSqlOptions options)
        {
            SmartSqlOptions = options;
            SmartSqlOptions.Setup();
            _logger = LoggerFactory.CreateLogger <SmartSqlMapper>();
            _dataReaderDeserializer = DeserializerFactory.Create();
            NestedObjectConvertFactory convertFactory = new NestedObjectConvertFactory();

            _nestedObjectConverter = new NestedObjectConverter(convertFactory);
        }
Exemplo n.º 5
0
        public void EmptyDeserializeFactory_Create_Throws()
        {
            var factory = new DeserializerFactory();

            Assert.Throws <TypeCannotBeDeserializedException>(() => factory.Create(typeof(int)));
        }