Exemplo n.º 1
0
        private bool checkSessionAlive(Session session)
        {
            IRestResponse response = RequestUtil.NewInstance(Globals.TRADINGPOST_HOST, string.Empty)
                .SetCookie("s", session.Key)
                .Execute();

            if ((int)response.StatusCode < 400)
                return true; // good
            else if ((int)response.StatusCode == 503)
                return false; // expired
            else if ((int)response.StatusCode == 401)
                return false; // failed
            else
                throw new TradingPostOfflineException();
        }
Exemplo n.º 2
0
        private Session getNewSession()
        {
            if (string.IsNullOrWhiteSpace(Email) || string.IsNullOrWhiteSpace(Password))
                throw new CredentialsNotFoundException();

            IRestResponse response = RequestUtil.NewInstance(Globals.AUTH_HOST, Globals.AUTH_PATH_LOGIN)
                .SetMethod(Method.POST)
                .SetParameter("email", Email)
                .SetParameter("password", Password)
                .SetFollowRedirects(false)
                .Execute();

            string key = null;

            foreach (Parameter header in response.Headers)
            {
                if (header.Name == "Set-Cookie")
                {
                    Match m = m_SESSION_COOKIE_REGEX.Match((string)header.Value);
                    if (m.Success)
                    {
                        key = m.Groups[1].Value;
                        break;
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(key))
            {
                Session session = new Session(key);

                saveSession(session);

                return session;
            }
            else
                throw new LoginFailedException();
        }
Exemplo n.º 3
0
 private void saveSession(Session session)
 {
     TextWriter tw = File.AppendText(m_CSV_SESSION_FILE);
     tw.WriteLine(session.Key + "," + session.IsGameSession.ToString() + "," +  session.Created.ToBinary());
     tw.Close();
 }