using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using AutoMapper; using WebsitePanel.WebDav.Core.Client; using WebsitePanel.WebDav.Core.Config; using WebsitePanel.WebDav.Core.Extensions; using WebsitePanel.WebDavPortal.FileOperations; using WebsitePanel.WebDavPortal.Models.FileSystem; namespace WebsitePanel.WebDavPortal.Mapping.Profiles.Webdav { public class ResourceTableItemProfile : Profile { /// /// Gets the name of the profile. /// /// /// The name of the profile. /// public override string ProfileName { get { return this.GetType().Name; } } /// /// Override this method in a derived class and call the CreateMap method to associate that map with this profile. /// Avoid calling the class from this method. /// protected override void Configure() { var openerManager = new FileOpenerManager(); Mapper.CreateMap() .ForMember(ti => ti.DisplayName, x => x.MapFrom(hi => hi.DisplayName.Trim('/'))) .ForMember(ti => ti.Href, x => x.MapFrom(hi => hi.Href)) .ForMember(ti => ti.Type, x => x.MapFrom(hi => hi.ItemType.GetDescription().ToLowerInvariant())) .ForMember(ti => ti.IconHref, x => x.MapFrom(hi => hi.ItemType == ItemType.Folder ? WebDavAppConfigManager.Instance.FileIcons.FolderPath.Trim('~') : WebDavAppConfigManager.Instance.FileIcons[Path.GetExtension(hi.DisplayName.Trim('/'))].Trim('~'))) .ForMember(ti => ti.IsTargetBlank, x => x.MapFrom(hi => openerManager.GetIsTargetBlank(hi))) .ForMember(ti => ti.LastModified, x => x.MapFrom(hi => hi.LastModified)) .ForMember(ti => ti.LastModifiedFormated, x => x.MapFrom(hi => hi.LastModified == DateTime.MinValue ? "--" : (new WebDavResource(null, hi)).LastModified.ToString("dd/MM/yyyy hh:mm tt"))) .ForMember(ti => ti.Size, x => x.MapFrom(hi => hi.ContentLength)) .ForMember(ti => ti.IsFolder, x => x.MapFrom(hi => hi.ItemType == ItemType.Folder)); } } }