本文整理汇总了C#中UmbracoHelper类的典型用法代码示例。如果您正苦于以下问题:C# UmbracoHelper类的具体用法?C# UmbracoHelper怎么用?C# UmbracoHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UmbracoHelper类属于命名空间,在下文中一共展示了UmbracoHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Post
// POST umbraco/api/umbcontact/post
public HttpResponseMessage Post([FromBody]UmbContactMail message)
{
// Return errors if the model validation fails
// The model defines validations for empty or invalid email addresses
// See the UmbContactMail class below
if (ModelState.IsValid == false)
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState.First().Value.Errors.First().ErrorMessage);
// In order to allow editors to configure the email address where contact
// mails will be sent, we require that to be set in a property with the
// alias umbEmailTo - This property needs to be sent into this API call
var umbraco = new UmbracoHelper(UmbracoContext);
var content = umbraco.TypedContent(message.SettingsNodeId);
if (content == null)
return Request.CreateErrorResponse(HttpStatusCode.BadRequest,
"Please provide a valid node Id on which the umbEmailTo property is defined.");
var mailTo = content.GetPropertyValue<string>("umbEmailTo");
if (string.IsNullOrWhiteSpace(mailTo))
return Request.CreateErrorResponse(HttpStatusCode.BadRequest,
string.Format("The umbEmailTo property on node {0} (Id {1}) does not exists or has not been filled in.",
content.Name, content.Id));
// If we have a valid email address to send the email to, we can try to
// send it. If the is an error, it's most likely caused by a wrong SMTP configuration
return TrySendMail(message, mailTo)
? new HttpResponseMessage(HttpStatusCode.OK)
: Request.CreateErrorResponse(HttpStatusCode.ServiceUnavailable,
"Could not send email. Make sure the server settings in the mailSettings section of the Web.config file are configured correctly. For a detailed error, check ~/App_Data/Logs/UmbracoTraceLog.txt.");
}
示例2: GetListOfCommentsForPage
public List<CommentViewModel> GetListOfCommentsForPage()
{
UmbracoHelper helper = new UmbracoHelper(this.UmbracoContext);
// IPublishedContent content = helper.TypedContent(PageId);
IPublishedContent content = helper.TypedContentAtRoot().FirstOrDefault();
List<CommentViewModel> ListOfComments = new List<CommentViewModel>();
var ListOfCommentsContent = content.DescendantsOrSelf("Comment");
foreach (var item in ListOfCommentsContent)
{
if (item.ContentType.Alias == "Comment")
{
ListOfComments.Add(new CommentViewModel
{
Name = item.GetPropertyValue("name").ToString(),
Email = item.GetPropertyValue("email").ToString(),
Comment = item.GetPropertyValue("comment").ToString(),
DateAndTime = item.GetPropertyValue("dateAndTime").ToString()
});
}
}
return ListOfComments;
}
示例3: CreateMainNav
public static IList<MenuItem> CreateMainNav(this IPublishedContent currentContent)
{
var items = new List<MenuItem>();
var homeNode = currentContent.AncestorOrSelf(1);
var umbracoConextProvider = DependencyResolver.Current.GetService<IUmbracoConextProvider>();
var umbracoHelper = new UmbracoHelper(umbracoConextProvider.GetUmbracoContext());
//Home Page
//items.Add(new MenuItem
//{
// Id = homeNode.Id,
// IsActive = homeNode.Id == currentContent.Id,
// Name = homeNode.Name,
// NodeTypeAlias = homeNode.DocumentTypeAlias,
// Url = homeNode.Url,
// SortOrder = homeNode.SortOrder,
// Content=homeNode,
// IsVisible = homeNode.IsVisible()
//});
items.AddRange(GetMenuItmes(homeNode, currentContent, 2, umbracoHelper));
return items;
}
示例4: ToBasketViewLineItem
///
/// Utility extension to map a to a BasketViewLine item.
/// Notice that the ContentId is pulled from the extended data. The name can either
/// be the Merchello product name via lineItem.Name or the Umbraco content page
/// name with umbracoHelper.Content(contentId).Name
///
///
///The to be mapped
///
private static BasketViewLineItem ToBasketViewLineItem(this ILineItem lineItem)
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var contentId = lineItem.ExtendedData.ContainsKey("umbracoContentId") ? int.Parse(lineItem.ExtendedData["umbracoContentId"]) : 0;
var umbracoName = umbracoHelper.Content(contentId).Name;
var merchelloProductName = lineItem.Name;
return new BasketViewLineItem()
{
Key = lineItem.ExtendedData.GetProductKey(),// lineItem.Key,
ContentId = contentId,
ExtendedData = DictionaryToString(lineItem.ExtendedData),
Name = merchelloProductName,
//Name = umbracoName,
Sku = lineItem.Sku,
UnitPrice = lineItem.Price,
TotalPrice = lineItem.TotalPrice,
Quantity = lineItem.Quantity,
Images = lineItem.ExtendedData.GetValue("images")
};
}
示例5: UmbracoApiController
protected UmbracoApiController(UmbracoContext umbracoContext)
{
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
UmbracoContext = umbracoContext;
InstanceId = Guid.NewGuid();
Umbraco = new UmbracoHelper(umbracoContext);
}
示例6: Configure
protected override void Configure()
{
Mapper.CreateMap<IPublishedContent, ContentInteractiveImageModel>()
.ForMember(model => model.ExplanationsText, expression => expression.ResolveUsing(node => node.GetPropertyValue<string>("explanationsText")))
.ForMember(model => model.FooterText, expression => expression.ResolveUsing(node => node.GetPropertyValue<string>("bodyText")))
.ForMember(model => model.Image, expression => expression.ResolveUsing(node =>
{
var helper = new UmbracoHelper(UmbracoContext.Current);
var imageMedia = helper.TypedMedia(node.GetPropertyValue<int>("image"));
if (imageMedia == null)
return string.Empty;
return imageMedia.Url;
}))
.ForMember(model => model.Items, expression => expression.ResolveUsing(node =>
{
var items = new List<ContentInteractiveImageItemModel>();
foreach (var childNode in node.Children.Where(content => content.DocumentTypeAlias.Equals("InteractiveImagePopUp", StringComparison.OrdinalIgnoreCase)))
{
items.Add(new ContentInteractiveImageItemModel
{
BodyText = childNode.GetPropertyValue<string>("bodyText"),
Title = childNode.GetPropertyValue<string>("title"),
BottomRightY = childNode.GetPropertyValue<int>("bottomRightY"),
BottomRightX = childNode.GetPropertyValue<int>("bottomRightX"),
TopLeftX = childNode.GetPropertyValue<int>("topLeftX"),
TopLeftY = childNode.GetPropertyValue<int>("topLeftY")
});
}
return items;
}));
}
示例7: Company
public IPublishedContent Company()
{
var memberCompany = GetMember();
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
// DKO: získá napojení na stránku firmy z nastavení uživatele v členské sekci
return umbracoHelper.Content(memberCompany.Properties["CompanyPage"].Value);
}
示例8: VideoService
// private readonly IMemberService _memberService;
public VideoService(IContentService content)
{
_content = content;
_context = new UmbracoContextProvider();
//var umbracoConextProvider = DependencyResolver.Current.GetService<IUmbracoConextProvider>();
_umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
}
示例9: GetSiteMap
/// <summary>
/// Возвращает дерево узлов для вывода человеческой карты сайта.
/// Каждый объект в коллекции представляет собой дублет, где
/// Item1 — узел документа (IPublishedContent),
/// Item2 — поддерево аналогичной структуры (пустое для листьев).
/// </summary>
/// <returns></returns>
public static Tuple<IPublishedContent, dynamic> GetSiteMap()
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var mainPage = umbracoHelper.TypedContentSingleAtXPath("/root/pubMainPage");
if (mainPage == null) throw new Exception("Не найдена главная страница сайта.");
return Tuple.Create<IPublishedContent, dynamic>(mainPage, GetBranch(mainPage));
}
示例10: Crawl
/// <summary>
/// The crawl.
/// </summary>
/// <param name="site">
/// The site.
/// </param>
/// <param name="doc">
/// The doc.
/// </param>
public void Crawl(UmbracoContext site, XmlDocument doc)
{
/*
* We're going to crawl the site layer-by-layer which will put the upper levels
* of the site nearer the top of the sitemap.xml document as opposed to crawling
* the tree by parent/child relationships, which will go deep on each branch before
* crawling the entire site.
*/
var helper = new UmbracoHelper(UmbracoContext.Current);
var siteRoot = helper.TypedContentAtRoot().First();
var node = SitemapGenerator.CreateNode(siteRoot, site);
if (node.IsPage && node.IsListedInNavigation && node.ShouldIndex)
{
SitemapGenerator.AppendUrlElement(doc, node);
}
var items = siteRoot.Descendants();
if (items != null)
{
foreach (var item in items)
{
node = SitemapGenerator.CreateNode(item, site);
if (node.IsPage && node.IsListedInNavigation && node.ShouldIndex)
{
SitemapGenerator.AppendUrlElement(doc, node);
}
}
}
}
示例11: RenderDocTypeGridEditorItem
public static HtmlString RenderDocTypeGridEditorItem(this HtmlHelper helper,
IPublishedContent content,
string viewPath = "",
string actionName = "",
object model = null)
{
if (content == null)
return new HtmlString(string.Empty);
var controllerName = content.DocumentTypeAlias + "Surface";
if (!string.IsNullOrWhiteSpace(viewPath))
viewPath = viewPath.TrimEnd('/') + "/";
if (string.IsNullOrWhiteSpace(actionName))
actionName = content.DocumentTypeAlias;
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
if (umbracoHelper.SurfaceControllerExists(controllerName, actionName, true))
{
return helper.Action(actionName, controllerName, new
{
dtgeModel = model ?? content,
dtgeViewPath = viewPath
});
}
if (!string.IsNullOrWhiteSpace(viewPath))
return helper.Partial(viewPath + content.DocumentTypeAlias + ".cshtml", content);
return helper.Partial(content.DocumentTypeAlias, content);
}
示例12: GetStoreRoot
/// <summary>
/// The get store root.
/// </summary>
/// <returns>
/// The <see cref="IPublishedContent"/>.
/// </returns>
public static IPublishedContent GetStoreRoot()
{
if (StoreRoot != null) return StoreRoot;
var umbraco = new UmbracoHelper(UmbracoContext.Current);
StoreRoot = umbraco.TypedContentSingleAtXPath(WebConfigurationManager.AppSettings["Bazaar:XpathToStore"]);
return StoreRoot;
}
示例13: GetImageUrl
public static string GetImageUrl(this UmbracoContext context, IPublishedContent node, string propertyName)
{
var helper = new UmbracoHelper(context);
var imageId = node.GetPropertyValue<int>(propertyName);
var typedMedia = helper.TypedMedia(imageId);
return typedMedia != null ? typedMedia.Url : null;
}
示例14: GetAllUrlsForWildCardUrls
public IEnumerable<string> GetAllUrlsForWildCardUrls(IEnumerable<string> wildCardUrls, UmbracoHelper uh)
{
List<string> resolvedUrls = new List<string>();
if (wildCardUrls == null || !wildCardUrls.Any())
{
return resolvedUrls;
}
IEnumerable<string> allContentUrls = GetAllContentUrls(uh);
foreach(string wildCardUrl in wildCardUrls)
{
if(!wildCardUrl.Contains('*'))
{
//it doesnt even contain a wildcard.
continue;
}
//Make one for modifing
string mutableWildCardUrl = wildCardUrl;
//take off the trailing slash if there is one
mutableWildCardUrl = mutableWildCardUrl.TrimEnd('/');
//take off the *
mutableWildCardUrl = mutableWildCardUrl.TrimEnd('*');
//We can get wild cards by seeing if any of the urls start with the mutable wild card url
resolvedUrls.AddRange(allContentUrls.Where(x => x.StartsWith(mutableWildCardUrl)));
}
return resolvedUrls;
}
示例15: XmlRssHandler
public XmlRssHandler()
{
umbContext = UmbracoContext.Current;
appContext = ApplicationContext.Current;
services = appContext.Services;
helper = new UmbracoHelper( umbContext );
}