protected override DeviceInformation DoGetDeviceInformation(string userAgent)
        {
            Assert.ArgumentNotNull(userAgent, "userAgent");

            using (new ReadScope(_readerWriterLockSlim))
            {
                var dd = new DeviceDetector(userAgent);
                dd.Parse();

                var        browserMatchResult = dd.GetBrowserClient().Match;
                DeviceType deviceType         = DeviceType.Computer;
                if (dd.IsMobile())
                {
                    deviceType = DeviceType.MobilePhone;
                }

                DeviceInformation deviceInformation = new DeviceInformation
                {
                    Browser            = browserMatchResult?.Name ?? "desktop",
                    DeviceIsSmartphone = dd.IsMobile(),
                    DeviceModelName    = dd.GetDeviceName(),
                    DeviceType         = deviceType,
                    DeviceVendor       = dd.GetModel()
                };

                return(deviceInformation);
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates the analytic entry if one is deemed to be necessary
        /// This method relies on DeviceDetector.NET. Details at https://github.com/totpero/DeviceDetector.NET
        /// It is advisable to frequently check for updates, especially to the regexes folder (situated in the Resources folder of this project)
        /// </summary>
        /// <param name="Ado"></param>
        /// <param name="requestDTO"></param>
        /// <param name="hRequest"></param>
        /// <param name="request"></param>
        internal static void Create(ADO Ado, dynamic requestDTO, HttpRequest hRequest, JSONRPC_API request)
        {
            //If this method doesn't require analytic logging then exit the function here
            if (!MethodReader.MethodHasAttribute(request.method, "Analytic"))
            {
                return;
            }

            Analytic_DTO aDto = new Analytic_DTO();


            if (hRequest.UserLanguages != null)
            {
                if (hRequest.UserLanguages.Count() > 0)
                {
                    if (hRequest.UserLanguages[0].Length >= 2)
                    {
                        aDto.EnvironmentLngIsoCode = hRequest.UserLanguages[0].Substring(0, 2);
                    }
                }
            }

            //Get a masked version of the ip address
            aDto.NltMaskedIp = getMaskedIp(request.ipAddress);

            //Get the matrix field from the calling DTO
            if (MethodReader.DynamicHasProperty(requestDTO, "jStatQueryExtension"))
            {
                aDto.matrix = requestDTO.jStatQueryExtension.extension.Matrix;
            }

            // Get the Referer
            aDto.NltReferer = hRequest.UrlReferrer == null || String.IsNullOrEmpty(hRequest.UrlReferrer.Host) ? null : hRequest.UrlReferrer.Host;

            //The m2m parameter will not be translated into a DTO property so we just read it from the request parameters if it exists
            if (MethodReader.DynamicHasProperty(requestDTO, "m2m"))
            {
                aDto.NltM2m = requestDTO.m2m;
            }
            else
            {
                aDto.NltM2m = true;
            }

            if (MethodReader.DynamicHasProperty(requestDTO, "widget"))
            {
                aDto.NltWidget = requestDTO.widget;
            }

            if (MethodReader.DynamicHasProperty(requestDTO, "user"))
            {
                aDto.NltUser = requestDTO.user;
            }

            // Get the DateTime
            aDto.NltDate = DateTime.Now;


            //Get Format information
            if (MethodReader.DynamicHasProperty(requestDTO, "jStatQueryExtension"))
            {
                if (MethodReader.DynamicHasProperty(requestDTO.jStatQueryExtension.extension.Format, "Type") && MethodReader.DynamicHasProperty(requestDTO.jStatQueryExtension.extension.Format, "Version"))
                {
                    aDto.FrmType    = requestDTO.jStatQueryExtension.extension.Format.Type;
                    aDto.FrmVersion = requestDTO.jStatQueryExtension.extension.Format.Version;
                }
            }


            //Get the device detector and populate the dto attributes
            DeviceDetector deviceDetector = GetDeviceDetector(request.userAgent);

            aDto.NltBotFlag = deviceDetector.IsBot();


            //If it's a bot, then that overrules everything else
            if (aDto.NltBotFlag)
            {
                aDto.NltM2m    = false;
                aDto.NltUser   = false;
                aDto.NltWidget = false;
            }

            if (deviceDetector.GetBrowserClient().Match != null)
            {
                aDto.NltBrowser = deviceDetector.GetBrowserClient().Match.Name;
            }

            if (deviceDetector.GetOs().Match != null)
            {
                aDto.NltOs = deviceDetector.GetOs().Match.Name;
            }


            var valids = new Analytic_VLD().Validate(aDto);

            //validate whatever has been returned
            if (!valids.IsValid)
            {
                foreach (var fail in valids.Errors)
                {
                    Log.Instance.Debug("Analytic method failed validation:" + request.method + " :" + fail.ErrorMessage);
                }
                return;
            }

            //Create the analytic entry
            Analytic_ADO ado = new Analytic_ADO(Ado);

            if (ado.Create(aDto) == 0)
            {
                Log.Instance.Debug("Failed to create Analytic:" + request.method);
                return;
            }

            return;
        }
コード例 #3
0
        internal static void Create(HttpRequest hRequest, string method, string userAgent, string ipaddress, string matrixCode, bool m2m, Format_DTO_Read format)
        {
            ADO Ado = new ADO("defaultConnection");

            try
            {
                Analytic_DTO aDto = new Analytic_DTO()
                {
                    NltMaskedIp = ipaddress, matrix = matrixCode, NltM2m = m2m, NltDate = DateTime.Now, FrmType = format.FrmType, FrmVersion = format.FrmVersion
                };


                // Get the Referer
                aDto.NltReferer = hRequest.UrlReferrer == null || String.IsNullOrEmpty(hRequest.UrlReferrer.Host) ? Configuration_BSO.GetCustomConfig("analytic.referrer-not-applicable") : hRequest.UrlReferrer.Host;


                //Get the device detector and populate the dto attributes
                DeviceDetector deviceDetector = GetDeviceDetector(hRequest.UserAgent);

                aDto.NltBotFlag = deviceDetector.IsBot();

                if (deviceDetector.GetBrowserClient().Match != null)
                {
                    aDto.NltBrowser = deviceDetector.GetBrowserClient().Match.Name;
                }

                if (deviceDetector.GetOs().Match != null)
                {
                    aDto.NltOs = deviceDetector.GetOs().Match.Name;
                }


                var valids = new Analytic_VLD().Validate(aDto);

                //validate whatever has been returned
                if (!valids.IsValid)
                {
                    foreach (var fail in valids.Errors)
                    {
                        Log.Instance.Debug("Analytic method failed validation:" + method + " :" + fail.ErrorMessage);
                    }
                    return;
                }

                //Create the analytic entry
                Analytic_ADO ado = new Analytic_ADO(Ado);

                if (ado.Create(aDto) == 0)
                {
                    Log.Instance.Debug("Failed to create Analytic:" + method);
                    return;
                }

                return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                Ado.Dispose();
            }
        }