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));
        }
        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));
        }
Esempio n. 3
0
        /// <summary>
        /// Lists the buckets for a given project, synchronously but lazily.
        /// </summary>
        /// <remarks>
        /// This method fetches the buckets lazily, making requests to the underlying service
        /// for a page of results at a time, as required. To retrieve all the buckets in a single collection,
        /// simply call LINQ's <c>ToList()</c> method on the returned sequence.
        /// </remarks>
        /// <param name="projectId">The ID of the project to list the buckets from. Must not be null.</param>
        /// <param name="options">The options for the operation. May be null, in which case
        /// defaults will be supplied.</param>
        /// <returns>A sequence of buckets within the project.</returns>
        public IEnumerable <Bucket> ListBuckets(string projectId, ListBucketsOptions options = null)
        {
            Preconditions.CheckNotNull(projectId, nameof(projectId));
            var initialRequest = CreateListBucketsRequest(projectId, options);

            return(s_bucketPageStreamer.Fetch(initialRequest));
        }
        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);
        }
 /// <summary>
 /// Lists the name of the subscriptions for this topic.
 /// </summary>
 /// <param name="topic">The name of the topic that subscriptions are attached to.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public override IEnumerable <string> ListTopicSubscriptions(
     string topic,
     CallSettings callSettings = null) => s_listTopicSubscriptionsPageStreamer.Fetch(
     callSettings,
     new ListTopicSubscriptionsRequest
 {
     Topic = topic,
 },
     _callListTopicSubscriptions);
 /// <summary>
 /// Lists matching topics.
 /// </summary>
 /// <param name="project">The name of the cloud project that topics belong to.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public override IEnumerable <Topic> ListTopics(
     string project,
     CallSettings callSettings = null) => s_listTopicsPageStreamer.Fetch(
     callSettings,
     new ListTopicsRequest
 {
     Project = project,
 },
     _callListTopics);
Esempio n. 7
0
 /// <summary>
 /// Lists logs-based metrics.
 /// </summary>
 /// <param name="project_name">
 /// Required. The resource name of the project containing the metrics.
 /// Example: `"projects/my-project-id"`.
 /// </param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public override IEnumerable <LogMetric> ListLogMetrics(
     string projectName,
     CallSettings callSettings = null) => s_listLogMetricsPageStreamer.Fetch(
     callSettings,
     new ListLogMetricsRequest
 {
     ProjectName = projectName,
 },
     _callListLogMetrics);
Esempio n. 8
0
 /// <summary>
 /// Lists log entries.  Use this method to retrieve log entries from Cloud
 /// Logging.  For ways to export log entries, see
 /// [Exporting Logs](/logging/docs/export).
 /// </summary>
 /// <param name="project_ids">
 /// Required. One or more project IDs or project numbers from which to retrieve
 /// log entries.  Examples of a project ID: `"my-project-1A"`, `"1234567890"`.
 /// </param>
 /// <param name="filter">
 /// Optional. An [advanced logs filter](/logging/docs/view/advanced_filters).
 /// The filter is compared against all log entries in the projects specified by
 /// `projectIds`.  Only entries that match the filter are retrieved.  An empty
 /// filter matches all log entries.
 /// </param>
 /// <param name="order_by">
 /// Optional. How the results should be sorted.  Presently, the only permitted
 /// values are `"timestamp"` (default) and `"timestamp desc"`.  The first
 /// option returns entries in order of increasing values of
 /// `LogEntry.timestamp` (oldest first), and the second option returns entries
 /// in order of decreasing timestamps (newest first).  Entries with equal
 /// timestamps are returned in order of `LogEntry.insertId`.
 /// </param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public override IEnumerable <LogEntry> ListLogEntries(
     IEnumerable <string> projectIds,
     string filter,
     string orderBy,
     CallSettings callSettings = null) => s_listLogEntriesPageStreamer.Fetch(
     callSettings,
     new ListLogEntriesRequest
 {
     ProjectIds = { projectIds },
     Filter     = filter,
     OrderBy    = orderBy,
 },
     _callListLogEntries);
