Esempio n. 1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListAccountsResponse response = new ListAccountsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Accounts", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Account, AccountUnmarshaller>(AccountUnmarshaller.Instance);
                    response.Accounts = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Esempio n. 2
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonOrganizationsConfig config = new AmazonOrganizationsConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonOrganizationsClient client = new AmazonOrganizationsClient(creds, config);

            ListAccountsResponse resp = new ListAccountsResponse();

            do
            {
                ListAccountsRequest req = new ListAccountsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListAccounts(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Accounts)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        /// <summary>
        /// Creates the Organizations client and then calls its
        /// ListAccountsAsync method.
        /// </summary>
        static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            var request = new ListAccountsRequest
            {
                MaxResults = 5,
            };

            var response = new ListAccountsResponse();

            try
            {
                do
                {
                    response = await client.ListAccountsAsync(request);

                    response.Accounts.ForEach(a => DisplayAccounts(a));
                    if (response.NextToken is not null)
                    {
                        request.NextToken = response.NextToken;
                    }
                } while (response.NextToken is not null);
            }
            catch (AWSOrganizationsNotInUseException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
        public ListAccountsResponse listAccounts(string nextToken = null)
        {
            AmazonOrganizationsClient client = new AmazonOrganizationsClient();

            ListAccountsRequest request = new ListAccountsRequest()
            {
                NextToken = nextToken
            };
            ListAccountsResponse response = client.ListAccountsAsync(request).Result;

            return(response);
        }
Esempio n. 5
0
        public ICommandResponse ParseResponse(WebResponse webResponse)
        {
            var response       = new ListAccountsResponse();
            var responseStream = webResponse.GetResponseStream();

            if ((responseStream != null) && (responseStream.CanRead))
            {
                var responseDocument = XDocument.Load(responseStream);
                response.Accounts =
                    responseDocument.Root.Elements()
                    .Where(e => e.Name.LocalName.Equals("account", StringComparison.InvariantCultureIgnoreCase))
                    .Select(Account.From);
            }

            return(response);
        }
Esempio n. 6
0
        private async Task <List <Account> > GetAccountsFromServiceAsync(MyBusinessService service)
        {
            List <Account> accounts = new List <Account>();

            try
            {
                ListAccountsResponse accountsResult = await service.Accounts.List().ExecuteAsync().ConfigureAwait(false);

                accounts.AddRange(accountsResult.Accounts);
            }
            catch (Exception e)
            {
                await OutputAsync(e.Message);
            }

            return(accounts);
        }
Esempio n. 7
0
        public JArray accountsWrapper()
        {
            JArray accountsArray = new JArray();

            ListAccountsResponse response = listAccounts();

            while (response.NextToken != null)
            {
                // LambdaLogger.Log("next set..." + Environment.NewLine);
                foreach (Amazon.Organizations.Model.Account awsAccount in response.Accounts)
                {
                    // LambdaLogger.Log(awsAccount.Id + Environment.NewLine);
                    if (awsAccount.Status == AccountStatus.ACTIVE)
                    {
                        accountsArray.Add(awsAccount.Id);
                    }
                }

                Thread.Sleep(100);

                response = listAccounts(response.NextToken);
            }

            Thread.Sleep(100);

            // LambdaLogger.Log("One set only..." + Environment.NewLine);
            foreach (Amazon.Organizations.Model.Account awsAccount in response.Accounts)
            {
                // LambdaLogger.Log(awsAccount.Id + Environment.NewLine);
                if (awsAccount.Status == AccountStatus.ACTIVE)
                {
                    accountsArray.Add(awsAccount.Id);
                }
            }

            foreach (string accountId in Environment.GetEnvironmentVariable("AdditionalAccounts").Split(","))
            {
                accountsArray.Add(accountId);
            }

            return(accountsArray);
        }
Esempio n. 8
0
        /// <summary>Gets and prints all accounts for the logged in user.</summary>
        /// <returns>The last page of retrieved accounts.</returns>
        private IList <Account> GetAllAccounts()
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Listing all AdSense accounts");
            Console.WriteLine("=================================================================");

            // Retrieve account list in pages and display data as we receive it.
            string pageToken = null;
            ListAccountsResponse accountResponse = null;

            do
            {
                var accountRequest = service.Accounts.List();
                accountRequest.PageSize  = maxListPageSize;
                accountRequest.PageToken = pageToken;
                accountResponse          = accountRequest.Execute();

                if (!accountResponse.Accounts.IsNullOrEmpty())
                {
                    foreach (var account in accountResponse.Accounts)
                    {
                        Console.WriteLine("Account with ID \"{0}\" and name \"{1}\" was found.", account.Name,
                                          account.DisplayName);
                    }
                }
                else
                {
                    Console.WriteLine("No accounts found.");
                }

                pageToken = accountResponse.NextPageToken;
            } while (pageToken != null);
            Console.WriteLine();

            // Return the last page of accounts, so that the main sample has something to run.
            return(accountResponse.Accounts);
        }