public MTProtoConnection(TransportConfig transportConfig, [NotNull] ITransportFactory transportFactory, [NotNull] TLRig tlRig, [NotNull] IMessageIdGenerator messageIdGenerator, [NotNull] IHashServices hashServices, [NotNull] IEncryptionServices encryptionServices) { Argument.IsNotNull(() => transportFactory); Argument.IsNotNull(() => tlRig); Argument.IsNotNull(() => messageIdGenerator); Argument.IsNotNull(() => hashServices); Argument.IsNotNull(() => encryptionServices); _transportFactory = transportFactory; _tlRig = tlRig; _messageIdGenerator = messageIdGenerator; _hashServices = hashServices; _encryptionServices = encryptionServices; DefaultRpcTimeout = Defaults.RpcTimeout; DefaultConnectTimeout = Defaults.ConnectTimeout; _tlRig.PrepareSerializersForAllTLObjectsInAssembly(typeof(ITLAsyncMethods).GetAssemblyEx()); _sessionId = GetNextSessionId(); // Init transport. _transport = _transportFactory.CreateTransport(transportConfig); // History of messages in/out. _inMessages.ObserveOn(DefaultScheduler.Instance).Subscribe(_inMessagesHistory); _outMessages.ObserveOn(DefaultScheduler.Instance).Subscribe(_outMessagesHistory); // Connector in/out. _transport.ObserveOn(DefaultScheduler.Instance).Do(bytes => LogMessageInOut(bytes, "IN")).Subscribe(ProcessIncomingMessageBytes); _outMessages.ObserveOn(DefaultScheduler.Instance) .Do(message => LogMessageInOut(message.MessageBytes, "OUT")) .Subscribe(message => _transport.Send(message.MessageBytes)); _inMessages.ObserveOn(DefaultScheduler.Instance).Subscribe(ProcessIncomingMessage); }
public void PrepareSerializersForAllTLObjectsInAssembly(Assembly assembly) { _tlRig.PrepareSerializersForAllTLObjectsInAssembly(assembly); }