public IRestResponse Get(SPViewItemRequest request) { var response = new DefaultRestResponse { Name = "View" }; var errors = new List <string>(); ValidateUrl(request.Url, errors); var listId = ValidateListId(request.ListId, errors); var viewId = ValidateViewId(request.ViewId, errors); if (errors.Any()) { response.Errors = errors.ToArray(); return(response); } response.Data = cacheService.Get(CacheKey(listId, viewId, request.Url), CacheScope.Context | CacheScope.Process); if (response.Data == null) { try { using (var clientContext = new SPContext(request.Url, IntegrationManagerPlugin.CurrentAuth(request.Url), runAsServiceAccount: true)) { var site = clientContext.Site; clientContext.Load(site, s => s.Id); var web = clientContext.Web; clientContext.Load(web, w => w.Id); var list = clientContext.Web.Lists.GetById(listId); var view = list.GetView(viewId); clientContext.Load(view, RestSPView.InstanceQuery); clientContext.ExecuteQuery(); response.Data = new SPViewItemData { Item = new RestSPView(view), SiteId = site.Id, WebId = web.Id }; } cacheService.Put(CacheKey(listId, viewId, request.Url), response.Data, CacheScope.Context | CacheScope.Process, new string[] { }, CacheTimeOut); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the RESTApi.Views.Get() method for ListId: {1} ViewId: {2} SPWebUrl: '{3}'. The exception message is: {4}", ex.GetType(), listId, viewId, request.Url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); response.Errors = new[] { plugin.Translate(SharePointEndpoints.Translations.UnknownError) }; } } return(response); }
public IRestResponse List(SPViewCollectionRequest request) { var response = new DefaultRestResponse { Name = "Views" }; var errors = new List <string>(); ValidateUrl(request.Url, errors); var listId = ValidateListId(request.ListId, errors); if (errors.Any()) { response.Errors = errors.ToArray(); return(response); } string url = request.Url; string viewNameFilter = request.ViewNameFilter; int pageSize = request.PageSize; int pageIndex = request.PageIndex; var viewCollection = (IEnumerable <View>)cacheService.Get(CacheKey(url, listId), CacheScope.Context | CacheScope.Process); if (viewCollection == null) { try { using (var clientContext = new SPContext(url, IntegrationManagerPlugin.CurrentAuth(url), runAsServiceAccount: true)) { var list = clientContext.Web.Lists.GetById(listId); viewCollection = clientContext.LoadQuery(list.Views.Include(RestSPView.InstanceQuery)); clientContext.ExecuteQuery(); } cacheService.Put(CacheKey(url, listId), viewCollection, CacheScope.Context | CacheScope.Process, new string[] { }, CacheTimeOut); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the RESTApi.View.List() method ListId:{1} SPWebUrl: '{2}'. The exception message is: {3}", ex.GetType(), listId, url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); response.Errors = new[] { plugin.Translate(SharePointEndpoints.Translations.UnknownError) }; } } if (viewCollection != null) { try { Func <View, bool> filter = (v => true); bool hasViewNameFilter = !String.IsNullOrEmpty(viewNameFilter); if (hasViewNameFilter) { filter = v => v.Title.Contains(viewNameFilter, StringComparison.OrdinalIgnoreCase); } List <View> viewList = viewCollection.Where(filter).ToList(); response.Data = new SPViewCollectionData(viewList.Skip(pageIndex).Take(pageSize).Select(view => new RestSPView(view)), viewList.Count); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the RESTApi.View.List() method while processing not empty collection of Views for ListId: {1} SPWebUrl: '{2}'. The exception message is: {3}", ex.GetType(), listId, url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); response.Errors = new[] { plugin.Translate(SharePointEndpoints.Translations.UnknownError) }; } } return(response); }
public IRestResponse List(SPUserOrGroupRequest request, bool onlyGroups = false, bool onlyUsers = false) { var response = new DefaultRestResponse { Name = "List" }; var errors = new List <string>(); ValidateUrl(request.Url, errors); if (errors.Any()) { response.Errors = errors.ToArray(); return(response); } string url = request.Url; string search = request.Search; int pageSize = request.PageSize > 0 ? request.PageSize : DefaultPageSize; int pageIndex = request.PageIndex > 0 ? request.PageIndex : 0; response.Data = cacheService.Get(CacheKey(url, onlyGroups, onlyUsers, search, pageSize, pageIndex), CacheScope.Context | CacheScope.Process); if (response.Data == null) { try { using (var clientContext = new SPContext(url, IntegrationManagerPlugin.CurrentAuth(url), runAsServiceAccount: true)) { var web = clientContext.Web; clientContext.Load(web, w => w.Id); var site = clientContext.Site; clientContext.Load(site, s => s.Id); var query = CamlQuery.CreateAllItemsQuery(pageSize); query.ViewXml = String.Concat("<View><Query>", ViewFieldsSection(RestSPUserOrGroup.ViewFields), WhereSection(search, onlyGroups, onlyUsers), "</Query></View>"); if (pageIndex > 0) { var tempListItems = web.SiteUserInfoList.GetItems(CamlQuery.CreateAllItemsQuery(pageSize * pageIndex)); clientContext.Load(tempListItems, itemsCollection => itemsCollection.ListItemCollectionPosition); clientContext.ExecuteQuery(); query.ListItemCollectionPosition = tempListItems.ListItemCollectionPosition; } var siteUsersAndGroups = clientContext.LoadQuery(web.SiteUserInfoList.GetItems(query)); clientContext.ExecuteQuery(); response.Data = siteUsersAndGroups.Select(RestSPUserOrGroup.Get).ToArray(); } cacheService.Put(CacheKey(url, onlyGroups, onlyUsers, search, pageSize, pageIndex), response.Data, CacheScope.Context | CacheScope.Process, new string[] { }, CacheTimeOut); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the RESTApi.GroupsAndUsers.List() method for SPWebUrl: '{1}' Search: '{2}' OnlyGroups: {3} OnlyUsers: {4}. The exception message is: {5}", ex.GetType(), url, search, onlyGroups, onlyUsers, ex.Message); SPLog.RoleOperationUnavailable(ex, message); response.Errors = new[] { plugin.Translate(SharePointEndpoints.Translations.UnknownError) }; } } return(response); }
public IRestResponse List(SPListCollectionRequest request) { var response = new DefaultRestResponse { Name = "Lists" }; var errors = new List <string>(); ValidateUrl(request.Url, errors); if (errors.Any()) { response.Errors = errors.ToArray(); return(response); } string url = request.Url; string includeType = request.ListType; string excludeType = request.ExcludeListType; string listNameFilter = request.ListNameFilter; int pageSize = request.PageSize; int pageIndex = request.PageIndex; var listCollection = (IEnumerable <List>)cacheService.Get(CacheKey(url, includeType, excludeType), CacheScope.Context | CacheScope.Process); if (listCollection == null) { try { using (var clientContext = new SPContext(url, IntegrationManagerPlugin.CurrentAuth(url), runAsServiceAccount: true)) { ListTemplateType includeLookUpTemplate; ListTemplateType excludeLookUpTemplate; var includeItemsByTemplate = TryGetTemplateType(includeType, out includeLookUpTemplate); var excludeItemsByTemplate = TryGetTemplateType(excludeType, out excludeLookUpTemplate); if (includeItemsByTemplate) { var lookUpTemplateValue = (int)includeLookUpTemplate; listCollection = clientContext.LoadQuery(clientContext.Web.Lists.Where(list => list.BaseTemplate == lookUpTemplateValue && list.Hidden == false).Include(RestSPList.InstanceQuery)); } else if (excludeItemsByTemplate) { var lookUpTemplateValue = (int)excludeLookUpTemplate; listCollection = clientContext.LoadQuery(clientContext.Web.Lists.Where(list => list.BaseTemplate != lookUpTemplateValue && list.Hidden == false).Include(RestSPList.InstanceQuery)); } else { listCollection = clientContext.LoadQuery(clientContext.Web.Lists.Include(RestSPList.InstanceQuery)); } clientContext.ExecuteQuery(); } cacheService.Put(CacheKey(url, includeType, excludeType), listCollection, CacheScope.Context | CacheScope.Process, new string[] { }, CacheTimeOut); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the RESTApi.Lists.List() method for SPWebUrl: '{1}'. The exception message is: {2}", ex.GetType(), url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); response.Errors = new[] { plugin.Translate(SharePointEndpoints.Translations.UnknownError) }; } } if (listCollection != null) { try { Func <List, bool> filter = (m => true); bool hasListNameFilter = !String.IsNullOrEmpty(listNameFilter); if (hasListNameFilter) { filter = l => l.Title.StartsWith(listNameFilter, StringComparison.OrdinalIgnoreCase) || listNameFilter.Split(' ').Where(f => !string.IsNullOrWhiteSpace(f)).All(f => l.Title.Split(' ').Any(t => t.StartsWith(f, StringComparison.OrdinalIgnoreCase))); } List <List> itemsList = listCollection.Where(filter).ToList(); response.Data = new SPListCollectionData(itemsList.Skip(pageIndex).Take(pageSize).Select(item => new RestSPList(item)), itemsList.Count); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the RESTApi.Lists.List() method while processing not empty collection of Lists from SPWebUrl: '{1}'. The exception message is: {2}", ex.GetType(), url, ex.Message); SPLog.RoleOperationUnavailable(ex, message); response.Errors = new[] { plugin.Translate(SharePointEndpoints.Translations.UnknownError) }; } } return(response); }
public Authentication Get(string url) { return IntegrationManagerPlugin.CurrentAuth(url); }