Пример #1
0
 internal PnPCore.IList GetList(PnP.Core.Services.PnPContext context, params System.Linq.Expressions.Expression <Func <PnPCore.IList, object> >[] selectors)
 {
     PnPCore.IList returnList = null;
     if (_corelist != null)
     {
         returnList = _corelist;
     }
     if (_list != null)
     {
         returnList = context.Web.Lists.GetById(_list.Id, selectors);
     }
     else if (_id != Guid.Empty)
     {
         returnList = context.Web.Lists.GetById(_id, selectors);
     }
     else if (!string.IsNullOrEmpty(_name))
     {
         returnList = context.Web.Lists.GetByTitle(_name, selectors);
         if (returnList == null)
         {
             var url = _name;
             context.Web.EnsurePropertiesAsync(w => w.ServerRelativeUrl).GetAwaiter().GetResult();
             if (!_name.ToLower().StartsWith(context.Web.ServerRelativeUrl.ToLower()))
             {
                 url = $"{context.Web.ServerRelativeUrl}/{url.TrimStart('/')}";
             }
             try
             {
                 returnList = context.Web.Lists.GetByServerRelativeUrl(url, selectors);
             }
             catch (PnP.Core.SharePointRestServiceException)
             {
                 throw new PSInvalidOperationException("List not found");
             }
         }
     }
     if (returnList != null)
     {
         returnList.EnsureProperties(l => l.Id, l => l.OnQuickLaunch, l => l.Title, l => l.Hidden, l => l.ContentTypesEnabled, l => l.RootFolder);
     }
     return(returnList);
 }
Пример #2
0
 internal PnPCore.IList GetList(PnPBatch batch, bool throwError = true, params System.Linq.Expressions.Expression <Func <PnPCore.IList, object> >[] selectors)
 {
     PnPCore.IList returnList = null;
     if (_corelist != null)
     {
         returnList = _corelist;
     }
     if (_list != null)
     {
         var batchedList = batch.GetCachedList(_list.Id);
         if (batchedList != null)
         {
             return(batchedList);
         }
         returnList = batch.Context.Web.Lists.GetById(_list.Id, selectors);
     }
     else if (_id != Guid.Empty)
     {
         var batchedList = batch.GetCachedList(_id);
         if (batchedList != null)
         {
             return(batchedList);
         }
         returnList = batch.Context.Web.Lists.GetById(_id, selectors);
     }
     else if (!string.IsNullOrEmpty(_name))
     {
         var batchedList = batch.GetCachedList(_name);
         if (batchedList != null)
         {
             return(batchedList);
         }
         returnList = batch.Context.Web.Lists.GetByTitle(_name, selectors);
         if (returnList == null)
         {
             var url = _name;
             batch.Context.Web.EnsureProperties(w => w.ServerRelativeUrl);
             if (!_name.ToLower().StartsWith(batch.Context.Web.ServerRelativeUrl.ToLower()))
             {
                 url = $"{batch.Context.Web.ServerRelativeUrl}/{url.TrimStart('/')}";
             }
             try
             {
                 batchedList = batch.GetCachedList(url);
                 if (batchedList != null)
                 {
                     return(batchedList);
                 }
                 returnList = batch.Context.Web.Lists.GetByServerRelativeUrl(url, selectors);
             }
             catch (PnP.Core.SharePointRestServiceException e) when((e.Error as PnP.Core.SharePointRestError)?.Code == "System.IO.FileNotFoundException" && !throwError)
             {
                 return(null);
             }
             catch (PnP.Core.SharePointRestServiceException ex)
             {
                 throw new PSInvalidOperationException((ex.Error as PnP.Core.SharePointRestError).Message);
             }
         }
     }
     if (returnList != null)
     {
         returnList.EnsureProperties(l => l.Id, l => l.OnQuickLaunch, l => l.Title, l => l.Hidden, l => l.ContentTypesEnabled, l => l.RootFolder, l => l.Fields.QueryProperties(f => f.Id, f => f.Title, f => f.InternalName, f => f.TypeAsString));
         batch.CacheList(returnList);
     }
     return(returnList);
 }