Пример #1
0
        private OfflineEntry GetCacheEntry(Uri uri, Guid requestId)
        {
            var filteredQueryParameters = uri.ParseQueryString()
                                          .Where(p => p.Key != "_")

                                          // Sanitize empty values (query string wo value)
                                          .Select(p => p.Key + (p.Value != null ? "=" : string.Empty) + (string.IsNullOrEmpty(p.Value) ? string.Empty : p.Value));

            var mappedUri = new UriBuilder(uri);

            mappedUri.Query = string.Join("&", filteredQueryParameters);

            // TODO: review if trimming trailing slash is correct
            var flatString = mappedUri.Uri.ToString().TrimEnd('/');

            OfflineEntry entry = null;

            lock (this.cacheIndex)
            {
                if (!this.cacheIndex.TryGetValue(flatString, out entry))
                {
                    entry = new OfflineEntry {
                        RequestId = requestId, Key = flatString
                    };
                }
            }

            return(entry);
        }
        private OfflineEntry GetCacheEntry(Uri uri, Guid requestId)
        {
            var filteredQueryParameters = uri.ParseQueryString()
                .Where(p => p.Key != "_")

                // Sanitize empty values (query string wo value)
                .Select(p => p.Key + (p.Value != null ? "=" : string.Empty) + (string.IsNullOrEmpty(p.Value) ? string.Empty : p.Value));

            var mappedUri = new UriBuilder(uri);
            mappedUri.Query = string.Join("&", filteredQueryParameters);

            // TODO: review if trimming trailing slash is correct
            var flatString = mappedUri.Uri.ToString().TrimEnd('/');

            OfflineEntry entry = null;
            lock (this.cacheIndex)
            {
                if (!this.cacheIndex.TryGetValue(flatString, out entry))
                {
                    entry = new OfflineEntry { RequestId = requestId, Key = flatString };
                }
            }

            return entry;
        }
        private static async Task<HttpResponseMessage> RetrieveOfflineResponseMessageAsync(HttpRequestMessage request, OfflineEntry entry, StorageFile file)
        {
            var cachedByteArray = await ReadBytesAsync(file);
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.RequestMessage = request;
            response.Content = new ByteArrayContent(cachedByteArray);
            
            MediaTypeHeaderValue contentType;
            if (MediaTypeHeaderValue.TryParse(entry.ContentType, out contentType))
            {
                response.Content.Headers.ContentType = contentType;
            }

            response.Content.Headers.Add(WebServer.CachedContentKey, "true");

            return response;
        }
Пример #4
0
        private static async Task <HttpResponseMessage> RetrieveOfflineResponseMessageAsync(HttpRequestMessage request, OfflineEntry entry, StorageFile file)
        {
            var cachedByteArray = await ReadBytesAsync(file);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.RequestMessage = request;
            response.Content        = new ByteArrayContent(cachedByteArray);

            MediaTypeHeaderValue contentType;

            if (MediaTypeHeaderValue.TryParse(entry.ContentType, out contentType))
            {
                response.Content.Headers.ContentType = contentType;
            }

            response.Content.Headers.Add(WebServer.CachedContentKey, "true");

            return(response);
        }