public NestedServiceIdentitiesIterator(IDeviceScopeApiClientProvider securityScopesApiClientProvider) { this.clientProvider = Preconditions.CheckNotNull(securityScopesApiClientProvider); // Put the first node (the actor device) into the queue this.actorClient = this.clientProvider.CreateNestedDeviceScopeClient(); this.remainingEdgeNodes = new Queue <IDeviceScopeApiClient>(); this.remainingEdgeNodes.Enqueue(this.actorClient); }
public async Task <IEnumerable <ServiceIdentity> > GetNext() { // Check for the empty-case if (this.remainingEdgeNodes.Count == 0) { return(Enumerable.Empty <ServiceIdentity>()); } // Get the next item in the queue IDeviceScopeApiClient currentNode = this.remainingEdgeNodes.Dequeue(); var serviceIdentities = new List <ServiceIdentity>(); // Make the call to upstream and fetch the next batch of identities ScopeResult scopeResult = await currentNode.GetIdentitiesInScopeAsync(); if (scopeResult != null) { Events.ScopeResultReceived(scopeResult); if (scopeResult.Devices != null) { serviceIdentities.AddRange(scopeResult.Devices.Select(d => d.ToServiceIdentity())); } if (scopeResult.Modules != null) { serviceIdentities.AddRange(scopeResult.Modules.Select(m => m.ToServiceIdentity())); } if (!string.IsNullOrWhiteSpace(scopeResult.ContinuationLink)) { // Since there's a continuation link, we're not done enumerating // the identities under the current device scope. Enqueue another // item in the queue to handle the continuation IDeviceScopeApiClient continuationClient = this.clientProvider.CreateOnBehalfOf(currentNode.TargetEdgeDeviceId, Option.Some(scopeResult.ContinuationLink)); this.remainingEdgeNodes.Enqueue(continuationClient); } } else { Events.NullResult(); } foreach (ServiceIdentity identity in serviceIdentities) { // The current device itself will come back as part of the query, // make sure we don't re-enqueue it again if (identity.IsEdgeDevice && identity.DeviceId != currentNode.TargetEdgeDeviceId) { // Enqueue a new item for every child Edge in this batch. IDeviceScopeApiClient childClient = this.clientProvider.CreateOnBehalfOf(identity.DeviceId, Option.None <string>()); this.remainingEdgeNodes.Enqueue(childClient); } } return(serviceIdentities.AsEnumerable()); }
public ServiceIdentitiesIterator(IDeviceScopeApiClient securityScopesApiClient) { this.securityScopesApiClient = Preconditions.CheckNotNull(securityScopesApiClient, nameof(securityScopesApiClient)); this.HasNext = true; Events.IteratorCreated(); }
public ServiceProxy(IDeviceScopeApiClient securityScopesApiClient) { this.securityScopesApiClient = Preconditions.CheckNotNull(securityScopesApiClient, nameof(securityScopesApiClient)); }