Example #1
-1
		public void Save(Session session)
		{
			using (var stream = new FileStream($"{session.SessionUserId}.dat", FileMode.OpenOrCreate))
			{
				var result = session.ToBytes();
				stream.Write(result, 0, result.Length);
			}
		}
Example #2
-1
        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");

			_transport = new TcpTransport();
			_session = Session.TryLoadOrCreateNew(store, sessionUserId);
		}
Example #3
-1
		public void Save(Session session)
		{
			
		}
Example #4
-1
		public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
		{
			Session session;

			try
			{
				session = store.Load(sessionUserId);
			}
			catch
			{
				session = new Session(store) { Id = GenerateRandomUlong(), SessionUserId = sessionUserId };
			}

			return session;
		}
Example #5
-1
		public TelegramClient(ISessionStore store, string sessionUserId)
		{
			_transport = new TcpTransport();
			_session = Session.TryLoadOrCreateNew(store, sessionUserId);
		}
Example #6
-1
		public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
		{
			Session session;

			try
			{
				session = store.Load(sessionUserId);
			}
			catch
			{
				session = new Session(store)
				{
					Id = GenerateRandomUlong(),
					SessionUserId = sessionUserId,
					ServerAddress = defaultConnectionAddress,
					Port = defaultConnectionPort
				};
			}

			return session;
		}