Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Ensure config file is setup
            if (!File.Exists(Server.MapPath(ConfigFile)))
            {
                throw new Exception("Config file not found");
            }

            var    serializer = new JavaScriptSerializer();
            string jsonText   = System.IO.File.ReadAllText(Server.MapPath(ConfigFile));

            Config = serializer.Deserialize <Dictionary <string, dynamic> >(jsonText);

            if (Config["username"] == "your_api_username")
            {
                throw new Exception("Please configure your username, secret and site_id");
            }

            ObjHd4 = new Hd4(Request, ConfigFile);

            // View information for a specific handset
            Response.Write("<h1>Nokia N95 Properties</h1><p>");
            if (ObjHd4.DeviceView("Nokia", "N95"))
            {
                Response.Write(ObjHd4.GetRawReply());
            }
            else
            {
                Response.Write(ObjHd4.GetError());
            }
            Response.Write("</p>");
        }
        protected void Page_Load(dynamic sender, EventArgs e)
        {
            var fileName = "/benchmarkData.txt";

            try
            {
                if (File.Exists(Server.MapPath(fileName)))
                {
                    using (var sr = new StreamReader(Server.MapPath(fileName)))
                    {
                        string line;

                        while ((line = sr.ReadLine()) != null)
                        {
                            var item        = line.Trim().Split(new[] { "|" }, StringSplitOptions.None);
                            var requestBody = new Dictionary <string, dynamic>();
                            requestBody["user-agent"] = item[0];
                            if (item.Length > 1)
                            {
                                requestBody["x-wap-profile"] = item[1];
                            }
                            else
                            {
                                requestBody["x-wap-profile"] = string.Empty;
                            }
                            _headers.Add(requestBody);
                        }
                    }
                }
                else
                {
                    Response.Write("File not exist.");
                }
            }
            catch (Exception ex)
            {
                Response.Write("File error: " + ex.Message);
            }
            var objHd = new Hd4(Request);

            FlyThrough(objHd);
            lblTotDetect.Text    = TotalCount.ToString();
            lblTimeElapsed.Text  = (TotalMilliSec / 1000).ToString(CultureInfo.InvariantCulture) + " sec.";
            lblDetectPerSec.Text = ((Convert.ToDouble(TotalCount) * 1000) / TotalMilliSec).ToString(CultureInfo.InvariantCulture);
        }
        public void FlyThrough(Hd4 objHd)
        {
            var deviceModelList = new List <DeviceModel>();

            TotalCount = 1;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Reset();
            stopwatch.Start();
            foreach (var header in _headers)
            {
                var result = objHd.DeviceDetect(header);
                TotalCount++;
            }

            stopwatch.Stop();
            TotalMilliSec = stopwatch.ElapsedMilliseconds;

            grdDeviceModel.DataSource = deviceModelList;
            grdDeviceModel.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Ensure config file is setup
            if (!File.Exists(Server.MapPath(ConfigFile)))
            {
                throw new Exception("Config file not found");
            }

            var    serializer = new JavaScriptSerializer();
            string jsonText   = System.IO.File.ReadAllText(Server.MapPath(ConfigFile));

            Config = serializer.Deserialize <Dictionary <string, dynamic> >(jsonText);

            if (Config["username"] == "your_api_username")
            {
                throw new Exception("Please configure your username, secret and site_id");
            }

            ObjHd4 = new Hd4(Request, ConfigFile);

            // This manually sets the headers that a Nokia N95 would set.
            // Other agents you also might like to try
            // Mozilla/5.0 (BlackBerry; U; BlackBerry 9300; es) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.534 Mobile Safari/534.8+
            // Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN95-3/20.2.011 Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413
            // Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5
            Response.Write("<h1>Simple Detection - Setting Headers for an N95</h1><p>");
            //   objHD4.setDetectVar("user-agent","Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN95-3/20.2.011 Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413");
//objHD4.setDetectVar("x-wap-profile","http://nds1.nds.nokia.com/uaprof/NN95-1r100.xml");
            //if (objHD4.siteDetect())
            //{
            //    Response.Write(objHD4.getRawReply());
            //}
            //else
            //{
            //    Response.Write(objHD4.getError());
            //}
            Response.Write("</p>");
        }