//====================================================================
//
// COPYRIGHT (C) 2006 OPINIONATEDGEEK LTD.
//
// The contents of this file are subject to License from OpinionatedGeek;
// you may not use this file except in compliance with the License.
// You may obtain a License from OpinionatedGeek Ltd. Software distributed
// under the License is distributed "as is" and without any warranty
// as to merchantability or fitness for a particular purpose or any
// other warranties either expressed or implied. The author will
// not be liable for data loss, damages, loss of profits or any
// other kind of loss while using or misusing this software.
//
// For more information visit http://www.opinionatedgeek.com/
//
//====================================================================
//
// File name: $RCSfile: AlchemyPathProvider.cs,v $
//
// CVS File: $Source: C://CVSRoot/Alchemy/Core/Modules/AlchemyPathProvider.cs,v $
//
// Last Modified: $Date: 2006/03/08 14:16:51 $
//
// Author: $Author: Geoff $
//
// Version: $Revision: 1.3 $
//
//====================================================================
using System;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Util;
using System.Web.Hosting;
namespace OpinionatedGeek.Applications.Alchemy
{
[SourceVersion ("$RCSfile: AlchemyPathProvider.cs,v $", "$Source: C://CVSRoot/Alchemy/Core/Modules/AlchemyPathProvider.cs,v $", "$Date: 2006/03/08 14:16:51 $", "$Author: Geoff $", "$Revision: 1.3 $", "")]
public class AlchemyPathProvider : VirtualPathProvider
{
private const string ProjectsPrefix = "_alchemy\\project\\";
private const string PeoplePrefix = "_alchemy\\personal\\";
private string _baseProjectLocation = null;
private string _basePeopleLocation = null;
public AlchemyPathProvider ()
{
string applicationLocation = HostingEnvironment.ApplicationPhysicalPath;
_baseProjectLocation = Path.Combine (applicationLocation, ProjectsPrefix);
_basePeopleLocation = Path.Combine (applicationLocation, PeoplePrefix);
return;
}
public override bool FileExists (string virtualPath)
{
bool exists = false;
Uri fullUri = new Uri (HttpContext.Current.Request.Url, virtualPath);
AlchemyUri alchemyUrl = new AlchemyUri (fullUri);
if ((alchemyUrl.IsProject) || (alchemyUrl.IsPerson))
{
VirtualAlchemyFile file = new VirtualAlchemyFile (virtualPath, this.GetPhysicalName (alchemyUrl));
exists = file.Exists;
}
else
{
exists = base.FileExists (virtualPath);
}
return exists;
}
public override bool DirectoryExists (string virtualPath)
{
bool exists = false;
Uri fullUri = new Uri (HttpContext.Current.Request.Url, virtualPath);
AlchemyUri alchemyUrl = new AlchemyUri (fullUri);
if ((alchemyUrl.IsProject) || (alchemyUrl.IsPerson))
{
VirtualAlchemyDirectory dir = new VirtualAlchemyDirectory (virtualPath, this.GetPhysicalName (alchemyUrl));
exists = dir.Exists;
}
else
{
exists = base.DirectoryExists (virtualPath);
}
return exists;
}
public override VirtualFile GetFile (string virtualPath)
{
VirtualFile file = null;
Uri fullUri = new Uri (HttpContext.Current.Request.Url, virtualPath);
AlchemyUri alchemyUrl = new AlchemyUri (fullUri);
if ((alchemyUrl.IsProject) || (alchemyUrl.IsPerson))
{
file = new VirtualAlchemyFile (virtualPath, this.GetPhysicalName (alchemyUrl));
}
else
{
file = base.GetFile (virtualPath);
}
return file;
}
public override VirtualDirectory GetDirectory (string virtualPath)
{
VirtualDirectory directory = null;
Uri fullUri = new Uri (HttpContext.Current.Request.Url, virtualPath);
AlchemyUri alchemyUrl = new AlchemyUri (fullUri);
if ((alchemyUrl.IsProject) || (alchemyUrl.IsPerson))
{
directory = new VirtualAlchemyDirectory (virtualPath, this.GetPhysicalName (alchemyUrl));
}
else
{
directory = base.GetDirectory (virtualPath);
}
return directory;
}
public override CacheDependency GetCacheDependency (string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
{
Uri fullUri = new Uri (HttpContext.Current.Request.Url, virtualPath);
AlchemyUri alchemyUrl = new AlchemyUri (fullUri);
CacheDependency dependency = null;
if ((alchemyUrl.IsProject) || (alchemyUrl.IsPerson))
{
dependency = new CacheDependency (this.GetPhysicalName (alchemyUrl));
}
else
{
dependency = base.GetCacheDependency (virtualPath, virtualPathDependencies, utcStart);
}
return dependency;
}
private string GetPhysicalName (AlchemyUri url)
{
string physicalName = url.Path;
if ((url.IsPerson) || (url.IsProject))
{
string trimmedPath;
string baseLocation;
if (url.IsPerson)
{
trimmedPath = url.Path.Substring (AlchemyUri.PeoplePrefix.Length);
baseLocation = _basePeopleLocation;
}
else
{
trimmedPath = url.Path.Substring (AlchemyUri.ProjectsPrefix.Length);
baseLocation = _baseProjectLocation;
}
trimmedPath = trimmedPath.Substring (url.Space.Length);
trimmedPath = trimmedPath.TrimStart ('/');
trimmedPath = trimmedPath.Replace ('/', '\\');
physicalName = Path.Combine (baseLocation, trimmedPath);
}
return physicalName;
}
}
}