// Drops the selected policy async Task ShowDropPolicy() { try { var policy = SelectedRetentionPolicy; if (policy == null || string.IsNullOrWhiteSpace(SelectedDatabase)) { return; } var wasDefault = policy.Default; // Confirm the drop if (DialogResult.OK == MessageBox.Show(string.Format("Drop retention policy: {0}?", policy.Name), "Confirm Drop", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)) { var response = await InfluxDbClient.DropRetentionPolicyAsync(SelectedDatabase, policy.Name); if (!response.Success) { AppForm.DisplayError(response.Body); } // If this was the default policy and was dropped if (wasDefault) { policies = await InfluxDbClient.GetRetentionPoliciesAsync(SelectedDatabase); if (policies.Count() > 0) { // Try to find the autogen/default var rp = (from r in policies where r.Name.ToLower() == "autogen" select r).FirstOrDefault(); // Otherwise try to find another policy with a different name if (rp == null) { rp = (from r in policies where r.Name != policy.Name select r).FirstOrDefault(); } if (rp != null) { // If a new retention policy was found, make it the default response = await InfluxDbClient.AlterRetentionPolicyAsync(SelectedDatabase, rp.Name, rp.Duration, rp.ReplicationCopies, true); } } } // Reload latest data await ExecuteRequestAsync(); } } catch (Exception ex) { AppForm.DisplayException(ex); } }