private static void DeleteAllModels(int iteration) { foreach (ModelData md in client.GetModels()) { try { client.DeleteModel(md.Id); Log.Ok("Successfully deleted Model {" + md.Id + "}. Attempt [" + iteration + "]"); } catch (RequestFailedException e2) { //Log.Error("Failed to delete Model {" + md.Id + "}"); //Log.Error(e2.Message); // skip this and go to the next one } } try { IEnumerable <ModelData> c = client.GetModels() as IEnumerable <ModelData>; if (c.Count <ModelData>() > 0) { DeleteAllModels(iteration + 1); } } catch (Exception) { return; } }
private void DeleteAllModels(DigitalTwinsClient client, int iteration) { foreach (DigitalTwinsModelData modelData in client.GetModels()) { try { client.DeleteModel(modelData.Id); Log.Ok($"Deleted model '{modelData.Id}' (Iteration {iteration})"); } catch (RequestFailedException ex) when(ex.Status == (int)HttpStatusCode.Conflict) { // This model is a dependent and will be deleted in the next iteration. } catch (Exception ex) { Log.Error($"Failed to delete model '{modelData.Id}': {ex.Message}"); } } if (client.GetModels().Any()) { DeleteAllModels(client, iteration + 1); } }