コード例 #1
0
        /// <summary>
        /// Instantiates a custom request object that provides input for device detection.
        /// </summary>
        /// <param name="context">Implementation of IServiceProvider Interface</param>
        public WurflCloudRequest(IServiceProvider externalContext)
        {
            _context = externalContext;

            var context = new GeneralHttpContext(externalContext);

            // Copy input headers into the internal collection
            _requestHeaders = new Dictionary <String, String>();
            var request = context.Request;

            if (request == null)
            {
                return;
            }

            UserAgent = request.UserAgent ?? String.Empty;

            var headers = context.Request.Headers;

            for (var i = 0; i < headers.Count; i++)
            {
                var key   = headers.GetKey(i);
                var value = headers.Get(i);
                AddRequestHeader(key, value);
            }
        }
コード例 #2
0
        /// <summary>
        /// Prepares the request to be sent to the cloud (adds headers and formats the URL)
        /// </summary>
        /// <param name="context">Implementation of IServiceProvider Interface</param>
        /// <param name="userAgent">Alternate UA???</param>
        /// <param name="reqParams">Params ???</param>
        /// <returns>URL for the cloud request</returns>
        public String InitializeRequest(IServiceProvider externalContext, String userAgent, Dictionary <String, String> reqParams)
        {
            if (externalContext == null)
            {
                return(PrepareRequestFromUserAgentOnly(userAgent, reqParams));
            }

            var context = new GeneralHttpContext(externalContext);

            // If the reportInterval is enabled and past the report age, include the report data in the next request
            //if (_config.ReportInterval > 0 && _cache.GetReportAge() >= _config.ReportInterval)
            //    AddCloudCountersHeader();

            // Prepare the request
            var request = context.Request;

            if (request == null)
            {
                return(String.Empty);
            }
            var headers = request.Headers;

            // Grab (and concatenates) server variables for reporting purposes
            var remoteAddress = String.Empty;
            var httpForwarded = String.Empty;

            if (request.ServerVariables != null)
            {
                remoteAddress = request.ServerVariables[HeaderNames.RemoteAddr];
                httpForwarded = request.ServerVariables[HeaderNames.HttpXForwardedFor];
            }
            var via = String.Join(",", new[] { remoteAddress, httpForwarded }).Trim(',').Trim();

            AddRequestHeader(HeaderNames.XForwardedFor, via);

            // Copy input headers into the internal collection
            if (headers != null)
            {
                for (var i = 0; i < headers.Count; i++)
                {
                    var key   = headers.GetKey(i);
                    var value = headers.Get(i);
                    AddRequestHeader(key, value);
                }
            }

            // Ensure a user-agent header is present
            EnsureUserAgent(userAgent);

            // Keep on preparing internal data for the cloud request: now adding capabilities
            var reqPath = BuildRequestPath(_capabilities);

            // Finally, adding other headers
            AddOtherHeaders(reqPath);
            return(reqPath);
        }
コード例 #3
0
        public override DeviceInfo GetDevice(IServiceProvider externalContext)
        {
            if (externalContext == null)
            {
                return(new DeviceInfo());
            }
            var context = new GeneralHttpContext(externalContext);
            // User agent strings are hashed to produce shorter keys for the cache.
            var userAgent = context.Request.UserAgent ?? String.Empty;

            // Attempts to read from the cache
            var device = ReadFromCache(userAgent);

            return(device ?? new DeviceInfo());
        }
コード例 #4
0
        public override Boolean SetDevice(IServiceProvider externalContext, DeviceInfo device)
        {
            if (device == null)
            {
                return(false);
            }
            if (externalContext == null)
            {
                return(false);
            }

            var context = new GeneralHttpContext(externalContext);
            // User agent strings are hashed to produce shorter keys for the cache.
            var userAgent = context.Request.UserAgent ?? String.Empty;

            WriteToCache(userAgent, device);
            return(true);
        }