public static Models.Item GetShareFileItem(ShareFileDriveInfo driveInfo, string path, string[] select = null, string[] expand = null) { Client.Requests.IQuery <Models.Item> query = null; if (!string.IsNullOrEmpty(path)) { // this regex matches all supported powershell path syntaxes: // drive-qualified - users:/username // provider-qualified - membership::users:/username // provider-internal - users:/username var match = Regex.Match(path, @"(?:membership::)?(?:\w+:[\\/])?(?<path>.+)$", RegexOptions.IgnoreCase); if (match.Success) { string sfPath = match.Groups["path"].Value; sfPath = sfPath.Replace('\\', '/'); if (!sfPath.StartsWith("/")) { sfPath = "/" + sfPath; } query = driveInfo.RootUri != null?driveInfo.Client.Items.ByPath(driveInfo.RootUri, sfPath) : driveInfo.Client.Items.ByPath(sfPath); } } else { query = driveInfo.RootUri != null?driveInfo.Client.Items.Get(driveInfo.RootUri) : driveInfo.Client.Items.ByPath("/"); } if (query != null) { return(ExecuteQuery <Models.Item>(query, select, expand)); } else { return(null); } }
public static Models.ODataFeed <Models.Item> GetShareFileChildren(ShareFileDriveInfo driveInfo, string path, string[] select = null, string[] expand = null) { var item = GetShareFileItem(driveInfo, path, new string[] { "Id", "url" }); if (item != null && item is Models.Folder) { var query = driveInfo.Client.Items.GetChildren(item.url); return(ExecuteQuery <Models.ODataFeed <Models.Item> >(query, select, expand)); } return(null); }
public static IEnumerable <Models.Item> GetShareFileItems(ShareFileDriveInfo driveInfo, string path, string[] select = null, string[] expand = null) { Client.Requests.IQuery <Models.ODataFeed <Models.Item> > query = null; if (!string.IsNullOrEmpty(path)) { // this regex matches all supported powershell path syntaxes: // drive-qualified - users:/username // provider-qualified - membership::users:/username // provider-internal - users:/username var match = Regex.Match(path, @"(?:membership::)?(?:\w+:[\\/])?(?<path>.+)$", RegexOptions.IgnoreCase); if (match.Success) { string sfPath = match.Groups["path"].Value; sfPath = sfPath.Replace('\\', '/'); if (!sfPath.StartsWith("/")) { sfPath = "/" + sfPath; } if (sfPath.IndexOf('*') > 0) { var starIndex = sfPath.LastIndexOf('*'); var parentIdx = sfPath.LastIndexOf('/'); if (parentIdx >= 0) { var sfPathParent = parentIdx > 0 ? sfPath.Substring(0, parentIdx) : "/"; var sfPathFile = sfPath.Substring(parentIdx + 1, starIndex - parentIdx - 1); var sfItem = (driveInfo.RootUri != null ? driveInfo.Client.Items.ByPath(driveInfo.RootUri, sfPathParent) : driveInfo.Client.Items.ByPath(sfPathParent)).Select("Id").Execute(); var filter = new StartsWithFilter("Name", sfPathFile, true); query = driveInfo.Client.Items.GetChildren(sfItem.url).Filter(filter); } } } } if (query != null) { var feed = ExecuteQuery <Models.ODataFeed <Models.Item> >(query, select, expand); return(feed.Feed); } else { return(null); } }