diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs b/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs index d339b384..e5ff425c 100644 --- a/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs +++ b/WebsitePanel/Sources/WebsitePanel.Providers.EnterpriseStorage.Windows2012/Windows2012.cs @@ -297,7 +297,7 @@ namespace WebsitePanel.Providers.EnterpriseStorage searchPaths = searchPaths.Where(x => !string.IsNullOrEmpty(x)).ToArray(); } - using (new WindowsIdentity(userPrincipalName).Impersonate()) + //using (new WindowsIdentity(userPrincipalName).Impersonate()) { using (var conn = new OleDbConnection("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';")) { @@ -341,7 +341,6 @@ namespace WebsitePanel.Providers.EnterpriseStorage file.RelativeUrl = file.FullName.Replace(Path.Combine(rootFolder, searchPath), "").Trim('\\'); } } - result.Add(file); } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/Entities/OpenerCollection.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/Entities/OpenerCollection.cs new file mode 100644 index 00000000..3ec0e347 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/Entities/OpenerCollection.cs @@ -0,0 +1,38 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using WebsitePanel.WebDav.Core.Config.WebConfigSections; +using WebsitePanel.WebDavPortal.WebConfigSections; + +namespace WebsitePanel.WebDav.Core.Config.Entities +{ + public class OpenerCollection : AbstractConfigCollection, IReadOnlyCollection + { + private readonly IList _targetBlankMimeTypeExtensions; + + public OpenerCollection() + { + _targetBlankMimeTypeExtensions = ConfigSection.TypeOpener.Cast().ToList(); + } + + public IEnumerator GetEnumerator() + { + return _targetBlankMimeTypeExtensions.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count + { + get { return _targetBlankMimeTypeExtensions.Count; } + } + + public bool Contains(string extension) + { + return _targetBlankMimeTypeExtensions.Any(x => x.Extension == extension); + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/IWebDavAppConfig.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/IWebDavAppConfig.cs index e4c882c8..86ce78de 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/IWebDavAppConfig.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/IWebDavAppConfig.cs @@ -14,5 +14,6 @@ namespace WebsitePanel.WebDav.Core.Config OfficeOnlineCollection OfficeOnline { get; } OwaSupportedBrowsersCollection OwaSupportedBrowsers { get; } FilesToIgnoreCollection FilesToIgnore { get; } + OpenerCollection FileOpener { get; } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OpenerElement.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OpenerElement.cs new file mode 100644 index 00000000..8df1ac80 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OpenerElement.cs @@ -0,0 +1,33 @@ +using System; +using System.Configuration; + +namespace WebsitePanel.WebDav.Core.Config.WebConfigSections +{ + public class OpenerElement : ConfigurationElement + { + private const string ExtensionKey = "extension"; + private const string MemeTypeKey = "mimeType"; + private const string TargetBlankKey = "isTargetBlank"; + + [ConfigurationProperty(ExtensionKey, IsKey = true, IsRequired = true)] + public string Extension + { + get { return this[ExtensionKey].ToString(); } + set { this[ExtensionKey] = value; } + } + + [ConfigurationProperty(MemeTypeKey, IsKey = true, IsRequired = true)] + public string MimeType + { + get { return this[MemeTypeKey].ToString(); } + set { this[MemeTypeKey] = value; } + } + + [ConfigurationProperty(TargetBlankKey, IsKey = true, IsRequired = true)] + public bool IstargetBlank + { + get { return Convert.ToBoolean(this[TargetBlankKey]); } + set { this[TargetBlankKey] = value; } + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OpenerElementCollection.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OpenerElementCollection.cs new file mode 100644 index 00000000..5d32ba9c --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/OpenerElementCollection.cs @@ -0,0 +1,19 @@ +using System; +using System.Configuration; + +namespace WebsitePanel.WebDav.Core.Config.WebConfigSections +{ + [ConfigurationCollection(typeof(OpenerElement))] + public class OpenerElementCollection : ConfigurationElementCollection + { + protected override ConfigurationElement CreateNewElement() + { + return new OpenerElement(); + } + + protected override object GetElementKey(ConfigurationElement element) + { + return ((OpenerElement)element).Extension; + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/WebDavExplorerConfigurationSettingsSection.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/WebDavExplorerConfigurationSettingsSection.cs index 46c9aa48..d471a912 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/WebDavExplorerConfigurationSettingsSection.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebConfigSections/WebDavExplorerConfigurationSettingsSection.cs @@ -19,6 +19,7 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections private const string OwaSupportedBrowsersKey = "owaSupportedBrowsers"; private const string OfficeOnlineKey = "officeOnline"; private const string FilesToIgnoreKey = "filesToIgnore"; + private const string TypeOpenerKey = "typeOpener"; public const string SectionName = "webDavExplorerConfigurationSettings"; @@ -99,6 +100,13 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections set { this[OfficeOnlineKey] = value; } } + [ConfigurationProperty(TypeOpenerKey, IsDefaultCollection = false)] + public OpenerElementCollection TypeOpener + { + get { return (OpenerElementCollection)this[TypeOpenerKey]; } + set { this[TypeOpenerKey] = value; } + } + [ConfigurationProperty(FilesToIgnoreKey, IsDefaultCollection = false)] public FilesToIgnoreElementCollection FilesToIgnore { diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebDavAppConfigManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebDavAppConfigManager.cs index 6256228d..696c1d54 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebDavAppConfigManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Config/WebDavAppConfigManager.cs @@ -20,6 +20,7 @@ namespace WebsitePanel.WebDav.Core.Config OfficeOnline = new OfficeOnlineCollection(); OwaSupportedBrowsers = new OwaSupportedBrowsersCollection(); FilesToIgnore = new FilesToIgnoreCollection(); + FileOpener = new OpenerCollection(); } public static WebDavAppConfigManager Instance @@ -60,5 +61,6 @@ namespace WebsitePanel.WebDav.Core.Config public OfficeOnlineCollection OfficeOnline { get; private set; } public OwaSupportedBrowsersCollection OwaSupportedBrowsers { get; private set; } public FilesToIgnoreCollection FilesToIgnore { get; private set; } + public OpenerCollection FileOpener { get; private set; } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IResource.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IResource.cs index 81ba89af..d1545431 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IResource.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IResource.cs @@ -83,7 +83,6 @@ namespace WebsitePanel.WebDav.Core { { var property = _properties.FirstOrDefault(x => x.Name.Name == "getcontenttype"); - return property == null ? MediaTypeNames.Application.Octet : property.StringValue; } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj index da6f7c89..67043bd5 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj @@ -107,6 +107,7 @@ + @@ -119,10 +120,12 @@ + + diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs index 5664658a..c4c8591b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs @@ -84,7 +84,9 @@ namespace WebsitePanel.WebDavPortal.Controllers { var resource = _webdavManager.GetResource(pathPart); - return new FileStreamResult(resource.GetReadStream(), resource.ContentType); + var mimeType = _openerManager.GetMimeType(Path.GetExtension(pathPart)); + + return new FileStreamResult(resource.GetReadStream(), mimeType); } try @@ -347,6 +349,11 @@ namespace WebsitePanel.WebDavPortal.Controllers break; } } + + if (Request.Browser.IsMobileDevice) + { + item.IsTargetBlank = false; + } } } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerManager.cs index d068a277..a362692d 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerManager.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Net; +using System.Net.Mime; using System.Web; using System.Web.Mvc; using WebsitePanel.WebDav.Core; @@ -14,12 +15,21 @@ namespace WebsitePanel.WebDavPortal.FileOperations { public class FileOpenerManager { + private readonly IDictionary _officeOperationTypes = new Dictionary(); private readonly IDictionary _operationTypes = new Dictionary(); public FileOpenerManager() { if (WebDavAppConfigManager.Instance.OfficeOnline.IsEnabled) - _operationTypes.AddRange(WebDavAppConfigManager.Instance.OfficeOnline.ToDictionary(x => x.Extension, y => FileOpenerType.OfficeOnline)); + { + _officeOperationTypes.AddRange( + WebDavAppConfigManager.Instance.OfficeOnline.ToDictionary(x => x.Extension, + y => FileOpenerType.OfficeOnline)); + } + + _operationTypes.AddRange( + WebDavAppConfigManager.Instance.FileOpener.ToDictionary(x => x.Extension, + y => FileOpenerType.Open)); } public string GetUrl(IHierarchyItem item, UrlHelper urlHelper) @@ -48,14 +58,35 @@ namespace WebsitePanel.WebDavPortal.FileOperations public bool GetIsTargetBlank(IHierarchyItem item) { var opener = this[Path.GetExtension(item.DisplayName)]; + var result = false; switch (opener) { case FileOpenerType.OfficeOnline: - return true; - default: - return false; + { + result = true; + break; + } + case FileOpenerType.Open: + { + result = true; + break; + } } + + return result; + } + + public string GetMimeType(string extension) + { + var opener = WebDavAppConfigManager.Instance.FileOpener.FirstOrDefault(x => x.Extension.ToLowerInvariant() == extension.ToLowerInvariant()); + + if (opener == null) + { + return MediaTypeNames.Application.Octet; + } + + return opener.MimeType; } public FileOpenerType this[string fileExtension] @@ -63,8 +94,16 @@ namespace WebsitePanel.WebDavPortal.FileOperations get { FileOpenerType result; - if (_operationTypes.TryGetValue(fileExtension, out result) && CheckBrowserSupport()) + if (_officeOperationTypes.TryGetValue(fileExtension, out result) && CheckBrowserSupport()) + { return result; + } + + if (_operationTypes.TryGetValue(fileExtension, out result)) + { + return result; + } + return FileOpenerType.Download; } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerType.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerType.cs index af460893..9483893e 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerType.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/FileOperations/FileOpenerType.cs @@ -2,6 +2,6 @@ { public enum FileOpenerType { - Download, OfficeOnline + Download, OfficeOnline, Open } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Mapping/Profiles/Webdav/ResourceTableItemProfile.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Mapping/Profiles/Webdav/ResourceTableItemProfile.cs index b38bad24..a20e44b3 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Mapping/Profiles/Webdav/ResourceTableItemProfile.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Mapping/Profiles/Webdav/ResourceTableItemProfile.cs @@ -43,8 +43,7 @@ namespace WebsitePanel.WebDavPortal.Mapping.Profiles.Webdav .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.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)); diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml index 26739b88..274f677b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml @@ -1,4 +1,5 @@ -@using WebsitePanel.WebDav.Core +@using System.Net.Mime +@using WebsitePanel.WebDav.Core @using WebsitePanel.WebDav.Core.Client @using WebsitePanel.WebDav.Core.Config @using WebsitePanel.WebDavPortal.FileOperations @@ -11,7 +12,8 @@ @{ string actualPath = Model.ItemType == ItemType.Folder ? "~/Content/Images/folder_100x100.png" : WebDavAppConfigManager.Instance.FileIcons[Path.GetExtension(Model.DisplayName.Trim('/'))]; string name = Model.DisplayName.Trim('/'); - var opener = new FileOpenerManager()[Path.GetExtension(Model.DisplayName)]; + var _opener = new FileOpenerManager(); + var opener = _opener[Path.GetExtension(Model.DisplayName)]; bool isTargetBlank; string href = "/"; switch (opener) @@ -31,6 +33,13 @@ bool showStatistic = Model.ItemType == ItemType.Folder && Model.IsRootItem && resource != null; + var contentTypeProperty = Model.Properties.FirstOrDefault(x => x.Name.Name == "getcontenttype"); + + if (isTargetBlank == false && Model.ItemType != ItemType.Folder) + { + isTargetBlank = _opener.GetIsTargetBlank(Model) && !Request.Browser.IsMobileDevice; + } + int percent = 0; if (showStatistic) diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config index 06262a66..265b5f6e 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Web.config @@ -92,6 +92,13 @@ + + + + + + +