Пример #1
0
        protected GetSessionResponseModel Get_Session_Implementation()
        {
            string useragent = HttpContext.Current.Request.UserAgent;
            HttpBrowserCapabilities browser = new HttpBrowserCapabilities {
                Capabilities = new Hashtable {
                    { string.Empty, useragent }
                }
            };
            BrowserCapabilitiesFactory factory = new BrowserCapabilitiesFactory();

            factory.ConfigureBrowserCapabilities(new NameValueCollection(), browser);

            GetSessionRequestModel request = new GetSessionRequestModel()
            {
                Type       = 1,
                Connection = new JsonConnection()
                {
                    IP   = Config.IP,
                    Port = Config.Port
                },
                Browser = new JsonBrowser()
                {
                    Name    = browser.Browser,
                    Version = browser.Version
                }
            };

            HttpPostAgent <GetSessionRequestModel, GetSessionResponseModel> agent = new HttpPostAgent <GetSessionRequestModel, GetSessionResponseModel>();

            agent.Url  = Config.Get_Session;
            agent.Body = request;

            return(agent.Send());
        }
        private static HttpBrowserCapabilities ConfigureBasedOnAgentString(string agentString)
        {
            var         caps  = new HttpBrowserCapabilities();
            IDictionary items = new Dictionary <string, object>();

            items.Add(string.Empty, agentString);
            caps.SetItems(items);

            _BrowserCapsFactory.ConfigureBrowserCapabilities(_DefaultHeaders, caps);
            return(caps);
        }
Пример #3
0
        public static HttpBrowserCapabilities GetHttpBrowserCapabilities(NameValueCollection headers, string userAgent)
        {
            var factory     = new BrowserCapabilitiesFactory();
            var browserCaps = new HttpBrowserCapabilities();
            var hashtable   = new Hashtable(180, StringComparer.OrdinalIgnoreCase);

            hashtable[string.Empty]  = userAgent;
            browserCaps.Capabilities = hashtable;
            factory.ConfigureBrowserCapabilities(headers, browserCaps);
            factory.ConfigureCustomCapabilities(headers, browserCaps);
            return(browserCaps);
        }
Пример #4
0
        /// <summary>
        /// Browsers the capabilities.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public static HttpBrowserCapabilities BrowserCapabilities(this HttpRequest request)
        {
            var userAgent   = request.UserAgent;
            var userBrowser = new HttpBrowserCapabilities {
                Capabilities = new Hashtable {
                    { string.Empty, userAgent }
                }
            };
            var factory = new BrowserCapabilitiesFactory();

            factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);

            return(userBrowser);
        }
Пример #5
0
        public static string getBrowser()
        {
            var userAgent   = HttpContext.Current.Request.UserAgent;
            var userBrowser = new HttpBrowserCapabilities {
                Capabilities = new Hashtable {
                    { string.Empty, userAgent }
                }
            };
            var factory = new BrowserCapabilitiesFactory();

            factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);
            var bb = userBrowser.Browser;

            return(bb.ToLower());
        }
Пример #6
0
        // We need to call the .ctor of SimpleWorkerRequest that depends on HttpRuntime so for unit testing
        // simply create the browser capabilities by going directly through the factory.
        private static HttpBrowserCapabilitiesBase CreateBrowserThroughFactory(string userAgent)
        {
            HttpBrowserCapabilities browser = new HttpBrowserCapabilities
            {
                Capabilities = new Dictionary <string, string> {
                    { String.Empty, userAgent }
                }
            };

            BrowserCapabilitiesFactory factory = new BrowserCapabilitiesFactory();

            factory.ConfigureBrowserCapabilities(new NameValueCollection(), browser);

            return(new HttpBrowserCapabilitiesWrapper(browser));
        }
Пример #7
0
        public static HttpBrowserCapabilities GetCapabilities()
        {
            var capabilities = new HttpBrowserCapabilities();

            var hashtable = new Hashtable(180, StringComparer.OrdinalIgnoreCase);

            hashtable[string.Empty]   = GetUserAgent();
            capabilities.Capabilities = hashtable;

            var capabilitiesFactory = new BrowserCapabilitiesFactory();
            var headers             = new NameValueCollection();

            capabilitiesFactory.ConfigureBrowserCapabilities(headers, capabilities);
            capabilitiesFactory.ConfigureCustomCapabilities(headers, capabilities);

            return(capabilities);
        }
Пример #8
0
        private BrowserInfo getBrowserInfo(string userAgent)
        {
            var browser = new HttpBrowserCapabilities
            {
                Capabilities = new Hashtable {
                    { string.Empty, userAgent }
                }
            };
            var factory = new BrowserCapabilitiesFactory();

            factory.ConfigureBrowserCapabilities(new NameValueCollection(), browser);


            var request = new Mock <HttpRequestBase>();

            request.Setup(b => b.UserAgent).Returns(userAgent);
            request.Setup(b => b.Browser).Returns(new HttpBrowserCapabilitiesWrapper(browser));

            return(new BrowserInfo(request.Object));
        }
