protected void Page_Load(object sender, EventArgs e) { try { logDataBase = DataContextConfiguration.ContextCollection["Baase"]; } catch (Exception) { } string ua = Request.QueryString["ua"]; TerminalModel tm = new TerminalModel(); if (ua != null && ua.Length > 0) { UserAgentParser uap = new UserAgentParser(); uap.OnProcessUnknowUa += new ProcessUnknowUaEventHandler(uap_OnProcessUnknowUa); tm = uap.ParseUserAgent(ua); //Response.Write("tm.Browser=" + tm.Browser); //Response.Write("tm.Brand=" + tm.Brand); //Response.Write("tm.Model=" + tm.Model); //Response.Write("tm.Platform=" + tm.Platform); } else { } JavaScriptSerializer ser = new JavaScriptSerializer(); String jsonStr = ser.Serialize(tm); Response.Write(jsonStr); }
public void RecognizesCustomClients(string userAgent, string expectedClient, string expectedMajor, string expectedMinor, string expectedPatch) { var parsed = _parser.ParseUserAgent(userAgent); _testOutputHelper.WriteLine(parsed.ToString()); Assert.Equal(expectedClient, parsed.Family); Assert.Equal(expectedMajor, parsed.Major); Assert.Equal(expectedMinor, parsed.Minor); Assert.Equal(expectedPatch, parsed.Patch); }
public TerminalModel ParseUserAgent(string useragent) { if (useragent.Length <= 0) { return(new TerminalModel()); } else { TerminalModel tm = uap.ParseUserAgent(useragent.Trim()); return(tm); } }
static void Main(string[] args) { // Dalvlk/l.6.0 (Llnux; U; Androld 4.2.l; M353 Bulld/JOP40D) // Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); UserAgentParser uap = new UserAgentParser(); uap.OnProcessUnknowUa += new ProcessUnknowUaEventHandler(uap_OnProcessUnknowUa); TerminalModel tm = uap.ParseUserAgent("w2(mt6589/4); 4.3.1; s530w2p05v05; zh-cn"); Console.WriteLine("tm.Browser=" + tm.Browser); Console.WriteLine("tm.Brand=" + tm.Brand); Console.WriteLine("tm.Model=" + tm.Model); Console.WriteLine("tm.Platform=" + tm.Platform); Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); uap.Clear(); Console.ReadKey(); // string strReadFilePath = @"aa.txt"; // StreamReader srReadFile = new StreamReader(strReadFilePath); // while (!srReadFile.EndOfStream) // { // string strReadLine = srReadFile.ReadLine(); //读取每行数据 // if (strReadLine != null) // { // TerminalModel tm = uap.ParseUserAgent(strReadLine); // if (tm.Platform != null && tm.Platform.Length > 1) { //// Console.WriteLine(strReadLine); //屏幕打印每行数据 //// Console.WriteLine ("tm.Browser=" + tm.Browser); //// Console.WriteLine ("tm.Brand=" + tm.Brand); //// Console.WriteLine ("tm.Model=" + tm.Model); //// Console.WriteLine ("tm.Platform=" + tm.Platform); // } else { //// Console.WriteLine(strReadLine); //屏幕打印每行数据 // } // } // } // srReadFile.Close(); //string strReadFilePath = @"../../uaa.txt"; // StreamReader srReadFile = new StreamReader(strReadFilePath); //float total = 0; //float haveNum = 0; //float ucUser = 0; //int ucnum = 0; //int allnum = 0; //while (!srReadFile.EndOfStream) //{ // string strReadLine = srReadFile.ReadLine(); //读取每行数据 // if (strReadLine != null) // { // total++; // Stopwatch sw = new Stopwatch(); // sw.Start(); // TerminalModel tm = uap.ParseUserAgent(strReadLine); // sw.Stop(); // if (tm.Platform != null && tm.Platform.Length > 1) // { // haveNum++; // Console.WriteLine(strReadLine); //屏幕打印每行数据 // string[] sArray = strReadLine.Split('\t'); // if (sArray[1].Length > 0) // { // int result = int.Parse(sArray[1].ToString()); // Console.WriteLine("ALL+" + result); // allnum += result; // } // if (tm.Browser.Equals("UCBrowser")) // { // ucUser++; // Console.WriteLine(strReadLine); //屏幕打印每行数据 // sArray = strReadLine.Split('\t'); // if (sArray[1].Length > 0) // { // int result = int.Parse(sArray[1].ToString()); // Console.WriteLine("UC+" + result); // ucnum += result; // } // } // Console.WriteLine (strReadLine); //屏幕打印每行数据 // Console.WriteLine ("tm.Browser=" + tm.Browser); // Console.WriteLine ("tm.Brand=" + tm.Brand); // Console.WriteLine ("tm.Model=" + tm.Model); // Console.WriteLine ("tm.Platform=" + tm.Platform); // Console.WriteLine ("^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); // Console.WriteLine("++++>" + sw.ElapsedMilliseconds); // } // else // { // Console.WriteLine (strReadLine); //屏幕打印每行数据 // Console.WriteLine("---->" + sw.ElapsedMilliseconds); // } // } //} //关闭读取流文件 //srReadFile.Close(); //Console.WriteLine("total:" + total); //Console.WriteLine("haveNum:" + haveNum); //Console.WriteLine("PER:" + haveNum / total * 100 + "%"); //Console.WriteLine("ucUser:"******"UC:" + ucnum); //Console.WriteLine("总:" + allnum); }