Example #1
0
        // insert into tb_user_info
        private void InsertUserInfo(SqlConnection sc, UserInfo ui)
        {
            try
            {
                if (sc != null)
                {
                    // first query, if exist, then update the activate_time
                    string strQuery = String.Format("select id from tb_user_info where token = '{0}' and ip = '{1}'", ui.fingerprint.token, ui.fingerprint.ip);
                    string strSQL = "";
                    using (DataSet dt = SqlHelper.ExecuteDataset(sc, CommandType.Text, strQuery))
                    {
                        if (dt == null || dt.Tables.Count == 0 || (dt.Tables.Count == 1 && dt.Tables[0].Rows.Count == 0))
                            // insert
                            strSQL = String.Format("insert into tb_user_info (token, ip, agent, language, color_depth, screen_resolution, time_zone, platform, register_time, activate_time, device, os, country, province, city, province_code) values ('{0}', '{1}', '{2}', '{3}', {4}, '{5}', {6}, '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}')",
                                ui.fingerprint.token, ui.fingerprint.ip, ui.fingerprint.agent, ui.fingerprint.language, ui.fingerprint.color_depth, ui.fingerprint.screen_resolution, ui.fingerprint.time_zone, ui.fingerprint.platform, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ui.fingerprint.device, ui.fingerprint.os, ui.fingerprint.country, ui.fingerprint.province, ui.fingerprint.city, ui.fingerprint.province_code);
                        else
                            // update
                            strSQL = String.Format("update tb_user_info set activate_time = '{0}' where token = '{1}' and ip = '{2}'", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ui.fingerprint.token, ui.fingerprint.ip);

                        try
                        {
                            SqlHelper.ExecuteNonQuery(sc, CommandType.Text, strSQL);
                        }
                        catch (Exception e)
                        {
                            AdssLogger.WriteLog("Exception in InsertUserInfo(): " + e.Message);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                AdssLogger.WriteLog("Exception in InsertUserInfo(): " + e.Message);
            }
        }
Example #2
0
        //private string m_strIp = "";
        public void ProcessRequest(HttpContext context)
        {
            string strIP = GetVisitorIPAddress();
            //m_strIp = "99.237.172.93";
            GeoLocation gl = GetGeoLocation(strIP);
            //m_strIp = GetVisitorIPAddress();
            if (context.Request.InputStream.Length > 0)
            {
                //m_strIp = GetVisitorIPAddress();
                //uploadObj.user_token = result;
                ////uploadObj.user_agent = fp.userAgentKey();
                //uploadObj.user_agent = bi.name + '-' + bi.version;
                //uploadObj.user_language = fp.languageKey();
                //uploadObj.user_color_depth = fp.colorDepthKey();
                //uploadObj.user_screen_resolution = fp.screenResolutionKey();
                //uploadObj.user_time_zone = fp.timezoneOffsetKey();
                //uploadObj.user_platform = fp.platformKey().toString().replace("navigatorPlatform: ", "");
                StreamReader oSR = new StreamReader(context.Request.InputStream);
                string str = oSR.ReadToEnd();
                oSR.Close();

                UserFingerPrint uf = Deserialize(str);
                UserInfo ui = new UserInfo();
                ui.fingerprint = uf;

                ui.fingerprint.country = string.IsNullOrEmpty(gl.country_name) ? "all" : gl.country_name;
                ui.fingerprint.province = string.IsNullOrEmpty(gl.region_name) ? "all" : gl.region_name;
                ui.fingerprint.city = string.IsNullOrEmpty(gl.city) ? "all" : gl.city;
                ui.fingerprint.province_code = string.IsNullOrEmpty(gl.region_code) ? "all" : gl.region_code;
                if (ui != null && !string.IsNullOrEmpty(ui.fingerprint.token))
                {
                    ui.fingerprint.ip = strIP;

                    using (TransactionScope ts = new TransactionScope())
                    {
                        string strConn = ConfigurationManager.ConnectionStrings["sqlserver"].ConnectionString;
                        try
                        {
                            using (SqlConnection sc = new SqlConnection(strConn))
                            {
                                InsertUserInfo(sc, ui);
                                ts.Complete();
                            }
                        }
                        catch (Exception ex)
                        {
                            //System.Diagnostics.Trace.WriteLine(ex.Message);
                            AdssLogger.WriteLog("Exception in sql tracsaction: " + ex.Message);
                        }
                    }
                }
            }
            context.Response.AppendHeader("Access-Control-Allow-Origin", "*");
            context.Response.ContentType = "text/plain";
            context.Response.Write(strIP);
        }