示例#1
0
 public void SaveTechInfo(int guestid, GuestTechInfoTransport techInfo) {
     InvokeSafeSingleCall(() => {
         var isbot = guestid == UserAgentValidationPolicy.BOT_GUID;
         var lowerUserAgent = techInfo.UserAgent.ToLower();
         var guestExistsBrowser = GuestExistsBrowser.DataSource
             .WhereEquals(GuestExistsBrowser.Fields.Useragent, lowerUserAgent)
             .First(GuestExistsBrowser.Fields.ID);
         var now = DateTime.UtcNow;
         if (guestExistsBrowser == null) {
             guestExistsBrowser = new GuestExistsBrowser {
                 Datecreated = now,
                 Browsertype = techInfo.BrowserType,
                 Isbot = isbot,
                 Ismobile = techInfo.IsMobile,
                 Os = techInfo.Os,
                 Useragent = lowerUserAgent,
                 Version = techInfo.Version
             };
             guestExistsBrowser.Save();
         }
         if (guestid != UserAgentValidationPolicy.BOT_GUID && _cacheBrowserInfosByGuest[guestid] != guestExistsBrowser.ID) {
             var newGuestTechInfo = new GuestTechInfo {
                 Datecreated = now,
                 GuestexistsbrowserID = guestExistsBrowser.ID,
                 GuestID = guestid
             };
             newGuestTechInfo.Save();
             _cacheBrowserInfosByGuest[guestid] = guestExistsBrowser.ID;
         }
         return (object)null;
     }, null);
 }
示例#2
0
 public void SaveTechInfoTest()
 {
     var guest = Factory.CreateDao<Guest>();
     var guestTechInfoTransport = new GuestTechInfoTransport {
         Version = 66,
         BrowserType = "Opr",
         Os = "osX",
         IsMobile = false,
         UserAgent = "UA"
     };
     new UserProvider().SaveTechInfo(guest.ID, guestTechInfoTransport);
     Assert.AreEqual(1, GuestTechInfo.DataSource.Count());
     Assert.AreEqual(1, GuestExistsBrowser.DataSource.Count());
     var guestTechInfo = GuestTechInfo.DataSource.First();
     var guestExistBrowser = GuestExistsBrowser.DataSource.First();
     Assert.AreEqual(guestTechInfoTransport.Version, guestExistBrowser.Version);
     Assert.AreEqual(guestTechInfoTransport.BrowserType, guestExistBrowser.Browsertype);
     Assert.AreEqual(guestTechInfoTransport.Os, guestExistBrowser.Os);
     Assert.AreEqual(guestTechInfoTransport.IsMobile, guestExistBrowser.Ismobile);
     Assert.AreEqual(guestTechInfoTransport.UserAgent.ToLower(), guestExistBrowser.Useragent);
     Assert.AreEqual(guestExistBrowser.ID, guestTechInfo.GuestexistsbrowserID);
     Assert.AreEqual(guest.ID, guestTechInfo.GuestID);
 }