2017-01-16 20:59:50 +01:00
|
|
|
|
/* Copyright (c) Citrix Systems, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-09-07 12:02:07 +02:00
|
|
|
|
using System.ComponentModel;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Drawing;
|
2017-05-25 17:29:27 +02:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using XenAdmin.Actions;
|
2017-05-25 17:29:27 +02:00
|
|
|
|
using XenAdmin.Alerts;
|
|
|
|
|
using XenAdmin.Controls;
|
|
|
|
|
using XenAdmin.Core;
|
2017-09-07 12:02:07 +02:00
|
|
|
|
using XenAdmin.Properties;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Wizards.NewPolicyWizard;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
2017-05-25 17:29:27 +02:00
|
|
|
|
namespace XenAdmin.Dialogs.ScheduledSnapshots
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-05-25 17:29:27 +02:00
|
|
|
|
public partial class ScheduledSnapshotsDialog: XenDialogBase
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
private readonly Pool Pool;
|
|
|
|
|
private bool updatingPolicies;
|
2017-09-05 00:07:22 +02:00
|
|
|
|
|
2017-05-25 17:29:27 +02:00
|
|
|
|
public ScheduledSnapshotsDialog(Pool pool)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
: base(pool.Connection)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Pool = pool;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
InitializeComponent();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
chevronButton1.Text = Messages.SHOW_RUN_HISTORY;
|
|
|
|
|
chevronButton1.Image = Properties.Resources.PDChevronDown;
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
|
|
|
|
ColumnExpand.DefaultCellStyle.NullValue = null;
|
|
|
|
|
comboBoxTimeSpan.SelectedIndex = 0;
|
|
|
|
|
dataGridViewRunHistory.Columns[2].ValueType = typeof(DateTime);
|
|
|
|
|
dataGridViewRunHistory.Columns[2].DefaultCellStyle.Format = Messages.DATEFORMAT_DMY_HM;
|
|
|
|
|
panelHistory.Visible = false;
|
2017-05-25 15:56:13 +02:00
|
|
|
|
RefreshPoolTitle(pool);
|
2017-09-07 12:02:07 +02:00
|
|
|
|
RefreshButtons();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2017-09-05 00:07:22 +02:00
|
|
|
|
|
2017-05-25 17:29:27 +02:00
|
|
|
|
public ScheduledSnapshotsDialog() { }
|
2017-09-05 00:07:22 +02:00
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
private PolicyRow SelectedVmssRow
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (dataGridViewPolicies.SelectedRows.Count > 0)
|
|
|
|
|
return dataGridViewPolicies.SelectedRows[0] as PolicyRow;
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int RunHistoryTimeSpan
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (comboBoxTimeSpan.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0: //top 10 messages (default)
|
|
|
|
|
return 0;
|
|
|
|
|
case 1:
|
|
|
|
|
return 24; //messages from past 24 Hrs
|
|
|
|
|
case 2:
|
|
|
|
|
return 7 * 24; //messages from last 7 days
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class PolicyRow : DataGridViewRow
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private DataGridViewTextBoxCell _name = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell _numVMs = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell _nextRunTime = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell _status = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextAndImageCell _lastResult = new DataGridViewTextAndImageCell();
|
2017-09-11 14:22:12 +02:00
|
|
|
|
|
|
|
|
|
private readonly DateTime? _serverLocalTime;
|
2017-09-05 00:07:22 +02:00
|
|
|
|
private readonly VMSS _policy;
|
2017-09-07 12:02:07 +02:00
|
|
|
|
private readonly List<XenAPI.Message> _alertMessages;
|
|
|
|
|
|
|
|
|
|
public bool IsBusy { get; set; }
|
2017-09-05 00:07:22 +02:00
|
|
|
|
|
|
|
|
|
public VMSS Policy { get { return _policy; } }
|
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
public List<XenAPI.Message> AlertMessages { get { return _alertMessages; } }
|
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
public string PolicyName { get; private set; }
|
|
|
|
|
public string PolicyStatus { get; private set; }
|
|
|
|
|
public int PolicyVmCount { get; private set; }
|
|
|
|
|
public DateTime? PolicyNextRunTime { get; private set; }
|
|
|
|
|
public string PolicyLastResult { get; private set; }
|
|
|
|
|
private Bitmap PolicyLastResultImage { get; set; }
|
|
|
|
|
|
|
|
|
|
public PolicyRow(VMSS policy, List<XenAPI.Message> alertMessages, DateTime? serverLocalTime)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
Cells.AddRange(_name, _status, _numVMs, _nextRunTime, _lastResult);
|
2016-02-18 11:49:40 +01:00
|
|
|
|
_policy = policy;
|
2017-09-07 12:02:07 +02:00
|
|
|
|
_alertMessages = alertMessages;
|
2017-09-11 14:22:12 +02:00
|
|
|
|
_serverLocalTime = serverLocalTime;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
RefreshRow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshRow()
|
|
|
|
|
{
|
2017-09-11 14:22:12 +02:00
|
|
|
|
PolicyName = _policy.Name();
|
|
|
|
|
PolicyVmCount = _policy.VMs.FindAll(vm => _policy.Connection.Resolve(vm).is_a_real_vm()).Count;
|
|
|
|
|
PolicyStatus = _policy.enabled ? Messages.ENABLED : Messages.DISABLED;
|
|
|
|
|
|
|
|
|
|
if (_serverLocalTime.HasValue)
|
|
|
|
|
PolicyNextRunTime = _policy.GetNextRunTime(_serverLocalTime.Value);
|
|
|
|
|
else
|
|
|
|
|
PolicyNextRunTime = null;
|
2017-09-03 04:33:29 +02:00
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
if (_alertMessages.Count > 0)
|
2017-09-05 00:07:22 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
if (_alertMessages[0].priority == PolicyAlert.INFO_PRIORITY)
|
2017-09-05 00:07:22 +02:00
|
|
|
|
{
|
2017-09-11 14:22:12 +02:00
|
|
|
|
PolicyLastResult = Messages.VMSS_SUCCEEDED;
|
|
|
|
|
PolicyLastResultImage = Resources._075_TickRound_h32bit_16;
|
2017-09-05 00:07:22 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-09-11 14:22:12 +02:00
|
|
|
|
PolicyLastResult = Messages.FAILED;
|
|
|
|
|
PolicyLastResultImage = Resources._075_WarningRound_h32bit_16;
|
2017-09-05 00:07:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
else
|
2017-09-05 00:07:22 +02:00
|
|
|
|
{
|
2017-09-11 14:22:12 +02:00
|
|
|
|
PolicyLastResult = Messages.NOT_YET_RUN;
|
|
|
|
|
PolicyLastResultImage = null;
|
2017-09-05 00:07:22 +02:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
_name.Value = PolicyName;
|
|
|
|
|
_numVMs.Value = PolicyVmCount;
|
|
|
|
|
_status.Value = PolicyStatus;
|
|
|
|
|
_lastResult.Value = PolicyLastResult;
|
|
|
|
|
_lastResult.Image = PolicyLastResultImage;
|
|
|
|
|
_nextRunTime.Value = PolicyNextRunTime.HasValue
|
|
|
|
|
? HelpersGUI.DateTimeToString(PolicyNextRunTime.Value, Messages.DATEFORMAT_DMY_HM, true)
|
2017-09-05 00:07:22 +02:00
|
|
|
|
: Messages.VMSS_HOST_NOT_LIVE;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshPoolTitle(Pool pool)
|
|
|
|
|
{
|
|
|
|
|
int protectedVMs = 0;
|
|
|
|
|
int realVMs = 0;
|
|
|
|
|
|
2016-02-17 09:02:24 +01:00
|
|
|
|
foreach (var vm in pool.Connection.Cache.VMs)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2017-09-03 04:33:29 +02:00
|
|
|
|
if (vm.is_a_real_vm() && vm.Show(Properties.Settings.Default.ShowHiddenVMs))
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2016-02-17 09:02:24 +01:00
|
|
|
|
realVMs++;
|
2017-05-25 15:56:13 +02:00
|
|
|
|
if (vm.Connection.Resolve(vm.snapshot_schedule) != null)
|
2016-02-17 09:02:24 +01:00
|
|
|
|
protectedVMs++;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
2016-02-17 09:02:24 +01:00
|
|
|
|
labelPolicyTitle.Text = string.Format(Helpers.IsPool(pool.Connection)
|
2017-05-25 15:56:13 +02:00
|
|
|
|
? Messages.VMSS_SCHEDULED_SNAPSHOTS_DEFINED_FOR_POOL
|
|
|
|
|
: Messages.VMSS_SCHEDULED_SNAPSHOTS_DEFINED_FOR_SERVER,
|
2017-09-03 04:33:29 +02:00
|
|
|
|
pool.Name().Ellipsise(45), protectedVMs, realVMs);
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
private void VMSSCollectionChanged(object sender, EventArgs e)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2017-09-11 14:22:12 +02:00
|
|
|
|
LoadPolicies();
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
2016-01-29 12:34:44 +01:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
private void LoadPolicies()
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2017-09-11 14:22:12 +02:00
|
|
|
|
var action = new LoadVmssAction(Pool.Connection);
|
|
|
|
|
action.Completed += action_Completed;
|
|
|
|
|
action.RunAsync();
|
2017-09-07 12:02:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
private void action_Completed(ActionBase sender)
|
2017-09-07 12:02:07 +02:00
|
|
|
|
{
|
2017-09-11 14:22:12 +02:00
|
|
|
|
var action = sender as LoadVmssAction;
|
|
|
|
|
if (action == null || !action.Succeeded)
|
2017-09-07 12:02:07 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2017-09-11 14:22:12 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
panelLoading.Visible = false;
|
|
|
|
|
updatingPolicies = true;
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
var selectedPolicyUuids = (from PolicyRow row in dataGridViewPolicies.SelectedRows
|
|
|
|
|
select row.Policy.uuid).ToList();
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
var rowList = from kvp in action.SnapshotSchedules select new PolicyRow(kvp.Key, kvp.Value, action.ServerLocalTime);
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
Func<PolicyRow, object> comparer = p => p.PolicyName;
|
|
|
|
|
if (dataGridViewPolicies.SortedColumn != null)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridViewPolicies.SortedColumn.Index == NameColum.Index)
|
|
|
|
|
comparer = p => p.PolicyName;
|
|
|
|
|
else if (dataGridViewPolicies.SortedColumn.Index == EnabledColumn.Index)
|
|
|
|
|
comparer = p => p.PolicyStatus;
|
|
|
|
|
else if (dataGridViewPolicies.SortedColumn.Index == ColumnVMs.Index)
|
|
|
|
|
comparer = p => p.PolicyVmCount;
|
|
|
|
|
else if (dataGridViewPolicies.SortedColumn.Index == DescriptionColum.Index)
|
|
|
|
|
comparer = p => p.PolicyNextRunTime;
|
|
|
|
|
else if (dataGridViewPolicies.SortedColumn.Index == ColumnLastResult.Index)
|
|
|
|
|
comparer = p => p.PolicyLastResult;
|
|
|
|
|
}
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
var rows = dataGridViewPolicies.SortOrder == SortOrder.Descending
|
|
|
|
|
? rowList.OrderByDescending(comparer) : rowList.OrderBy(comparer);
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
dataGridViewPolicies.SuspendLayout();
|
|
|
|
|
dataGridViewPolicies.Rows.Clear();
|
|
|
|
|
dataGridViewPolicies.Rows.AddRange(rows.Cast<DataGridViewRow>().ToArray());
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
foreach (PolicyRow row in dataGridViewPolicies.Rows)
|
|
|
|
|
row.Selected = selectedPolicyUuids.Contains(row.Policy.uuid);
|
|
|
|
|
|
|
|
|
|
if (dataGridViewPolicies.SelectedRows.Count == 0 && dataGridViewPolicies.Rows.Count > 0)
|
|
|
|
|
dataGridViewPolicies.Rows[0].Selected = true;
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
2017-09-11 14:22:12 +02:00
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
dataGridViewPolicies.ResumeLayout();
|
|
|
|
|
updatingPolicies = false;
|
2017-09-05 00:07:22 +02:00
|
|
|
|
|
2017-09-11 14:22:12 +02:00
|
|
|
|
if (action.ServerLocalTime.HasValue)
|
|
|
|
|
{
|
|
|
|
|
string time= HelpersGUI.DateTimeToString(action.ServerLocalTime.Value, Messages.DATEFORMAT_WDMY_HM_LONG, true);
|
|
|
|
|
labelServerTime.Text = string.Format(Messages.SERVER_TIME, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshPoolTitle(Pool);
|
|
|
|
|
RefreshButtons();
|
|
|
|
|
RefreshHistoryLabel();
|
|
|
|
|
RefreshHistoryGrid();
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 15:56:13 +02:00
|
|
|
|
private void VMProtectionPoliciesDialog_Load(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
panelLoading.Visible = true;
|
2017-05-25 15:56:13 +02:00
|
|
|
|
Pool.Connection.Cache.RegisterBatchCollectionChanged<VMSS>(VMSSCollectionChanged);
|
2017-09-11 14:22:12 +02:00
|
|
|
|
LoadPolicies();
|
2017-09-07 12:02:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 14:22:29 +02:00
|
|
|
|
private void VMProtectionPoliciesDialog_FormClosed(object sender, FormClosedEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-06 14:22:29 +02:00
|
|
|
|
Pool.Connection.Cache.DeregisterBatchCollectionChanged<VMSS>(VMSSCollectionChanged);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2017-09-07 12:02:07 +02:00
|
|
|
|
|
|
|
|
|
private void dataGridViewPolicies_SelectionChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
if (updatingPolicies)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
RefreshButtons();
|
2017-09-07 12:02:07 +02:00
|
|
|
|
RefreshHistoryLabel();
|
|
|
|
|
RefreshHistoryGrid();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshButtons()
|
|
|
|
|
{
|
2017-09-06 14:22:29 +02:00
|
|
|
|
if (dataGridViewPolicies.SelectedRows.Count == 1)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
var row = SelectedVmssRow;
|
|
|
|
|
buttonEnable.Text = row.Policy.enabled ? Messages.DISABLE : Messages.ENABLE;
|
|
|
|
|
buttonEnable.Enabled = !row.IsBusy && (row.Policy.VMs.Count != 0 || row.Policy.enabled);
|
|
|
|
|
buttonProperties.Enabled = !row.IsBusy;
|
|
|
|
|
buttonRunNow.Enabled = !row.IsBusy && row.Policy.enabled;
|
|
|
|
|
comboBoxTimeSpan.Enabled = !row.IsBusy;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
buttonProperties.Enabled = buttonEnable.Enabled = buttonRunNow.Enabled =
|
|
|
|
|
comboBoxTimeSpan.Enabled = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2016-02-16 10:49:39 +01:00
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
buttonDelete.Enabled = (from PolicyRow row in dataGridViewPolicies.SelectedRows where !row.IsBusy select row).Any();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 14:22:29 +02:00
|
|
|
|
#region Button event handlers
|
|
|
|
|
|
|
|
|
|
private void buttonNew_Click(object sender, System.EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-06 14:22:29 +02:00
|
|
|
|
new NewPolicyWizard(Pool).Show(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonCancel_Click(object sender, System.EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.Close();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 15:56:13 +02:00
|
|
|
|
private void buttonEnable_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
var row = SelectedVmssRow;
|
|
|
|
|
if (row != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
row.IsBusy = true;
|
|
|
|
|
RefreshButtons();
|
|
|
|
|
new ChangePolicyEnabledAction(row.Policy).RunAsync();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-25 15:56:13 +02:00
|
|
|
|
|
2017-09-06 14:22:29 +02:00
|
|
|
|
private void buttonRunNow_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
var row = SelectedVmssRow;
|
|
|
|
|
if (row != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
row.IsBusy = true;
|
|
|
|
|
RefreshButtons();
|
|
|
|
|
new RunPolicyNowAction(row.Policy).RunAsync();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 15:56:13 +02:00
|
|
|
|
private void buttonProperties_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
var row = SelectedVmssRow;
|
|
|
|
|
if (row != null)
|
2016-02-15 05:35:26 +01:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
using (PropertiesDialog propertiesDialog = new PropertiesDialog(row.Policy))
|
|
|
|
|
propertiesDialog.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-06 14:22:29 +02:00
|
|
|
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var selectedPolicies = new List<VMSS>();
|
|
|
|
|
int numberOfProtectedVMs = 0;
|
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
foreach (PolicyRow row in dataGridViewPolicies.SelectedRows)
|
2017-09-06 14:22:29 +02:00
|
|
|
|
{
|
2017-09-07 12:02:07 +02:00
|
|
|
|
selectedPolicies.Add(row.Policy);
|
|
|
|
|
numberOfProtectedVMs += row.Policy.VMs.Count;
|
2017-09-06 14:22:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
string text = selectedPolicies.Count == 1
|
|
|
|
|
? String.Format(numberOfProtectedVMs == 0
|
|
|
|
|
? Messages.CONFIRM_DELETE_POLICY_0
|
|
|
|
|
: Messages.CONFIRM_DELETE_POLICY, selectedPolicies[0].Name(), numberOfProtectedVMs)
|
|
|
|
|
: string.Format(numberOfProtectedVMs == 0
|
|
|
|
|
? Messages.CONFIRM_DELETE_POLICIES_0
|
|
|
|
|
: Messages.CONFIRM_DELETE_POLICIES, numberOfProtectedVMs);
|
|
|
|
|
|
2017-09-06 14:22:29 +02:00
|
|
|
|
using (var dlg = new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Warning, text, Messages.DELETE_VMSS_TITLE),
|
|
|
|
|
ThreeButtonDialog.ButtonYes,
|
|
|
|
|
ThreeButtonDialog.ButtonNo))
|
|
|
|
|
{
|
|
|
|
|
if (dlg.ShowDialog(this) == DialogResult.Yes)
|
2017-09-07 12:02:07 +02:00
|
|
|
|
{
|
|
|
|
|
foreach (PolicyRow row in dataGridViewPolicies.SelectedRows)
|
|
|
|
|
row.IsBusy = true;
|
|
|
|
|
|
|
|
|
|
RefreshButtons();
|
2017-09-06 14:22:29 +02:00
|
|
|
|
new DestroyPolicyAction(Pool.Connection, selectedPolicies).RunAsync();
|
2017-09-07 12:02:07 +02:00
|
|
|
|
}
|
2017-09-06 14:22:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 15:56:13 +02:00
|
|
|
|
private void chevronButton1_ButtonClick(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (chevronButton1.Text == Messages.HIDE_RUN_HISTORY)
|
|
|
|
|
{
|
2016-02-15 05:35:26 +01:00
|
|
|
|
chevronButton1.Text = Messages.SHOW_RUN_HISTORY;
|
|
|
|
|
chevronButton1.Image = Properties.Resources.PDChevronDown;
|
2017-09-07 12:02:07 +02:00
|
|
|
|
panelHistory.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-15 05:35:26 +01:00
|
|
|
|
chevronButton1.Text = Messages.HIDE_RUN_HISTORY;
|
|
|
|
|
chevronButton1.Image = Properties.Resources.PDChevronUp;
|
2017-09-07 12:02:07 +02:00
|
|
|
|
panelHistory.Visible = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 15:56:13 +02:00
|
|
|
|
private void chevronButton1_KeyDown(object sender, KeyEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Space)
|
|
|
|
|
chevronButton1_ButtonClick(sender, e);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2016-06-13 11:10:25 +02:00
|
|
|
|
internal override string HelpName
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-05-25 15:56:13 +02:00
|
|
|
|
return "VMSnapshotSchedulesDialog";
|
2016-06-13 11:10:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-07 12:02:07 +02:00
|
|
|
|
private void dataGridViewRunHistory_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.RowIndex >= 0)
|
|
|
|
|
{
|
|
|
|
|
HistoryRow row = (HistoryRow)dataGridViewRunHistory.Rows[e.RowIndex];
|
|
|
|
|
if (row.Alert.Type != "info")
|
|
|
|
|
{
|
|
|
|
|
row.Expanded = !row.Expanded;
|
|
|
|
|
row.RefreshRow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void comboBoxTimeSpan_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
RefreshHistoryGrid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshHistoryGrid()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dataGridViewRunHistory.SuspendLayout();
|
|
|
|
|
dataGridViewRunHistory.Rows.Clear();
|
|
|
|
|
|
|
|
|
|
var row = SelectedVmssRow;
|
|
|
|
|
if (row == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var vmss = row.Policy;
|
|
|
|
|
var messages = row.AlertMessages;
|
|
|
|
|
|
|
|
|
|
int hoursFromNow = RunHistoryTimeSpan;
|
|
|
|
|
|
|
|
|
|
DateTime currentTime = DateTime.Now;
|
|
|
|
|
DateTime offset = currentTime.Add(new TimeSpan(-hoursFromNow, 0, 0));
|
|
|
|
|
|
|
|
|
|
if (hoursFromNow == 0)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 10 && i < messages.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var msg = messages[i];
|
|
|
|
|
var alert = new PolicyAlert(msg.priority, msg.name, msg.timestamp, msg.body, vmss.Name());
|
|
|
|
|
dataGridViewRunHistory.Rows.Add(new HistoryRow(alert));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var msg in messages)
|
|
|
|
|
{
|
|
|
|
|
if (msg.timestamp >= offset)
|
|
|
|
|
{
|
|
|
|
|
var alert = new PolicyAlert(msg.priority, msg.name, msg.timestamp, msg.body, vmss.Name());
|
|
|
|
|
dataGridViewRunHistory.Rows.Add(new HistoryRow(alert));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
dataGridViewRunHistory.ResumeLayout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshHistoryLabel()
|
|
|
|
|
{
|
|
|
|
|
var row = SelectedVmssRow;
|
|
|
|
|
if (row == null)
|
|
|
|
|
{
|
|
|
|
|
labelHistory.Text = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string name = row.Policy.Name();
|
|
|
|
|
|
|
|
|
|
// ellipsise if necessary
|
|
|
|
|
using (Graphics g = labelHistory.CreateGraphics())
|
|
|
|
|
{
|
|
|
|
|
int maxWidth = labelShow.Left - labelHistory.Left;
|
|
|
|
|
int availableWidth = maxWidth - (int)g.MeasureString(string.Format(Messages.HISTORY_FOR_POLICY, ""), labelHistory.Font).Width;
|
|
|
|
|
name = name.Ellipsise(new Rectangle(0, 0, availableWidth, labelHistory.Height), labelHistory.Font);
|
|
|
|
|
}
|
|
|
|
|
labelHistory.Text = string.Format(Messages.HISTORY_FOR_POLICY, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class HistoryRow : DataGridViewRow
|
|
|
|
|
{
|
|
|
|
|
private DataGridViewImageCell _expand = new DataGridViewImageCell();
|
|
|
|
|
private DataGridViewTextAndImageCell _result = new DataGridViewTextAndImageCell();
|
|
|
|
|
private DataGridViewTextBoxCell _dateTime = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell _description = new DataGridViewTextBoxCell();
|
|
|
|
|
public readonly PolicyAlert Alert;
|
|
|
|
|
|
|
|
|
|
public HistoryRow(PolicyAlert alert)
|
|
|
|
|
{
|
|
|
|
|
Alert = alert;
|
|
|
|
|
Cells.AddRange(_expand, _result, _dateTime, _description);
|
|
|
|
|
RefreshRow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DefaultValue(false)]
|
|
|
|
|
public bool Expanded { get; set; }
|
|
|
|
|
|
|
|
|
|
public void RefreshRow()
|
|
|
|
|
{
|
|
|
|
|
_expand.Value = Expanded ? Resources.expanded_triangle : Resources.contracted_triangle;
|
|
|
|
|
if (Alert.Type == "info")
|
|
|
|
|
_expand.Value = null;
|
|
|
|
|
|
|
|
|
|
if (Alert.Type == "error")
|
|
|
|
|
{
|
|
|
|
|
_result.Image = Properties.Resources._075_WarningRound_h32bit_16;
|
|
|
|
|
_result.Value = Messages.ERROR;
|
|
|
|
|
}
|
|
|
|
|
else if (Alert.Type == "warn")
|
|
|
|
|
{
|
|
|
|
|
_result.Image = Properties.Resources._075_WarningRound_h32bit_16;
|
|
|
|
|
_result.Value = Messages.WARNING;
|
|
|
|
|
}
|
|
|
|
|
else if (Alert.Type == "info")
|
|
|
|
|
{
|
|
|
|
|
_result.Image = Properties.Resources._075_TickRound_h32bit_16;
|
|
|
|
|
_result.Value = Messages.INFORMATION;
|
|
|
|
|
}
|
|
|
|
|
_dateTime.Value = Alert.Time;
|
|
|
|
|
if (Alert.Type == "error")
|
|
|
|
|
_description.Value = Expanded ? string.Format("{0}\r\n{1}", Alert.ShortFormatBody, Alert.Text) : Alert.ShortFormatBody.Ellipsise(80);
|
|
|
|
|
else
|
|
|
|
|
_description.Value = Expanded ? Alert.Text : Alert.ShortFormatBody.Ellipsise(90);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-15 05:35:26 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|