/// <summary> /// Data is assumed to be there, so use TryDelete /// </summary> /// <param name="service"></param> protected virtual void CleanupDataPostInitialization(IOrganizationService service) { var totalWatch = new Stopwatch(); totalWatch.Start(); var requests = new OrganizationRequestCollection(); foreach (var id in EntityIds.Where(e => e.Key != "businessunit").SelectMany(entityType => entityType.Value)) { requests.Add(new DeleteRequest { Target = Entities[id] }); } if (requests.Any()) { var response = (ExecuteMultipleResponse)service.Execute( new ExecuteMultipleRequest() { Settings = new ExecuteMultipleSettings() { ContinueOnError = true, ReturnResponses = false }, Requests = requests, }); ThrowExceptionForFaults(response, requests); totalWatch.Stop(); Debug.WriteLine("Total Time to delete {0} entities of types {1} (ms): {2}", requests.Count, String.Join(", ", requests.Select(s => ((DeleteRequest)s).Target.LogicalName).Distinct()), totalWatch.ElapsedMilliseconds); } List <Guid> businessIds; if (!EntityIds.TryGetValue("businessunit", out businessIds)) { return; } foreach (var id in businessIds) { service.DeleteBusinessUnit(id); } }
/// <summary> /// Data is assumed to be there, so use TryDelete /// </summary> /// <param name="service"></param> protected virtual void CleanupDataPostInitialization(IOrganizationService service) { var totalWatch = new Stopwatch(); totalWatch.Start(); var requests = new OrganizationRequestCollection(); foreach (var id in EntityIds.Where(e => e.Key != "businessunit").SelectMany(entityType => entityType.Value)) { requests.Add(new DeleteRequest { Target = Entities[id] }); } if (requests.Any()) { var response = (ExecuteMultipleResponse)service.Execute( new ExecuteMultipleRequest() { Settings = new ExecuteMultipleSettings() { ContinueOnError = true, ReturnResponses = false }, Requests = requests, }); ThrowExceptionForFaults(response, requests); totalWatch.Stop(); Debug.WriteLine("Total Time to delete {0} entities of types {1} (ms): {2}", requests.Count, String.Join(", ", requests.Select(s => ((DeleteRequest)s).Target.LogicalName).Distinct()), totalWatch.ElapsedMilliseconds); } List<Guid> businessIds; if (!EntityIds.TryGetValue("businessunit", out businessIds)) { return; } foreach (var id in businessIds) { service.DeleteBusinessUnit(id); } }