webdav portal search added
This commit is contained in:
parent
cc16aca8d0
commit
82a9151241
24 changed files with 807 additions and 413 deletions
|
@ -14,6 +14,7 @@ using WebsitePanel.WebDav.Core.Config;
|
|||
using WebsitePanel.WebDav.Core.Exceptions;
|
||||
using WebsitePanel.WebDav.Core.Extensions;
|
||||
using WebsitePanel.WebDav.Core.Interfaces.Managers;
|
||||
using WebsitePanel.WebDav.Core.Interfaces.Security;
|
||||
using WebsitePanel.WebDav.Core.Resources;
|
||||
using WebsitePanel.WebDav.Core.Security.Cryptography;
|
||||
using WebsitePanel.WebDav.Core.Wsp.Framework;
|
||||
|
@ -24,15 +25,17 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
{
|
||||
private readonly ICryptography _cryptography;
|
||||
private readonly WebDavSession _webDavSession;
|
||||
private readonly IWebDavAuthorizationService _webDavAuthorizationService;
|
||||
|
||||
private readonly ILog Log;
|
||||
|
||||
private bool _isRoot = true;
|
||||
private IFolder _currentFolder;
|
||||
|
||||
public WebDavManager(ICryptography cryptography)
|
||||
public WebDavManager(ICryptography cryptography, IWebDavAuthorizationService webDavAuthorizationService)
|
||||
{
|
||||
_cryptography = cryptography;
|
||||
_webDavAuthorizationService = webDavAuthorizationService;
|
||||
Log = LogManager.GetLogger(this.GetType());
|
||||
|
||||
_webDavSession = new WebDavSession();
|
||||
|
@ -84,6 +87,36 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
return sortedChildren;
|
||||
}
|
||||
|
||||
public IEnumerable<IHierarchyItem> SearchFiles(int itemId, string pathPart, string searchValue, string uesrPrincipalName, bool recursive)
|
||||
{
|
||||
pathPart = (pathPart ?? string.Empty).Replace("/","\\");
|
||||
|
||||
var items = WspContext.Services.EnterpriseStorage.SearchFiles(itemId, pathPart, searchValue, uesrPrincipalName, recursive);
|
||||
|
||||
var resources = Convert(items, new Uri(WebDavAppConfigManager.Instance.WebdavRoot).Append(WspContext.User.OrganizationId, pathPart));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(pathPart))
|
||||
{
|
||||
var rootItems = ConnectToWebDavServer().ToArray();
|
||||
|
||||
foreach (var resource in resources)
|
||||
{
|
||||
var rootItem = rootItems.FirstOrDefault(x => x.Name == resource.DisplayName);
|
||||
|
||||
if (rootItem == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
resource.ContentLength = rootItem.Size;
|
||||
resource.AllocatedSpace = rootItem.FRSMQuotaMB;
|
||||
resource.IsRootItem = true;
|
||||
}
|
||||
}
|
||||
|
||||
return FilterResult(resources);
|
||||
}
|
||||
|
||||
public bool IsFile(string path)
|
||||
{
|
||||
string folder = GetFileFolder(path);
|
||||
|
@ -290,6 +323,7 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rootFolders;
|
||||
}
|
||||
|
||||
|
@ -307,6 +341,33 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
return pathPart.StartsWith('/' + toRemove) ? pathPart.Substring(toRemove.Length + 1) : pathPart;
|
||||
}
|
||||
|
||||
private IEnumerable<WebDavResource> Convert(IEnumerable<SystemFile> files, Uri baseUri)
|
||||
{
|
||||
var convertResult = new List<WebDavResource>();
|
||||
|
||||
var credentials = new NetworkCredential(WspContext.User.Login,
|
||||
_cryptography.Decrypt(WspContext.User.EncryptedPassword),
|
||||
WebDavAppConfigManager.Instance.UserDomain);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
var webDavitem = new WebDavResource();
|
||||
|
||||
webDavitem.SetCredentials(credentials);
|
||||
|
||||
webDavitem.SetHref(baseUri.Append(file.RelativeUrl.Replace("\\","/")));
|
||||
|
||||
webDavitem.SetItemType(file.IsDirectory? ItemType.Folder : ItemType.Resource);
|
||||
webDavitem.SetLastModified(file.Changed);
|
||||
webDavitem.ContentLength = file.Size;
|
||||
webDavitem.AllocatedSpace = file.FRSMQuotaMB;
|
||||
|
||||
convertResult.Add(webDavitem);
|
||||
}
|
||||
|
||||
return convertResult;
|
||||
}
|
||||
|
||||
private byte[] ReadFully(Stream input)
|
||||
{
|
||||
var buffer = new byte[16 * 1024];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue