Skip to content

Commit

Permalink
v7.0.4450-Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
ITHitBuild committed Sep 25, 2018
1 parent 59177ec commit ec1a656
Show file tree
Hide file tree
Showing 222 changed files with 14,104 additions and 9,719 deletions.
5 changes: 3 additions & 2 deletions CS/CalDAVServer.FileSystemStorage.AspNet/Acl/AclFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;

using ITHit.WebDAV.Server;
using ITHit.WebDAV.Server.Paging;

namespace CalDAVServer.FileSystemStorage.AspNet.Acl
{
Expand Down Expand Up @@ -38,12 +39,12 @@ public AclFolder(DavContext context) : base(context, "acl", PATH)
/// </summary>
/// <param name="propNames">Property names to be fetched lated.</param>
/// <returns>Children of this folder.</returns>
public override async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(IList<PropertyName> propNames)
public override async Task<PageResults> GetChildrenAsync(IList<PropertyName> propNames, long? offset, long? nResults, IList<OrderProperty> orderProps)
{
IList<IHierarchyItemAsync> children = new List<IHierarchyItemAsync>();
children.Add(new UserFolder(Context));
children.Add(new GroupFolder(Context));
return children;
return new PageResults(children, null);
}
}
}
10 changes: 7 additions & 3 deletions CS/CalDAVServer.FileSystemStorage.AspNet/Acl/GroupFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using ITHit.WebDAV.Server;
using ITHit.WebDAV.Server.Acl;
using ITHit.WebDAV.Server.Paging;

