public async Task <List <Client> > GetClientsAsync(bool includeCLIDs, int?clientId) { try { string sessionId = ""; AdescomCTMSoapWrapper atmanCTMWithoutProxyClassesClient = new AdescomCTMSoapWrapper(_configuration); ConcurrentBag <Client> clients = new ConcurrentBag <Client>(); sessionId = await atmanCTMWithoutProxyClassesClient.LoginAsync( _configuration.GetValue <string>("WebServiceConnectionSettings:ResellerLogin"), _configuration.GetValue <string>("WebServiceConnectionSettings:ResellerPassword"), _configuration.GetValue <int>("WebServiceConnectionSettings:SessionTimeout")); clientDetailsArray clientDetailsArray = await atmanCTMWithoutProxyClassesClient.GetClientsAsync(); List <clientDetails> clientDetailsFiltered; if (clientId.HasValue) { clientDetailsFiltered = clientDetailsArray.clients.Where(c => c.clientID == clientId.Value).ToList(); } else { clientDetailsFiltered = clientDetailsArray.clients.ToList(); } if (includeCLIDs) { if (clientDetailsArray != null && clientDetailsArray.count > 0) { Parallel.ForEach(clientDetailsFiltered, new ParallelOptions { MaxDegreeOfParallelism = 1 }, (client) => { GetCLIDsForClient(client, atmanCTMWithoutProxyClassesClient, clients); }); } } else { foreach (clientDetails clientDetails in clientDetailsFiltered) { clients.Add(new Client(clientDetails.clientID, clientDetails.billingDetails.name, new List <Clid>() { })); } } await atmanCTMWithoutProxyClassesClient.LogoutAsync(sessionId); return(clients.ToList()); } catch (AggregateException ex) { throw new Exception(ex.InnerException.Message); } }
public async Task <List <ClientBilling> > GetBillingForClientsAsync(List <Client> clients, DateTime startDate, DateTime endDate) { try { string sessionId = ""; AdescomCTMSoapWrapper atmanCTMWithoutProxyClassesClient = new AdescomCTMSoapWrapper(_configuration); BillingQueryOptions billingQueryOptions = new BillingQueryOptions() { incoming = false, outgoing = true, includeZeroDuration = false }; ConcurrentBag <ClientBilling> clientsBillings = new ConcurrentBag <ClientBilling>(); sessionId = await atmanCTMWithoutProxyClassesClient.LoginAsync( _configuration.GetValue <string>("WebServiceConnectionSettings:ResellerLogin"), _configuration.GetValue <string>("WebServiceConnectionSettings:ResellerPassword"), _configuration.GetValue <int>("WebServiceConnectionSettings:SessionTimeout")); Parallel.ForEach(clients, new ParallelOptions { MaxDegreeOfParallelism = 20 }, (client) => { GetBillingForClient(startDate, endDate, client, atmanCTMWithoutProxyClassesClient, billingQueryOptions, clientsBillings); }); await atmanCTMWithoutProxyClassesClient.LogoutAsync(sessionId); return(clientsBillings.ToList()); } catch (AggregateException ex) { throw new Exception(ex.InnerException.Message); } }