BaseControllerSession MakeBaseControllerSession(TTLITradeWSDEV.clientLoginResponseLoginResp resp)
        {
            BaseControllerSession session = new BaseControllerSession();

            session.fullname         = resp.fullname;
            session.clientID         = resp.clientId;
            session.sessionID        = resp.sessionID;
            session.accountSeq       = resp.accountSeq;
            session.accountType      = resp.accountType;
            session.tradingAccSeq    = resp.tradingAccSeq;
            session.tradingAccStatus = resp.tradingAccStatus;
            session.tradingAccList   = Newtonsoft.Json.JsonConvert.SerializeObject(resp.tradingAccList);
            if (resp.tradingAccList != null && resp.tradingAccList.Length > 0)
            {
                var acc = resp.tradingAccList[0];
                if (acc != null)
                {
                    session.hasTradingAcc              = true;
                    session.ttL_accountSeqField        = acc.accountSeq;
                    session.ttL_accountTypeField       = acc.accountType;
                    session.ttL_defaultSubAccountField = acc.defaultSubAccount;
                    session.ttL_investorTypeIDField    = acc.investorTypeID;
                    session.ttL_tradingAccSeqField     = acc.tradingAccSeq;
                    session.ttL_tradingAccStatusField  = acc.tradingAccStatus;
                }
            }
            return(session);
        }
        public BaseControllerSession getSession(bool excludePostLogin = false)
        {
            BaseControllerSession session = new BaseControllerSession();

            session.isLoggedIn = false;

            if (!excludePostLogin)
            {
                if (Session["TTLClient"] != null)
                {
                    TTLITradeWSDEV.clientLoginResponseLoginResp resp = (TTLITradeWSDEV.clientLoginResponseLoginResp)(Session["TTLClient"]);
                    session            = MakeBaseControllerSession(resp);
                    session.isLoggedIn = true;

                    if (Session["TTLAccount"] != null)
                    {
                        TTLITradeWSDEV.queryAccountDetailsResponseQueryAccountDetailsResp resp2 = (TTLITradeWSDEV.queryAccountDetailsResponseQueryAccountDetailsResp)(Session["TTLAccount"]);
                        session.email = resp2.email;
                    }

                    if (Session["jsessionID"] != null)
                    {
                        string jsessionID = (string)Session["jsessionID"];
                        session.jsessionID = jsessionID;
                    }
                }
            }

            if (excludePostLogin || !session.isLoggedIn)
            {
                Session["isKeptAlive"] = false;
            }

            session.fontSize = SessionLogin.getFontSizeNormal();
            if (Session["fontSize"] != null)
            {
                session.fontSize = (int)Session["fontSize"];
            }

            if (Session["isKeptAlive"] != null)
            {
                session.isKeptAlive = (bool)Session["isKeptAlive"];
            }
            else
            {
                session.isKeptAlive = false;
            }

            return(session);
        }
        public async Task <QPIAPIResponse> loginQPI(string username, string password, TTLITradeWSDEV.clientLoginResponseLoginResp resp)
        {
            /* QPI */

            HttpClient client = new HttpClient();

            string domain  = "GEMINIS";
            string uid     = username;
            string ts      = DateTime.Now.ToString("yyyyMMddHHmmss");
            string env_key = "UAT";

            var enqstr = "";

            enqstr += "domain=" + domain;
            enqstr += "&uid=" + uid;
            enqstr += "&password="******"d6sd$#sf";
            enqstr += "&ts=" + ts;
            enqstr += "&env_key=" + env_key;

            System.Security.Cryptography.SHA256Managed crypt = new System.Security.Cryptography.SHA256Managed();
            System.Text.StringBuilder hash = new System.Text.StringBuilder();
            byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(enqstr), 0, Encoding.UTF8.GetByteCount(enqstr));
            foreach (byte theByte in crypto)
            {
                hash.Append(theByte.ToString("x2"));
            }
            string hashstr = hash.ToString();



            var query = HttpUtility.ParseQueryString(string.Empty);

            query["domain"] = domain;
            query["uid"]    = uid;
            query["ts"]     = ts;
            query["token"]  = hashstr;
            string queryString = query.ToString();

            client.BaseAddress = new Uri("http://uat.quotepower.com/web/geminis/login.jsp");

            // List data response.
            HttpResponseMessage response = client.GetAsync("?" + queryString).Result;  // Blocking call!

            if (response.IsSuccessStatusCode)
            {
                string json = await response.Content.ReadAsStringAsync();

                var qpiapiresponse = JsonConvert.DeserializeObject <QPIAPIResponse>(json);

                return(qpiapiresponse);

                // Parse the response body. Blocking!

                /*
                 * var dataObjects = response.Content.ReadAsAsync<IEnumerable<DataObject>>().Result;
                 * foreach (var d in dataObjects)
                 * {
                 *  Console.WriteLine("{0}", d.Name);
                 * }
                 */
            }
            return(null);
        }
 public void setSession(TTLITradeWSDEV.clientLoginResponseLoginResp resp)
 {
     Session["TTLClient"] = resp;
 }