protected override void SharedContext() { _requestContext = CreateDependency <HttpContextBase>(); _request = CreateDependency <HttpRequestBase>(); _response = CreateDependency <HttpResponseBase>(); _cachePolicy = CreateDependency <HttpCachePolicyBase>(); _imageCache = CreateDependency <IImageCache>(); _browserCapFactory = new BrowserCapabilitiesFactory(); _headers = new NameValueCollection(); _queryString = new NameValueCollection(); _outputStream = new MemoryStream(); _request.SetupGet(s => s.CurrentExecutionFilePath).Returns("/Content/images/scotland.svg"); _request.SetupGet(s => s.CurrentExecutionFilePathExtension).Returns(".svg"); _request.SetupGet(s => s.Headers).Returns(_headers); _request.SetupGet(s => s.QueryString).Returns(_queryString); _response.SetupAllProperties(); _response.SetupGet(s => s.Cache).Returns(_cachePolicy.Object); _response.SetupGet(s => s.OutputStream).Returns(_outputStream); _requestContext.SetupGet(s => s.Request).Returns(_request.Object); _requestContext.SetupGet(s => s.Response).Returns(_response.Object); _handler = new FakeSvgMagicHandler(_imageCache.Object); _handler.ResourceExistsFunc = resourcePath => true; _handler.GetResourceStreamFunc = (s, e) => GetSampleImageStream(); _handler.GetResourceUpdateDateTimeFunc = s => DateTime.Now; }
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()); }
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); }
/// <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); }
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()); }
// 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)); }
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); }
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)); }
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); }
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; } }