/// <summary> /// Gets a list of <see cref="User" /> objects that are members of a give <see cref="Group" />. /// </summary> /// <param name="objectId">Unique identifier of the <see cref="Group" />.</param> /// <returns>A view with the list of <see cref="User" /> objects.</returns> public async Task <ActionResult> GetMembers(string objectId) { IList <User> users = new List <User>(); try { ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient(); IGroup group = await client.Groups.GetByObjectId(objectId).ExecuteAsync(); IGroupFetcher groupFetcher = group as IGroupFetcher; IPagedCollection <IDirectoryObject> pagedCollection = await groupFetcher.Members.ExecuteAsync(); do { List <IDirectoryObject> directoryObjects = pagedCollection.CurrentPage.ToList(); foreach (IDirectoryObject directoryObject in directoryObjects) { if (directoryObject is User) { users.Add((User)directoryObject); } } pagedCollection = await pagedCollection.GetNextPageAsync(); } while (pagedCollection != null && pagedCollection.MorePagesAvailable); } catch (Exception e) { if (Request.QueryString["reauth"] == "True") { // // Send an OpenID Connect sign-in request to get a new set of tokens. // If the user still has a valid session with Azure AD, they will not be prompted for their credentials. // The OpenID Connect middleware will return to this controller after the sign-in response has been handled. // HttpContext.GetOwinContext() .Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType); } // // The user needs to re-authorize. Show them a message to that effect. // ViewBag.ErrorMessage = "AuthorizationRequired"; return(View()); } return(View(users)); }
protected override void BindLocalUI() { Blog blog = Config.CurrentBlog; IPagedCollection <MetaTag> tags = Repository.GetMetaTagsForBlog(blog, _pageIndex, resultsPager.PageSize); ContainsTags = tags.Count > 0; // we want to databind either way so we can alter the DOM via JavaScript and AJAX requests. MetatagRepeater.DataSource = tags; MetatagRepeater.DataBind(); resultsPager.ItemCount = tags.MaxItems; resultsPager.PageSize = Preferences.ListingItemCount; resultsPager.PageIndex = _pageIndex; base.BindLocalUI(); }
public static async Task <Group> FindGroupByObjectId(IActiveDirectoryClient client, string groupId) { List <IGroup> foundGroups = null; IGroup retrievedGroup = null; IPagedCollection <IGroup> groupsCollection = await client.Groups .Where(g => g.ObjectId.Equals(groupId)) .ExecuteAsync(); foundGroups = groupsCollection.CurrentPage.ToList(); if (foundGroups.Count > 0) { retrievedGroup = foundGroups[0]; } return((Group)retrievedGroup); }
public List <Tuple <string, IDirectoryObject> > GetAdGroupMembers(Group RetrievedGroup, IConfiguration Configuration, Logger Logger) { List <Tuple <string, IDirectoryObject> > DirectoryObjects = new List <Tuple <string, IDirectoryObject> >(); if (RetrievedGroup.ObjectId != null) { IGroupFetcher retrievedGroupFetcher = RetrievedGroup; try { IPagedCollection <IDirectoryObject> GroupMembers = retrievedGroupFetcher.Members.ExecuteAsync().Result; do { List <IDirectoryObject> directoryObjects = GroupMembers.CurrentPage.ToList(); foreach (IDirectoryObject directoryObject in directoryObjects) { if (directoryObject is User) { DirectoryObjects.Add(Tuple.Create("user", directoryObject)); } if (directoryObject is Contact) { DirectoryObjects.Add(Tuple.Create("contact", directoryObject)); } if (directoryObject is Group) { DirectoryObjects.Add(Tuple.Create("group", directoryObject)); } } GroupMembers = GroupMembers.GetNextPageAsync().Result; } while (GroupMembers != null); } catch (Exception ex) { Console.WriteLine("Error retrieving Group membership {0} {1}", ex.Message, ex.InnerException != null ? ex.InnerException.Message : ""); Logger.Error(String.Format("Error retrieving Group membership {0} {1}", ex.Message, ex.InnerException != null ? ex.InnerException.Message : "")); } return(DirectoryObjects); } else { return(DirectoryObjects); } }
//Mail Folders operations public static async Task <IPagedCollection <IFolder> > GetMailFoldersAsync() { OutlookServicesClient outlookClient = await GetOutlookClientAsync(); IPagedCollection <IFolder> foldersResults = await outlookClient.Me.Folders.ExecuteAsync(); string folderId = foldersResults.CurrentPage[0].Id; if (string.IsNullOrEmpty(folderId)) { return(null); } Debug.WriteLine("First mail folder in the collection: " + folderId); return(foldersResults); }
public static IEnumerable <LinkValue> CreateLinkValueCollection <TItem>( Uri linkTargetUri, IPagedCollection <TItem> pagedCollection) { if (linkTargetUri == null) { throw new ArgumentNullException(nameof(linkTargetUri)); } if (pagedCollection == null) { throw new ArgumentNullException(nameof(pagedCollection)); } var linkValues = new List <LinkValue> { CreateLinkValue( linkTargetUri, LinkRelationRegistry.Start, 0, pagedCollection.Limit), }; if (pagedCollection.HasPrevious) { linkValues.Add( CreateLinkValue( linkTargetUri, LinkRelationRegistry.Previous, pagedCollection.Offset - pagedCollection.Limit, pagedCollection.Limit)); } if (pagedCollection.HasNext) { linkValues.Add( CreateLinkValue( linkTargetUri, LinkRelationRegistry.Next, pagedCollection.Offset + pagedCollection.Limit, pagedCollection.Limit)); } return(linkValues); }
//Extension methods for the IPagedCollection interfaces returned //by the Microsoft.Graph.GraphService //The GraphServiceExtension methods use these extension methods //to interact with the IPagedCollection interfaces returned by the //Microsoft.Graph.GraphService public static async Task <TElement[]> GetAllAsnyc <TElement>( this IPagedCollection <TElement> pagedCollection) { var list = new List <TElement>(); var collection = pagedCollection; while (true) { list.AddRange(collection.CurrentPage); if (!collection.MorePagesAvailable) { break; } collection = await collection.GetNextPageAsync(); } return(list.ToArray()); }
public async Task <IPagedCollection <PlaylistDetail> > Handle(GetPlaylistListQuery request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } _logger.LogInformation("Handle {QueryType} for playlists like {PlaylistName} with page number {PageNumber} and page size {PageSize}", nameof(GetPlaylistListQuery), request.Name, request.PageNumber, request.PageSize); IPlaylistFilter filter = _playlistFilter .WhereTrackIdEquals(request.TrackId) .WhereNameLike(request.Name); IPagedCollection <Playlist> playlistsDomain = await _catalogRepository.GetPlaylists(filter, request.PageNumber, request.PageSize, cancellationToken); var playlists = _mapper.Map <IReadOnlyList <PlaylistDetail> >(playlistsDomain); return(new PagedCollection <PlaylistDetail>(playlists, playlistsDomain.ItemCount, playlistsDomain.CurrentPageNumber, playlistsDomain.PageSize)); }
public static IEnumerable <LinkValue> GetLinkValues <TItem>( this ActionContext context, IPagedCollection <TItem> pagedCollection) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (pagedCollection == null) { return(Enumerable.Empty <LinkValue>()); } return(LinkValueHelpers.CreateLinkValueCollection( new Uri(context.HttpContext.Request.GetDisplayUrl()), pagedCollection)); }
private void BindList() { Edit.Visible = false; IPagedCollection <Link> selectionList = Repository.GetPagedLinks(filterCategoryID, _resultsPageNumber, resultsPager.PageSize, true); if (selectionList.Count > 0) { resultsPager.ItemCount = selectionList.MaxItems; rprSelectionList.DataSource = selectionList; rprSelectionList.DataBind(); } else { // TODO: no existing items handling. add label and indicate no existing items. pop open edit. } }
public IList <IAzureServicePrincipal> GetAllPrincipals() { List <IAzureServicePrincipal> _spPrincipals = new List <IAzureServicePrincipal>(); var _client = this.GetActiveDirectoryClient(); ///Get principals /// IPagedCollection <IServicePrincipal> _principals = null; try { _principals = _client.ServicePrincipals.Take(999).ExecuteAsync().Result; if (_principals != null) { do { List <IServicePrincipal> princList = _principals.CurrentPage.ToList(); foreach (IServicePrincipal princ in princList) { var _spPrincipal = new Internal.ServicePrincipal(); _spPrincipal.PrincipalNames = princ.ServicePrincipalNames; _spPrincipal.AppId = princ.AppId; _spPrincipal.DisplayName = princ.DisplayName; _spPrincipal.ReplyUrls = princ.ReplyUrls; var _creds = princ.PasswordCredentials; if (_creds.Count != 0) { var _pwdCredentials = princ.PasswordCredentials.FirstOrDefault(); _spPrincipal.EndDate = _pwdCredentials.EndDate; } _spPrincipals.Add(_spPrincipal); } _principals = _principals.GetNextPageAsync().Result; } while (_principals != null); } } catch (Exception _ex) { //TOO LOGGING throw; } return(_spPrincipals); }
public IList <IAzureServicePrincipal> GetExpiredPrincipals() { List <IAzureServicePrincipal> _spPrincipals = new List <IAzureServicePrincipal>(); var _client = this.GetActiveDirectoryClient(); ///Get principals IPagedCollection <IServicePrincipal> _principals = null; try { _principals = _client.ServicePrincipals.Take(999).ExecuteAsync().Result; if (_principals != null) { do { List <IServicePrincipal> _allSpns = _principals.CurrentPage.Where(pwdcred => pwdcred.PasswordCredentials.Count > 0).ToList(); var _expiredPrincipals = _allSpns.Where(kc => kc.PasswordCredentials.FirstOrDefault().EndDate < DateTime.Now).ToList(); foreach (IServicePrincipal _spn in _expiredPrincipals) { var _spPrincipal = new Internal.ServicePrincipal(); _spPrincipal.PrincipalNames = _spn.ServicePrincipalNames; _spPrincipal.AppId = _spn.AppId; _spPrincipal.DisplayName = _spn.DisplayName; _spPrincipal.ReplyUrls = _spn.ReplyUrls; var _creds = _spn.PasswordCredentials.FirstOrDefault(); _spPrincipal.EndDate = _creds.EndDate; _spPrincipals.Add(_spPrincipal); } _principals = _principals.GetNextPageAsync().Result; } while (_principals != null); } } catch (AggregateException ae) { //TOO LOGGING // ae.Handle(HandleException); this.ExceptionHandler(ae); } return(_spPrincipals); }
public async static void LoadGroups() { authString = string.Format("https://login.microsoftonline.com/{0}/oauth2/authorize", TenantName); GroupList = new List <Group>(); ActiveDirectoryClient client = GetClient(); IPagedCollection <IGroup> coll = await client.Groups.ExecuteAsync(); while (coll != null) { List <IGroup> groups = coll.CurrentPage.ToList(); foreach (IGroup group in groups) { GroupList.Add((Group)group); } coll = coll.GetNextPageAsync().Result; } }
public List <IApplicationInformation> GetAllApplications() { List <IApplicationInformation> _applications = new List <IApplicationInformation>(); var _client = this.GetActiveDirectoryClient(); IPagedCollection <IApplication> _azureApplications = null; try { _azureApplications = _client.Applications.Take(999).ExecuteAsync().Result; if (_azureApplications != null) { foreach (var _azureApp in _azureApplications.CurrentPage.ToList()) { var _appInfo = new ApplicationInformation { AppId = _azureApp.AppId, DiplayName = _azureApp.DisplayName, ReplyUrls = _azureApp.ReplyUrls, IdentifierUris = _azureApp.IdentifierUris }; if (_azureApp.PasswordCredentials.Count != 0) { _appInfo.EndDate = _azureApp.PasswordCredentials.FirstOrDefault().EndDate; } if (_azureApp.KeyCredentials.Count != 0) { _appInfo.EndDate = _azureApp.KeyCredentials.FirstOrDefault().EndDate; } _applications.Add(_appInfo); } } return(_applications); } catch (Exception ex) { throw; } }
public string GetHtml(IPagedCollection <IVirtualMachine> machines) { if (_vmListHtmlBase == null) { _vmListHtmlBase = GetWebContentFile("VmList.html"); } StringBuilder finalDiv = new StringBuilder(); foreach (IVirtualMachine machine in machines) { string vmForm = GetVmControlContent(machine); finalDiv.Append(vmForm); } string finalPage = _vmListHtmlBase.Replace("{{main-content}}", finalDiv.ToString()); return(finalPage); }
// GET: Admin/Push public async Task <ActionResult> Push() { List <string> members = new List <string>(); members.Add(" "); // The Azure AD Graph API for my directory is available at this URL. const string serviceRootURL = "https://graph.windows.net/xumimixugmail.onmicrosoft.com"; // Instantiate an instance of ActiveDirectoryClient. Uri serviceRoot = new Uri(serviceRootURL); ActiveDirectoryClient adClient = new ActiveDirectoryClient( serviceRoot, async() => await GetAppTokenAsync()); //IGroup group IPagedCollection <IDirectoryObject> pagedCollection = await adClient.Groups .GetByObjectId("802a838b-15cd-4e01-80a5-f4f223bfcce3") .Members .ExecuteAsync(); //IPagedCollection <IDirectoryObject> pagedCollection = group.Members; //IPagedCollection <IUser> pagedCollection = await adClient.Users.ExecuteAsync(); if (pagedCollection != null) { do { List <IDirectoryObject> userList = pagedCollection.CurrentPage.ToList(); foreach (IDirectoryObject userObject in userList) { if (userObject is User) { User user = userObject as User; members.Add(user.DisplayName); } } pagedCollection = await pagedCollection.GetNextPageAsync(); } while (pagedCollection != null); } ViewData["members"] = new SelectList(members); return(View()); }
/// <summary> /// Gets a list of <see cref="User" /> objects from Graph. /// </summary> /// <returns>A view with the list of <see cref="User" /> objects.</returns> public async Task <ActionResult> Index() { var userList = new List <User>(); try { ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient(); IPagedCollection <IUser> pagedCollection = await client.Users.ExecuteAsync(); if (pagedCollection != null) { do { List <IUser> usersList = pagedCollection.CurrentPage.ToList(); foreach (IUser user in usersList) { userList.Add((User)user); } pagedCollection = await pagedCollection.GetNextPageAsync(); } while (pagedCollection != null); } } catch (Exception e) { if (Request.QueryString["reauth"] == "True") { // // Send an OpenID Connect sign-in request to get a new set of tokens. // If the user still has a valid session with Azure AD, they will not be prompted for their credentials. // The OpenID Connect middleware will return to this controller after the sign-in response has been handled. // HttpContext.GetOwinContext() .Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType); } // // The user needs to re-authorize. Show them a message to that effect. // ViewBag.ErrorMessage = "AuthorizationRequired"; return(View(userList)); } return(View(userList)); }
public IList <IApplicationInformation> GetExpiredApplicationInDays(double numberOfDays) { List <IApplicationInformation> _applications = new List <IApplicationInformation>(); var _client = this.GetActiveDirectoryClient(); IPagedCollection <IApplication> _azureApplications = null; try { _azureApplications = _client.Applications.Take(999).ExecuteAsync().Result; if (_azureApplications != null) { List <IApplication> _apps = _azureApplications.CurrentPage.Where(x => x.PasswordCredentials.Count > 0).ToList(); //var _expiredApps = _apps.Where(x => x.PasswordCredentials.FirstOrDefault().EndDate >= DateTime.Now || x.KeyCredentials.FirstOrDefault().EndDate >= DateTime.Now && // x.KeyCredentials.FirstOrDefault().EndDate <= DateTime.Now.AddDays(numberOfDays) || // x.PasswordCredentials.FirstOrDefault().EndDate <= DateTime.Now.AddDays(numberOfDays)).ToList(); var _expiredApps = _apps.Where(x => x.PasswordCredentials.FirstOrDefault().EndDate >= DateTime.Now && x.PasswordCredentials.FirstOrDefault().EndDate <= DateTime.Now.AddDays(numberOfDays)).ToList(); foreach (var _expiredApp in _expiredApps) { var _appInfo = new ApplicationInformation { AppId = _expiredApp.AppId, DiplayName = _expiredApp.DisplayName, ReplyUrls = _expiredApp.ReplyUrls, IdentifierUris = _expiredApp.IdentifierUris }; if (_expiredApp.PasswordCredentials.Count != 0) { _appInfo.EndDate = _expiredApp.PasswordCredentials.FirstOrDefault().EndDate; } _applications.Add(_appInfo); } } return(_applications); } catch (Exception ex) { throw; } }
private void BindList() { noCommentsMessage.Visible = false; if (Request.QueryString[Keys.QRYSTR_PAGEINDEX] != null) { _pageIndex = Convert.ToInt32(Request.QueryString[Keys.QRYSTR_PAGEINDEX]); } resultsPager.UrlFormat = "Default.aspx?pg={0}&status=" + _feedbackStatusFilter; resultsPager.PageSize = Preferences.ListingItemCount; resultsPager.PageIndex = _pageIndex; // Deleted is a special case. If a feedback has the deleted // bit set, it is in the trash no matter what other bits are set. FeedbackStatusFlag excludeFilter = _feedbackStatusFilter == FeedbackStatusFlag.Deleted ? FeedbackStatusFlag.None : FeedbackStatusFlag.Deleted; IPagedCollection <FeedbackItem> selectionList = Repository.GetPagedFeedback(_pageIndex , resultsPager.PageSize , _feedbackStatusFilter , excludeFilter , Master.FeedbackType); if (selectionList.Count > 0) { resultsPager.Visible = true; resultsPager.ItemCount = selectionList.MaxItems; feedbackRepeater.DataSource = selectionList; feedbackRepeater.ItemCreated += FeedbackItemDataBound; feedbackRepeater.DataBind(); } else { resultsPager.Visible = false; noCommentsMessage.Text = _uiState.NoCommentsHtml; feedbackRepeater.Controls.Clear(); noCommentsMessage.Visible = true; btnEmpty.Visible = false; } Master.BindCounts(); }
public IEnumerable <ReleaseApproval> ListPendingApprovalsForASpecificARelease() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient2 releaseClient = connection.GetClient <ReleaseHttpClient2>(); var releases = releaseClient.GetReleasesAsync(project: projectName).Result; int releaseIdFilter = releases.FirstOrDefault().Id; List <ReleaseApproval> releaseApprovals = new List <ReleaseApproval>(); // Iterate (as needed) to get the full set of approvals int continuationToken = 0; bool parseResult; do { IPagedCollection <ReleaseApproval> releaseApprovalsPage = releaseClient.GetApprovalsAsync2(project: projectName, releaseIdsFilter: new List <int> { releaseIdFilter }, continuationToken: continuationToken).Result; releaseApprovals.AddRange(releaseApprovalsPage); int parsedContinuationToken = 0; parseResult = int.TryParse(releaseApprovalsPage.ContinuationToken, out parsedContinuationToken); if (parseResult) { continuationToken = parsedContinuationToken; } } while ((continuationToken != 0) && parseResult); // Show the approvals foreach (ReleaseApproval releaseApproval in releaseApprovals) { Console.WriteLine("{0} {1}", releaseApproval.Id.ToString().PadLeft(6), releaseApproval.Status); } return(releaseApprovals); }
/// <summary> /// Gets a list of <see cref="Contact" /> objects from Graph. /// </summary> /// <returns>A view with the list of <see cref="Contact" /> objects.</returns> public async Task <ActionResult> Index() { List <Contact> contactList = new List <Contact>(); try { ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient(); // Get all results into a list IPagedCollection <IContact> contacts = await client.Contacts.ExecuteAsync(); do { List <IContact> currentPage = contacts.CurrentPage.ToList(); foreach (IContact contact in currentPage) { contactList.Add((Contact)contact); } contacts = await contacts.GetNextPageAsync(); } while (contacts != null && contacts.MorePagesAvailable); } catch (Exception e) { if (Request.QueryString["reauth"] == "True") { // // Send an OpenID Connect sign-in request to get a new set of tokens. // If the user still has a valid session with Azure AD, they will not be prompted for their credentials. // The OpenID Connect middleware will return to this controller after the sign-in response has been handled. // HttpContext.GetOwinContext() .Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType); } // // The user needs to re-authorize. Show them a message to that effect. // ViewBag.ErrorMessage = "AuthorizationRequired"; return(View()); } return(View(contactList)); }
public static async Task <T[]> ExecuteAllAsync <T>(this IPagedCollection <T> collection) { var list = new List <T>(); var c = collection; while (true) { list.AddRange(c.CurrentPage); if (c.MorePagesAvailable) { c = await c.GetNextPageAsync(); } else { break; } } return(list.ToArray()); }
public List <IApplication> List(int pageNumber, out bool moreAvailable) { IPagedCollection <IApplication> applicationList = null; List <IApplication> applications = null; moreAvailable = false; applicationList = _activeDirectoryClient.Applications.ExecuteAsync().Result; IPagedCollection <IServicePrincipal> servicePrincipals = _activeDirectoryClient.ServicePrincipals.Where(s => s.AppId == "00000002-0000-0000-c000-000000000000").ExecuteAsync().Result; if (applicationList != null) { applications = applicationList.CurrentPage.ToList(); moreAvailable = applicationList.MorePagesAvailable; if (pageNumber > 1) { for (int i = 1; i < pageNumber; i++) { if (moreAvailable) { applicationList = applicationList.GetNextPageAsync().Result; if (applicationList != null) { applications = applicationList.CurrentPage.ToList(); moreAvailable = applicationList.MorePagesAvailable; } else { applications = new List <IApplication>(); } } } } } else { applications = new List <IApplication>(); } return(applications.OrderBy(a => a.DisplayName).ToList()); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log, ExecutionContext context) { FunctionHelpers helper = new FunctionHelpers(nameof(GetVms), log, context); AzureVmManager vmManager = AzureVmManager.CreateVmManagerInstance(helper); IPagedCollection <IVirtualMachine> machines = await vmManager.GetVirtualMachinesAsync(); VmHtmlMaker vmHtmlMaker = new VmHtmlMaker(context.FunctionAppDirectory, req); string html = vmHtmlMaker.GetHtml(machines); var result = new ContentResult { Content = html, ContentType = "text/html" }; return(result); }
public static async Task <IEnumerable <TSource> > GetAllAsync <TSource>(this IPagedCollection <TSource> source) { var list = new List <TSource>(); if (null != source.CurrentPage) { list.AddRange(source.CurrentPage); } while (source.MorePagesAvailable) { source = await source.GetNextPageAsync(); if (null != source.CurrentPage) { list.AddRange(source.CurrentPage); } } return(list); }
public void GetAllDeployments() { Task.Run(async() => { try { IPagedCollection <IDeployment> list = await azure.Deployments.ListAsync(); if (list != null) { int n = 0; } } catch (Exception ex) { if (feedback != null) { feedback.OnTaskException(ex); } } }).Wait(); }
/// <summary> /// This method demonstrates how to get all groups for a user with the pager logic /// </summary> /// <param name="azureClient">ActiveDirectoryClient object</param> private static void GetAllGroups(ActiveDirectoryClient azureClient) { Console.WriteLine("Listing all groups..."); List <IGroup> groups = new List <IGroup>(); IPagedCollection <IGroup> pagedCollection = azureClient.Groups.ExecuteAsync().Result; if (pagedCollection != null) { do //append pages to the list { groups.AddRange(pagedCollection.CurrentPage.ToList()); pagedCollection = pagedCollection.GetNextPageAsync().Result; } while (pagedCollection != null && pagedCollection.MorePagesAvailable); } foreach (var group in groups) { Console.WriteLine("Group: " + group.DisplayName); } }
public static async Task <bool> IsPrincipalNameAvailable(IActiveDirectoryClient client, string principalName) { //********************************************************************* // People picker // Search for a user using text string "Us" match against userPrincipalName, displayName, giveName, surname // Requires minimum of User.ReadBasic.All. //********************************************************************* List <IUser> usersList = null; IPagedCollection <IUser> searchResults = null; IUserCollection userCollection = client.Users; searchResults = await userCollection.Where(user => user.UserPrincipalName.StartsWith(principalName)).Take(1).ExecuteAsync(); usersList = searchResults.CurrentPage.ToList(); return(usersList.Count == 0); }
public async Task GetAllUsers() { Dictionary <String, User> usersDict = new Dictionary <String, User>(); IPagedCollection <IUser> pagedCollection = await this.client.Users.ExecuteAsync(); if (pagedCollection != null) { do { List <IUser> templist = pagedCollection.CurrentPage.ToList(); foreach (IUser user in templist) { if (!usersDict.ContainsKey(user.UserPrincipalName)) { usersDict.Add(user.UserPrincipalName, (User)user); } } pagedCollection = await pagedCollection.GetNextPageAsync(); } while (pagedCollection != null && pagedCollection.MorePagesAvailable); } }
public static async Task <bool> AnyAsync <T>(this IPagedCollection <T> collection, Func <T, bool> predicate) { var c = collection; while (true) { if (c.CurrentPage.Any(predicate)) { return(true); } if (c.MorePagesAvailable) { c = await c.GetNextPageAsync(); } else { break; } } return(false); }
private static void ReadAndPopulatePostChildren(IPagedCollection<BlogMLPost> bmlPosts, IDataReader reader, string foreignKey, PostChildrenPopulator populatePostChildren) { for (int i = 0; i < bmlPosts.Count; i++) { BlogMLPost post = bmlPosts[i]; int postId = int.Parse(post.ID); // We are going to make use of the fact that everything is ordered by Post Id ASC // to optimize this... while (reader.Read()) { int postIdForeignKey = DataHelper.ReadInt32(reader, foreignKey); if (postId < postIdForeignKey) { while (postId < postIdForeignKey && i < bmlPosts.Count) { i++; post = bmlPosts[i]; postId = int.Parse(post.ID); } } if (postId > postIdForeignKey) continue; if (postId == postIdForeignKey) populatePostChildren(post); } } }
public BatchElementResult(IPagedCollection successResult) { SuccessResult = successResult; }
public void Initialize() { _collection = new PagedCollection<string>(new List<string> { "one" }, 1, 1, 3); }
public int GetCount(IPagedCollection collection) { return ((IPagedCollection<Referrer>)collection).Count; }
private static void PopulateTrackbacks(IPagedCollection<BlogMLPost> bmlPosts, IDataReader reader) { PostChildrenPopulator populator = delegate(BlogMLPost bmlPost) { bmlPost.Trackbacks.Add(ObjectHydrator.LoadTrackbackFromDataReader(reader)); }; ReadAndPopulatePostChildren(bmlPosts, reader, "EntryId", populator); }
public int GetCount(IPagedCollection collection) { return ((IPagedCollection<MetaTag>)collection).Count; }
public int GetCount(IPagedCollection collection) { return ((IPagedCollection<Entry>)collection).Count; }
public int GetCount(IPagedCollection collection) { return ((IPagedCollection<KeyWord>)collection).Count; }
public int GetCount(IPagedCollection collection) { return ((IPagedCollection<FeedbackItem>)collection).Count; }
public int GetCount(IPagedCollection collection) { return ((IPagedCollection<BlogInfo>)collection).Count; }
private static void PopulateCategories(IPagedCollection<BlogMLPost> posts, IDataReader reader) { PostChildrenPopulator populator = delegate(BlogMLPost bmlPost) { bmlPost.Categories.Add(DataHelper.ReadInt32(reader, "CategoryId").ToString(CultureInfo.InvariantCulture)); }; ReadAndPopulatePostChildren(posts, reader, "Id", populator); }
protected void WritePostsPage(IPagedCollection<BlogMLPost> posts) { foreach (BlogMLPost bmlPost in posts) { WritePost(bmlPost); } Writer.Flush(); //Flushes this page of posts. }