Пример #9
0
 public string[] GetBrowerInformation()
 {
     string[] Result = new string[3];
     try
     {
         var userAgent   = HttpContext.Current.Request.UserAgent;
         var userBrowser = new HttpBrowserCapabilities {
             Capabilities = new Hashtable {
                 { string.Empty, userAgent }
             }
         };
         var factory = new BrowserCapabilitiesFactory();
         factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);
         Result[0] = userBrowser.Capabilities["browser"].ToString();
         Result[1] = userBrowser.Capabilities["version"].ToString();
         Result[2] = userAgent;
     }
     catch
     {
         Result[0] = "NA"; Result[1] = "NA"; Result[2] = "NA";
         return(Result);
     }
     return(Result);
 }
Пример #10
0
        public static void ProcessQueue([QueueTrigger(queueName: Utility.QUEUE)] string request,
                                        [DocumentDB(Utility.URL_TRACKING, Utility.URL_STATS, CreateIfNotExists = true, ConnectionStringSetting = "CosmosDb")] out dynamic doc,
                                        TraceWriter log)
        {
            try
            {
                AnalyticsEntry parsed = Utility.ParseQueuePayload(request);
                var            page   = parsed.LongUrl.AsPage(HttpUtility.ParseQueryString);

                telemetry.TrackPageView(page);
                log.Info($"Tracked page view {page}");

                var analytics = parsed.LongUrl.ExtractCampaignAndMedium(HttpUtility.ParseQueryString);
                var campaign  = analytics.Item1;
                var medium    = analytics.Item2;

                if (!string.IsNullOrWhiteSpace(medium))
                {
                    telemetry.TrackEvent(medium);
                    log.Info($"Tracked custom event: {medium}");
                }

                // cosmos DB
                var normalize = new[] { '/' };
                doc      = new ExpandoObject();
                doc.id   = Guid.NewGuid().ToString();
                doc.page = page.TrimEnd(normalize);
                if (!string.IsNullOrWhiteSpace(parsed.ShortUrl))
                {
                    doc.shortUrl = parsed.ShortUrl;
                }
                if (!string.IsNullOrWhiteSpace(campaign))
                {
                    doc.campaign = campaign;
                }
                if (parsed.Referrer != null)
                {
                    doc.referrerUrl  = parsed.Referrer.AsPage(HttpUtility.ParseQueryString);
                    doc.referrerHost = parsed.Referrer.DnsSafeHost;
                }
                if (!string.IsNullOrWhiteSpace(parsed.Agent))
                {
                    doc.agent = parsed.Agent;
                    try
                    {
                        var capabilities = new HttpBrowserCapabilities()
                        {
                            Capabilities = new Hashtable {
                                { string.Empty, parsed.Agent }
                            }
                        };
                        var factory = new BrowserCapabilitiesFactory();
                        factory.ConfigureBrowserCapabilities(new NameValueCollection(), capabilities);
                        factory.ConfigureCustomCapabilities(new NameValueCollection(), capabilities);
                        if (!string.IsNullOrEmpty(capabilities.Browser))
                        {
                            var browser        = capabilities.Browser;
                            var version        = capabilities.MajorVersion;
                            var browserVersion = $"{browser} {capabilities.MajorVersion}";
                            doc.browser            = browser;
                            doc.browserVersion     = version;
                            doc.browserWithVersion = browserVersion;
                        }
                        if (capabilities.Crawler)
                        {
                            doc.crawler = 1;
                        }
                        if (capabilities.IsMobileDevice)
                        {
                            doc.mobile = 1;
                            var manufacturer = capabilities.MobileDeviceManufacturer;
                            var model        = capabilities.MobileDeviceModel;
                            doc.mobileManufacturer = manufacturer;
                            doc.mobileModel        = model;
                            doc.mobileDevice       = $"{manufacturer} {model}";
                        }
                        else
                        {
                            doc.desktop = 1;
                        }
                        if (!string.IsNullOrWhiteSpace(capabilities.Platform))
                        {
                            doc.platform = capabilities.Platform;
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error($"Error parsing user agent [{parsed.Agent}]", ex);
                    }
                }
                doc.count     = 1;
                doc.timestamp = parsed.TimeStamp;
                doc.host      = parsed.LongUrl.DnsSafeHost;
                if (!string.IsNullOrWhiteSpace(medium))
                {
                    ((IDictionary <string, object>)doc).Add(medium, 1);
                }
                log.Info($"CosmosDB: {doc.id}|{doc.page}|{parsed.ShortUrl}|{campaign}|{medium}");
            }
            catch (Exception ex)
            {
                log.Error("An unexpected error occurred", ex);
                throw;
            }
        }