using System; using System.Web; using System.Web.Mvc; using System.Web.Routing; using System.Web.UI; using Umbraco.Core; using Umbraco.Core.Logging; using Umbraco.Core.Services; using umbraco.BusinessLogic; using umbraco.DataLayer; namespace Umbraco.Web.UI.Controls { /// /// A control that exposes the helpful Umbraco context objects /// public abstract class UmbracoControl : Control { /// /// Default constructor /// /// protected UmbracoControl(UmbracoContext umbracoContext) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); UmbracoContext = umbracoContext; Umbraco = new UmbracoHelper(umbracoContext); } /// /// Empty constructor, uses Singleton to resolve the UmbracoContext /// protected UmbracoControl() : this(UmbracoContext.Current) { } /// /// Returns an UmbracoHelper object /// public UmbracoHelper Umbraco { get; private set; } /// /// Returns an ILogger /// public ILogger Logger { get { return ProfilingLogger.Logger; } } /// /// Returns a ProfilingLogger /// public ProfilingLogger ProfilingLogger { get { return UmbracoContext.Application.ProfilingLogger; } } public UmbracoContext UmbracoContext { get; private set; } protected ApplicationContext ApplicationContext { get { return UmbracoContext.Application; } } protected DatabaseContext DatabaseContext { get { return ApplicationContext.DatabaseContext; } } protected ServiceContext Services { get { return ApplicationContext.Services; } } 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 the legacy SqlHelper /// protected ISqlHelper SqlHelper { get { return Application.SqlHelper; } } } }