namespace CalDAVServer.FileSystemStorage.AspNet.Acl
{
Expand Down Expand Up @@ -39,10 +40,13 @@ public GroupFolder(DavContext context) : base(context, "groups", PATH)
/// Retrieves list of windows groups.
/// </summary>
/// <param name="properties">Properties which will be requested from the item by the engine later.</param>
/// <returns>Enumerable with groups.</returns>
public override async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(IList<PropertyName> properties)
/// <param name="offset">The number of children to skip before returning the remaining items. Start listing from from next item.</param>
/// <param name="nResults">The number of items to return.</param>
/// <param name="orderProps">List of order properties requested by the client.</param>
/// <returns>Enumerable with groups and a total number of users.</returns>
public override async Task<PageResults> GetChildrenAsync(IList<PropertyName> propNames, long? offset, long? nResults, IList<OrderProperty> orderProps)
{
return Context.PrincipalOperation<IEnumerable<IHierarchyItemAsync>>(getGroups);
return new PageResults(Context.PrincipalOperation<IEnumerable<IHierarchyItemAsync>>(getGroups), null);
}

/// <summary>
Expand Down
12 changes: 8 additions & 4 deletions CS/CalDAVServer.FileSystemStorage.AspNet/Acl/UserFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using ITHit.WebDAV.Server;
using ITHit.WebDAV.Server.Acl;
using ITHit.WebDAV.Server.Paging;

namespace CalDAVServer.FileSystemStorage.AspNet.Acl
{
Expand Down Expand Up @@ -38,11 +39,14 @@ public UserFolder(DavContext context) : base(context, "users", PATH)
/// <summary>
/// Retrieves users.
/// </summary>
/// <param name="properties">List of properties which will be retrieved by the engine later.</param>
/// <returns>Enumerable with users.</returns>
public override async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(IList<PropertyName> properties)
/// <param name="properties">List of properties which will be retrieved by the engine later.</param>
/// <param name="offset">The number of children to skip before returning the remaining items. Start listing from from next item.</param>
/// <param name="nResults">The number of items to return.</param>
/// <param name="orderProps">List of order properties requested by the client.</param>
/// <returns>Enumerable with users and a total number of users.</returns>
public override async Task<PageResults> GetChildrenAsync(IList<PropertyName> propNames, long? offset, long? nResults, IList<OrderProperty> orderProps)
{
return Context.PrincipalOperation<IEnumerable<IHierarchyItemAsync>>(getUsers);
return new PageResults(Context.PrincipalOperation<IEnumerable<IHierarchyItemAsync>>(getUsers), null);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
function InitAjaxFileBrowser() {
var webDavFolderUrl = window.opener != null ? window.opener.webDavFolderUrl : '/';
var selectedFolder = window.opener != null ? window.opener.location.href : '/';
var selectedFolder = window.opener != null ? window.opener.location.href.replace(window.opener.location.hash, '') : '/';
// Customize the look of Ajax File Browser below
// http://www.webdavsystem.com/ajaxfilebrowser/programming/settings_reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>7E714ECA-A44E-461D-80CB-55E52D54BF2F</ProjectGuid>
<ProjectGuid>1700789B-97AA-4452-AEF6-18BB99786F6A</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
Expand Down Expand Up @@ -123,10 +123,10 @@
</ItemGroup>
<ItemGroup>
<Reference Include="ITHit.WebDAV.Server">
<HintPath>..\packages\ITHit.WebDAV.Server.6.1.4325\lib\net451\ITHit.WebDAV.Server.dll</HintPath>
<HintPath>..\packages\ITHit.WebDAV.Server.7.0.4450-Beta\lib\net451\ITHit.WebDAV.Server.dll</HintPath>
</Reference>
<Reference Include="ITHit.WebDAV.Server.Web">
<HintPath>..\packages\ITHit.WebDAV.Server.Web.6.1.4325\lib\net451\ITHit.WebDAV.Server.Web.dll</HintPath>
<HintPath>..\packages\ITHit.WebDAV.Server.Web.7.0.4450-Beta\lib\net451\ITHit.WebDAV.Server.Web.dll</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup>
Expand All @@ -144,7 +144,7 @@
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>9658</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:9543/</IISUrl>
<IISUrl>http://localhost:18713/</IISUrl>
<NTLMAuthentication>True</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task<IEnumerable<ICalendarFileAsync>> QueryAsync(string rawQuery, I
{
// For the sake of simplicity we just call GetChildren returning all items.
// Typically you will return only items that match the query.
return (await GetChildrenAsync(propNames.ToList())).Cast<ICalendarFileAsync>();
return (await GetChildrenAsync(propNames.ToList(), null, null, null)).Page.Cast<ICalendarFileAsync>();
}

/// <summary>
Expand Down
96 changes: 88 additions & 8 deletions CS/CalDAVServer.FileSystemStorage.AspNet/DavFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

Expand All @@ -12,6 +13,7 @@
using CalDAVServer.FileSystemStorage.AspNet.Acl;
using CalDAVServer.FileSystemStorage.AspNet.ExtendedAttributes;
using ITHit.WebDAV.Server.Search;
using ITHit.WebDAV.Server.Paging;

namespace CalDAVServer.FileSystemStorage.AspNet
{
Expand Down Expand Up @@ -56,14 +58,17 @@ protected DavFolder(DirectoryInfo directory, DavContext context, string path)
: base(directory, context, path.TrimEnd('/') + "/")
{
dirInfo = directory;
}
}

/// <summary>
/// Called when children of this folder are being listed.
/// Called when children of this folder with paging information are being listed.
/// </summary>
/// <param name="propNames">List of properties to retrieve with the children. They will be queried by the engine later.</param>
/// <returns>Children of this folder.</returns>
public virtual async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(IList<PropertyName> propNames)
/// <param name="offset">The number of children to skip before returning the remaining items. Start listing from from next item.</param>
/// <param name="nResults">The number of items to return.</param>
/// <param name="orderProps">List of order properties requested by the client.</param>
/// <returns>Items requested by the client and a total number of items in this folder.</returns>
public virtual async Task<PageResults> GetChildrenAsync(IList<PropertyName> propNames, long? offset, long? nResults, IList<OrderProperty> orderProps)
{
// Enumerates all child files and folders.
// You can filter children items in this implementation and
Expand All @@ -73,7 +78,18 @@ public virtual async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(ILi
IList<IHierarchyItemAsync> children = new List<IHierarchyItemAsync>();

FileSystemInfo[] fileInfos = null;
long totalItems = 0;
fileInfos = dirInfo.GetFileSystemInfos();
totalItems = fileInfos.Length;

// Apply sorting.
fileInfos = SortChildren(fileInfos, orderProps);

// Apply paging.
if (offset.HasValue && nResults.HasValue)
{
fileInfos = fileInfos.Skip((int)offset.Value).Take((int)nResults.Value).ToArray();
}

foreach (FileSystemInfo fileInfo in fileInfos)
{
Expand All @@ -85,7 +101,7 @@ public virtual async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(ILi
}
}

return children;
return new PageResults(children, totalItems);
}

/// <summary>
Expand Down Expand Up @@ -152,7 +168,7 @@ public override async Task CopyToAsync(IItemCollectionAsync destFolder, string d

// Copy children.
IFolderAsync createdFolder = (IFolderAsync)await context.GetHierarchyItemAsync(targetPath);
foreach (DavHierarchyItem item in await GetChildrenAsync(new PropertyName[0]))
foreach (DavHierarchyItem item in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page)
{
if (!deep && item is DavFolder)
{
Expand Down Expand Up @@ -212,7 +228,7 @@ public override async Task MoveToAsync(IItemCollectionAsync destFolder, string d
// Move child items.
bool movedSuccessfully = true;
IFolderAsync createdFolder = (IFolderAsync)await context.GetHierarchyItemAsync(targetPath);
foreach (DavHierarchyItem item in await GetChildrenAsync(new PropertyName[0]))
foreach (DavHierarchyItem item in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page)
{
try
{
Expand Down Expand Up @@ -245,7 +261,7 @@ public override async Task DeleteAsync(MultistatusException multistatus)
}
*/
bool allChildrenDeleted = true;
foreach (IHierarchyItemAsync child in await GetChildrenAsync(new PropertyName[0]))
foreach (IHierarchyItemAsync child in (await GetChildrenAsync(new PropertyName[0], null, null, null)).Page)
{
try
{
Expand Down Expand Up @@ -274,5 +290,69 @@ private bool IsRecursive(DavFolder destFolder)
{
return destFolder.Path.StartsWith(Path);
}

/// <summary>
/// Sorts array of FileSystemInfo according to the specified order.
/// </summary>
/// <param name="fileInfos">Array of files and folders to sort.</param>
/// <param name="orderProps">Sorting order.</param>
/// <returns>Sorted list of files and folders.</returns>
private FileSystemInfo[] SortChildren(FileSystemInfo[] fileInfos, IList<OrderProperty> orderProps)
{
if (orderProps != null && orderProps.Count() != 0)
{
// map DAV properties to FileSystemInfo
Dictionary<string, string> mappedProperties = new Dictionary<string, string>()
{ { "displayname", "Name" }, { "getlastmodified", "LastWriteTime" }, { "getcontenttype", "Extension" },
{ "quota-used-bytes", "ContentLength" }, { "is-directory", "IsDirectory" } };
IOrderedEnumerable<FileSystemInfo> orderedFileInfos = null;
int index = 0;

foreach (OrderProperty ordProp in orderProps)
{
string propertyName = mappedProperties[ordProp.Property.Name];
Func<FileSystemInfo, object> sortFunc = null;
PropertyInfo propertyInfo = (typeof(FileSystemInfo)).GetProperties().FirstOrDefault(p => p.Name.Equals(propertyName, StringComparison.InvariantCultureIgnoreCase));
if (propertyInfo != null)
{
sortFunc = p => p.GetType().GetProperty(propertyInfo.Name).GetValue(p);
}
else if (propertyName == "IsDirectory")
{
sortFunc = p => p.IsDirectory();
}
else if (propertyName == "ContentLength")
{
sortFunc = p => p is FileInfo ? (p as FileInfo).Length : 0;
}

if (sortFunc != null)
{
if (index++ == 0)
{
if (ordProp.Ascending)
orderedFileInfos = fileInfos.OrderBy(sortFunc);
else
orderedFileInfos = fileInfos.OrderByDescending(sortFunc);
}
else
{
if (ordProp.Ascending)
orderedFileInfos = orderedFileInfos.ThenBy(sortFunc);
else
orderedFileInfos = orderedFileInfos.ThenByDescending(sortFunc);
}
}

}

if (orderedFileInfos != null)
{
fileInfos = orderedFileInfos.ToArray();
}
}

return fileInfos;
}
}
}
11 changes: 7 additions & 4 deletions CS/CalDAVServer.FileSystemStorage.AspNet/DavLocationFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;

using ITHit.WebDAV.Server;

using ITHit.WebDAV.Server.Paging;

namespace CalDAVServer.FileSystemStorage.AspNet
{
Expand Down Expand Up @@ -84,8 +84,11 @@ private DavLocationFolder(DirectoryInfo directory, DavContext context, string pa
/// Retrieves children of this folder: /acl/, /calendars/ and /addressbooks/ folders.
/// </summary>
/// <param name="propNames">Properties requested by client application for each child.</param>
/// <param name="offset">The number of children to skip before returning the remaining items. Start listing from from next item.</param>
/// <param name="nResults">The number of items to return.</param>
/// <param name="orderProps">List of order properties requested by the client.</param>
/// <returns>Children of this folder.</returns>
public override async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(IList<PropertyName> propNames)
public override async Task<PageResults> GetChildrenAsync(IList<PropertyName> propNames, long? offset, long? nResults, IList<OrderProperty> orderProps)
{
List<IHierarchyItemAsync> children = new List<IHierarchyItemAsync>();

Expand All @@ -94,9 +97,9 @@ public override async Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(IL
children.Add(new Acl.AclFolder(context));

// Get [DavLocation]/calendars/ and [DavLocation]/addressbooks/ folders.
children.AddRange(await base.GetChildrenAsync(propNames));
children.AddRange((await base.GetChildrenAsync(propNames, null, null, null)).Page);

return children;
return new PageResults(children, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ public static async Task<bool> IsExtendedAttributesSupportedAsync(this FileSyste
return await extendedAttribute.IsExtendedAttributesSupportedAsync(info.FullName);
}

/// <summary>
/// Checks whether a FileInfo or DirectoryInfo object is a directory, or intended to be a directory.
/// </summary>
/// <param name="fileSystemInfo"></param>
/// <returns></returns>
public static bool IsDirectory(this FileSystemInfo fileSystemInfo)
{
if (fileSystemInfo == null)
{
return false;
}

if ((int)fileSystemInfo.Attributes != -1)
{
// if attributes are initialized check the directory flag
return fileSystemInfo.Attributes.HasFlag(FileAttributes.Directory);
}

return fileSystemInfo is DirectoryInfo;
}


/// <summary>
/// Checks extended attribute existence.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion CS/CalDAVServer.FileSystemStorage.AspNet/LogicalFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;

using ITHit.WebDAV.Server;
using ITHit.WebDAV.Server.Paging;

namespace CalDAVServer.FileSystemStorage.AspNet
{
Expand Down Expand Up @@ -65,6 +66,6 @@ public async Task UpdatePropertiesAsync(IList<PropertyValue> setProps, IList<Pro
throw new NotImplementedException();
}

public abstract Task<IEnumerable<IHierarchyItemAsync>> GetChildrenAsync(IList<PropertyName> propNames);
public abstract Task<PageResults> GetChildrenAsync(IList<PropertyName> propNames, long? offset, long? nResults, IList<OrderProperty> orderProps);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task GetPageDataAsync()
// Get list of folders that contain user calendars and enumerate calendars in each folder.
foreach (IItemCollectionAsync folder in await discovery.GetCalendarHomeSetAsync())
{
IEnumerable<IHierarchyItemAsync> children = await folder.GetChildrenAsync(new PropertyName[0]);
IEnumerable<IHierarchyItemAsync> children = (await folder.GetChildrenAsync(new PropertyName[0], null, null, null)).Page;
AllUserCalendars.AddRange(children.Where(x => x is ICalendarFolderAsync));
}
}
Expand Down
4 changes: 2 additions & 2 deletions CS/CalDAVServer.FileSystemStorage.AspNet/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ITHit.WebDAV.Server" version="6.1.4325" targetFramework="net451" />
<package id="ITHit.WebDAV.Server.Web" version="6.1.4325" targetFramework="net451" />
<package id="ITHit.WebDAV.Server" version="7.0.4450-Beta" targetFramework="net451" />
<package id="ITHit.WebDAV.Server.Web" version="7.0.4450-Beta" targetFramework="net451" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net451" />
</packages>
Loading

0 comments on commit ec1a656

Please sign in to comment.