internal PnPCore.IContentType GetContentTypeOrWarn(Cmdlet cmdlet, PnPCore.IList list)
        {
            var ct = GetContentType(list);

            if (ct is null)
            {
                cmdlet.WriteWarning(NotFoundMessage(list));
            }

            return(ct);
        }
Пример #2
0
 internal PnPCore.IListItem GetListItem(PnPCore.IList list)
 {
     PnPCore.IListItem item = null;
     if (_coreItem != null)
     {
         item = _coreItem;
     }
     if (_id != uint.MinValue)
     {
         item = list.Items.GetById((int)_id);
     }
     return(item);
 }
        internal PnP.Core.Model.SharePoint.IContentType GetContentType(PnP.Core.Model.SharePoint.IList list)
        {
            if (_contentType is object)
            {
                var stringId = _contentType.EnsureProperty(c => c.StringId);
                return(list.ContentTypes.FirstOrDefault(c => c.StringId == stringId));
            }
            var id = _idOrName.ToLower().StartsWith("0x0") ? _idOrName : null;

            if (!string.IsNullOrEmpty(id))
            {
                return(list.ContentTypes.FirstOrDefault(c => c.Id == id));
            }

            return(list.ContentTypes.FirstOrDefault(c => c.Name == _idOrName));
        }
Пример #4
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);
 }
Пример #5
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);
 }
Пример #6
0
 public ListPipeBind(PnPCore.IList list)
 {
     _corelist = list ?? throw new ArgumentNullException(nameof(list));
 }
 internal string GetIdOrThrow(string paramName, PnPCore.IList list)
 => GetId(list)
 ?? throw new PSArgumentException(NotFoundMessage(list), paramName);
 public string GetId(PnPCore.IList list)
 => GetId()
 ?? list.ContentTypes.Where(ct => ct.Name == _idOrName).FirstOrDefault()?.StringId;
 private string NotFoundMessage(PnPCore.IList list)
 => $"Content type '{this}' not found in list '{new ListPipeBind(list)}'.";
Пример #10
0
        internal PnPCore.IContentType GetContentTypeOrError(Cmdlet cmdlet, string paramName, PnPCore.IList list)
        {
            var ct = GetContentType(list);

            if (ct is null)
            {
                cmdlet.WriteError(new ErrorRecord(new PSArgumentException(NotFoundMessage(list), paramName), "CONTENTTYPEDOESNOTEXIST", ErrorCategory.InvalidArgument, this));
            }
            return(ct);
        }
Пример #11
0
        internal PnP.Core.Model.SharePoint.IContentType GetContentType(PnPBatch batch, PnP.Core.Model.SharePoint.IList list)
        {
            PnPCore.IContentType returnCt = null;
            if (_contentType is object)
            {
                var stringId  = _contentType.EnsureProperty(c => c.StringId);
                var batchedCt = batch.GetCachedContentType(stringId);
                if (batchedCt != null)
                {
                    return(batchedCt);
                }
                returnCt = list.ContentTypes.FirstOrDefault(c => c.StringId == stringId);
            }
            var id = _idOrName.ToLower().StartsWith("0x0") ? _idOrName : null;

            if (!string.IsNullOrEmpty(id))
            {
                var batchedCt = batch.GetCachedContentType(id);
                if (batchedCt != null)
                {
                    return(batchedCt);
                }
                returnCt = list.ContentTypes.FirstOrDefault(c => c.Id == id);
            }
            else
            {
                var batchedCt = batch.GetCachedContentType(_idOrName);
                if (batchedCt != null)
                {
                    return(batchedCt);
                }
                returnCt = list.ContentTypes.FirstOrDefault(c => c.Name == _idOrName);
            }
            if (returnCt != null)
            {
                returnCt.EnsureProperties(ct => ct.StringId);
                batch.CacheContentType(returnCt);
            }
            return(returnCt);
        }