Exemplo n.º 1
0
        /// <summary>
        /// Gets an <see cref="Microsoft.SharePoint.SPList"/> object with the given server-relative URL.
        /// </summary>
        /// <param name="listUrl">Server-relative URL of list.</param>
        /// <returns>An <see cref="Microsoft.SharePoint.SPList"/> object in cache. NULL if site or list of given GUID does not exist.</returns>
        /// <exception cref="System.ArgumentNullException">Throws when input parameter <paramref name="listUrl"/> is null.</exception>
        public SPList TryGetList(string listUrl)
        {
            CommonHelper.ConfirmNotNull(listUrl, "listUrl");
            SPListLookupKey listInfo = hashtable.EnsureKeyValue(listUrl, () => GetListInfoFromUrl(listUrl));

            return(GetList(listInfo.WebId, listInfo.ListId));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets an <see cref="Microsoft.SharePoint.SPContentType"/> object representing list content type of the specified content type ID under the specified list.
        /// </summary>
        /// <param name="listUrl">Server-relative URL of the list.</param>
        /// <param name="contentTypeId">List content type ID.</param>
        /// <returns>An <see cref="Microsoft.SharePoint.SPContentType"/> object in cache. NULL if list content type of given content type ID does not exist, or the specified list does not exist.</returns>
        /// <exception cref="System.ArgumentNullException">Throws when input parameter <paramref name="listUrl"/> is null.</exception>
        public SPContentType GetContentType(string listUrl, SPContentTypeId contentTypeId)
        {
            CommonHelper.ConfirmNotNull(listUrl, "listUrl");
            SPListLookupKey        listInfo  = hashtable.EnsureKeyValue(listUrl, () => GetListInfoFromUrl(listUrl));
            SPContentTypeLookupKey lookupKey = new SPContentTypeLookupKey(listInfo.ListId, contentTypeId);

            return(GetOrAdd(lookupKey, () => GetList(listInfo.WebId, listInfo.ListId).ContentTypes[contentTypeId]));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the given <see cref="Microsoft.SharePoint.SPList"/> object to the cache.
        /// If a <see cref="Microsoft.SharePoint.SPList"/> with the same list ID already exists in cache, the given one is ignored.
        /// </summary>
        /// <param name="list">List object.</param>
        /// <returns>An <see cref="Microsoft.SharePoint.SPList"/> object in cache. Returned object is not necessary the same instance as the given one.</returns>
        /// <exception cref="System.ArgumentNullException">Throws when input parameter <paramref name="list"/> is null.</exception>
        public SPList AddList(SPList list)
        {
            CommonHelper.ConfirmNotNull(list, "list");
            SPListLookupKey lookupKey = new SPListLookupKey(list);

            hashtable.EnsureKeyValue(list.RootFolder.ServerRelativeUrl, () => lookupKey);
            return(GetOrAdd(lookupKey, list));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets an <see cref="Microsoft.SharePoint.SPList"/> object with the given server-relative URL.
 /// </summary>
 /// <param name="listUrl">Server-relative URL of list.</param>
 /// <returns>An <see cref="Microsoft.SharePoint.SPList"/> object in cache. NULL if site or list of given GUID does not exist.</returns>
 /// <exception cref="System.ArgumentNullException">Throws when input parameter <paramref name="listUrl"/> is null.</exception>
 public SPList TryGetList(string listUrl)
 {
     CommonHelper.ConfirmNotNull(listUrl, "listUrl");
     try {
         SPListLookupKey listInfo = listUrls.EnsureKeyValue(listUrl, GetListInfoFromUrl);
         return(GetList(listInfo.WebId, listInfo.ListId));
     } catch (ArgumentException) {
         return(null);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Gets an <see cref="Microsoft.SharePoint.SPList"/> objectof the spcified list GUID, under specified site.
        /// </summary>
        /// <param name="webId">Site GUID.</param>
        /// <param name="listId">List GUID.</param>
        /// <returns>An <see cref="Microsoft.SharePoint.SPList"/> object in cache. NULL if site or list of given GUID does not exist.</returns>
        public SPList GetList(Guid webId, Guid listId)
        {
            SPListLookupKey lookupKey = new SPListLookupKey(webId, listId);
            SPList          list      = GetOrAdd(lookupKey, () => GetWeb(webId).Lists[listId]);

            if (list != null)
            {
                hashtable.EnsureKeyValue(list.RootFolder.ServerRelativeUrl, () => lookupKey);
            }
            return(list);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets an <see cref="Microsoft.SharePoint.SPWeb"/> object with the given URL.
        /// </summary>
        /// <param name="webUrl">Site URL.</param>
        /// <returns>An <see cref="Microsoft.SharePoint.SPWeb"/> object in cache. NULL if site of given URL does not exist.</returns>
        public SPWeb TryGetWeb(string webUrl)
        {
            CommonHelper.ConfirmNotNull(webUrl, "webUrl");
            SPListLookupKey lookupKey = hashtable[webUrl] as SPListLookupKey;

            if (lookupKey != null)
            {
                return(GetWeb(lookupKey.WebId));
            }
            SPWeb web = SPExtensionHelper.OpenWebSafe(contextSite, webUrl, false);

            if (web != null)
            {
                SPWeb returnValue = AddWeb(web);
                if (returnValue != web)
                {
                    web.Dispose();
                }
                return(returnValue);
            }
            return(null);
        }