本文整理汇总了C#中UmbracoHelper.Media方法的典型用法代码示例。如果您正苦于以下问题:C# UmbracoHelper.Media方法的具体用法?C# UmbracoHelper.Media怎么用?C# UmbracoHelper.Media使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UmbracoHelper
的用法示例。
在下文中一共展示了UmbracoHelper.Media方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetThumbnailUrl
/// <summary>
/// Gets thumbnail url.
/// Checks if thumbnail is defined in post, if not - returns crop of main image, if it is absent - default thumbnail image crop.
///
/// Priority: 1.Thumbnail 2.Image 3.Default site thumbnail
///
/// TODO: checking for crops and creating files from coordinates, get solution to helper problem (use services)
/// </summary>
/// <param name="post"></param>
/// <param name="cropName"></param>
/// <param name="cropThumb">use thumbnail crop if set to true</param>
/// <param name="useDefaultThumb">use default image if thumb is not found</param>
/// <returns>thumbnail url</returns>
public static String GetThumbnailUrl(IPublishedContent post, String cropName = "", bool cropThumb = false)
{
String result = "";
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
try
{
var thumbnailID = post.GetPropertyValue("thumbnail");
if (thumbnailID == null || thumbnailID == String.Empty)
{
//no thumbnail
var pictureID = post.GetPropertyValue("image");
if (pictureID != String.Empty && pictureID != null)
{
var picture = umbracoHelper.Media(pictureID);
if (cropName != "")
{
var thumbnail = picture.AsDynamic().imageCropper.crops.Find("@name", cropName);
result = thumbnail.url;
}
}
else
{
//return default thumb
IMediaService mediaService = ApplicationContext.Current.Services.MediaService;
IEnumerable<IMedia> buffer = mediaService.GetByLevel(1).Where(x => x.Name == "Default");
if (buffer.Any())
{
IMedia defaultFolder = buffer.First();
buffer = mediaService.GetChildren(defaultFolder.Id);
if (buffer.Any())
{
buffer = buffer.Where(x => x.Name == "default-thumbnail");
if (buffer.Any() && cropName != "")
{
IMedia defaultThumb = buffer.First();
result = GetCrop(defaultThumb.GetValue<String>("imageCropper"), cropName);
}
}
}
}
}
else
{
var thumbnail = umbracoHelper.Media(thumbnailID);
result = thumbnail.Url;
if (cropThumb && cropName != "")
{
thumbnail = thumbnail.AsDynamic().imageCropper.crops.Find("@name", cropName);
result = thumbnail.url;
}
}
}
catch (Exception e)
{
if (UmbracoContext.Current.IsDebug)
{
//throw e;
}
}
return result;
}
示例2: TranslateSearchResultToBlogEntry
public static BlogEntry TranslateSearchResultToBlogEntry(IPublishedContent results)
{
var helper = new UmbracoHelper(UmbracoContext.Current);
var post = new BlogEntry();
post.Title = results.GetPropertyValue<string>("uBlogsyContentTitle");
var auth = helper.Content(results.GetPropertyValue<string>("uBlogsyPostAuthor"));
post.Author = auth.uBlogsyAuthorName;
var date = results.GetPropertyValue<string>("uBlogsyPostDate");
post.Date = DateTime.Parse(date).ToString("D");
var image = results.GetPropertyValue<string>("uBlogsyPostImage");
if (!string.IsNullOrEmpty(image))
post.Image = helper.Media(image).umbracoFile;
post.Summary = results.GetPropertyValue<string>("uBlogsyContentSummary");
post.Url = results.Url();
return post;
}