Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public Detector(string userAgent)
        {
            DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);

            DeviceDetector dd = new DeviceDetector(userAgent);

            // OPTIONAL: Set caching method
            // By default static cache is used, which works best within one php process (memory array caching)
            // To cache across requests use caching in files or memcache
            dd.SetCache(new DictionaryCache());

            // OPTIONAL: If called, GetBot() will only return true if a bot was detected  (speeds up detection a bit)
            dd.DiscardBotInformation();

            // OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then)
            dd.SkipBotDetection();

            dd.Parse();

            if (dd.IsBot())
            {
                // handle bots,spiders,crawlers,...
                var botInfo = dd.GetBot();
            }
            else
            {
                var clientInfo = dd.GetClient(); // holds information about browser, feed reader, media player, ...
                var osInfo     = dd.GetOs();
                var device     = dd.GetDeviceName();
                var brand      = dd.GetBrandName();
                var model      = dd.GetModel();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 解析 User-Agent
        /// </summary>
        /// <param name="ua">User-Agent</param>
        public UserAgentTo(string ua)
        {
            DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);

            if (ua != null)
            {
                var dd = new DeviceDetector(ua);
                dd.DiscardBotInformation();

                dd.Parse();
                if (IsBot = dd.IsBot())
                {
                    var botInfo = dd.GetBot();
                    if (botInfo.Success)
                    {
                        BrowserName = botInfo.Match.Name;
                    }
                }
                else
                {
                    var clientInfo = dd.GetClient();
                    if (clientInfo.Success)
                    {
                        BrowserName    = clientInfo.Match.Name;
                        BrowserType    = clientInfo.Match.Type;
                        BrowserVersion = clientInfo.Match.Version;
                    }
                    var osInfo = dd.GetOs();
                    if (osInfo.Success)
                    {
                        SystemName      = osInfo.Match.Name;
                        SystemShortName = osInfo.Match.ShortName;
                        SystemVersion   = osInfo.Match.Version;
                        SystemPlatform  = osInfo.Match.Platform;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private DeviceDetector GetDeviceDetectorConfigured()
        {
            var ua = _detection.UserAgent;

            DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);

            var dd = new DeviceDetector(ua.ToString());

            // OPTIONAL: Set caching method By default static cache is used, which works best within one
            // php process (memory array caching) To cache across requests use caching in files or
            // memcache add using DeviceDetectorNET.Cache;
            dd.SetCache(new DictionaryCache());

            // OPTIONAL: If called, GetBot() will only return true if a bot was detected (speeds up
            // detection a bit)
            dd.DiscardBotInformation();

            // OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as
            // regular devices then)
            dd.SkipBotDetection();
            dd.Parse();
            return(dd);
        }
Exemplo n.º 4
0
        [ValidateAntiForgeryToken] //protect against CSRF attacks
        public async Task <IActionResult> Kontakt(Inquiry inquiry)
        {
            var userAgent = Request.Headers["User-Agent"].ToString();

            // OPTIONAL: Set version truncation to none, so full versions will be returned
            // By default only minor versions will be returned (e.g. X.Y)
            // for other options see VERSION_TRUNCATION_* constants in DeviceParserAbstract class
            // add using DeviceDetectorNET.Parser;
            DeviceDetector.SetVersionTruncation(VersionTruncation.VERSION_TRUNCATION_NONE);

            var dd = new DeviceDetector(userAgent);

            // OPTIONAL: Set caching method
            // By default static cache is used, which works best within one php process (memory array caching)
            // To cache across requests use caching in files or memcache
            // add using DeviceDetectorNET.Cache;
            dd.SetCache(new DictionaryCache());

            // OPTIONAL: If called, GetBot() will only return true if a bot was detected  (speeds up detection a bit)
            dd.DiscardBotInformation();

            // OPTIONAL: If called, bot detection will completely be skipped (bots will be detected as regular devices then)
            dd.SkipBotDetection();

            dd.Parse();

            if (dd.IsBot())
            {
                // handle bots,spiders,crawlers,...
                var botInfo = dd.GetBot();
                inquiry.Browser         = "BOT";
                inquiry.OperatingSystem = "BOT";
                inquiry.Device          = "BOT";
                inquiry.Brand           = "BOT";
                inquiry.Model           = "BOT";
            }
            else
            {
                var clientInfo = dd.GetClient(); // holds information about browser, feed reader, media player, ...
                var osInfo     = dd.GetOs();
                var device     = dd.GetDeviceName();
                var brand      = dd.GetBrandName();
                var model      = dd.GetModel();

                inquiry.Browser         = $"{clientInfo.Match.Name} ({clientInfo.Match.Version})";
                inquiry.OperatingSystem = $"{osInfo.Match.Name} ({osInfo.Match.Version}) {osInfo.Match.Platform}";
                var deviceResult = device == "" ? inquiry.Device = "N/A" : inquiry.Device = device;
                var brandResult  = brand == "" ? inquiry.Brand = "N/A" : inquiry.Brand = brand;
                var modelResult  = model == "" ? inquiry.Model = "N/A" : inquiry.Model = model;
            }

            //local Environment
            //OperatingSystem os = Environment.OSVersion;
            //var platform = os.Platform.ToString();
            //var version = os.Version.ToString();
            //var servicePack = os.ServicePack.ToString();

            var remoteIpAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();

            inquiry.IpAddress = remoteIpAddress;

            inquiry.CreatedDate = DateTime.Now;
            inquiry.Status      = "New";
            inquiry.HoursSpend  = 0;
            inquiry.HourPrice   = 400;
            inquiry.InvoiceNo   = "N/A";
            inquiry.Payment     = "N/A";


            if (ModelState.IsValid)
            {
                var inquiryId = await contex.Inquiries.FirstOrDefaultAsync(x => x.Id == inquiry.Id);

                if (inquiryId != null)
                {
                    ModelState.AddModelError("", "Nastapil bland, ponow wpis.");
                    return(View());
                }

                //string attachmentName = "noimagecar.png";
                //if (inquiry.AttachmentUpload != null)
                //{
                //    string uploadsDir = Path.Combine(webHostEnvironment.WebRootPath, "media/cars");
                //    attachmentName = Guid.NewGuid().ToString() + "_" + inquiry.AttachmentUpload.FileName;
                //    string filePath = Path.Combine(uploadsDir, attachmentName);
                //    FileStream fs = new FileStream(filePath, FileMode.Create);
                //    await inquiry.AttachmentUpload.CopyToAsync(fs);
                //    fs.Close();
                //}
                //inquiry.Attachment = attachmentName;



                contex.Add(inquiry);
                await contex.SaveChangesAsync();

                TempData["Success"] = "Wiadomosc zostala wyslana!";

                return(RedirectToAction("Kontakt"));
            }

            return(View());
        }