/// <summary>
        /// Get resource.
        /// </summary>
        public AppResourceResponse GetResource(AppResourceRequest request, IDictionary <string, string> vars)
        {
            var           resname = request.Uri.GetComponents(UriComponents.Path, UriFormat.Unescaped).Replace('/', '.');
            Func <Stream> stream;

            if (!_resMap.Value.TryGetValue(resname, out stream))
            {
                return(null);
            }
            return
                (new AppResourceResponse(
                     stream,
                     GetMimeType(Path.GetExtension(request.Uri.LocalPath)),
                     -1,
                     200));
        }
Exemple #2
0
 AppResourceResponse IAppResource.GetResource(AppResourceRequest request, IDictionary <string, string> vars)
 {
     _request = request;
     _vars    = vars;
     try
     {
         var ms     = new MemoryStream();
         var writer = new StreamWriter(ms);
         WriteText(request, writer);
         writer.Flush();
         ms.Seek(0, SeekOrigin.Begin);
         return(new AppResourceResponse(() => ms, MimeType, ms.Length, 200));
     }
     finally
     {
         _request = null;
         _vars    = null;
     }
 }
        /// <summary>
        /// Get application resource.
        /// </summary>
        public AppResourceResponse GetResource(AppResourceRequest request)
        {
            var table = _templateTable.Value;

            if (request.Uri.Scheme != _schemeName)
            {
                return(null);
            }
            // Replace base address in uri because UriTemplateTable.BaseAddress always starts with http://localhost/
            var match =
                table.MatchSingle(
                    new Uri(
                        table.BaseAddress,
                        request.Uri.GetComponents(UriComponents.HostAndPort | UriComponents.PathAndQuery, UriFormat.Unescaped)));

            return
                (((IAppResource)match?.Data)?
                 .GetResource(
                     request,
                     match
                     .BoundVariables
                     .AllKeys
                     .ToDictionary(k => k, k => match.BoundVariables[k], StringComparer.OrdinalIgnoreCase)));
        }
Exemple #4
0
 /// <summary>
 /// Write text to output.
 /// </summary>
 protected abstract void WriteText(AppResourceRequest request, TextWriter writer);