2012-09-03 07:54:09 +07:00
using System ;
2015-01-28 19:46:05 +11:00
using System.ComponentModel ;
2012-09-03 07:54:09 +07:00
using System.Web ;
2012-09-27 08:30:35 +07:00
using System.Web.Security ;
2012-09-14 09:09:23 +07:00
using System.Xml.Linq ;
using System.Xml.XPath ;
2012-09-03 07:54:09 +07:00
using Umbraco.Core ;
2012-09-27 08:30:35 +07:00
using Umbraco.Core.Dictionary ;
2012-09-14 09:09:23 +07:00
using Umbraco.Core.Dynamics ;
2012-09-05 09:35:24 +07:00
using Umbraco.Core.Models ;
2014-03-18 17:08:21 +11:00
using Umbraco.Core.Security ;
2015-01-28 19:46:05 +11:00
using Umbraco.Core.Services ;
2013-03-19 17:54:37 -01:00
using Umbraco.Core.Xml ;
2013-09-28 17:13:23 +02:00
using Umbraco.Web.Routing ;
2014-03-11 14:23:51 +11:00
using Umbraco.Web.Security ;
2012-09-05 09:35:24 +07:00
using System.Collections.Generic ;
2015-10-16 13:36:10 +02:00
using System.IO ;
using System.Web.Mvc ;
using System.Web.Routing ;
2014-08-20 12:31:54 -06:00
using Umbraco.Core.Cache ;
2012-09-03 07:54:09 +07:00
namespace Umbraco.Web
{
2013-10-24 12:50:43 +11:00
/// <summary>
2012-09-03 07:54:09 +07:00
/// A helper class that provides many useful methods and functionality for using Umbraco in templates
/// </summary>
2015-02-18 17:14:55 +01:00
public class UmbracoHelper : IUmbracoComponentRenderer
{
2012-09-03 07:54:09 +07:00
private readonly UmbracoContext _umbracoContext ;
2012-10-02 01:35:39 +05:00
private readonly IPublishedContent _currentPage ;
2015-02-18 17:14:55 +01:00
private readonly ITypedPublishedContentQuery _typedQuery ;
2015-05-18 13:38:14 +10:00
private readonly IDynamicPublishedContentQuery _dynamicQuery ;
2015-02-18 17:14:55 +01:00
private readonly HtmlStringUtilities _stringUtilities = new HtmlStringUtilities ( ) ;
private IUmbracoComponentRenderer _componentRenderer ;
private PublishedContentQuery _query ;
private MembershipHelper _membershipHelper ;
2015-07-30 14:03:17 +02:00
private TagQuery _tag ;
2015-02-18 17:14:55 +01:00
private IDataTypeService _dataTypeService ;
private UrlProvider _urlProvider ;
private ICultureDictionary _cultureDictionary ;
2013-10-24 13:31:10 +11:00
/// <summary>
/// Lazy instantiates the tag context
/// </summary>
2015-07-30 14:03:17 +02:00
public TagQuery TagQuery
2013-10-24 13:31:10 +11:00
{
2015-07-30 14:03:17 +02:00
//TODO: Unfortunately we cannot change this return value to be ITagQuery
// since it's a breaking change, need to fix it for v8
// http://issues.umbraco.org/issue/U4-6899
2015-07-20 15:37:40 +02:00
get
{
return _tag ? ?
( _tag = new TagQuery ( UmbracoContext . Application . Services . TagService ,
_typedQuery ? ? ContentQuery ) ) ;
}
2013-10-24 13:31:10 +11:00
}
2013-10-24 12:50:43 +11:00
/// <summary>
2015-02-18 17:14:55 +01:00
/// Lazy instantiates the query context if not specified in the constructor
2013-10-24 12:50:43 +11:00
/// </summary>
2015-02-18 17:14:55 +01:00
public PublishedContentQuery ContentQuery
{
get
{
//If the content query doesn't exist it will either be created with the ITypedPublishedContentQuery, IDynamicPublishedContentQuery
// used to construct this instance or with the content caches of the UmbracoContext
return _query ? ?
( _query = _typedQuery ! = null
? new PublishedContentQuery ( _typedQuery , _dynamicQuery )
: new PublishedContentQuery ( UmbracoContext . ContentCache , UmbracoContext . MediaCache ) ) ;
}
}
2013-10-24 12:50:43 +11:00
/// <summary>
/// Helper method to ensure an umbraco context is set when it is needed
/// </summary>
2015-02-18 17:14:55 +01:00
public UmbracoContext UmbracoContext
2013-10-24 12:50:43 +11:00
{
get
{
if ( _umbracoContext = = null )
{
throw new NullReferenceException ( "No " + typeof ( UmbracoContext ) + " reference has been set for this " + typeof ( UmbracoHelper ) + " instance" ) ;
}
return _umbracoContext ;
}
}
/// <summary>
2015-02-18 17:14:55 +01:00
/// Lazy instantiates the membership helper if not specified in the constructor
/// </summary>
public MembershipHelper MembershipHelper
{
get { return _membershipHelper ? ? ( _membershipHelper = new MembershipHelper ( UmbracoContext ) ) ; }
}
/// <summary>
/// Lazy instantiates the UrlProvider if not specified in the constructor
/// </summary>
public UrlProvider UrlProvider
{
get { return _urlProvider ? ? ( _urlProvider = UmbracoContext . UrlProvider ) ; }
}
/// <summary>
/// Lazy instantiates the IDataTypeService if not specified in the constructor
/// </summary>
public IDataTypeService DataTypeService
{
get { return _dataTypeService ? ? ( _dataTypeService = UmbracoContext . Application . Services . DataTypeService ) ; }
}
/// <summary>
/// Lazy instantiates the IUmbracoComponentRenderer if not specified in the constructor
/// </summary>
public IUmbracoComponentRenderer UmbracoComponentRenderer
{
get { return _componentRenderer ? ? ( _componentRenderer = new UmbracoComponentRenderer ( UmbracoContext ) ) ; }
}
#region Constructors
/// <summary>
/// Empty constructor to create an umbraco helper for access to methods that don't have dependencies
2013-10-24 12:50:43 +11:00
/// </summary>
public UmbracoHelper ( )
2015-02-18 17:14:55 +01:00
{
}
/// <summary>
/// Constructor accepting all dependencies
/// </summary>
/// <param name="umbracoContext"></param>
/// <param name="content"></param>
/// <param name="typedQuery"></param>
/// <param name="dynamicQuery"></param>
/// <param name="tagQuery"></param>
/// <param name="dataTypeService"></param>
/// <param name="urlProvider"></param>
/// <param name="cultureDictionary"></param>
/// <param name="componentRenderer"></param>
/// <param name="membershipHelper"></param>
/// <remarks>
/// This constructor can be used to create a testable UmbracoHelper
/// </remarks>
public UmbracoHelper ( UmbracoContext umbracoContext , IPublishedContent content ,
ITypedPublishedContentQuery typedQuery ,
IDynamicPublishedContentQuery dynamicQuery ,
ITagQuery tagQuery ,
IDataTypeService dataTypeService ,
UrlProvider urlProvider ,
ICultureDictionary cultureDictionary ,
IUmbracoComponentRenderer componentRenderer ,
MembershipHelper membershipHelper )
{
if ( umbracoContext = = null ) throw new ArgumentNullException ( "umbracoContext" ) ;
if ( content = = null ) throw new ArgumentNullException ( "content" ) ;
if ( typedQuery = = null ) throw new ArgumentNullException ( "typedQuery" ) ;
if ( dynamicQuery = = null ) throw new ArgumentNullException ( "dynamicQuery" ) ;
if ( tagQuery = = null ) throw new ArgumentNullException ( "tagQuery" ) ;
if ( dataTypeService = = null ) throw new ArgumentNullException ( "dataTypeService" ) ;
if ( urlProvider = = null ) throw new ArgumentNullException ( "urlProvider" ) ;
if ( cultureDictionary = = null ) throw new ArgumentNullException ( "cultureDictionary" ) ;
if ( componentRenderer = = null ) throw new ArgumentNullException ( "componentRenderer" ) ;
if ( membershipHelper = = null ) throw new ArgumentNullException ( "membershipHelper" ) ;
_umbracoContext = umbracoContext ;
2015-07-30 14:03:17 +02:00
_tag = new TagQuery ( tagQuery ) ;
2015-02-18 17:14:55 +01:00
_dataTypeService = dataTypeService ;
_urlProvider = urlProvider ;
_cultureDictionary = cultureDictionary ;
_componentRenderer = componentRenderer ;
_membershipHelper = membershipHelper ;
_currentPage = content ;
_typedQuery = typedQuery ;
_dynamicQuery = dynamicQuery ;
2013-10-24 12:50:43 +11:00
}
2015-02-18 17:14:55 +01:00
[Obsolete("Use the constructor specifying all dependencies")]
[EditorBrowsable(EditorBrowsableState.Never)]
2013-11-02 13:22:48 +11:00
public UmbracoHelper ( UmbracoContext umbracoContext , IPublishedContent content , PublishedContentQuery query )
2013-10-24 12:50:43 +11:00
: this ( umbracoContext )
{
if ( content = = null ) throw new ArgumentNullException ( "content" ) ;
2013-11-02 13:22:48 +11:00
if ( query = = null ) throw new ArgumentNullException ( "query" ) ;
2013-10-24 12:50:43 +11:00
_currentPage = content ;
2013-11-02 13:22:48 +11:00
_query = query ;
2013-10-24 12:50:43 +11:00
}
2012-11-05 11:27:28 +06:00
2015-02-18 17:14:55 +01:00
/// <summary>
/// Custom constructor setting the current page to the parameter passed in
/// </summary>
/// <param name="umbracoContext"></param>
/// <param name="content"></param>
public UmbracoHelper ( UmbracoContext umbracoContext , IPublishedContent content )
: this ( umbracoContext )
{
if ( content = = null ) throw new ArgumentNullException ( "content" ) ;
_currentPage = content ;
}
/// <summary>
/// Standard constructor setting the current page to the page that has been routed to
/// </summary>
/// <param name="umbracoContext"></param>
public UmbracoHelper ( UmbracoContext umbracoContext )
{
if ( umbracoContext = = null ) throw new ArgumentNullException ( "umbracoContext" ) ;
if ( umbracoContext . RoutingContext = = null ) throw new NullReferenceException ( "The RoutingContext on the UmbracoContext cannot be null" ) ;
_umbracoContext = umbracoContext ;
if ( _umbracoContext . IsFrontEndUmbracoRequest )
{
_currentPage = _umbracoContext . PublishedContentRequest . PublishedContent ;
}
}
2012-09-03 07:54:09 +07:00
2015-02-18 17:14:55 +01:00
[Obsolete("Use the constructor specifying all dependencies")]
[EditorBrowsable(EditorBrowsableState.Never)]
2013-11-02 13:22:48 +11:00
public UmbracoHelper ( UmbracoContext umbracoContext , PublishedContentQuery query )
2013-10-24 12:50:43 +11:00
: this ( umbracoContext )
{
2013-11-02 13:22:48 +11:00
if ( query = = null ) throw new ArgumentNullException ( "query" ) ;
_query = query ;
2015-02-18 17:14:55 +01:00
}
#endregion
2013-10-24 12:50:43 +11:00
2013-01-25 06:13:47 +03:00
/// <summary>
/// Returns the current IPublishedContent item assigned to the UmbracoHelper
/// </summary>
/// <remarks>
/// Note that this is the assigned IPublishedContent item to the UmbracoHelper, this is not necessarily the Current IPublishedContent item
/// being rendered. This IPublishedContent object is contextual to the current UmbracoHelper instance.
///
/// In some cases accessing this property will throw an exception if there is not IPublishedContent assigned to the Helper
/// this will only ever happen if the Helper is constructed with an UmbracoContext and it is not a front-end request
/// </remarks>
/// <exception cref="InvalidOperationException">Thrown if the UmbracoHelper is constructed with an UmbracoContext and it is not a front-end request</exception>
public IPublishedContent AssignedContentItem
{
get
{
if ( _currentPage = = null )
throw new InvalidOperationException ( "Cannot return the " + typeof ( IPublishedContent ) . Name + " because the " + typeof ( UmbracoHelper ) . Name + " was constructed with an " + typeof ( UmbracoContext ) . Name + " and the current request is not a front-end request." ) ;
return _currentPage ;
}
}
/// <summary>
2012-11-14 10:47:40 +05:00
/// Renders the template for the specified pageId and an optional altTemplateId
/// </summary>
/// <param name="pageId"></param>
/// <param name="altTemplateId">If not specified, will use the template assigned to the node</param>
/// <returns></returns>
public IHtmlString RenderTemplate ( int pageId , int? altTemplateId = null )
2015-02-18 17:14:55 +01:00
{
2015-03-24 15:12:58 +11:00
return UmbracoComponentRenderer . RenderTemplate ( pageId , altTemplateId ) ;
2015-02-18 17:14:55 +01:00
}
2012-09-03 07:54:09 +07:00
#region RenderMacro
/// <summary>
/// Renders the macro with the specified alias.
/// </summary>
/// <param name="alias">The alias.</param>
/// <returns></returns>
public IHtmlString RenderMacro ( string alias )
{
2015-03-24 15:12:58 +11:00
return UmbracoComponentRenderer . RenderMacro ( alias , new { } ) ;
2012-09-03 07:54:09 +07:00
}
/// <summary>
/// Renders the macro with the specified alias, passing in the specified parameters.
/// </summary>
/// <param name="alias">The alias.</param>
/// <param name="parameters">The parameters.</param>
/// <returns></returns>
public IHtmlString RenderMacro ( string alias , object parameters )
2012-09-08 07:13:03 +07:00
{
2015-03-24 15:12:58 +11:00
return UmbracoComponentRenderer . RenderMacro ( alias , parameters . ToDictionary < object > ( ) ) ;
2012-09-08 07:13:03 +07:00
}
/// <summary>
/// Renders the macro with the specified alias, passing in the specified parameters.
/// </summary>
/// <param name="alias">The alias.</param>
/// <param name="parameters">The parameters.</param>
/// <returns></returns>
public IHtmlString RenderMacro ( string alias , IDictionary < string , object > parameters )
2012-09-03 07:54:09 +07:00
{
2015-03-24 15:12:58 +11:00
return UmbracoComponentRenderer . RenderMacro ( alias , parameters ) ;
2013-09-24 13:34:29 +10:00
}
2012-09-29 08:49:21 +07:00
2012-09-03 07:54:09 +07:00
#endregion
2012-09-05 09:35:24 +07:00
#region Field
/// <summary>
/// Renders an field to the template
/// </summary>
/// <param name="fieldAlias"></param>
/// <param name="altFieldAlias"></param>
/// <param name="altText"></param>
/// <param name="insertBefore"></param>
/// <param name="insertAfter"></param>
/// <param name="recursive"></param>
/// <param name="convertLineBreaks"></param>
/// <param name="removeParagraphTags"></param>
/// <param name="casing"></param>
/// <param name="encoding"></param>
2012-10-08 05:40:55 -10:00
/// <param name="formatAsDate"></param>
/// <param name="formatAsDateWithTime"></param>
/// <param name="formatAsDateWithTimeSeparator"></param>
//// <param name="formatString"></param>
2012-09-05 09:35:24 +07:00
/// <returns></returns>
2012-10-01 02:48:08 +05:00
public IHtmlString Field ( string fieldAlias ,
string altFieldAlias = "" , string altText = "" , string insertBefore = "" , string insertAfter = "" ,
2012-09-05 09:35:24 +07:00
bool recursive = false , bool convertLineBreaks = false , bool removeParagraphTags = false ,
RenderFieldCaseType casing = RenderFieldCaseType . Unchanged ,
2012-10-08 05:40:55 -10:00
RenderFieldEncodingType encoding = RenderFieldEncodingType . Unchanged ,
bool formatAsDate = false ,
bool formatAsDateWithTime = false ,
string formatAsDateWithTimeSeparator = "" )
2013-01-25 06:13:47 +03:00
{
2015-07-21 14:58:34 -07:00
return UmbracoComponentRenderer . Field ( AssignedContentItem , fieldAlias , altFieldAlias ,
2012-10-08 05:40:55 -10:00
altText , insertBefore , insertAfter , recursive , convertLineBreaks , removeParagraphTags ,
2015-02-18 17:14:55 +01:00
casing , encoding , formatAsDate , formatAsDateWithTime , formatAsDateWithTimeSeparator ) ;
2012-09-05 09:35:24 +07:00
}
/// <summary>
/// Renders an field to the template
/// </summary>
/// <param name="currentPage"></param>
/// <param name="fieldAlias"></param>
/// <param name="altFieldAlias"></param>
2012-09-05 09:36:30 +07:00
/// <param name="altText"></param>
2012-09-05 09:35:24 +07:00
/// <param name="insertBefore"></param>
/// <param name="insertAfter"></param>
/// <param name="recursive"></param>
/// <param name="convertLineBreaks"></param>
/// <param name="removeParagraphTags"></param>
/// <param name="casing"></param>
2012-10-08 05:40:55 -10:00
/// <param name="encoding"></param>
/// <param name="formatAsDate"></param>
/// <param name="formatAsDateWithTime"></param>
/// <param name="formatAsDateWithTimeSeparator"></param>
//// <param name="formatString"></param>
2012-09-05 09:35:24 +07:00
/// <returns></returns>
2012-10-02 01:35:39 +05:00
public IHtmlString Field ( IPublishedContent currentPage , string fieldAlias ,
2012-10-01 02:48:08 +05:00
string altFieldAlias = "" , string altText = "" , string insertBefore = "" , string insertAfter = "" ,
2012-09-05 09:35:24 +07:00
bool recursive = false , bool convertLineBreaks = false , bool removeParagraphTags = false ,
RenderFieldCaseType casing = RenderFieldCaseType . Unchanged ,
2012-10-08 05:40:55 -10:00
RenderFieldEncodingType encoding = RenderFieldEncodingType . Unchanged ,
bool formatAsDate = false ,
bool formatAsDateWithTime = false ,
string formatAsDateWithTimeSeparator = "" )
2015-02-18 17:14:55 +01:00
{
2015-07-21 14:58:34 -07:00
return UmbracoComponentRenderer . Field ( currentPage , fieldAlias , altFieldAlias ,
2015-02-18 17:14:55 +01:00
altText , insertBefore , insertAfter , recursive , convertLineBreaks , removeParagraphTags ,
casing , encoding , formatAsDate , formatAsDateWithTime , formatAsDateWithTimeSeparator ) ;
2012-09-05 09:35:24 +07:00
}
#endregion
2012-09-27 08:30:35 +07:00
#region Dictionary
/// <summary>
/// Returns the dictionary value for the key specified
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public string GetDictionaryValue ( string key )
{
2015-05-18 13:38:14 +10:00
return CultureDictionary [ key ] ;
2012-09-27 08:30:35 +07:00
}
2015-05-18 13:38:14 +10:00
/// <summary>
/// Returns the ICultureDictionary for access to dictionary items
/// </summary>
public ICultureDictionary CultureDictionary
{
get
{
if ( _cultureDictionary = = null )
{
var factory = CultureDictionaryFactoryResolver . Current . Factory ;
_cultureDictionary = factory . CreateDictionary ( ) ;
}
return _cultureDictionary ;
}
}
2012-09-27 08:30:35 +07:00
#endregion
#region Membership
2015-01-28 19:46:05 +11:00
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use the IsProtected method that only specifies path")]
public bool IsProtected ( int documentId , string path )
2012-09-27 08:30:35 +07:00
{
2015-01-28 19:46:05 +11:00
return IsProtected ( path . EnsureEndsWith ( "," + documentId ) ) ;
2012-09-27 08:30:35 +07:00
}
2015-01-28 19:46:05 +11:00
/// <summary>
/// Check if a document object is protected by the "Protect Pages" functionality in umbraco
/// </summary>
/// <param name="path">The full path of the document object to check</param>
/// <returns>True if the document object is protected</returns>
public bool IsProtected ( string path )
{
return UmbracoContext . Application . Services . PublicAccessService . IsProtected ( path ) ;
}
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Use the MemberHasAccess method that only specifies path")]
public bool MemberHasAccess ( int nodeId , string path )
{
return MemberHasAccess ( path . EnsureEndsWith ( "," + nodeId ) ) ;
}
/// <summary>
/// Check if the current user has access to a document
/// </summary>
/// <param name="path">The full path of the document object to check</param>
/// <returns>True if the current user has access or if the current document isn't protected</returns>
public bool MemberHasAccess ( string path )
{
if ( IsProtected ( path ) )
{
2015-02-18 17:14:55 +01:00
return MembershipHelper . IsLoggedIn ( )
2015-01-28 19:46:05 +11:00
& & UmbracoContext . Application . Services . PublicAccessService . HasAccess ( path , GetCurrentMember ( ) , Roles . Provider ) ;
}
return true ;
}
2012-09-27 08:30:35 +07:00
2014-08-20 12:31:54 -06:00
/// <summary>
/// Gets (or adds) the current member from the current request cache
/// </summary>
private MembershipUser GetCurrentMember ( )
{
return UmbracoContext . Application . ApplicationCache . RequestCache
. GetCacheItem < MembershipUser > ( "UmbracoHelper.GetCurrentMember" , ( ) = >
{
var provider = Core . Security . MembershipProviderExtensions . GetMembersMembershipProvider ( ) ;
return provider . GetCurrentUser ( ) ;
} ) ;
}
2012-09-27 08:30:35 +07:00
/// <summary>
/// Whether or not the current member is logged in (based on the membership provider)
/// </summary>
/// <returns>True is the current user is logged in</returns>
public bool MemberIsLoggedOn ( )
{
2015-02-18 17:14:55 +01:00
return MembershipHelper . IsLoggedIn ( ) ;
2012-09-27 08:30:35 +07:00
}
#endregion
#region NiceUrls
/// <summary>
/// Returns a string with a friendly url from a node.
/// IE.: Instead of having /482 (id) as an url, you can have
/// /screenshots/developer/macros (spoken url)
/// </summary>
/// <param name="nodeId">Identifier for the node that should be returned</param>
/// <returns>String with a friendly url from a node</returns>
public string NiceUrl ( int nodeId )
{
2013-09-05 17:47:13 +02:00
return Url ( nodeId ) ;
2012-09-27 08:30:35 +07:00
}
2013-09-05 17:47:13 +02:00
/// <summary>
/// Gets the url of a content identified by its identifier.
/// </summary>
/// <param name="contentId">The content identifier.</param>
/// <returns>The url for the content.</returns>
public string Url ( int contentId )
{
2015-02-18 17:14:55 +01:00
return UrlProvider . GetUrl ( contentId ) ;
2013-09-05 17:47:13 +02:00
}
2013-09-28 17:13:23 +02:00
/// <summary>
/// Gets the url of a content identified by its identifier, in a specified mode.
/// </summary>
/// <param name="contentId">The content identifier.</param>
/// <param name="mode">The mode.</param>
/// <returns>The url for the content.</returns>
public string Url ( int contentId , UrlProviderMode mode )
{
2015-02-18 17:14:55 +01:00
return UrlProvider . GetUrl ( contentId , mode ) ;
2013-09-28 17:13:23 +02:00
}
2012-09-27 08:30:35 +07:00
/// <summary>
/// This method will always add the domain to the path if the hostnames are set up correctly.
/// </summary>
/// <param name="nodeId">Identifier for the node that should be returned</param>
/// <returns>String with a friendly url with full domain from a node</returns>
public string NiceUrlWithDomain ( int nodeId )
{
2013-09-05 17:47:13 +02:00
return UrlAbsolute ( nodeId ) ;
2012-09-27 08:30:35 +07:00
}
2013-09-05 17:47:13 +02:00
/// <summary>
/// Gets the absolute url of a content identified by its identifier.
/// </summary>
/// <param name="contentId">The content identifier.</param>
/// <returns>The absolute url for the content.</returns>
public string UrlAbsolute ( int contentId )
{
2015-02-18 17:14:55 +01:00
return UrlProvider . GetUrl ( contentId , true ) ;
2013-09-05 17:47:13 +02:00
}
2012-09-27 08:30:35 +07:00
#endregion
2014-03-11 14:23:51 +11:00
#region Members
public IPublishedContent TypedMember ( object id )
{
var asInt = id . TryConvertTo < int > ( ) ;
2015-02-18 17:14:55 +01:00
return asInt ? MembershipHelper . GetById ( asInt . Result ) : MembershipHelper . GetByProviderKey ( id ) ;
2014-03-11 14:23:51 +11:00
}
public IPublishedContent TypedMember ( int id )
{
2015-02-18 17:14:55 +01:00
return MembershipHelper . GetById ( id ) ;
2014-03-11 14:23:51 +11:00
}
public IPublishedContent TypedMember ( string id )
{
var asInt = id . TryConvertTo < int > ( ) ;
2015-02-18 17:14:55 +01:00
return asInt ? MembershipHelper . GetById ( asInt . Result ) : MembershipHelper . GetByProviderKey ( id ) ;
2014-03-11 14:23:51 +11:00
}
public dynamic Member ( object id )
{
var asInt = id . TryConvertTo < int > ( ) ;
return asInt
2015-02-18 17:14:55 +01:00
? MembershipHelper . GetById ( asInt . Result ) . AsDynamic ( )
: MembershipHelper . GetByProviderKey ( id ) . AsDynamic ( ) ;
2014-03-11 14:23:51 +11:00
}
public dynamic Member ( int id )
{
2015-02-18 17:14:55 +01:00
return MembershipHelper . GetById ( id ) . AsDynamic ( ) ;
2014-03-11 14:23:51 +11:00
}
public dynamic Member ( string id )
{
var asInt = id . TryConvertTo < int > ( ) ;
return asInt
2015-02-18 17:14:55 +01:00
? MembershipHelper . GetById ( asInt . Result ) . AsDynamic ( )
: MembershipHelper . GetByProviderKey ( id ) . AsDynamic ( ) ;
2014-03-11 14:23:51 +11:00
}
#endregion
#region Content
2012-09-14 09:09:23 +07:00
2014-03-11 14:23:51 +11:00
public IPublishedContent TypedContent ( object id )
2012-11-21 09:09:37 +05:00
{
2013-10-24 12:50:43 +11:00
int intId ;
2013-11-02 13:22:48 +11:00
return ConvertIdObjectToInt ( id , out intId ) ? ContentQuery . TypedContent ( intId ) : null ;
2012-11-21 09:09:37 +05:00
}
2012-10-02 22:10:18 +05:00
public IPublishedContent TypedContent ( int id )
2012-10-02 21:58:07 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContent ( id ) ;
2012-10-02 21:58:07 +05:00
}
2012-10-02 22:10:18 +05:00
public IPublishedContent TypedContent ( string id )
2012-10-02 21:58:07 +05:00
{
2013-10-24 12:50:43 +11:00
int intId ;
2013-11-02 13:22:48 +11:00
return ConvertIdObjectToInt ( id , out intId ) ? ContentQuery . TypedContent ( intId ) : null ;
2012-10-02 21:58:07 +05:00
}
2013-03-19 17:54:37 -01:00
public IPublishedContent TypedContentSingleAtXPath ( string xpath , params XPathVariable [ ] vars )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContentSingleAtXPath ( xpath , vars ) ;
2013-03-19 17:54:37 -01:00
}
2012-11-21 09:09:37 +05:00
public IEnumerable < IPublishedContent > TypedContent ( params object [ ] ids )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContent ( ConvertIdsObjectToInts ( ids ) ) ;
2012-11-21 09:09:37 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
2012-10-02 22:10:18 +05:00
public IEnumerable < IPublishedContent > TypedContent ( params int [ ] ids )
2012-10-02 21:58:07 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContent ( ids ) ;
2012-10-02 21:58:07 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedContent ( params string [ ] ids )
2012-10-02 21:58:07 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContent ( ConvertIdsObjectToInts ( ids ) ) ;
2012-10-02 21:58:07 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedContent ( IEnumerable < object > ids )
2012-11-21 09:09:37 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContent ( ConvertIdsObjectToInts ( ids ) ) ;
2012-11-21 09:09:37 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedContent ( IEnumerable < string > ids )
2012-10-02 22:55:36 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContent ( ConvertIdsObjectToInts ( ids ) ) ;
2012-10-02 22:55:36 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedContent ( IEnumerable < int > ids )
2012-10-02 22:55:36 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContent ( ids ) ;
2012-10-02 22:55:36 +05:00
}
2013-03-19 17:54:37 -01:00
public IEnumerable < IPublishedContent > TypedContentAtXPath ( string xpath , params XPathVariable [ ] vars )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContentAtXPath ( xpath , vars ) ;
2013-03-19 17:54:37 -01:00
}
2013-04-10 12:49:45 -02:00
public IEnumerable < IPublishedContent > TypedContentAtXPath ( XPathExpression xpath , params XPathVariable [ ] vars )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContentAtXPath ( xpath , vars ) ;
2013-04-10 12:49:45 -02:00
}
2013-02-02 03:22:30 +06:00
public IEnumerable < IPublishedContent > TypedContentAtRoot ( )
2013-02-01 06:28:54 -01:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedContentAtRoot ( ) ;
2013-02-01 06:28:54 -01:00
}
2012-11-21 09:09:37 +05:00
public dynamic Content ( object id )
{
2013-10-24 12:50:43 +11:00
int intId ;
2013-11-02 13:22:48 +11:00
return ConvertIdObjectToInt ( id , out intId ) ? ContentQuery . Content ( intId ) : DynamicNull . Null ;
2012-11-21 09:09:37 +05:00
}
2012-10-02 21:58:07 +05:00
public dynamic Content ( int id )
2012-09-14 09:09:23 +07:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Content ( id ) ;
2012-09-14 09:09:23 +07:00
}
2012-10-02 21:58:07 +05:00
public dynamic Content ( string id )
2012-09-14 09:09:23 +07:00
{
2013-10-24 12:50:43 +11:00
int intId ;
2013-11-02 13:22:48 +11:00
return ConvertIdObjectToInt ( id , out intId ) ? ContentQuery . Content ( intId ) : DynamicNull . Null ;
2012-09-14 09:09:23 +07:00
}
2013-03-19 17:54:37 -01:00
public dynamic ContentSingleAtXPath ( string xpath , params XPathVariable [ ] vars )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . ContentSingleAtXPath ( xpath , vars ) ;
2013-03-19 17:54:37 -01:00
}
2013-04-10 12:49:45 -02:00
public dynamic ContentSingleAtXPath ( XPathExpression xpath , params XPathVariable [ ] vars )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . ContentSingleAtXPath ( xpath , vars ) ;
2013-04-10 12:49:45 -02:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
2013-04-10 12:49:45 -02:00
public dynamic Content ( params object [ ] ids )
2012-11-21 09:09:37 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Content ( ConvertIdsObjectToInts ( ids ) ) ;
2012-11-21 09:09:37 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content ( params int [ ] ids )
2012-09-14 09:09:23 +07:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Content ( ids ) ;
2012-09-14 09:09:23 +07:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content ( params string [ ] ids )
2012-09-14 09:09:23 +07:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Content ( ConvertIdsObjectToInts ( ids ) ) ;
2012-09-14 09:09:23 +07:00
}
2012-09-27 08:30:35 +07:00
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content ( IEnumerable < object > ids )
2012-11-21 09:09:37 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Content ( ConvertIdsObjectToInts ( ids ) ) ;
2012-11-21 09:09:37 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content ( IEnumerable < int > ids )
2012-10-02 22:55:36 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Content ( ids ) ;
2012-10-02 22:55:36 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the contents corresponding to the identifiers.
/// </summary>
/// <param name="ids">The content identifiers.</param>
/// <returns>The existing contents corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing content, it will be missing in the returned value.</remarks>
public dynamic Content ( IEnumerable < string > ids )
2012-10-02 22:55:36 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Content ( ConvertIdsObjectToInts ( ids ) ) ;
2012-10-02 22:55:36 +05:00
}
2013-03-19 17:54:37 -01:00
public dynamic ContentAtXPath ( string xpath , params XPathVariable [ ] vars )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . ContentAtXPath ( xpath , vars ) ;
2013-03-19 17:54:37 -01:00
}
2013-04-10 12:49:45 -02:00
public dynamic ContentAtXPath ( XPathExpression xpath , params XPathVariable [ ] vars )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . ContentAtXPath ( xpath , vars ) ;
2013-04-10 12:49:45 -02:00
}
2013-02-01 06:28:54 -01:00
public dynamic ContentAtRoot ( )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . ContentAtRoot ( ) ;
2013-10-24 12:50:43 +11:00
}
private bool ConvertIdObjectToInt ( object id , out int intId )
{
var s = id as string ;
if ( s ! = null )
{
return int . TryParse ( s , out intId ) ;
}
if ( id is int )
{
intId = ( int ) id ;
return true ;
}
throw new InvalidOperationException ( "The value of parameter 'id' must be either a string or an integer" ) ;
}
private IEnumerable < int > ConvertIdsObjectToInts ( IEnumerable < object > ids )
{
var list = new List < int > ( ) ;
foreach ( var id in ids )
{
int intId ;
if ( ConvertIdObjectToInt ( id , out intId ) )
{
list . Add ( intId ) ;
}
}
return list ;
2013-02-01 06:28:54 -01:00
}
2012-09-14 09:09:23 +07:00
#endregion
#region Media
2012-11-21 09:09:37 +05:00
/// <summary>
/// Overloaded method accepting an 'object' type
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <remarks>
/// We accept an object type because GetPropertyValue now returns an 'object', we still want to allow people to pass
/// this result in to this method.
/// This method will throw an exception if the value is not of type int or string.
/// </remarks>
public IPublishedContent TypedMedia ( object id )
{
2013-10-24 12:50:43 +11:00
int intId ;
2013-11-02 13:22:48 +11:00
return ConvertIdObjectToInt ( id , out intId ) ? ContentQuery . TypedMedia ( intId ) : null ;
2012-11-21 09:09:37 +05:00
}
2012-10-02 22:10:18 +05:00
public IPublishedContent TypedMedia ( int id )
2012-10-02 21:58:07 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedMedia ( id ) ;
2012-10-02 21:58:07 +05:00
}
2012-09-27 08:30:35 +07:00
2012-10-02 22:10:18 +05:00
public IPublishedContent TypedMedia ( string id )
2012-10-02 21:58:07 +05:00
{
2013-10-24 12:50:43 +11:00
int intId ;
2013-11-02 13:22:48 +11:00
return ConvertIdObjectToInt ( id , out intId ) ? ContentQuery . TypedMedia ( intId ) : null ;
2012-10-02 21:58:07 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedMedia ( params object [ ] ids )
2012-11-21 09:09:37 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedMedia ( ConvertIdsObjectToInts ( ids ) ) ;
2012-11-21 09:09:37 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedMedia ( params int [ ] ids )
2012-10-02 21:58:07 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedMedia ( ids ) ;
2012-10-02 21:58:07 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedMedia ( params string [ ] ids )
2012-10-02 21:58:07 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedMedia ( ConvertIdsObjectToInts ( ids ) ) ;
2012-10-02 21:58:07 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedMedia ( IEnumerable < object > ids )
2012-11-21 09:09:37 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedMedia ( ConvertIdsObjectToInts ( ids ) ) ;
2012-11-21 09:09:37 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedMedia ( IEnumerable < int > ids )
2012-10-02 22:55:36 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedMedia ( ids ) ;
2012-10-02 22:55:36 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public IEnumerable < IPublishedContent > TypedMedia ( IEnumerable < string > ids )
2012-10-02 22:55:36 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedMedia ( ConvertIdsObjectToInts ( ids ) ) ;
2012-10-02 22:55:36 +05:00
}
2013-02-02 03:22:30 +06:00
public IEnumerable < IPublishedContent > TypedMediaAtRoot ( )
2013-02-01 06:28:54 -01:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . TypedMediaAtRoot ( ) ;
2013-02-01 06:28:54 -01:00
}
2012-11-21 09:09:37 +05:00
public dynamic Media ( object id )
{
2013-10-24 12:50:43 +11:00
int intId ;
2013-11-02 13:22:48 +11:00
return ConvertIdObjectToInt ( id , out intId ) ? ContentQuery . Media ( intId ) : DynamicNull . Null ;
2012-11-21 09:09:37 +05:00
}
2012-10-02 21:58:07 +05:00
public dynamic Media ( int id )
2012-09-14 09:09:23 +07:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Media ( id ) ;
2012-09-14 09:09:23 +07:00
}
2012-10-02 21:58:07 +05:00
public dynamic Media ( string id )
2012-09-14 09:09:23 +07:00
{
2013-10-24 12:50:43 +11:00
int intId ;
2013-11-02 13:22:48 +11:00
return ConvertIdObjectToInt ( id , out intId ) ? ContentQuery . Media ( intId ) : DynamicNull . Null ;
2012-09-14 09:09:23 +07:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media ( params object [ ] ids )
2012-11-21 09:09:37 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Media ( ConvertIdsObjectToInts ( ids ) ) ;
2012-11-21 09:09:37 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media ( params int [ ] ids )
2012-09-14 09:09:23 +07:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Media ( ids ) ;
2012-09-14 09:09:23 +07:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media ( params string [ ] ids )
2012-09-14 09:09:23 +07:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Media ( ConvertIdsObjectToInts ( ids ) ) ;
2012-09-14 09:09:23 +07:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media ( IEnumerable < object > ids )
2012-11-21 09:09:37 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Media ( ConvertIdsObjectToInts ( ids ) ) ;
2012-11-21 09:09:37 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media ( IEnumerable < int > ids )
2012-10-02 22:55:36 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Media ( ids ) ;
2012-10-02 22:55:36 +05:00
}
2015-09-04 10:42:56 +02:00
/// <summary>
/// Gets the medias corresponding to the identifiers.
/// </summary>
/// <param name="ids">The media identifiers.</param>
/// <returns>The existing medias corresponding to the identifiers.</returns>
/// <remarks>If an identifier does not match an existing media, it will be missing in the returned value.</remarks>
public dynamic Media ( IEnumerable < string > ids )
2012-10-02 22:55:36 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Media ( ConvertIdsObjectToInts ( ids ) ) ;
2012-10-02 22:55:36 +05:00
}
2013-02-01 06:28:54 -01:00
public dynamic MediaAtRoot ( )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . MediaAtRoot ( ) ;
2013-02-01 06:28:54 -01:00
}
2012-09-14 09:09:23 +07:00
#endregion
2013-10-24 12:50:43 +11:00
2012-09-14 09:09:23 +07:00
#region Search
/// <summary>
/// Searches content
/// </summary>
/// <param name="term"></param>
/// <param name="useWildCards"></param>
/// <param name="searchProvider"></param>
/// <returns></returns>
public dynamic Search ( string term , bool useWildCards = true , string searchProvider = null )
2012-10-18 08:00:07 +05:00
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Search ( term , useWildCards , searchProvider ) ;
2012-10-18 08:00:07 +05:00
}
/// <summary>
/// Searhes content
/// </summary>
/// <param name="criteria"></param>
/// <param name="searchProvider"></param>
/// <returns></returns>
public dynamic Search ( Examine . SearchCriteria . ISearchCriteria criteria , Examine . Providers . BaseSearchProvider searchProvider = null )
{
2013-11-02 13:22:48 +11:00
return ContentQuery . Search ( criteria , searchProvider ) ;
2012-10-18 08:00:07 +05:00
}
/// <summary>
/// Searches content
/// </summary>
/// <param name="term"></param>
/// <param name="useWildCards"></param>
/// <param name="searchProvider"></param>
/// <returns></returns>
public IEnumerable < IPublishedContent > TypedSearch ( string term , bool useWildCards = true , string searchProvider = null )
2012-09-14 09:09:23 +07:00
{
2014-06-05 17:30:16 +02:00
return ContentQuery . TypedSearch ( term , useWildCards , searchProvider ) ;
2012-09-14 09:09:23 +07:00
}
/// <summary>
/// Searhes content
/// </summary>
/// <param name="criteria"></param>
/// <param name="searchProvider"></param>
/// <returns></returns>
2012-10-18 08:00:07 +05:00
public IEnumerable < IPublishedContent > TypedSearch ( Examine . SearchCriteria . ISearchCriteria criteria , Examine . Providers . BaseSearchProvider searchProvider = null )
2012-09-14 09:09:23 +07:00
{
2014-06-05 17:30:16 +02:00
return ContentQuery . TypedSearch ( criteria , searchProvider ) ;
2012-09-14 09:09:23 +07:00
}
#endregion
#region Xml
public dynamic ToDynamicXml ( string xml )
{
if ( string . IsNullOrWhiteSpace ( xml ) ) return null ;
var xElement = XElement . Parse ( xml ) ;
return new DynamicXml ( xElement ) ;
}
public dynamic ToDynamicXml ( XElement xElement )
{
return new DynamicXml ( xElement ) ;
}
public dynamic ToDynamicXml ( XPathNodeIterator xpni )
{
return new DynamicXml ( xpni ) ;
}
#endregion
#region Strings
2012-09-27 08:30:35 +07:00
/// <summary>
/// Replaces text line breaks with html line breaks
/// </summary>
/// <param name="text">The text.</param>
/// <returns>The text with text line breaks replaced with html linebreaks (<br/>)</returns>
public string ReplaceLineBreaksForHtml ( string text )
{
2015-02-18 17:14:55 +01:00
return _stringUtilities . ReplaceLineBreaksForHtml ( text ) ;
2012-09-27 08:30:35 +07:00
}
/// <summary>
/// Returns an MD5 hash of the string specified
/// </summary>
/// <param name="text">The text to create a hash from</param>
/// <returns>Md5 has of the string</returns>
public string CreateMd5Hash ( string text )
{
return text . ToMd5 ( ) ;
}
2012-09-14 09:09:23 +07:00
public HtmlString StripHtml ( IHtmlString html , params string [ ] tags )
{
return StripHtml ( html . ToHtmlString ( ) , tags ) ;
}
public HtmlString StripHtml ( DynamicNull html , params string [ ] tags )
{
return new HtmlString ( string . Empty ) ;
}
public HtmlString StripHtml ( string html , params string [ ] tags )
{
2015-02-18 17:14:55 +01:00
return _stringUtilities . StripHtmlTags ( html , tags ) ;
2012-09-14 09:09:23 +07:00
}
2015-02-18 17:14:55 +01:00
2012-09-14 09:09:23 +07:00
public string Coalesce ( params object [ ] args )
{
2015-02-18 17:14:55 +01:00
return _stringUtilities . Coalesce < DynamicNull > ( args ) ;
2012-09-14 09:09:23 +07:00
}
public string Concatenate ( params object [ ] args )
{
2015-02-18 17:14:55 +01:00
return _stringUtilities . Concatenate < DynamicNull > ( args ) ;
2012-09-14 09:09:23 +07:00
}
public string Join ( string seperator , params object [ ] args )
{
2015-02-18 17:14:55 +01:00
return _stringUtilities . Join < DynamicNull > ( seperator , args ) ;
2012-09-14 09:09:23 +07:00
}
public IHtmlString Truncate ( IHtmlString html , int length )
{
return Truncate ( html . ToHtmlString ( ) , length , true , false ) ;
}
public IHtmlString Truncate ( IHtmlString html , int length , bool addElipsis )
{
return Truncate ( html . ToHtmlString ( ) , length , addElipsis , false ) ;
}
public IHtmlString Truncate ( IHtmlString html , int length , bool addElipsis , bool treatTagsAsContent )
{
return Truncate ( html . ToHtmlString ( ) , length , addElipsis , treatTagsAsContent ) ;
}
public IHtmlString Truncate ( DynamicNull html , int length )
{
return new HtmlString ( string . Empty ) ;
}
public IHtmlString Truncate ( DynamicNull html , int length , bool addElipsis )
{
return new HtmlString ( string . Empty ) ;
}
public IHtmlString Truncate ( DynamicNull html , int length , bool addElipsis , bool treatTagsAsContent )
{
return new HtmlString ( string . Empty ) ;
}
public IHtmlString Truncate ( string html , int length )
{
return Truncate ( html , length , true , false ) ;
}
public IHtmlString Truncate ( string html , int length , bool addElipsis )
{
return Truncate ( html , length , addElipsis , false ) ;
}
public IHtmlString Truncate ( string html , int length , bool addElipsis , bool treatTagsAsContent )
{
2015-02-18 17:14:55 +01:00
return _stringUtilities . Truncate ( html , length , addElipsis , treatTagsAsContent ) ;
2012-09-14 09:09:23 +07:00
}
#endregion
#region If
public HtmlString If ( bool test , string valueIfTrue , string valueIfFalse )
{
return test ? new HtmlString ( valueIfTrue ) : new HtmlString ( valueIfFalse ) ;
}
public HtmlString If ( bool test , string valueIfTrue )
{
return test ? new HtmlString ( valueIfTrue ) : new HtmlString ( string . Empty ) ;
}
#endregion
2012-09-20 13:16:38 +07:00
2014-02-21 10:17:29 +00:00
#region Prevalues
public string GetPreValueAsString ( int id )
{
2015-02-18 17:14:55 +01:00
return DataTypeService . GetPreValueAsString ( id ) ;
2014-02-21 10:17:29 +00:00
}
#endregion
2014-09-23 19:10:51 +02:00
#region canvasdesigner
2014-06-30 19:28:33 +02:00
2015-10-16 13:36:10 +02:00
[Obsolete("Use EnableCanvasDesigner on the HtmlHelper extensions instead")]
public IHtmlString EnableCanvasDesigner ( )
2014-06-30 19:28:33 +02:00
{
2014-09-23 16:30:27 +02:00
return EnableCanvasDesigner ( string . Empty , string . Empty ) ;
2014-06-30 19:28:33 +02:00
}
2015-10-16 13:36:10 +02:00
[Obsolete("Use EnableCanvasDesigner on the HtmlHelper extensions instead")]
public IHtmlString EnableCanvasDesigner ( string canvasdesignerConfigPath )
2014-06-30 19:28:33 +02:00
{
2014-09-23 19:10:51 +02:00
return EnableCanvasDesigner ( canvasdesignerConfigPath , string . Empty ) ;
2014-06-30 19:28:33 +02:00
}
2015-10-16 13:36:10 +02:00
[Obsolete("Use EnableCanvasDesigner on the HtmlHelper extensions instead")]
public IHtmlString EnableCanvasDesigner ( string canvasdesignerConfigPath , string canvasdesignerPalettesPath )
2014-05-21 13:53:00 +02:00
{
2015-10-16 13:36:10 +02:00
var html = CreateHtmlHelper ( "" ) ;
var urlHelper = new UrlHelper ( UmbracoContext . HttpContext . Request . RequestContext ) ;
return html . EnableCanvasDesigner ( urlHelper , UmbracoContext , canvasdesignerConfigPath , canvasdesignerPalettesPath ) ;
}
2014-05-21 13:53:00 +02:00
2015-10-16 13:36:10 +02:00
[Obsolete("This shouldn't need to be used but because the obsolete extension methods above don't have access to the current HtmlHelper, we need to create a fake one, unfortunately however this will not pertain the current views viewdata, tempdata or model state so should not be used")]
private HtmlHelper CreateHtmlHelper ( object model )
{
var cc = new ControllerContext
2014-05-21 13:53:00 +02:00
{
2015-10-16 13:36:10 +02:00
RequestContext = UmbracoContext . HttpContext . Request . RequestContext
} ;
var viewContext = new ViewContext ( cc , new FakeView ( ) , new ViewDataDictionary ( model ) , new TempDataDictionary ( ) , new StringWriter ( ) ) ;
var htmlHelper = new HtmlHelper ( viewContext , new ViewPage ( ) ) ;
return htmlHelper ;
}
2014-07-01 13:55:39 +02:00
2015-10-16 13:36:10 +02:00
[Obsolete("This shouldn't need to be used but because the obsolete extension methods above don't have access to the current HtmlHelper, we need to create a fake one, unfortunately however this will not pertain the current views viewdata, tempdata or model state so should not be used")]
private class FakeView : IView
{
public void Render ( ViewContext viewContext , TextWriter writer )
2014-05-30 19:56:51 +02:00
{
2014-05-21 13:53:00 +02:00
}
}
#endregion
2013-09-06 11:40:37 +10:00
/// <summary>
/// This is used in methods like BeginUmbracoForm and SurfaceAction to generate an encrypted string which gets submitted in a request for which
/// Umbraco can decrypt during the routing process in order to delegate the request to a specific MVC Controller.
/// </summary>
/// <param name="controllerName"></param>
/// <param name="controllerAction"></param>
/// <param name="area"></param>
/// <param name="additionalRouteVals"></param>
/// <returns></returns>
internal static string CreateEncryptedRouteString ( string controllerName , string controllerAction , string area , object additionalRouteVals = null )
{
Mandate . ParameterNotNullOrEmpty ( controllerName , "controllerName" ) ;
Mandate . ParameterNotNullOrEmpty ( controllerAction , "controllerAction" ) ;
Mandate . ParameterNotNull ( area , "area" ) ;
//need to create a params string as Base64 to put into our hidden field to use during the routes
var surfaceRouteParams = string . Format ( "c={0}&a={1}&ar={2}" ,
HttpUtility . UrlEncode ( controllerName ) ,
HttpUtility . UrlEncode ( controllerAction ) ,
area ) ;
var additionalRouteValsAsQuery = additionalRouteVals ! = null ? additionalRouteVals . ToDictionary < object > ( ) . ToQueryString ( ) : null ;
if ( additionalRouteValsAsQuery . IsNullOrWhiteSpace ( ) = = false )
surfaceRouteParams + = "&" + additionalRouteValsAsQuery ;
return surfaceRouteParams . EncryptWithMachineKey ( ) ;
}
2012-09-20 13:16:38 +07:00
2012-09-03 07:54:09 +07:00
}
}