private static void UnmarshallResult(XmlUnmarshallerContext context, ListSubscriptionsResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("NextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Subscriptions/member", targetDepth)) { var unmarshaller = SubscriptionUnmarshaller.Instance; var item = unmarshaller.Unmarshall(context); response.Subscriptions.Add(item); continue; } } } return; }
public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems) { AmazonSimpleNotificationServiceConfig config = new AmazonSimpleNotificationServiceConfig(); config.RegionEndpoint = region; ConfigureClient(config); AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient(creds, config); ListSubscriptionsResponse resp = new ListSubscriptionsResponse(); do { ListSubscriptionsRequest req = new ListSubscriptionsRequest { NextToken = resp.NextToken }; resp = client.ListSubscriptions(req); CheckError(resp.HttpStatusCode, "200"); foreach (var obj in resp.Subscriptions) { AddObject(obj); } }while (!string.IsNullOrEmpty(resp.NextToken)); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { ListSubscriptionsResponse response = new ListSubscriptionsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.IsStartElement) { if (context.TestExpression("ListSubscriptionsResult", 2)) { UnmarshallResult(context, response); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context); } } } return(response); }
public async System.Threading.Tasks.Task <ListSubscriptionsResponse> GetSubscriptionsAsync() { ListSubscriptionsResponse listSubscription = new ListSubscriptionsResponse(); using (AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(credentials, Amazon.RegionEndpoint.USEast2)) { ListSubscriptionsRequest request = new ListSubscriptionsRequest(); listSubscription = await snsClient.ListSubscriptionsAsync(); } return(listSubscription); }
public static async Task DeleteAllSubscriptionsWithPrefix(IAmazonSimpleNotificationService snsClient, string topicNamePrefix) { var deletedSubscriptionArns = new HashSet <string>(StringComparer.Ordinal); try { ListSubscriptionsResponse subscriptions = null; do { subscriptions = await snsClient.ListSubscriptionsAsync(subscriptions?.NextToken); // if everything returned here has already been deleted it is probably a good time to stop trying due to the eventual consistency if (subscriptions.Subscriptions.All(subscription => deletedSubscriptionArns.Contains(subscription.SubscriptionArn))) { return; } var deletionTasks = new List <Task>(subscriptions.Subscriptions.Count); deletionTasks.AddRange(subscriptions.Subscriptions .Where(subscription => !deletedSubscriptionArns.Contains(subscription.SubscriptionArn)) .Select(async subscription => { if (!subscription.TopicArn.Contains($":{topicNamePrefix}")) { return; } try { await snsClient.UnsubscribeAsync(subscription.SubscriptionArn).ConfigureAwait(false); deletedSubscriptionArns.Add(subscription.SubscriptionArn); } catch (Exception) { Console.WriteLine($"Unable to delete subscription '{subscription.SubscriptionArn}' '{subscription.TopicArn}'"); } })); await Task.WhenAll(deletionTasks).ConfigureAwait(false); } while (subscriptions.NextToken != null && subscriptions.Subscriptions.Count > 0); } catch (Exception) { Console.WriteLine($"Unable to delete subscriptions with topic prefix '{topicNamePrefix}'"); } }
public static void SNSListSubscriptions() { #region SNSListSubscriptions var snsClient = new AmazonSimpleNotificationServiceClient(); var request = new ListSubscriptionsRequest(); var response = new ListSubscriptionsResponse(); do { response = snsClient.ListSubscriptions(request); foreach (var sub in response.Subscriptions) { Console.WriteLine("Subscription: {0}", sub.SubscriptionArn); } request.NextToken = response.NextToken; } while (!string.IsNullOrEmpty(response.NextToken)); #endregion Console.ReadLine(); }
public async Task TestGetSubscriptionListAsyncException() { var responses = new ListSubscriptionsResponse[0]; PubsubService service = GetMockedService( (PubsubService s) => s.Projects, p => p.Subscriptions, s => s.List(It.IsAny <string>()), responses); var sourceUnderTest = new PubsubDataSource(service, ProjectName); try { await sourceUnderTest.GetSubscriptionListAsync(); Assert.Fail(); } finally { var subscriptionsMock = Mock.Get(service.Projects.Subscriptions); subscriptionsMock.Verify(s => s.List(ProjectResourceName), Times.AtLeastOnce); subscriptionsMock.Verify(s => s.List(It.IsNotIn(ProjectResourceName)), Times.Never); } }
/// <summary> /// 分页返回请求者的所有的订阅列表 /// </summary> public void ListSubscriptions() { // 设置请求对象 ListSubscriptionsRequest request = new ListSubscriptionsRequest { Limit = 10, Offset = 0, }; try { // 发送请求并返回响应 ListSubscriptionsResponse response = smnClient.SendRequest(request); int result = response.SubscriptionCount; Console.WriteLine("{0}", result); Console.ReadLine(); } catch (Exception e) { // 处理异常 Console.WriteLine("{0}", e.Message); } }
private static void UnmarshallResult(XmlUnmarshallerContext context, ListSubscriptionsResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("Subscriptions/member", targetDepth)) { response.Subscriptions.Add(SubscriptionUnmarshaller.GetInstance().Unmarshall(context)); continue; } if (context.TestExpression("NextToken", targetDepth)) { response.NextToken = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } } else if (context.IsEndElement && context.CurrentDepth < originalDepth) { return; } } return; }
protected override void ProcessRecord() { if (Subscription != null) { Subscription = Subscription.Select(item => GetProjectPrefixForSubscription(item, Project)).ToArray(); } // Handles the case where user wants to list all subscriptions in a particular topic. // In this case, we will have to make a call to get the name of all the subscriptions in that topic // before calling get request on each subscription. if (Topic != null) { Topic = GetProjectPrefixForTopic(Topic, Project); ProjectsResource.TopicsResource.SubscriptionsResource.ListRequest listRequest = Service.Projects.Topics.Subscriptions.List(Topic); do { ListTopicSubscriptionsResponse response = null; try { response = listRequest.Execute(); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { WriteResourceMissingError( exceptionMessage: $"Topic '{Topic}' does not exist in project '{Project}'.", errorId: "TopicNotFound", targetObject: Topic); } if (response?.Subscriptions != null) { // If user gives us a list of subscriptions to search for, we have to make sure that // those subscriptions belong to the topic. if (Subscription != null) { IEnumerable <string> selectedSubscriptions = response.Subscriptions .Where(sub => Subscription.Contains(sub, System.StringComparer.OrdinalIgnoreCase)); GetSubscriptions(selectedSubscriptions); } else { GetSubscriptions(response.Subscriptions); } } listRequest.PageToken = response.NextPageToken; }while (!Stopping && listRequest.PageToken != null); return; } // If no topic is given, then we are left with 2 cases: // 1. User gives us a list of subscriptions: we just find those subscriptions and returned. // 2. User does not give us any subscriptions: we just return all subscriptions in the project. if (Subscription != null && Subscription.Length > 0) { GetSubscriptions(Subscription.Select(item => GetProjectPrefixForSubscription(item, Project))); } else { ProjectsResource.SubscriptionsResource.ListRequest listRequest = Service.Projects.Subscriptions.List($"projects/{Project}"); do { ListSubscriptionsResponse response = listRequest.Execute(); if (response.Subscriptions != null) { WriteObject(response.Subscriptions, true); } listRequest.PageToken = response.NextPageToken; }while (!Stopping && listRequest.PageToken != null); } }