Esempio n. 9
0
        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));
        }
Esempio n. 10
0
        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));
        }
        /// <summary>
        /// Lists the name of the subscriptions for this topic.
        /// </summary>
        /// <param name="topic">The name of the topic that subscriptions are attached to.</param>
        /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
        /// <returns>The RPC response.</returns>
        public override IEnumerable <string> ListTopicSubscriptions(
            string topic,
            CallSettings callSettings = null)
        {
            ListTopicSubscriptionsRequest request = new ListTopicSubscriptionsRequest
            {
                Topic = topic,
            };

            return(s_listTopicSubscriptionsPageStreamer.Fetch(
                       request,
                       pageStreamRequest => GrpcClient.ListTopicSubscriptions(
                           pageStreamRequest,
                           _clientHelper.BuildCallOptions(null, callSettings))
                       ));
        }
        /// <summary>
        /// Lists matching topics.
        /// </summary>
        /// <param name="project">The name of the cloud project that topics belong to.</param>
        /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
        /// <returns>The RPC response.</returns>
        public override IEnumerable <Topic> ListTopics(
            string project,
            CallSettings callSettings = null)
        {
            ListTopicsRequest request = new ListTopicsRequest
            {
                Project = project,
            };

            return(s_listTopicsPageStreamer.Fetch(
                       request,
                       pageStreamRequest => GrpcClient.ListTopics(
                           pageStreamRequest,
                           _clientHelper.BuildCallOptions(null, callSettings))
                       ));
        }
        /// <summary>
        /// Lists log entries.  Use this method to retrieve log entries from Cloud
        /// Logging.  For ways to export log entries, see
        /// [Exporting Logs](/logging/docs/export).
        /// </summary>
        /// <param name="project_ids">
        /// Required. One or more project IDs or project numbers from which to retrieve
        /// log entries.  Examples of a project ID: `"my-project-1A"`, `"1234567890"`.
        /// </param>
        /// <param name="filter">
        /// Optional. An [advanced logs filter](/logging/docs/view/advanced_filters).
        /// The filter is compared against all log entries in the projects specified by
        /// `projectIds`.  Only entries that match the filter are retrieved.  An empty
        /// filter matches all log entries.
        /// </param>
        /// <param name="order_by">
        /// Optional. How the results should be sorted.  Presently, the only permitted
        /// values are `"timestamp"` (default) and `"timestamp desc"`.  The first
        /// option returns entries in order of increasing values of
        /// `LogEntry.timestamp` (oldest first), and the second option returns entries
        /// in order of decreasing timestamps (newest first).  Entries with equal
        /// timestamps are returned in order of `LogEntry.insertId`.
        /// </param>
        /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
        /// <returns>The RPC response.</returns>
        public override IEnumerable <LogEntry> ListLogEntries(
            IEnumerable <string> projectIds,
            string filter,
            string orderBy,
            CallSettings callSettings = null)
        {
            ListLogEntriesRequest request = new ListLogEntriesRequest
            {
                ProjectIds = { projectIds },
                Filter     = filter,
                OrderBy    = orderBy,
            };

            return(s_listLogEntriesPageStreamer.Fetch(
                       request,
                       pageStreamRequest => GrpcClient.ListLogEntries(
                           pageStreamRequest,
                           _clientHelper.BuildCallOptions(null, callSettings))
                       ));
        }
Esempio n. 14
0
        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) );
            }
        }
        /// <inheritdoc />
        public override IEnumerable <Object> ListObjects(string bucket, string prefix, ListObjectsOptions options = null)
        {
            var initialRequest = CreateListObjectsRequest(bucket, prefix, options);

            return(s_objectPageStreamer.Fetch(initialRequest));
        }