|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Signum.Utilities;
using System.Web.Routing;
using System.Web.Hosting;
using System.IO;
namespace Signum.Web.PortableAreas
{
public interface IFileRepository
{
bool FileExists(string file);
ActionResult GetFile(string file);
}
public static class FileRepositoryManager
{
static HashSet<IFileRepository> Repositories = new HashSet<IFileRepository>();
public static void Register(IFileRepository repository)
{
Repositories.Add(repository);
}
public static bool FileExists(string file)
{
return Repositories.Any(a => a.FileExists(file));
}
public static ActionResult GetFile(string file)
{
IFileRepository respository = Repositories.FirstOrDefault(a => a.FileExists(file));
if (respository == null)
return null;
return respository.GetFile(file);
}
}
public class EmbeddedFileExist : IRouteConstraint
{
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
object file = values[parameterName];
if (file == null)
return false;
return FileRepositoryManager.FileExists("~/" + file.ToString());
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.
www.signumframework.com
I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...