Esempio n. 1
0
        public TelegramClient(string phoneNumber, ITelegramPersist persist)
        {
            _phoneNumber = phoneNumber;

            try
            {
                var schema = new ApiSchema();

                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(Shemas.Schema)))
                    schema.Load(ms);
                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(Shemas.SchemaMtProto)))
                    schema.Load(ms);
                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(Shemas.SchemaEndToEnd)))
                    schema.Load(ms);

                _provider = new Provider(schema, Address, Port, phoneNumber.Replace("+", ""), persist);
                _provider.Updates += OnUpdate;
                _provider.Difference += OnDifference;
            }
            catch (TlException)
            {
                throw;
            }
            catch (Exception e)
            {
                e = e is AggregateException ? e.InnerException : e;
                throw new TlException(e);
            }
        }
Esempio n. 2
0
        public Provider(ApiSchema schema, string address, int port, string phone, ITelegramPersist persist)
        {
            _address = address;
            _port = port;
            _phone = phone;
            _persist = persist;
            _formatter = new Formatter();
            Combinator.Setup(schema, _formatter);

            _settings = LoadSettings();

            _connection = new TcpConnection(_address, _port, _formatter);
        }