Chinaunix首页 | 论坛 | 博客
  • 博客访问: 34083
  • 博文数量: 12
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 184
  • 用 户 组: 普通用户
  • 注册时间: 2014-01-22 11:52
文章分类
文章存档

2014年(12)

我的朋友

分类: C#/.net

2014-03-10 17:39:15

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;


namespace modeltest

{

   ///

   /// test11 的摘要说明

   ///


   public class test11 : IHttpHandler

   {


       public void ProcessRequest(HttpContext context)

       {

           context.Response.ContentType = "text/plain";

           HttpRequest request = context.Request;

           using (DB.Entities db = new DB.Entities())

           {

               try

               {

                   if (request.Params["jishu"] == "1")

                   {

                       string cu = request.Params["curUrl"];

                       string fu = request.Params["fromUrl"];

                       var pi = Convert.ToDateTime(request.Params["pagein"]);

                       string ip = request.UserHostAddress;

                       string id = Guid.NewGuid().ToString("N");

                       string screen_screen = request.QueryString["screen"];

                       string lang_lang = request.QueryString["lang"];

                       string ua = request.UserAgent;

                       string os32 = request.QueryString["os"];

                       int screen =this.getScreen(screen_screen);

                       int lang=this.getLang(lang_lang);

                       int type=this.getType(ua);

                       int os=this.getOs(ua,os32);

                       addSiteTrack(cu, fu, pi, ip, id, screen, lang, type, os);

                       context.Response.Write(id);

                   }

                   else if (request.Params["jishu"] == "2")

                   {

                       string id = request.Params["id"];

                       var st1 = db.SiteTrack.FirstOrDefault(c => c.id == id);

                       st1.pageout = Convert.ToDateTime(request.Params["pageout"]);

                   }


                   db.SaveChanges();

               }

               catch (Exception ex)

               {

                   Console.WriteLine(ex.Message);

               }

           }

       }

       //向siteTrack表赋值

       public void addSiteTrack(string cu,string fu,DateTime pi,string ip,string id,int screen,int lang,int type,int os)

       {

           DB.Entities db = new DB.Entities();

           DB.SiteTrack st = new DB.SiteTrack();

           st.curUrl = cu;

           st.fromUrl = fu;

           st.pagein = pi;

           st.ip = ip;

           st.id = id;

           st.screen = screen;

           st.lang = lang;

           st.type = type;

           st.os = os;

           db.SiteTrack.Add(st);

           db.SaveChanges();

       }

       //向screen表赋值

       public int getScreen(string screen_screen)

       {

           DB.Entities db = new DB.Entities();

           DB.BrowserScreen screen = new DB.BrowserScreen();

           var sc = db.BrowserScreen.FirstOrDefault(c => c.screen == screen_screen);

           if (sc == null)

           {

               screen.screen = screen_screen;

               db.BrowserScreen.Add(screen);

               db.SaveChanges();

               return screen.id;

           }

           else

           {

               return sc.id;

           }

       }

       //向lang表赋值

       public int getLang(string lang_lang)

       {

           DB.Entities db = new DB.Entities();

           DB.BrowserLang lang = new DB.BrowserLang();

           var l = db.BrowserLang.FirstOrDefault(c => c.lang == lang_lang);

           if (l == null)

           {

               switch (lang_lang)

               {

                   case "zh-cn": lang.comment = "简体中文";

                       break;

                   default:

                       break;

               }

               lang.lang = lang_lang;

               db.BrowserLang.Add(lang);

               db.SaveChanges();

               return lang.id;

           }

           else

           {

               return l.id;

           }

       }

       //向type表赋值

       public int getType(string us)

