webdav portal search added

This commit is contained in:
vfedosevich 2015-02-24 06:43:38 -08:00
parent cc16aca8d0
commit 82a9151241
24 changed files with 807 additions and 413 deletions

View file

@ -251,14 +251,14 @@ namespace WebsitePanel.WebDav.Core
{
get
{
string displayName = _href.AbsoluteUri.Replace(_baseUri.AbsoluteUri, "");
string displayName = _href.AbsoluteUri.Trim('/').Replace(_baseUri.AbsoluteUri.Trim('/'), "");
displayName = Regex.Replace(displayName, "\\/$", "");
Match displayNameMatch = Regex.Match(displayName, "([\\/]+)$");
if (displayNameMatch.Success)
{
displayName = displayNameMatch.Groups[1].Value;
}
return HttpUtility.UrlDecode(displayName);
return HttpUtility.UrlDecode(displayName.Trim('/'));
}
}
@ -473,15 +473,10 @@ namespace WebsitePanel.WebDav.Core
public void SetHref(Uri href)
{
_href = href;
string baseUri = _href.Scheme + "://" + _href.Host;
for (int i = 0; i < _href.Segments.Length - 1; i++)
{
if (_href.Segments[i] != "/")
{
baseUri += "/" + _href.Segments[i];
}
}
_baseUri = new Uri(baseUri);
var baseUrl = href.AbsoluteUri.Remove(href.AbsoluteUri.Length - href.Segments.Last().Length);
_baseUri = new Uri(baseUrl);
}
/// <summary>

View file

@ -14,6 +14,7 @@ namespace WebsitePanel.WebDav.Core.Interfaces.Managers
void UploadFile(string path, HttpPostedFileBase file);
void UploadFile(string path, byte[] bytes);
void UploadFile(string path, Stream stream);
IEnumerable<IHierarchyItem> SearchFiles(int itemId, string pathPart, string searchValue, string uesrPrincipalName, bool recursive);
IResource GetResource(string path);
string GetFileUrl(string path);
void DeleteResource(string path);

View file

@ -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];