Exemple #1
0
        public async Task <MTProtoGateway> GetFileGateway(ulong salt)
        {
            await _lock.WaitAsync();

//            fileGateway = new MTProtoGateway(this, fileSession);
            try {
                if (fileGateway != null)
                {
                    return(fileGateway);
                }

                if (fileSession == null)
                {
                    fileSession = new TelegramFileSession(Helpers.GenerateRandomUlong(), 0);
                }

                fileGateway = new MTProtoGateway(this, fileSession, false, salt);
                await fileGateway.ConnectAsync();

                return(fileGateway);
            }
            finally {
                _lock.Release();
            }
        }
Exemple #2
0
        // save timer end

        public async Task ConnectAsync()
        {
            try {
                if (gateway == null)
                {
                    logger.info("creating new mtproto gateway...");
                    gateway = new MTProtoGateway(MainDc, this, true, cachedSalt);
                    gateway.UpdatesEvent       += updates.ProcessUpdates;
                    gateway.BrokenSessionEvent += GatewayOnBrokenSessionEvent;

                    while (true)
                    {
                        try {
                            await gateway.ConnectAsync();

                            break;
                        } catch (MTProtoBrokenSessionException e) {
                            logger.info("broken session exception");
                        }
                    }
                    api = new TLApi(gateway);
                    logger.info("connection established, notifying");
                    //establishedTask.SetResult(null);

                    updates.RequestDifference();

                    gateway.ReconnectEvent += () => {
                        GoToOnline();
                        updates.RequestDifference();
                    };

                    GoToOnline();

                    if (!saveSessionTimerInitialized)
                    {
                        SaveSessionTimer();
                        saveSessionTimerInitialized = true;
                    }
                }
            }
            catch (Exception ex) {
                logger.error("session exception: {0}", ex);
                throw ex;
            }
        }