TryLoadOrCreateNew() public static method

public static TryLoadOrCreateNew ( ISessionStore store, string sessionUserId ) : Session
store ISessionStore
sessionUserId string
return Session
Example #1
0
 public TelegramClient(ISessionStore store, string sessionUserId, int apiId, string apiHash)
 {
     _apiId     = apiId;
     _apiHash   = apiHash;
     _session   = Session.TryLoadOrCreateNew(store, sessionUserId);
     _transport = new TcpTransport(_session.ServerAddress, _session.Port);
 }
Example #2
0
        public TelegramClient(ISessionStore store, string sessionUserId)
        {
            if (_apiId == 0)
            {
                throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");
            }

            if (string.IsNullOrEmpty(_apiHash))
            {
                throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");
            }

            _session   = Session.TryLoadOrCreateNew(store, sessionUserId);
            _transport = new TcpTransport(_session.ServerAddress, _session.Port);
        }
Example #3
0
        public TelegramClient(ISessionStore store, string sessionUserId, int apiId, string apiHash, string dcAddress, int dcPort)
        {
            _apiHash = apiHash;
            _apiId   = apiId;
            if (_apiId == 0)
            {
                throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");
            }

            if (string.IsNullOrEmpty(_apiHash))
            {
                throw new InvalidOperationException("Your API_ID is invalid. Do a configuration first https://github.com/sochix/TLSharp#quick-configuration");
            }

            if (string.IsNullOrEmpty(dcAddress))
            {
                _session = Session.TryLoadOrCreateNew(store, sessionUserId);
            }
            else
            {
                _session = Session.TryLoadOrCreateNew(store, sessionUserId, dcAddress, dcPort);
            }
        }
Example #4
-1
        public TelegramClient(int apiId, string apiHash,
                              ISessionStore store = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null)
        {
            if (apiId == default(int))
            {
                throw new MissingApiConfigurationException("API_ID");
            }
            if (string.IsNullOrEmpty(apiHash))
            {
                throw new MissingApiConfigurationException("API_HASH");
            }

            if (store == null)
            {
                store = new FileSessionStore();
            }

            TLContext.Init();
            _apiHash = apiHash;
            _apiId   = apiId;
            _handler = handler;

            _session   = Session.TryLoadOrCreateNew(store, sessionUserId);
            _transport = new TcpTransport(_session.ServerAddress, _session.Port, _handler);
        }
        /// <summary>
        /// Creates a new TelegramClient
        /// </summary>
        /// <param name="apiId">The API ID provided by Telegram. Get one at https://my.telegram.org </param>
        /// <param name="apiHash">The API Hash provided by Telegram. Get one at https://my.telegram.org </param>
        /// <param name="store">An ISessionStore object that will handle the session</param>
        /// <param name="sessionUserId">The name of the session that tracks login info about this TelegramClient connection</param>
        /// <param name="handler">A delegate to invoke when a connection is needed and that will return a TcpClient that will be used to connect</param>
        /// <param name="dcIpVersion">Indicates the preferred IpAddress version to use to connect to a Telegram server</param>
        public TelegramClient(int apiId, string apiHash,
                              ISessionStore store             = null, string sessionUserId = "session", TcpClientConnectionHandler handler = null,
                              DataCenterIPVersion dcIpVersion = DataCenterIPVersion.Default)
        {
            if (apiId == default(int))
            {
                throw new MissingApiConfigurationException("API_ID");
            }
            if (string.IsNullOrEmpty(apiHash))
            {
                throw new MissingApiConfigurationException("API_HASH");
            }

            if (store == null)
            {
                store = new FileSessionStore();
            }

            this.apiHash     = apiHash;
            this.apiId       = apiId;
            this.handler     = handler;
            this.dcIpVersion = dcIpVersion;

            session   = Session.TryLoadOrCreateNew(store, sessionUserId);
            transport = new TcpTransport(session.DataCenter.Address, session.DataCenter.Port, this.handler);
        }
Example #6
-1
        public TelegramClient()
        {
            var store = new FileSessionStore();

            _transport = new TcpTransport();
            _session   = Session.TryLoadOrCreateNew(store, sessionUserId);
        }
Example #7
-1
        public TelegramClient(int apiId, string apiHash, ISessionStore store = null, string sessionUserId = "session", string AppVersion = "1.0", string DeviceModel = "PC", string LangCode = "en", string SystemVersion = "Windows", TcpClientConnectionHandler handler = null)
        {
            try
            {
                if (apiId == default(int))
                {
                    throw new MissingApiConfigurationException("API_ID");
                }
                if (string.IsNullOrEmpty(apiHash))
                {
                    throw new MissingApiConfigurationException("API_HASH");
                }

                if (store == null)
                {
                    store = new FileSessionStore();
                }

                TLContext.Init();
                _apiHash       = apiHash;
                _apiId         = apiId;
                _appVersion    = AppVersion;
                _DeviceModel   = DeviceModel;
                _LangCode      = LangCode;
                _SystemVersion = SystemVersion;
                _handler       = handler;
                _session       = Session.TryLoadOrCreateNew(store, sessionUserId);
                _transport     = new TcpTransport(_session.ServerAddress, _session.Port, _handler);
            }
            catch
            {
                throw new Exception("Not connected to the internet");
            }
        }