Exemplo n.º 1
0
        private Type TransferType(Type typeIn)
        {
            var def     = _sutAlice.BuildDefinition(typeIn);
            var typeOut = _sutBob.BuildType(def);

            return(typeOut);
        }
Exemplo n.º 2
0
        public void Connect <TIn, TOut>(Expression expression, IObserver <TOut> observer)
        {
            var seralizedExpression = SerializationHelper.SerializeLinqExpression <TIn, TOut>(
                expression,
                _options.TypesToTransfer.ToArray());

            Channel channel = new Channel(_options.ConnectionString, ChannelCredentials.Insecure);
            var     client  = new StreamService.StreamServiceClient(channel.CreateCallInvoker());

            var definer         = new PortableTypeDefiner();
            var classDefinition = definer.BuildDefinition(typeof(TIn));
            var enums           = definer.BuildDefinitions(_options.TypesToTransfer.Where(t => t.IsEnum).ToArray());
            var types           = definer.BuildDefinitions(_options.TypesToTransfer.Where(t => !t.IsEnum).ToArray());

            _types = enums
                     .Concat(new[] { classDefinition })
                     .Concat(types)
                     .GroupBy(t => new { t.AssemblyName, t.ClassName })
                     .Select(g => g.First())
                     .ToArray();

            var queryEnvelope = new QueryEnvelope
            {
                Payload         = seralizedExpression,
                SourceTypeName  = classDefinition.ClassName,
                RegisteredTypes = JsonConvert.SerializeObject(_types),
                StreamPattern   = JsonConvert.SerializeObject(_streamPatterns)
            };

            _streamingCall = client.QueryStreamAsync(queryEnvelope);

            // TODO: No need for one thread per subscription - this can be made more efficient
            Task.Run(GetObserveTask(observer), _cancelSource.Token)
            .ContinueWith(_ => _cancelSource.Dispose());
        }