2013-02-05 05:00:16 +06:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Web;
|
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
|
using System.Web.Routing;
|
|
|
|
|
|
using System.Web.UI;
|
|
|
|
|
|
using Umbraco.Core;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
using Umbraco.Core.Cache;
|
2015-01-07 17:38:25 +11:00
|
|
|
|
using Umbraco.Core.Logging;
|
2016-12-16 17:56:10 +01:00
|
|
|
|
using Umbraco.Core.Persistence;
|
2013-02-05 05:00:16 +06:00
|
|
|
|
using Umbraco.Core.Services;
|
2017-05-30 18:13:11 +02:00
|
|
|
|
using Umbraco.Web.Composing;
|
2013-04-23 22:39:35 -10:00
|
|
|
|
using Umbraco.Web.Security;
|
2015-12-23 13:51:16 +01:00
|
|
|
|
using Umbraco.Web.UI.Pages;
|
2013-02-05 05:00:16 +06:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.UI.Controls
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A base class for all Presentation UserControls to inherit from
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract class UmbracoUserControl : UserControl
|
|
|
|
|
|
{
|
2016-09-01 19:06:08 +02:00
|
|
|
|
private ClientTools _clientTools;
|
|
|
|
|
|
private UrlHelper _url;
|
|
|
|
|
|
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Default constructor
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="umbracoContext"></param>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// <param name="services"></param>
|
|
|
|
|
|
/// <param name="appCache"></param>
|
|
|
|
|
|
protected UmbracoUserControl(UmbracoContext umbracoContext, ServiceContext services, CacheHelper appCache)
|
2013-02-05 05:00:16 +06:00
|
|
|
|
{
|
2016-09-01 19:06:08 +02:00
|
|
|
|
if (umbracoContext == null) throw new ArgumentNullException(nameof(umbracoContext));
|
2013-02-05 05:00:16 +06:00
|
|
|
|
UmbracoContext = umbracoContext;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
Umbraco = new UmbracoHelper(umbracoContext, services, appCache);
|
|
|
|
|
|
Members = new MembershipHelper(umbracoContext);
|
|
|
|
|
|
|
|
|
|
|
|
// fixme inject somehow
|
|
|
|
|
|
Logger = Current.Logger;
|
|
|
|
|
|
ProfilingLogger = Current.ProfilingLogger;
|
|
|
|
|
|
Services = Current.Services;
|
2013-02-05 05:00:16 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Empty constructor, uses Singleton to resolve the UmbracoContext
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected UmbracoUserControl()
|
2016-09-01 19:06:08 +02:00
|
|
|
|
: this(Current.UmbracoContext, Current.Services, Current.ApplicationCache)
|
|
|
|
|
|
{ }
|
2015-12-23 13:51:16 +01:00
|
|
|
|
|
2016-09-01 19:06:08 +02:00
|
|
|
|
// for debugging purposes
|
|
|
|
|
|
internal Guid InstanceId { get; } = Guid.NewGuid();
|
2014-01-28 16:58:55 +11:00
|
|
|
|
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets the Umbraco helper.
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
public UmbracoHelper Umbraco { get; }
|
2013-02-05 05:00:16 +06:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets the membership helper;
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
public MembershipHelper Members { get; }
|
2014-01-28 16:58:55 +11:00
|
|
|
|
|
2013-04-23 22:39:35 -10:00
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets the web security helper.
|
2013-04-23 22:39:35 -10:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
public WebSecurity Security => UmbracoContext.Security;
|
2013-04-23 22:39:35 -10:00
|
|
|
|
|
2015-01-16 15:47:44 +11:00
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets the logger.
|
2015-01-16 15:47:44 +11:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
public ILogger Logger { get; }
|
2015-01-16 15:47:44 +11:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets the ProfilingLogger.
|
2015-01-16 15:47:44 +11:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
public ProfilingLogger ProfilingLogger { get; }
|
2015-01-07 17:38:25 +11:00
|
|
|
|
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets the Umbraco context.
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
public UmbracoContext UmbracoContext { get; }
|
2013-02-05 05:00:16 +06:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets the services context.
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
public ServiceContext Services { get; }
|
2013-02-05 05:00:16 +06:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets an instance of ClientTools for access to the pages client API.
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
public ClientTools ClientTools
|
2013-02-05 05:00:16 +06:00
|
|
|
|
{
|
2016-09-01 19:06:08 +02:00
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var page = Page as BasePage;
|
|
|
|
|
|
return _clientTools ?? (_clientTools = page != null ? page.ClientTools : new ClientTools(Page));
|
|
|
|
|
|
}
|
2013-02-05 05:00:16 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// Gets a Url helper.
|
2013-02-05 05:00:16 +06:00
|
|
|
|
/// </summary>
|
2016-09-01 19:06:08 +02:00
|
|
|
|
/// <remarks>This URL helper is created without any route data and an empty request context.</remarks>
|
2017-05-12 14:49:44 +02:00
|
|
|
|
public UrlHelper Url => _url ?? (_url = new UrlHelper(Context.Request.RequestContext));
|
2013-02-05 05:00:16 +06:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|