本文整理汇总了C#中UmbracoHelper.TypedMedia方法的典型用法代码示例。如果您正苦于以下问题:C# UmbracoHelper.TypedMedia方法的具体用法?C# UmbracoHelper.TypedMedia怎么用?C# UmbracoHelper.TypedMedia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UmbracoHelper
的用法示例。
在下文中一共展示了UmbracoHelper.TypedMedia方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}));
}
示例2: 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;
}
示例3: ParseMedia
public static S3PublishedContent ParseMedia(string mediaId, UmbracoHelper umbracoHelper)
{
var media = umbracoHelper.TypedMedia(mediaId);
if (media != null)
{
var output = new S3PublishedContent(media);
output.Url = string.Format("{0}{1}", GlobalHelper.GetCdnDomain(), output.Url());
return output;
}
return null;
}
示例4: PrepareModel
private static List<NewsAjaxModel> PrepareModel(IEnumerable<IContent> news)
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
return news.Select(content => new NewsAjaxModel
{
shortDesc = content.Properties.First(x => x.Alias == "shortDesc").Value.ToString().RemoveParagraphs(),
shortDate = content.Properties.First(x => x.Alias == "shortDate").Value.ToString().RemoveParagraphs(),
shortTitle = content.Properties.First(x => x.Alias == "shortTitle").Value.ToString().RemoveParagraphs(),
shortIconUrl = umbracoHelper.TypedMedia(content.Properties.First(x => x.Alias == "shortIcon").Value).Url,
url = library.NiceUrl(Convert.ToInt32(content.Id)),
type = content.Properties.First(x => x.Alias == "typeDropdown").Value.ToString().RemoveParagraphs()
}).ToList();
}
示例5: Map
public static UmbracoImage Map(string imageId, UmbracoHelper helper, string cropName = CropHelper.ProductThumbnail)
{
if (!string.IsNullOrWhiteSpace(imageId))
{
var image = helper.TypedMedia(imageId);
if (image != null)
{
UmbracoImage umbImg = new UmbracoImage();
umbImg.ImageUrl = image.Url;
umbImg.AltText = image.Name;
umbImg.Crop = image.GetCrop(cropName);
return umbImg;
}
}
return null;
}
示例6: ConvertFrom
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var helper = new UmbracoHelper(UmbracoContext.Current);
if (value is JObject)
{
var model = JsonConvert.DeserializeObject<Image>(value.ToString());
if (model.id > 0)
{
model.Media = helper.TypedMedia(model.id);
return model;
}
}
return null;
}
示例7: MapMediaFile
/// <summary>
/// Native mapper for mapping a media picker property
/// </summary>
/// <param name="mapper">The mapper</param>
/// <param name="contentToMapFrom">Umbraco content item to map from</param>
/// <param name="propName">Name of the property to map</param>
/// <param name="isRecursive">Flag to indicate if property should be retrieved recursively up the tree</param>
/// <returns>MediaFile instance</returns>
public static object MapMediaFile(IUmbracoMapper mapper, IPublishedContent contentToMapFrom,
string propName, bool isRecursive)
{
// If Umbraco Core Property Editor Converters will get IPublishedContent, so try that first
var media = contentToMapFrom.GetPropertyValue<IPublishedContent>(propName, isRecursive, null);
if (media == null)
{
// If Umbraco Core Property Editor Converters not installed, need to dig out the Id
var mediaId = contentToMapFrom.GetPropertyValue<string>(propName, isRecursive, string.Empty);
if (!string.IsNullOrEmpty(mediaId))
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
media = umbracoHelper.TypedMedia(mediaId);
}
}
if (media != null)
{
return GetMediaFile(media, mapper.AssetsRootUrl);
}
return null;
}
示例8: MapMediaFileCollection
/// <summary>
/// Native mapper for mapping a multiple media picker property
/// </summary>
/// <param name="mapper">The mapper</param>
/// <param name="contentToMapFrom">Umbraco content item to map from</param>
/// <param name="propName">Name of the property to map</param>
/// <param name="isRecursive">Flag to indicate if property should be retrieved recursively up the tree</param>
/// <returns>MediaFile instance</returns>
public static object MapMediaFileCollection(IUmbracoMapper mapper, IPublishedContent contentToMapFrom,
string propName, bool isRecursive)
{
// If Umbraco Core Property Editor Converters will get IEnumerable<IPublishedContent>, so try that first
var mediaCollection = contentToMapFrom.GetPropertyValue<IEnumerable<IPublishedContent>>(propName, isRecursive, null);
if (mediaCollection == null)
{
// Also check for single IPublishedContent (which could get if multiple media disabled)
var media = contentToMapFrom.GetPropertyValue<IPublishedContent>(propName, isRecursive, null);
if (media != null)
{
mediaCollection = new List<IPublishedContent> { media };
}
if (mediaCollection == null)
{
// If Umbraco Core Property Editor Converters not installed, need to dig out the Ids
var mediaIds = contentToMapFrom.GetPropertyValue<string>(propName, isRecursive, string.Empty);
if (!string.IsNullOrEmpty(mediaIds))
{
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
mediaCollection = new List<IPublishedContent>();
foreach (var mediaId in mediaIds.Split(','))
{
((List<IPublishedContent>)mediaCollection).Add(umbracoHelper.TypedMedia(mediaId));
}
}
}
}
if (mediaCollection != null)
{
return GetMediaFileCollection(mediaCollection, mapper.AssetsRootUrl);
}
return null;
}
示例9: GetUmbracoObjectType
/// <summary>
/// temp replacement for built-in uQuery method (as that hits the database)
/// </summary>
/// <param name="id">the id of a content, media or member item</param>
/// <returns>an enum instance of the UmbracoObjectType</returns>
internal static uQuery.UmbracoObjectType GetUmbracoObjectType(int id)
{
// return variable
uQuery.UmbracoObjectType umbracoObjectType = uQuery.UmbracoObjectType.Unknown;
UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
// attempt to get content
if (umbracoHelper.TypedContent(id) != null)
{
umbracoObjectType = uQuery.UmbracoObjectType.Document;
}
else
{
// attempt to get media
if(umbracoHelper.TypedMedia(id) != null)
{
umbracoObjectType = uQuery.UmbracoObjectType.Media;
}
else
{
// attempt to get member
try
{
if (umbracoHelper.TypedMember(id) != null)
{
umbracoObjectType = uQuery.UmbracoObjectType.Member;
}
}
catch
{
// HACK: suppress Umbraco error
}
}
}
return umbracoObjectType;
}
示例10: GetImageUrl
/// <summary>
/// Gets image url by its id
/// </summary>
/// <param name="pictureID"></param>
/// <param name="cropName"></param>
/// <returns></returns>
public static string GetImageUrl(int pictureID, string cropName = "")
{
var result = "";
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var picture = umbracoHelper.TypedMedia(pictureID);
if (picture != null)
{
result = picture.GetPropertyValue<String>("umbracoFile");
if (cropName != "")
{
var crop = picture.AsDynamic().imageCropper.crops.Find("@name", cropName);
result = crop.url;
}
}
return result;
}
示例11: PurgeCloudflareCacheForMedia
protected void PurgeCloudflareCacheForMedia(IMediaService sender, SaveEventArgs<IMedia> e)
{
//If we have the cache buster turned off then just return.
if (!CloudflareConfiguration.Instance.PurgeCacheOn) { return; }
List<Crop> imageCropSizes = ImageCropperManager.Instance.GetAllCrops();
List<string> urls = new List<string>();
UmbracoHelper uh = new UmbracoHelper(UmbracoContext.Current);
//GetUmbracoDomains
IEnumerable<string> domains = UmbracoFlareDomainManager.Instance.AllowedDomains;
//delete the cloudflare cache for the saved entities.
foreach (IMedia media in e.SavedEntities)
{
if(media.IsNewEntity())
{
//If its new we don't want to purge the cache as this causes slow upload times.
continue;
}
try
{
//Check to see if the page has cache purging on publish disabled.
if (media.GetValue<bool>("cloudflareDisabledOnPublish"))
{
//it was disabled so just continue;
continue;
}
}
catch (Exception ex)
{
//continue;
}
IPublishedContent publishedMedia = uh.TypedMedia(media.Id);
if (publishedMedia == null)
{
e.Messages.Add(new EventMessage("Cloudflare Caching", "We could not find the IPublishedContent version of the media: "+media.Id+" you are trying to save.", EventMessageType.Error));
continue;
}
foreach(Crop crop in imageCropSizes)
{
urls.Add(publishedMedia.GetCropUrl(crop.alias));
}
urls.Add(publishedMedia.Url);
}
List<StatusWithMessage> results = CloudflareManager.Instance.PurgePages(UrlHelper.MakeFullUrlWithDomain(urls, domains,true));
if (results.Any() && results.Where(x => !x.Success).Any())
{
e.Messages.Add(new EventMessage("Cloudflare Caching", "We could not purge the Cloudflare cache. \n \n" + CloudflareManager.PrintResultsSummary(results), EventMessageType.Warning));
}
else if(results.Any())
{
e.Messages.Add(new EventMessage("Cloudflare Caching", "Successfully purged the cloudflare cache.", EventMessageType.Success));
}
}
示例12: GetAgentsSearchResult
public ActionResult GetAgentsSearchResult(string locationSearchText, string agentSearchText)
{
object result;
try
{
UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext);
int agentsMediaFolderId = 1408;
IEnumerable<Agent> agentEntities;
if (!String.IsNullOrEmpty(locationSearchText))
{
agentEntities = new GleanerDbContext().Agents.Where(x => x.HomeCity.Contains(locationSearchText)
|| x.HomeState.Contains(locationSearchText)
|| x.HomeZip.Contains(locationSearchText));
}
else if (!String.IsNullOrEmpty(agentSearchText))
{
agentEntities = new GleanerDbContext().Agents.Where(x => x.AgentFirstName.Contains(agentSearchText)
|| x.AgentLastName.Contains(agentSearchText));
}
else
{
agentEntities = new GleanerDbContext().Agents;
}
IEnumerable<IPublishedContent> agentMedias = null;
var agents = agentEntities.OrderBy(y => y.AgentFirstName + " " + y.AgentLastName).Select(x =>
{
var address = String.Format("{0}, {1}, {2} {3}", x.HomeCity == null ? null : x.HomeCity.Trim(), x.HomeStreet == null ? null : x.HomeStreet.Trim(), x.HomeState, x.HomeZip);
if (agentMedias == null)
{
agentMedias = umbracoHelper.TypedMedia(agentsMediaFolderId).Children;
}
IPublishedContent media;
char firstLetter = String.IsNullOrEmpty(x.AgentLastName) ? '0' : x.AgentLastName[0];
if (firstLetter <= 60)
{
media = agentMedias.First();
}
else if (firstLetter <= 72)
{
media = agentMedias.ElementAt(1);
}
else
{
media = agentMedias.Last();
}
return new
{
name = x.AgentFirstName + " " + x.AgentLastName,
url = "/agents/agent/?agentId=" + x.AgentNumber,
LatLng = "33.095783,-96.746641".Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries),
direction = "",
AgentPhoto = media.Url,
address,
x.AgcAgencyName,
x.BusinessPhone1,
x.EmailAddress
};
}
);
result = new
{
success = true,
data = HtmlHelperExtension.SerializeToJson(null, agents, false).ToHtmlString()
};
}
catch (Exception ex)
{
result = new
{
error = true,
exception = ex.Message
};
}
return Json(result, JsonRequestBehavior.AllowGet);
}
示例13: ConvertDataToSource
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
{
if (source == null)
{
return new UrlPicker.Umbraco.Models.UrlPicker();
}
var sourceString = source.ToString();
if (sourceString.DetectIsJson())
{
try
{
var pickers = JsonConvert.DeserializeObject<IEnumerable<Models.UrlPicker>>(sourceString);
var helper = new UmbracoHelper(UmbracoContext.Current);
foreach (var picker in pickers)
{
if (picker.TypeData.ContentId != null)
{
picker.TypeData.Content = helper.TypedContent(picker.TypeData.ContentId);
}
if (picker.TypeData.MediaId != null)
{
picker.TypeData.Media = helper.TypedMedia(picker.TypeData.MediaId);
}
switch (picker.Type)
{
case Models.UrlPicker.UrlPickerTypes.Content:
if (picker.TypeData.Content != null)
{
picker.Url = picker.TypeData.Content.Url;
picker.UrlAbsolute = picker.TypeData.Content.UrlAbsolute();
picker.Name = (picker.Meta.Title.IsNullOrWhiteSpace()) ? picker.TypeData.Content.Name : picker.Meta.Title;
}
break;
case Models.UrlPicker.UrlPickerTypes.Media:
if (picker.TypeData.Media != null)
{
picker.Url = picker.TypeData.Media.Url;
picker.UrlAbsolute = picker.TypeData.Media.Url();
picker.Name = (picker.Meta.Title.IsNullOrWhiteSpace()) ? picker.TypeData.Media.Name : picker.Meta.Title;
}
break;
default:
picker.Url = picker.TypeData.Url;
picker.UrlAbsolute = picker.TypeData.Url;
picker.Name = (picker.Meta.Title.IsNullOrWhiteSpace()) ? picker.TypeData.Url : picker.Meta.Title;
break;
}
}
return pickers;
}
catch (Exception ex)
{
LogHelper.Error<UrlPickerValueConverter>(ex.Message, ex);
return new List<UrlPicker.Umbraco.Models.UrlPicker>();
}
}
return sourceString;
}
示例14: Configure
protected override void Configure()
{
Mapper.CreateMap<IPublishedContent, MetaTagsModel>()
.ForMember(model => model.Keywords, expression => expression.ResolveUsing(node => node.GetPropertyValue<string>("metaKeywords")))
.ForMember(model => model.Description, expression => expression.ResolveUsing(node => node.GetPropertyValue<string>("metaDescription")));
Mapper.CreateMap<IPublishedContent, MainMenuModel>()
.ForMember(model => model.Items, expression => expression.ResolveUsing(node =>
{
var items = new List<MainMenuItemModel>();
var homePage = node.AncestorOrSelf(1);
items.Add(new MainMenuItemModel { IsSelected = (node.Id == homePage.Id), Link = "/", Title = "Home" });
var mainMenuNode = node.AncestorOrSelf(2);
foreach (var childNode in homePage.Children.Where(content =>
content.DocumentTypeAlias.Equals("Content", StringComparison.OrdinalIgnoreCase) ||
content.DocumentTypeAlias.Equals("ContentInteractiveImage", StringComparison.OrdinalIgnoreCase) ||
content.DocumentTypeAlias.Equals("SubMenu", StringComparison.OrdinalIgnoreCase)))
{
items.Add(new MainMenuItemModel
{
IsSelected = (mainMenuNode != null && childNode.Id == mainMenuNode.Id),
Link = childNode.Url,
Title = childNode.GetTitle()
});
}
return items;
}));
Mapper.CreateMap<IPublishedContent, FooterLinksModel>()
.ForMember(model => model.LeftSectionLinks, expression => expression.ResolveUsing(node =>
{
var helper = new UmbracoHelper(UmbracoContext.Current);
var items = new List<FooterLinkModel>();
foreach (var childNode in GetFooterChildNodes(node))
{
var item = new FooterLinkModel();
item.Title = childNode.GetTitle();
if (childNode.DocumentTypeAlias.Equals("Content", StringComparison.OrdinalIgnoreCase))
{
item.IsExternal = false;
item.Url = childNode.Url;
}
else if (childNode.DocumentTypeAlias.Equals("InternalLink", StringComparison.OrdinalIgnoreCase))
{
item.IsExternal = false;
var linkNode = helper.TypedContent(childNode.GetPropertyValue<int>("link"));
if (linkNode != null)
item.Url = linkNode.Url;
}
else if (childNode.DocumentTypeAlias.Equals("InternalMediaLink", StringComparison.OrdinalIgnoreCase))
{
item.IsExternal = false;
var linkMedia = helper.TypedMedia(childNode.GetPropertyValue<int>("link"));
if (linkMedia != null)
item.Url = linkMedia.GetPropertyValue<string>("umbracoFile");
}
else if (childNode.DocumentTypeAlias.Equals("ExternalLink", StringComparison.OrdinalIgnoreCase))
{
item.IsExternal = true;
item.Disclaimer = _stringModifier.CleanJSString(childNode.GetPropertyValue<string>("disclaimer"));
item.Url = childNode.GetPropertyValue<string>("link");
}
else
{
continue;
}
items.Add(item);
}
return items;
}));
}
示例15: ConvertSourceToObject
public override object ConvertSourceToObject(PublishedPropertyType propertyType, object source, bool preview)
{
if (source == null)
{
return new Models.UrlPicker();
}
var sourceString = source.ToString();
if (sourceString.DetectIsJson())
{
try
{
// hack to update v0.14 or lower version items to new format
if (sourceString.StartsWith("{"))
{
sourceString = string.Format("[{0}]", sourceString);
}
var pickers = JsonConvert.DeserializeObject<IEnumerable<Models.UrlPicker>>(sourceString);
var helper = new UmbracoHelper(UmbracoContext.Current);
foreach (var picker in pickers)
{
if (picker.TypeData.ContentId != null)
{
picker.TypeData.Content = helper.TypedContent(picker.TypeData.ContentId);
}
if (picker.TypeData.MediaId != null)
{
picker.TypeData.Media = helper.TypedMedia(picker.TypeData.MediaId);
}
switch (picker.Type)
{
case Models.UrlPicker.UrlPickerTypes.Content:
if (picker.TypeData.Content != null)
{
picker.Url = picker.TypeData.Content.Url;
picker.UrlAbsolute = picker.TypeData.Content.UrlAbsolute();
picker.Name = (picker.Meta.Title.IsNullOrWhiteSpace()) ? picker.TypeData.Content.Name : picker.Meta.Title;
}
break;
case Models.UrlPicker.UrlPickerTypes.Media:
if (picker.TypeData.Media != null)
{
picker.Url = picker.TypeData.Media.Url;
picker.UrlAbsolute = picker.TypeData.Media.Url();
picker.Name = (picker.Meta.Title.IsNullOrWhiteSpace()) ? picker.TypeData.Media.Name : picker.Meta.Title;
}
break;
default:
picker.Url = picker.TypeData.Url;
picker.UrlAbsolute = picker.TypeData.Url;
picker.Name = (picker.Meta.Title.IsNullOrWhiteSpace()) ? picker.TypeData.Url : picker.Meta.Title;
break;
}
}
if (IsMultipleDataType(propertyType.DataTypeId))
{
return pickers.Yield().Where(x => x != null);
}
else
{
return pickers.FirstOrDefault();
}
}
catch (Exception ex)
{
LogHelper.Error<UrlPickerValueConverter>(ex.Message, ex);
if (IsMultipleDataType(propertyType.DataTypeId))
{
return Enumerable.Empty<Models.UrlPicker>();
}
else
{
return new Models.UrlPicker();
}
}
}
return sourceString;
}