Пример #1
0
 private static T ExecuteQuery <T>(Client.Requests.IQuery <T> query, string[] select = null, string[] expand = null)
     where T : Models.ODataObject
 {
     if (select != null)
     {
         foreach (var s in select)
         {
             query.Select(s);
         }
     }
     if (expand != null)
     {
         foreach (var e in expand)
         {
             query.Expand(e);
             if (select != null)
             {
                 query.Select(e);
             }
         }
     }
     try
     {
         return(query.Execute());
     }
     catch (ODataException e)
     {
         if (e.Code != System.Net.HttpStatusCode.NotFound)
         {
             throw e;
         }
     }
     return(default(T));
 }
Пример #2
0
 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);
     }
 }
Пример #3
0
 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);
     }
 }