       {

           DB.Entities db = new DB.Entities();

           DB.BrowserType type = new DB.BrowserType();

           string type_type = "";

           if (us.IndexOf("MSIE 9.0") != -1)

           {

               type_type = "IE9";

           }

           else if (us.IndexOf("MSIE 8.0") != -1)

           {

               type_type = "IE8";

           }

           else if (us.IndexOf("MSIE 7.0") != -1)

           {

               type_type = "IE7";

           }

           else if (us.IndexOf("MSIE 6.0") != -1)

           {

               type_type = "IE6";

           }

           else if (us.IndexOf("MSIE 10.0") != -1)

           {

               type_type = "IE10";

           }

           else if (us.IndexOf("IE 11.0") != -1)

           {

               type_type = "IE11";

           }

           else if (us.IndexOf("Chrome") != -1)

           {

               type_type = "chrome";

           }

           else if (us.IndexOf("Firefox") != -1)

           {

               type_type = "Firefox";

           }

           else if (us.IndexOf("Opera") != -1)

           {

               type_type = "Opera";

           }

           else if (us.IndexOf("360SE") != -1)

           {

               type_type = "360";

           }

           var ty = db.BrowserType.FirstOrDefault(c => c.type == type_type);

           if (ty == null)

           {

               switch (type_type)

               {

                   case "IE9": type.comment = "IE9浏览器";

                       break;

                   case "IE8": type.comment = "IE8浏览器";

                       break;

                   case "360": type.comment = "360浏览器";

                       break;

                   case "Opera": type.comment = "Opera浏览器";

                       break;

                   case "Firefox": type.comment = "Firefox浏览器";

                       break;

                   case "IE11": type.comment = "IE11浏览器";

                       break;

                   case "IE10": type.comment = "IE10浏览器";

                       break;

                   case "IE7": type.comment = "IE7浏览器";

                       break;

                   case "IE6": type.comment = "IE6浏览器";

                       break;

                   case "chrome": type.comment = "chrome浏览器";

                       break;

                   default:

                       break;

               }

               type.type = type_type;

               db.BrowserType.Add(type);

               db.SaveChanges();

               return type.id;

           }

           else

           {

               return ty.id;

           }

       }

       //向os表赋值

       public int getOs(string ua,string os32)

       {

           DB.Entities db = new DB.Entities();

           DB.BrowserOS os = new DB.BrowserOS();

           string os_os = "";

           string os_os1 = "";

           if (ua.IndexOf("Windows NT 6.1") != -1)

           {

               os_os1 = "window7";

               os_os = "window7_" + os32;

           }

           else if (ua.IndexOf("Windows NT 6.2") != -1)

           {

               os_os1 = "window8";

               os_os = "window8_" + os32;

           }

           else if (ua.IndexOf("Windows NT 6.0") != -1)

           {

               os_os1 = "Vista";

               os_os = "Vista_" + os32;

           }

           else if (ua.IndexOf("Windows NT 5.0") != -1)

           {

               os_os1 = "Windows2000";

               os_os = "Windows2000_" + os32;

           }

           else if (ua.IndexOf("Windows NT 5.1") != -1)

           {

               os_os1 = "Windows XP";

               os_os = "Windows XP_" + os32;

           }

           else if (ua.IndexOf("Windows NT 5.2") != -1)

           {

               os_os1 = "Windows XP x64";

               os_os = "Windows XP x64" + os32;

           }

           else if (ua.IndexOf("Windows NT 6.3") != -1)

           {

               os_os1 = "Windows 8.1";

               os_os = "Windows 8.1_" + os32;

           }

           var o = db.BrowserOS.FirstOrDefault(c => c.os == os_os);

           if (o == null)

           {

               if (os_os.IndexOf("32") != -1)

               {

                   switch (os_os1)

                   {

                       case "window7": os.comment = "32位window7/Windows Server 2008R2系统";

                           break;

                       case "window8": os.comment = "32位window8/Windows Phone/Windows Server 2012系统";

                           break;

                       case "Vista": os.comment = "32位Vista/Windows Server 2008系统";

                           break;

                       case "Windows2000": os.comment = "32位Windows2000系统";

                           break;

                       case "Windows XP": os.comment = "32位Windows XP系统";

                           break;

                       case "Windows XP x64": os.comment = "32位Windows XP x64 Edition/Windows Server 2003/Windows Server 2003 R2系统";

                           break;

                       case "Windows 8.1": os.comment = "32位Windows 8.1/Windows Server 2012 R2系统";

                           break;

                       default:

                           break;

                   }

               }

               else if (os_os.IndexOf("64") != -1)

               {

                   switch (os_os1)

                   {

                       case "window7": os.comment = "64位window7/Windows Server 2008R2系统";

                           break;

                       case "window8": os.comment = "64位window8/Windows Phone/Windows Server 2012系统";

                           break;

                       case "Vista": os.comment = "64位Vista/Windows Server 2008系统";

                           break;

                       case "Windows2000": os.comment = "64位Windows2000系统";

                           break;

                       case "Windows XP": os.comment = "64位Windows XP系统";

                           break;

                       case "Windows XP x64": os.comment = "64位Windows XP x64 Edition/Windows Server 2003/Windows Server 2003 R2系统";

                           break;

                       case "Windows 8.1": os.comment = "64位Windows 8.1/Windows Server 2012 R2系统";

                           break;

                       default:

                           break;

                   }

               }

               os.os = os_os;

               db.BrowserOS.Add(os);

               db.SaveChanges();

               return os.id;

           }

           else

           {

               return o.id;

           }

       }

       public bool IsReusable

       {

           get

           {

               return false;

           }

       }

   }

}
阅读(1197) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~