Esempio n. 1
0
 public ContentResponse(ContentStorage content, Uri uri)
 {
     _content = content;
     _status = HttpStatusCode.InternalServerError;
     _record = ContentRecord.DefaultInstance;
     try
     {
         string path = uri.NormalizedPathAndQuery();
         if (_content.TryGetValue(path, out _record))
         {
             if (_record.HasContentRedirect)
                 _status = HttpStatusCode.Redirect;
             else
                 _status = HttpStatusCode.OK;
         }
         else
         {
             _record = ContentRecord.DefaultInstance;
             _status = HttpStatusCode.NotFound;
             Log.Warning("404 - {0}", path);
         }
     }
     catch (Exception  ex)
     {
         Log.Error(ex, "Exception on {0}", uri);
     }
 }
Esempio n. 2
0
 private void With(bool readOnly, string url, Action<ContentStorage, ContentRecord> action)
 {
     using (ContentStorage storage = new ContentStorage(StoragePath(url), readOnly))
     {
         string relpath = new Uri(url, UriKind.Absolute).NormalizedPathAndQuery();
         ContentRecord rec;
         if (storage.TryGetValue(relpath, out rec))
         {
             action(storage, rec);
         }
         else
             throw new ApplicationException("Path not found: " + relpath);
     }
 }