예제 #1
0
파일: WmCoreOp.cs 프로젝트: tmbx/kwm-ng
        /// <summary>
        /// Submit the Freemium web query.
        /// </summary>
        private void SubmitHttpQuery()
        {
            String ws_url = "https://" + KpsAddr + "/freemium/registration";
            String email = HttpUtility.UrlEncode(KpsUserName);
            String pwd = HttpUtility.UrlEncode(KpsUserPwd);
            String post_params = "email=" + email + "&pwd=" + pwd;

            m_httpQuery = new HttpQuery(new Uri(ws_url + "?" + post_params));
            m_httpQuery.UseCache = false;
            m_httpQuery.OnHttpQueryEvent += HandleHttpQueryResult;
            m_httpQuery.StartQuery();
        }
예제 #2
0
파일: WmCoreOp.cs 프로젝트: tmbx/kwm-ng
 /// <summary>
 /// Cancel the HTTP query specified and set its reference to null,
 /// if needed.
 /// </summary>
 protected void ClearHttpQuery(ref HttpQuery query)
 {
     if (query != null)
     {
         query.Cancel();
         query = null;
     }
 }
예제 #3
0
파일: WmCoreOp.cs 프로젝트: tmbx/kwm-ng
        /// <summary>
        /// Called when the HTTP query results are available.
        /// </summary>
        private void HandleHttpQueryResult(Object sender, HttpQueryEventArgs args)
        {
            if (m_httpQuery == null) return;
            HttpQuery query = m_httpQuery;
            m_httpQuery = null;

            try
            {
                if (args.Type == HttpQueryEventType.Done)
                {
                    if (query.Result == "confirm") m_httpResCode = EAnpRegisterKpsCode.EmailConfirm;

                    // This shouldn't fail through here, but it did.
                    else if (query.Result != "ok") throw new Exception(query.Result);
                }

                else if (args.Type == HttpQueryEventType.DnsError) throw new Exception(args.Ex.Message);

                else if (args.Type == HttpQueryEventType.HttpError)
                {
                    // When the web services responds with a 403, the response
                    // body is not an error string to display to the user. It
                    // is a protocol response the can be safely used here for
                    // exact match, to indicate the reason of failure of the
                    // registration process.
                    if (query.StatusCode != HttpStatusCode.Forbidden) throw new Exception(args.Ex.Message);

                    String r = query.Result;
                    if (r == "registration_disabled") m_httpResCode = EAnpRegisterKpsCode.NoAutoRegister;
                    else if (r == "user_login_taken") m_httpResCode = EAnpRegisterKpsCode.LoginTaken;
                    else if (r == "user_registration_locked") m_httpResCode = EAnpRegisterKpsCode.NoLicense;
                    else throw new Exception("protocol error: " + r);
                }
            }

            catch (Exception ex)
            {
                m_httpResCode = EAnpRegisterKpsCode.Failure;
                m_httpEx = ex;
            }

            OnQueryCompletion();
        }