示例#1
0
 public static DeleteOpportunityRequest Map(this DeleteOpportunityRequestDto deleteOpportunityRequestDto)
 {
     return(new DeleteOpportunityRequest()
     {
         deleteBy = deleteOpportunityRequestDto.DeleteBy,
         input = deleteOpportunityRequestDto.Input.Select(d => d.Map())
     });
 }
示例#2
0
        private async Task PurgeOpportunities()
        {
            int taskCount     = 0;
            int recordCounter = 0;

            Console.WriteLine("Loading Opportunities from Database. Please wait...");
            IEnumerable <MarketoOpportunity> marketoOpportunities = await _databaseRepository.GetMarketoOpportunities();

            Console.WriteLine("Starting Opportunities Purge");
            IEnumerable <MarketoOpportunity> opportunities = marketoOpportunities.ToList();

            Console.WriteLine("Opportunities to Purge: {0}", opportunities.Count());

            foreach (IEnumerable <MarketoOpportunity> opportunityBatch in opportunities.Chunk(300))
            {
                DeleteOpportunityRequestDto deleteOpportunityRequestDto = new DeleteOpportunityRequestDto()
                {
                    DeleteBy = "idField", Input = new List <DeleteOpportunityDto>()
                };
                List <DeleteOpportunityDto> deleteOpportunityDtos = new List <DeleteOpportunityDto>();

                List <Task> apiTasks = new List <Task>();

                foreach (MarketoOpportunity opportunity in opportunityBatch)
                {
                    deleteOpportunityDtos.Add(new DeleteOpportunityDto()
                    {
                        Id = opportunity.MarketoOpportunityId
                    });
                }

                deleteOpportunityRequestDto.Input = deleteOpportunityDtos;

                apiTasks.Add(_marketoGateway.DeleteOpportunity(deleteOpportunityRequestDto.Map()));
                taskCount++;
                recordCounter += 300;

                if (taskCount >= 10)
                {
                    if (taskCount % 10 == 0)
                    {
                        Console.WriteLine("Purging Opportunities - Task count: {0}, RecordCount: {1}", taskCount, recordCounter);
                        await Task.WhenAll(apiTasks);

                        Console.WriteLine("Purging Opportunities - Sleeping for {0} seconds on count: {1}", 21, taskCount);
                        await Task.Delay(21000);
                    }
                }
                else
                {
                    await Task.WhenAll(apiTasks);
                }
            }
        }