コード例 #1
0
        // 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);
            }
        }
コード例 #2
0
        // Binds retention policies for the current database
        async Task BindSelectedPolicy()
        {
            listView.Items.Clear();
            if (string.IsNullOrWhiteSpace(SelectedDatabase))
            {
                return;
            }

            listView.BeginUpdate();

            policies = await InfluxDbClient.GetRetentionPoliciesAsync(SelectedDatabase);

            foreach (var rp in policies)
            {
                var li = new ListViewItem(new string[]
                {
                    rp.Name,
                    rp.Duration,
                    rp.ShardGroupDuration,
                    rp.ReplicationCopies.ToString(),
                    rp.Default ? CheckMark : null
                })
                {
                    Tag = rp
                };

                listView.Items.Add(li);
            }

            // Select current policy if any
            if (SelectedRetentionPolicy != null)
            {
                foreach (ListViewItem li in listView.Items)
                {
                    if (li.Text == SelectedRetentionPolicy.Name)
                    {
                        li.Selected = true;
                        break;
                    }
                }
            }

            listView.EndUpdate();

            UpdateUIState();
        }
コード例 #3
0
        // Shows the alter policy dialog
        async Task ShowAlterPolicy()
        {
            try
            {
                var policy = SelectedRetentionPolicy;
                if (policy == null || string.IsNullOrWhiteSpace(SelectedDatabase))
                {
                    return;
                }

                var prevIsDefault = policy.Default;

                // Clear out the dialog values
                policyDialog.ResetPolicyValues();

                // Bind to current policy
                policyDialog.BindToPolicy(SelectedRetentionPolicy);

                if (policyDialog.ShowDialog() == DialogResult.OK)
                {
                    var name        = policyDialog.PolicyName;
                    var duration    = policyDialog.PolicyDuration;
                    var replication = policyDialog.PolicyReplication;
                    var isDefault   = policyDialog.PolicyDefault;

                    var response = await InfluxDbClient.AlterRetentionPolicyAsync(SelectedDatabase, name, duration, replication, isDefault);

                    if (!response.Success)
                    {
                        AppForm.DisplayError(response.Body);
                    }
                    else
                    {
                        // If default status chagned, attempt to update another policy as default
                        if (prevIsDefault != isDefault && !isDefault)
                        {
                            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);
            }
        }