/// <summary> /// Exports an <see cref="IMedia"/> item to xml as an <see cref="XElement"/> /// </summary> /// <param name="media">Media to export</param> /// <param name="deep">Optional parameter indicating whether to include descendents</param> /// <returns><see cref="XElement"/> containing the xml representation of the Media object</returns> internal XElement Export(IMedia media, bool deep = false) { //nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias); var nodeName = UmbracoSettings.UseLegacyXmlSchema ? "node" : media.ContentType.Alias.ToSafeAliasWithForcingCheck(); var xml = Export(media, nodeName); xml.Add(new XAttribute("nodeType", media.ContentType.Id)); xml.Add(new XAttribute("writerName", media.GetCreatorProfile().Name)); xml.Add(new XAttribute("writerID", media.CreatorId)); xml.Add(new XAttribute("version", media.Version)); xml.Add(new XAttribute("template", 0)); xml.Add(new XAttribute("nodeTypeAlias", media.ContentType.Alias)); if (deep) { var descendants = media.Descendants().ToArray(); var currentChildren = descendants.Where(x => x.ParentId == media.Id); AddChildXml(descendants, currentChildren, xml); } var medias = new XElement("MediaSet", xml); return(medias); }
/// <summary> /// Populates the properties. /// </summary> /// <param name="imageMedia">The image media.</param> /// <param name="userService">The user service.</param> private void PopulateProperties(IMedia imageMedia, IUserService userService) { Id = imageMedia.Id; Name = imageMedia.Name; Path = imageMedia.Path; CreatorName = imageMedia.GetCreatorProfile(userService).Name; CreateDate = imageMedia.CreateDate; UpdateDate = imageMedia.UpdateDate; }
/// <summary> /// Populates the properties. /// </summary> /// <param name="media">The image media.</param> /// <param name="userService">The user service.</param> /// <param name="includeChildrenDetails">if set to <c>true</c> [include children details].</param> private void PopulateProperties(IMedia media, IUserService userService, bool includeChildrenDetails) { Id = media.Id; Name = media.Name; Path = media.Path; CreatorName = media.GetCreatorProfile(userService).Name; IncludeChildrenDetails = includeChildrenDetails; if (includeChildrenDetails) { NumberOfFolders = media.Children().Where(p => p.ContentType.Alias == MediaTypeAlias.Folder).Count(); NumberOfImages = media.Children().Where(p => p.ContentType.Alias == MediaTypeAlias.Image).Count(); } }
/// <summary> /// Creates the xml representation for the <see cref="IMedia"/> object /// </summary> /// <param name="media"><see cref="IContent"/> to generate xml for</param> /// <returns>Xml representation of the passed in <see cref="IContent"/></returns> public static XElement ToXml(this IMedia media) { //nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias); var nodeName = UmbracoSettings.UseLegacyXmlSchema ? "node" : media.ContentType.Alias.ToSafeAliasWithForcingCheck(); var x = media.ToXml(nodeName); x.Add(new XAttribute("nodeType", media.ContentType.Id)); x.Add(new XAttribute("writerName", media.GetCreatorProfile().Name)); x.Add(new XAttribute("writerID", media.CreatorId)); x.Add(new XAttribute("version", media.Version)); x.Add(new XAttribute("template", 0)); if (UmbracoSettings.UseLegacyXmlSchema) { x.Add(new XAttribute("nodeTypeAlias", media.ContentType.Alias)); } return(x); }
/// <summary> /// Exports an <see cref="IMedia"/> item to xml as an <see cref="XElement"/> /// </summary> /// <param name="mediaService"></param> /// <param name="dataTypeService"></param> /// <param name="userService"></param> /// <param name="media">Media to export</param> /// <param name="deep">Optional parameter indicating whether to include descendents</param> /// <returns><see cref="XElement"/> containing the xml representation of the Media object</returns> public XElement Serialize(IMediaService mediaService, IDataTypeService dataTypeService, IUserService userService, IMedia media, bool deep = false) { //nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias); var nodeName = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema ? "node" : media.ContentType.Alias.ToSafeAliasWithForcingCheck(); var xml = Serialize(dataTypeService, media, nodeName); xml.Add(new XAttribute("nodeType", media.ContentType.Id)); xml.Add(new XAttribute("writerName", media.GetCreatorProfile(userService).Name)); xml.Add(new XAttribute("writerID", media.CreatorId)); xml.Add(new XAttribute("version", media.Version)); xml.Add(new XAttribute("template", 0)); xml.Add(new XAttribute("nodeTypeAlias", media.ContentType.Alias)); if (deep) { var descendants = mediaService.GetDescendants(media).ToArray(); var currentChildren = descendants.Where(x => x.ParentId == media.Id); AddChildXml(mediaService, dataTypeService, userService, descendants, currentChildren, xml); } return(xml); }
/// <summary> /// Exports an <see cref="IMedia"/> item to xml as an <see cref="XElement"/> /// </summary> /// <param name="media">Media to export</param> /// <param name="deep">Optional parameter indicating whether to include descendents</param> /// <returns><see cref="XElement"/> containing the xml representation of the Media object</returns> internal XElement Export(IMedia media, bool deep = false) { //nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias); var nodeName = UmbracoSettings.UseLegacyXmlSchema ? "node" : media.ContentType.Alias.ToSafeAliasWithForcingCheck(); var xml = Export(media, nodeName); xml.Add(new XAttribute("nodeType", media.ContentType.Id)); xml.Add(new XAttribute("writerName", media.GetCreatorProfile().Name)); xml.Add(new XAttribute("writerID", media.CreatorId)); xml.Add(new XAttribute("version", media.Version)); xml.Add(new XAttribute("template", 0)); xml.Add(new XAttribute("nodeTypeAlias", media.ContentType.Alias)); if (deep) { var descendants = media.Descendants().ToArray(); var currentChildren = descendants.Where(x => x.ParentId == media.Id); AddChildXml(descendants, currentChildren, xml); } return xml; }