public void ProcessRequest(HttpContext context) { const string cacheId = "Office365Icon"; var iconContent = (byte[])cacheService.Get(cacheId, Extensibility.Caching.Version1.CacheScope.Context | Extensibility.Caching.Version1.CacheScope.Process); if (iconContent == null) { var assemblyName = GetType().Assembly.GetName().Name; using (var memoryStream = new MemoryStream()) { using (var stream = EmbeddedResources.GetStream(assemblyName + ".Resources.OAuth.office365.png")) { stream.CopyTo(memoryStream); } iconContent = memoryStream.ToArray(); } cacheService.Put(cacheId, iconContent, Extensibility.Caching.Version1.CacheScope.Context | Extensibility.Caching.Version1.CacheScope.Process, null, CacheTimeOut); } context.Response.ContentType = "image/png"; context.Response.BinaryWrite(iconContent); }
public ApiList <SPListItem> List(SPList list, [Documentation(Name = "ViewFields", Type = typeof(List <string>)), Documentation(Name = "ViewQuery", Type = typeof(string))] IDictionary options) { if (list == null) { return(new ApiList <SPListItem>()); } var cacheId = string.Concat(SharePointListItemCacheId, string.Format("{0}_{1}", list.SPWebUrl, list.Id)); var cacheList = (ApiList <SPListItem>)cacheService.Get(cacheId, CacheScope.Context | CacheScope.Process); if (cacheList == null) { using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl))) { var sharepointList = clientContext.ToList(list.Id); ListItemCollection listItemCollection; if (options != null && options["ViewQuery"] != null) { var camlQuery = new CamlQuery { ViewXml = String.Format("<View><Query>{0}</Query></View>", options["ViewQuery"]) }; listItemCollection = sharepointList.GetItems(camlQuery); } else { listItemCollection = sharepointList.GetItems(CamlQuery.CreateAllItemsQuery()); } IEnumerable <ListItem> items; if (options != null && options["ViewFields"] != null) { var viewFields = (List <string>)options["ViewFields"]; items = clientContext.LoadQuery(listItemCollection.Include(CreateListItemLoadExpressions(viewFields))); } else { items = clientContext.LoadQuery(listItemCollection.Include(SPItemService.InstanceQuery)); } var userItemCollection = clientContext.Web.SiteUserInfoList.GetItems(CamlQuery.CreateAllItemsQuery()); IEnumerable <SP.ListItem> userItems = clientContext.LoadQuery( userItemCollection.Include(new Expression <Func <ListItem, object> >[] { item => item.Id, item => item["Picture"] })); var fieldsQuery = clientContext.LoadQuery(sharepointList.Fields.Where(field => !field.Hidden && field.Group != "_Hidden")); clientContext.ExecuteQuery(); var apiList = new ApiList <SPListItem>(); var fields = fieldsQuery.ToList(); foreach (var item in items) { apiList.Add(new SPListItem(item, fields)); } cacheService.Put(cacheId, apiList, CacheScope.Context | CacheScope.Process, new[] { GetTag(list.Id) }, CacheTimeOut); return(apiList); } } return(cacheList); }