Exemple #1
0
 public static Session TryLoadOrCreateNew(string serverAddress, int port, ISessionStore store = null)
 {
     return(store?.Load() ?? new Session(store)
     {
         id = GenerateRandomUlong(),
         serverAddress = serverAddress,
         port = port
     });
 }
        private static async Task <ISession> TryLoadOrCreateNew(ISessionStore sessionStore, IFactorySettings factorySettings)
        {
            var session = await sessionStore.Load().ConfigureAwait(false) ?? Session.Create();

            session.ServerAddress = factorySettings.ServerAddress;
            session.Port          = factorySettings.ServerPort;

            return(session);
        }
 public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
 {
     return(store.Load(sessionUserId) ?? new Session(store)
     {
         Id = GenerateRandomUlong(),
         SessionUserId = sessionUserId,
         ServerAddress = defaultConnectionAddress,
         Port = defaultConnectionPort
     });
 }
Exemple #4
0
 public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId, string serverAddress = "", int?serverPort = null)
 {
     return(store.Load(sessionUserId) ?? new Session(store)
     {
         Id = GenerateRandomUlong(),
         SessionUserId = sessionUserId,
         ServerAddress = string.IsNullOrEmpty(serverAddress) ? defaultConnectionAddress : serverAddress,
         Port = serverPort ?? defaultConnectionPort
     });
 }
Exemple #5
0
        public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
        {
            var defaultDataCenter = new DataCenter(defaultConnectionAddress, defaultConnectionPort);

            return(store.Load(sessionUserId) ?? new Session(store)
            {
                Id = GenerateRandomUlong(),
                SessionUserId = sessionUserId,
                DataCenter = defaultDataCenter,
            });
        }
Exemple #6
0
        internal static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
        {
            var session = store.Load(sessionUserId);

            if (null == session)
            {
                var defaultDataCenter = new DataCenter(null);
                session = new Session {
                    Id            = GenerateRandomUlong(),
                    SessionUserId = sessionUserId,
                    DataCenter    = defaultDataCenter,
                };
            }
            return(session);
        }
Exemple #7
0
        public static async Task <TelegramClient> Connect(
            int apiId,
            ISessionStore store = null,
            IPEndPoint endpoint = null,
            TgCallMiddlewareChain callMiddlewareChain             = null,
            TcpClientConnectionHandler tcpClientConnectionHandler = null
            )
        {
            store = store ?? new FileSessionStore("session.dat");
            var ep          = endpoint ?? DefaultEndpoint;
            var connectInfo = (await store.Load().ConfigureAwait(false))
                              .Map(SomeExt.ToSome).Map(ConnectInfo.FromSession)
                              .IfNone(ConnectInfo.FromInfo(apiId, ep));

            return(await Connect(connectInfo, store, callMiddlewareChain, tcpClientConnectionHandler));
        }
        private static async Task <IClientSession> TryLoadOrCreateNew(ISessionStore sessionStore, IFactorySettings factorySettings)
        {
            var newSession = new ClientSession();

            var sessionData = await sessionStore.Load();

            if (sessionData != null)
            {
                newSession.FromBytes(sessionData);
            }
            else
            {
                newSession.ServerAddress = factorySettings.ServerAddress;
                newSession.Port          = factorySettings.ServerPort;
            }

            return(newSession);
        }
Exemple #9
0
        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);
        }
        /// <summary>
        /// Loads a session for all requests that got the session cookie.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="HttpServer.RequestEventArgs"/> instance containing the event data.</param>
        private void OnRequest(object sender, RequestEventArgs e)
        {
            _currentSession = null;
            RequestCookie cookie = e.Request.Cookies[_cookieName];

            if (cookie == null)
            {
                return;
            }

            string id = cookie.Value;

            _currentSession = (TSession)_store.Load(id);
            SessionLoaded(this, EventArgs.Empty);
            if (_currentSession != null)
            {
                _store.Touch(_currentSession.SessionId);
            }
        }
        private static ISession TryLoadOrCreateNew(ISessionStore store, string sessionUserId, string serverAddress, int serverPort)
        {
            ulong GenerateSessionId()
            {
                var random = new Random();
                var rand   = ((ulong)random.Next() << 32) | (ulong)random.Next();

                return(rand);
            }

            var session = store.Load(sessionUserId) ?? new Session
            {
                Id            = GenerateSessionId(),
                SessionUserId = sessionUserId
            };

            session.ServerAddress = serverAddress;
            session.Port          = serverPort;

            return(session);
        }
Exemple #12
0
        public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId, string connectionAddress = defaultConnectionAddress, int connectionPort = defaultConnectionPort)
        {
            Session session;

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

            return(session);
        }
Exemple #13
0
 public static Session TryLoadOrCreateNew(ISessionStore store, string sessionUserId)
 {
     return store.Load(sessionUserId) ?? new Session(store)
     {
         Id = GenerateRandomUlong(),
         SessionUserId = sessionUserId,
         ServerAddress = defaultConnectionAddress,
         Port = defaultConnectionPort
     };
 }
Exemple #14
0
 public static Session GetSession(ISessionStore store, string sessionUserId, Session provided)
 {
     return(store.Load(sessionUserId) ?? provided ?? new Session(store, sessionUserId));
 }
Exemple #15
-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;
		}