using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Services;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
using Umbraco.Web.Security;
namespace Umbraco.Web.WebServices
{
///
/// An abstract web service class exposing common umbraco objects
///
public abstract class UmbracoWebService : WebService
{
protected UmbracoWebService()
: this(UmbracoContext.Current)
{
}
protected UmbracoWebService(UmbracoContext umbracoContext)
: this(LoggerResolver.Current.Logger, umbracoContext)
{
}
protected UmbracoWebService(ILogger logger, UmbracoContext umbracoContext)
{
if (logger == null) throw new ArgumentNullException("logger");
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
Logger = logger;
UmbracoContext = umbracoContext;
Umbraco = new UmbracoHelper(umbracoContext);
}
///
/// Returns the current ApplicationContext
///
public ApplicationContext ApplicationContext
{
get { return UmbracoContext.Application; }
}
public ILogger Logger { get; private set; }
///
/// Returns the current UmbracoContext
///
public UmbracoContext UmbracoContext { get; private set; }
///
/// Returns an UmbracoHelper object
///
public UmbracoHelper Umbraco { get; private set; }
private UrlHelper _url;
///
/// Returns a UrlHelper
///
///
/// This URL helper is created without any route data and an empty request context
///
public UrlHelper Url
{
get { return _url ?? (_url = new UrlHelper(new RequestContext(new HttpContextWrapper(Context), new RouteData()))); }
}
///
/// Returns a ServiceContext
///
public ServiceContext Services
{
get { return ApplicationContext.Services; }
}
///
/// Returns a DatabaseContext
///
public DatabaseContext DatabaseContext
{
get { return ApplicationContext.DatabaseContext; }
}
///
/// Returns a WebSecurity instance
///
public WebSecurity Security
{
get { return UmbracoContext.Security; }
}
}
}