private Task <List <GroupEntry> > GetGroupsAsync(bool force) { var entries = new List <GroupEntry>(); var request = _service.Groups.List(); request.Domain = SettingsService.Instance.Server.GSuite.Domain; request.Customer = SettingsService.Instance.Server.GSuite.Customer; var pageStreamer = new PageStreamer <Group, GroupsResource.ListRequest, Groups, string>( (req, token) => req.PageToken = token, res => res.NextPageToken, res => res.GroupsValue); var filter = CreateSetFromFilter(SettingsService.Instance.Sync.GroupFilter); foreach (var group in pageStreamer.Fetch(request)) { if (FilterOutResult(filter, group.Name)) { continue; } var entry = BuildGroup(group); entries.Add(entry); } return(Task.FromResult(entries)); }
private static GroupEntry BuildGroup(Group group) { var entry = new GroupEntry { ReferenceId = group.Id, ExternalId = group.Id, Name = group.Name }; var memberRequest = _service.Members.List(group.Id); var pageStreamer = new PageStreamer <Member, MembersResource.ListRequest, Members, string>( (req, token) => req.PageToken = token, res => res.NextPageToken, res => res.MembersValue); foreach (var member in pageStreamer.Fetch(memberRequest)) { if (!member.Role.Equals("member", StringComparison.InvariantCultureIgnoreCase) || !member.Status.Equals("active", StringComparison.InvariantCultureIgnoreCase)) { continue; } if (member.Type.Equals("user", StringComparison.InvariantCultureIgnoreCase)) { entry.UserMemberExternalIds.Add(member.Id); } else if (member.Type.Equals("group", StringComparison.InvariantCultureIgnoreCase)) { entry.GroupMemberReferenceIds.Add(member.Id); } } return(entry); }
private Task <List <UserEntry> > GetUsersAsync(bool force) { var entries = new List <UserEntry>(); var query = CreateGSuiteQueryFromFilter(SettingsService.Instance.Sync.UserFilter); var request = _service.Users.List(); request.Domain = SettingsService.Instance.Server.GSuite.Domain; request.Customer = SettingsService.Instance.Server.GSuite.Customer; request.Query = query; var pageStreamer = new PageStreamer <User, UsersResource.ListRequest, Users, string>( (req, token) => req.PageToken = token, res => res.NextPageToken, res => res.UsersValue); var filter = CreateSetFromFilter(SettingsService.Instance.Sync.UserFilter); foreach (var user in pageStreamer.Fetch(request)) { if (FilterOutResult(filter, user.PrimaryEmail)) { continue; } var entry = BuildUser(user, false); if (entry != null) { entries.Add(entry); } } var deletedRequest = _service.Users.List(); deletedRequest.Domain = SettingsService.Instance.Server.GSuite.Domain; deletedRequest.Customer = SettingsService.Instance.Server.GSuite.Customer; deletedRequest.Query = query; deletedRequest.ShowDeleted = "true"; var deletedPageStreamer = new PageStreamer <User, UsersResource.ListRequest, Users, string>( (req, token) => req.PageToken = token, res => res.NextPageToken, res => res.UsersValue); foreach (var user in deletedPageStreamer.Fetch(deletedRequest)) { if (FilterOutResult(filter, user.PrimaryEmail)) { continue; } var entry = BuildUser(user, true); if (entry != null) { entries.Add(entry); } } return(Task.FromResult(entries)); }
public static async Task <IList <Event> > FetchAllAsync(this EventsResource.ListRequest listRequest, DateTime?after = null, DateTime?before = null) { listRequest.TimeMin = after; listRequest.TimeMax = before; var pageStreamer = new PageStreamer <Event, EventsResource.ListRequest, Events, string>((request, token) => request.PageToken = token, response => response.NextPageToken, response => response.Items); return(await pageStreamer.FetchAllAsync(listRequest, CancellationToken.None)); }
public static async Task <List <Message> > ListAll(this UsersResource.MessagesResource.ListRequest request) { var pageStreamer = new PageStreamer <Message, UsersResource.MessagesResource.ListRequest, ListMessagesResponse, string>( (zRequest, zToken) => zRequest.PageToken = zToken, zResponse => zResponse.NextPageToken, zResponse => zResponse.Messages); var messages = await pageStreamer.FetchAllAsync(request, CancellationToken.None); return(messages.ToList()); }
public object GetFilesOfMimeType(string mimeType) { var pageStreamer = new PageStreamer <File, FilesResource.ListRequest, FileList, string>( (request, token) => request.PageToken = token, response => response.NextPageToken, response => response.Files); var req = driveService.Files.List(); req.PageSize = 1000; req.OrderBy = "name"; req.Q = String.Format("mimeType = '{0}'", mimeType); return(pageStreamer.Fetch(req)); }
public object GetFilesMatchingName(string name) { var pageStreamer = new PageStreamer <File, FilesResource.ListRequest, FileList, string>( (request, token) => request.PageToken = token, response => response.NextPageToken, response => response.Files); var req = driveService.Files.List(); req.PageSize = 1000; req.OrderBy = "name"; req.Q = String.Format("name contains '{0}'", name); req.Fields = "nextPageToken,files(id,name,kind,mimeType,createdTime,sharingUser,shared,size,modifiedTime,parents)"; return(pageStreamer.Fetch(req)); }
public override IEnumerable <IPathNode> GetNodeChildren(IProviderContext providerContext) { var pageStreamer = new PageStreamer <File, FilesResource.ListRequest, FileList, string>( (request, token) => request.PageToken = token, response => response.NextPageToken, response => response.Files); var req = _service.Files.List(); req.PageSize = 1000; req.OrderBy = "name"; req.Q = String.Format("'{0}' in parents", ParentId); req.Fields = "nextPageToken,files(id,name,kind,mimeType,createdTime,sharingUser,shared,size,modifiedTime,parents)"; var folders = new List <IPathNode>(); var files = new List <IPathNode>(); foreach (var file in pageStreamer.Fetch(req)) { yield return(new GoogleDriveItemPathNode(_service, file)); //var target = file.MimeType == "application/vnd.google-apps.folder" ? folders : files; //target.Add( new GoogleDriveItemPathNode(file) ); } }