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;
|
|
|
|
|
using System.ComponentModel;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.Controls;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
using XenAdmin.Core;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Dialogs;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
using XenAPI;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.TabPages
|
|
|
|
|
{
|
2018-08-10 10:38:55 +02:00
|
|
|
|
public partial class HistoryPage : NotificationsBasePage
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-13 11:52:15 +02:00
|
|
|
|
private const int MAX_HISTORY_ITEM = 1000;
|
|
|
|
|
|
2013-11-18 15:31:00 +01:00
|
|
|
|
internal event Action<IXenObject> GoToXenObjectRequested;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public HistoryPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
2019-08-28 15:57:36 +02:00
|
|
|
|
toolStripDdbFilterStatus.ImplementsQueued = false;
|
|
|
|
|
toolStripDdbFilterStatus.ImplementsIncomplete = false;
|
2013-08-12 15:00:29 +02:00
|
|
|
|
dataGridView.Sort(columnDate, ListSortDirection.Descending);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
toolStripTop.Renderer = new CustomToolStripRenderer();
|
2013-08-07 13:10:12 +02:00
|
|
|
|
toolStripSplitButtonDismiss.DefaultItem = tsmiDismissAll;
|
|
|
|
|
toolStripSplitButtonDismiss.Text = tsmiDismissAll.Text;
|
2013-11-25 09:42:17 +01:00
|
|
|
|
UpdateButtons();
|
2018-08-10 10:38:55 +02:00
|
|
|
|
|
2013-08-13 11:52:15 +02:00
|
|
|
|
ActionBase.NewAction += Action_NewAction;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 10:38:55 +02:00
|
|
|
|
#region NotificationPage overrides
|
|
|
|
|
protected override void RefreshPage()
|
2013-08-13 11:15:52 +02:00
|
|
|
|
{
|
|
|
|
|
toolStripDdbFilterLocation.InitializeHostList();
|
|
|
|
|
toolStripDdbFilterLocation.BuildFilterList();
|
2013-08-13 18:08:04 +02:00
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 10:38:55 +02:00
|
|
|
|
protected override void RegisterEventHandlers()
|
|
|
|
|
{
|
|
|
|
|
ConnectionsManager.History.CollectionChanged += History_CollectionChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void DeregisterEventHandlers()
|
|
|
|
|
{
|
|
|
|
|
ConnectionsManager.History.CollectionChanged -= History_CollectionChanged;
|
|
|
|
|
foreach (var action in ConnectionsManager.History)
|
|
|
|
|
DeregisterActionEvents(action);
|
|
|
|
|
}
|
2019-09-13 18:47:27 +02:00
|
|
|
|
|
|
|
|
|
public override string HelpID => "EventsPane";
|
|
|
|
|
|
2018-08-10 10:38:55 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
2013-08-13 11:52:15 +02:00
|
|
|
|
private void Action_NewAction(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
if (action == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-10-24 00:13:03 +02:00
|
|
|
|
Program.Invoke(Program.MainWindow,
|
2013-08-13 11:52:15 +02:00
|
|
|
|
() =>
|
|
|
|
|
{
|
|
|
|
|
int count = ConnectionsManager.History.Count;
|
|
|
|
|
if (count >= MAX_HISTORY_ITEM)
|
|
|
|
|
ConnectionsManager.History.RemoveAt(0);
|
|
|
|
|
ConnectionsManager.History.Add(action);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private void History_CollectionChanged(object sender, CollectionChangeEventArgs e)
|
|
|
|
|
{
|
2013-08-13 18:08:04 +02:00
|
|
|
|
Program.BeginInvoke(this, () =>
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
2017-07-14 19:08:54 +02:00
|
|
|
|
ActionBase action = e.Element as ActionBase;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
switch (e.Action)
|
|
|
|
|
{
|
|
|
|
|
case CollectionChangeAction.Add:
|
2013-08-13 11:15:52 +02:00
|
|
|
|
var actions = new List<ActionBase>(ConnectionsManager.History);
|
|
|
|
|
SortActions(actions);
|
|
|
|
|
var index = actions.IndexOf(action);
|
|
|
|
|
if (index > -1)
|
|
|
|
|
InsertActionRow(index, action);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case CollectionChangeAction.Remove:
|
2017-07-14 19:08:54 +02:00
|
|
|
|
if (action != null)
|
|
|
|
|
{
|
|
|
|
|
RemoveActionRow(action);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var range = e.Element as List<ActionBase>;
|
|
|
|
|
if (range != null)
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
2013-08-10 13:29:36 +02:00
|
|
|
|
break;
|
|
|
|
|
case CollectionChangeAction.Refresh:
|
|
|
|
|
BuildRowList();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
UpdateButtons();
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private void action_Changed(ActionBase sender)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-10-09 14:33:06 +02:00
|
|
|
|
var asyncAction = sender as AsyncAction;
|
|
|
|
|
if (asyncAction != null)
|
|
|
|
|
asyncAction.RecomputeCanCancel();
|
|
|
|
|
|
CA-147941: Fixed the RPU wizard hang in "Reconnecting Storage" and connecting action stuck in progress state
In some cases calling Control.Invoke() from a background thread causes that thread to go in a "sleep, wait, or join" mode, while waiting for Invoke to happen, although the UI thread is running normally.
If the Control is the MainWindow, it works as expected, but we've seen it happening while connecting or disconnecting from a large pool, on calling Invoke on controls like NavigationView, AlertSummaryPage, HistoryPage, etc.
To fix this, we call the Invoke on the MainWindow in all the places where we've seen the issue.
With this changes, the previous fix for CA-148245 (call RequestRefreshTreeView on CacheClearing event) is not needed anymore, so I removed that call.
Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
2014-10-10 14:16:50 +02:00
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
|
|
|
|
var row = FindRowFromAction(sender);
|
2015-05-18 18:51:46 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
if (row != null)
|
2015-05-18 18:51:46 +02:00
|
|
|
|
{
|
|
|
|
|
//the row is already in the grid, refresh and show or hide it
|
|
|
|
|
if (!FilterAction(sender))
|
|
|
|
|
{
|
|
|
|
|
row.RefreshSelf();
|
|
|
|
|
row.Visible = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
row.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!FilterAction(sender))
|
|
|
|
|
{
|
|
|
|
|
//adding the row to the grid, because it has not been there and now it should be visible based on active filters
|
|
|
|
|
CreateActionRow(sender);
|
|
|
|
|
}
|
2013-08-10 13:29:36 +02:00
|
|
|
|
|
|
|
|
|
UpdateButtons();
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 12:04:08 +02:00
|
|
|
|
private void SetFilterLabel()
|
|
|
|
|
{
|
2014-07-31 10:39:16 +02:00
|
|
|
|
toolStripLabelFiltersOnOff.Text = FilterIsOn
|
2013-08-13 12:04:08 +02:00
|
|
|
|
? Messages.FILTERS_ON
|
|
|
|
|
: Messages.FILTERS_OFF;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-31 10:39:16 +02:00
|
|
|
|
private bool FilterIsOn
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return toolStripDdbFilterDates.FilterIsOn
|
|
|
|
|
|| toolStripDdbFilterLocation.FilterIsOn
|
|
|
|
|
|| toolStripDdbFilterStatus.FilterIsOn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private void BuildRowList()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2014-04-28 16:04:23 +02:00
|
|
|
|
if (!Visible)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dataGridView.SuspendLayout();
|
|
|
|
|
dataGridView.Rows.Clear();
|
|
|
|
|
|
2015-05-18 18:51:46 +02:00
|
|
|
|
//creating a sorted list of actions that should currently be visible
|
|
|
|
|
var actions = ConnectionsManager.History.Where(a => !FilterAction(a)).ToList();
|
2013-08-13 11:15:52 +02:00
|
|
|
|
SortActions(actions);
|
2015-05-18 18:51:46 +02:00
|
|
|
|
|
|
|
|
|
//adding a row to the grid for each action
|
|
|
|
|
var rows = actions.Select(a => CreateActionRow(a)).ToList();
|
2013-08-10 13:29:36 +02:00
|
|
|
|
dataGridView.Rows.AddRange(rows.ToArray());
|
|
|
|
|
|
2015-05-18 18:51:46 +02:00
|
|
|
|
//registering to action events of all the actions
|
|
|
|
|
foreach (var action in ConnectionsManager.History)
|
|
|
|
|
RegisterActionEvents(action);
|
2013-08-13 12:04:08 +02:00
|
|
|
|
|
|
|
|
|
SetFilterLabel();
|
2013-08-10 13:29:36 +02:00
|
|
|
|
}
|
|
|
|
|
finally
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
dataGridView.ResumeLayout();
|
2014-07-31 10:39:16 +02:00
|
|
|
|
UpdateButtons();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 11:15:52 +02:00
|
|
|
|
private void SortActions(List<ActionBase> actions)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-12 15:00:29 +02:00
|
|
|
|
if (dataGridView.SortedColumn != null)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.SortedColumn.Index == columnStatus.Index)
|
|
|
|
|
actions.Sort(ActionBaseExtensions.CompareOnStatus);
|
|
|
|
|
else if (dataGridView.SortedColumn.Index == columnMessage.Index)
|
|
|
|
|
actions.Sort(ActionBaseExtensions.CompareOnTitle);
|
|
|
|
|
else if (dataGridView.SortedColumn.Index == columnLocation.Index)
|
|
|
|
|
actions.Sort(ActionBaseExtensions.CompareOnLocation);
|
|
|
|
|
else if (dataGridView.SortedColumn.Index == columnDate.Index)
|
|
|
|
|
actions.Sort(ActionBaseExtensions.CompareOnDateStarted);
|
|
|
|
|
|
|
|
|
|
if (dataGridView.SortOrder == SortOrder.Descending)
|
|
|
|
|
actions.Reverse();
|
|
|
|
|
}
|
2013-08-13 11:15:52 +02:00
|
|
|
|
}
|
2013-08-12 15:00:29 +02:00
|
|
|
|
|
2015-05-18 18:51:46 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns true when the action needs to be filtered out
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="action"></param>
|
|
|
|
|
/// <returns></returns>
|
2013-08-13 11:15:52 +02:00
|
|
|
|
private bool FilterAction(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
bool hide = false;
|
CA-147941: Fixed the RPU wizard hang in "Reconnecting Storage" and connecting action stuck in progress state
In some cases calling Control.Invoke() from a background thread causes that thread to go in a "sleep, wait, or join" mode, while waiting for Invoke to happen, although the UI thread is running normally.
If the Control is the MainWindow, it works as expected, but we've seen it happening while connecting or disconnecting from a large pool, on calling Invoke on controls like NavigationView, AlertSummaryPage, HistoryPage, etc.
To fix this, we call the Invoke on the MainWindow in all the places where we've seen the issue.
With this changes, the previous fix for CA-148245 (call RequestRefreshTreeView on CacheClearing event) is not needed anymore, so I removed that call.
Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
2014-10-10 14:16:50 +02:00
|
|
|
|
Program.Invoke(Program.MainWindow, () =>
|
2013-08-13 11:15:52 +02:00
|
|
|
|
hide = toolStripDdbFilterDates.HideByDate(action.Started)
|
|
|
|
|
|| toolStripDdbFilterLocation.HideByLocation(action.GetApplicableHosts())
|
|
|
|
|
|| toolStripDdbFilterStatus.HideByStatus(action));
|
|
|
|
|
return hide;
|
2013-08-12 15:00:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InsertActionRow(int index, ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
if (index < 0)
|
|
|
|
|
index = 0;
|
|
|
|
|
if (index > dataGridView.RowCount)
|
|
|
|
|
index = dataGridView.RowCount;
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
var row = CreateActionRow(action);
|
2013-08-12 15:00:29 +02:00
|
|
|
|
dataGridView.Rows.Insert(index, row);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
RegisterActionEvents(action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DataGridViewActionRow CreateActionRow(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
var row = new DataGridViewActionRow(action);
|
2015-05-18 18:51:46 +02:00
|
|
|
|
row.Visible = !FilterAction(action);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
row.DismissalRequested += row_DismissalRequested;
|
|
|
|
|
row.GoToXenObjectRequested += row_GoToXenObjectRequested;
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RegisterActionEvents(ActionBase action)
|
|
|
|
|
{
|
2018-08-10 10:38:55 +02:00
|
|
|
|
DeregisterActionEvents(action);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
action.Changed += action_Changed;
|
|
|
|
|
action.Completed += action_Changed;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-10 10:38:55 +02:00
|
|
|
|
private void DeregisterActionEvents(ActionBase action)
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
2015-05-18 18:51:46 +02:00
|
|
|
|
action.Changed -= action_Changed;
|
|
|
|
|
action.Completed -= action_Changed;
|
2018-08-10 10:38:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RemoveActionRow(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
DeregisterActionEvents(action);
|
2015-05-18 18:51:46 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
var row = FindRowFromAction(action);
|
|
|
|
|
if (row != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
dataGridView.Rows.Remove(row);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private DataGridViewActionRow FindRowFromAction(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewRow row in dataGridView.Rows)
|
|
|
|
|
{
|
|
|
|
|
var actionRow = row as DataGridViewActionRow;
|
|
|
|
|
if (actionRow == null)
|
|
|
|
|
continue;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
if (actionRow.Action == action)
|
|
|
|
|
return actionRow;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
return null;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private void ToggleExpandedState(int rowIndex)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-10 13:29:36 +02:00
|
|
|
|
var row = dataGridView.Rows[rowIndex] as DataGridViewActionRow;
|
|
|
|
|
if (row == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (row.Expanded)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2017-01-11 14:54:56 +01:00
|
|
|
|
row.Cells[columnExpander.Index].Value = Images.StaticImages.contracted_triangle;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
row.Cells[columnMessage.Index].Value = row.Action.GetTitle();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-01-11 14:54:56 +01:00
|
|
|
|
row.Cells[columnExpander.Index].Value = Images.StaticImages.expanded_triangle;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
row.Cells[columnMessage.Index].Value = row.Action.GetDetails();
|
|
|
|
|
}
|
|
|
|
|
row.Expanded = !row.Expanded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateButtons()
|
|
|
|
|
{
|
2014-07-31 10:39:16 +02:00
|
|
|
|
tsmiDismissAll.Enabled = ConnectionsManager.History.Any(a => a.IsCompleted);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
tsmiDismissSelected.Enabled = dataGridView.SelectedRows.Cast<DataGridViewActionRow>().Any(row => row.Action.IsCompleted);
|
2014-01-09 14:57:41 +01:00
|
|
|
|
toolStripSplitButtonDismiss.Enabled = tsmiDismissAll.Enabled || tsmiDismissSelected.Enabled;
|
|
|
|
|
|
|
|
|
|
if (toolStripSplitButtonDismiss.DefaultItem != null && !toolStripSplitButtonDismiss.DefaultItem.Enabled)
|
|
|
|
|
{
|
|
|
|
|
foreach (ToolStripItem item in toolStripSplitButtonDismiss.DropDownItems)
|
|
|
|
|
{
|
|
|
|
|
if (item.Enabled)
|
|
|
|
|
{
|
|
|
|
|
toolStripSplitButtonDismiss.DefaultItem = item;
|
|
|
|
|
toolStripSplitButtonDismiss.Text = item.Text;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-10 13:29:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 12:04:08 +02:00
|
|
|
|
#region Control event handlers
|
2013-08-10 13:29:36 +02:00
|
|
|
|
|
|
|
|
|
private void row_DismissalRequested(DataGridViewActionRow row)
|
|
|
|
|
{
|
2016-06-20 11:49:12 +02:00
|
|
|
|
if (ConnectionsManager.History.Count > 0)
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
2016-11-17 14:35:31 +01:00
|
|
|
|
if (!Program.RunInAutomatedTestMode && !Properties.Settings.Default.DoNotConfirmDismissEvents)
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlg = new NoIconDialog(Messages.MESSAGEBOX_LOG_DELETE,
|
|
|
|
|
ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo)
|
2016-06-20 11:49:12 +02:00
|
|
|
|
{
|
2016-11-17 14:35:31 +01:00
|
|
|
|
ShowCheckbox = true,
|
|
|
|
|
CheckboxCaption = Messages.DO_NOT_SHOW_THIS_MESSAGE
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
var result = dlg.ShowDialog(this);
|
|
|
|
|
Properties.Settings.Default.DoNotConfirmDismissEvents = dlg.IsCheckBoxChecked;
|
|
|
|
|
Settings.TrySaveSettings();
|
|
|
|
|
|
|
|
|
|
if (result != DialogResult.Yes)
|
|
|
|
|
return;
|
2016-06-20 11:49:12 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-17 14:35:31 +01:00
|
|
|
|
|
|
|
|
|
ConnectionsManager.History.Remove(row.Action);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void row_GoToXenObjectRequested(IXenObject obj)
|
|
|
|
|
{
|
2013-11-18 15:31:00 +01:00
|
|
|
|
if (GoToXenObjectRequested != null)
|
|
|
|
|
GoToXenObjectRequested(obj);
|
2013-08-10 13:29:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// If you click on the headers you can get -1 as the index.
|
|
|
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0 || e.ColumnIndex != columnExpander.Index)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ToggleExpandedState(e.RowIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-24 17:28:32 +02:00
|
|
|
|
private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (e.ColumnIndex != columnActions.Index)
|
|
|
|
|
ToggleExpandedState(e.RowIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
private void dataGridView_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
tsmiDismissSelected.Enabled = dataGridView.SelectedRows.Cast<DataGridViewActionRow>().Any(row => row.Action.IsCompleted);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2013-08-07 13:10:12 +02:00
|
|
|
|
|
2013-08-12 15:00:29 +02:00
|
|
|
|
private void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (dataGridView.Columns[e.ColumnIndex].SortMode == DataGridViewColumnSortMode.Automatic)
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 13:10:12 +02:00
|
|
|
|
|
|
|
|
|
private void toolStripSplitButtonDismiss_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
toolStripSplitButtonDismiss.DefaultItem = e.ClickedItem;
|
|
|
|
|
toolStripSplitButtonDismiss.Text = toolStripSplitButtonDismiss.DefaultItem.Text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiDismissAll_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-07-31 10:39:16 +02:00
|
|
|
|
if (ConnectionsManager.History.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
DialogResult result = DialogResult.Yes;
|
2016-11-17 14:35:31 +01:00
|
|
|
|
|
2014-07-31 10:39:16 +02:00
|
|
|
|
if (!Program.RunInAutomatedTestMode)
|
2013-08-07 13:10:12 +02:00
|
|
|
|
{
|
2016-11-17 14:35:31 +01:00
|
|
|
|
if (FilterIsOn)
|
2014-07-31 10:39:16 +02:00
|
|
|
|
{
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlog = new NoIconDialog(Messages.MESSAGEBOX_LOGS_DELETE,
|
2016-11-17 14:35:31 +01:00
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.DISMISS_ALL_CONFIRM_BUTTON, DialogResult.Yes),
|
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.DISMISS_FILTERED_CONFIRM_BUTTON, DialogResult.No, ThreeButtonDialog.ButtonType.NONE),
|
2014-07-31 10:39:16 +02:00
|
|
|
|
ThreeButtonDialog.ButtonCancel))
|
|
|
|
|
{
|
|
|
|
|
result = dlog.ShowDialog(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-17 14:35:31 +01:00
|
|
|
|
else if (!Properties.Settings.Default.DoNotConfirmDismissEvents)
|
2014-07-31 10:39:16 +02:00
|
|
|
|
{
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlog = new NoIconDialog(Messages.MESSAGEBOX_LOGS_DELETE_NO_FILTER,
|
2016-11-17 14:35:31 +01:00
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.DISMISS_ALL_YES_CONFIRM_BUTTON, DialogResult.Yes),
|
|
|
|
|
ThreeButtonDialog.ButtonCancel)
|
|
|
|
|
{
|
|
|
|
|
ShowCheckbox = true,
|
|
|
|
|
CheckboxCaption = Messages.DO_NOT_SHOW_THIS_MESSAGE
|
|
|
|
|
})
|
2014-07-31 10:39:16 +02:00
|
|
|
|
{
|
|
|
|
|
result = dlog.ShowDialog(this);
|
2016-11-17 14:35:31 +01:00
|
|
|
|
Properties.Settings.Default.DoNotConfirmDismissEvents = dlog.IsCheckBoxChecked;
|
|
|
|
|
Settings.TrySaveSettings();
|
2014-07-31 10:39:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result == DialogResult.Cancel)
|
|
|
|
|
return;
|
2013-08-07 13:10:12 +02:00
|
|
|
|
}
|
2014-07-31 10:39:16 +02:00
|
|
|
|
|
|
|
|
|
var actions = result == DialogResult.No
|
2015-05-18 18:51:46 +02:00
|
|
|
|
? (from DataGridViewActionRow row in dataGridView.Rows where row.Action != null && row.Action.IsCompleted && row.Visible select row.Action)
|
2014-10-09 20:17:41 +02:00
|
|
|
|
: ConnectionsManager.History.Where(action => action != null && action.IsCompleted);
|
2014-07-31 10:39:16 +02:00
|
|
|
|
|
|
|
|
|
ConnectionsManager.History.RemoveAll(actions.Contains);
|
2013-08-07 13:10:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void tsmiDismissSelected_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2016-11-17 14:35:31 +01:00
|
|
|
|
if (!Properties.Settings.Default.DoNotConfirmDismissEvents)
|
2013-11-18 15:31:00 +01:00
|
|
|
|
{
|
2020-04-22 15:47:03 +02:00
|
|
|
|
using (var dlog = new NoIconDialog(Messages.MESSAGEBOX_LOGS_DELETE_SELECTED,
|
2016-11-17 14:35:31 +01:00
|
|
|
|
ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo)
|
|
|
|
|
{
|
|
|
|
|
ShowCheckbox = true,
|
|
|
|
|
CheckboxCaption = Messages.DO_NOT_SHOW_THIS_MESSAGE
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
var result = dlog.ShowDialog(this);
|
|
|
|
|
Properties.Settings.Default.DoNotConfirmDismissEvents = dlog.IsCheckBoxChecked;
|
|
|
|
|
Settings.TrySaveSettings();
|
2013-11-18 15:31:00 +01:00
|
|
|
|
|
2016-11-17 14:35:31 +01:00
|
|
|
|
if (result != DialogResult.Yes)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-11-18 15:31:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 18:51:46 +02:00
|
|
|
|
var actions = from DataGridViewActionRow row in dataGridView.SelectedRows where row != null && row.Action != null && row.Action.IsCompleted && row.Visible select row.Action;
|
2013-08-07 13:10:12 +02:00
|
|
|
|
|
2013-11-18 15:31:00 +01:00
|
|
|
|
ConnectionsManager.History.RemoveAll(actions.Contains);
|
2013-08-07 13:10:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 11:15:52 +02:00
|
|
|
|
|
|
|
|
|
private void toolStripDdbFilterStatus_FilterChanged()
|
|
|
|
|
{
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripDdbFilterLocation_FilterChanged()
|
|
|
|
|
{
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripDdbFilterDates_FilterChanged()
|
|
|
|
|
{
|
|
|
|
|
BuildRowList();
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-07 13:10:12 +02:00
|
|
|
|
#endregion
|
2013-08-10 13:29:36 +02:00
|
|
|
|
|
|
|
|
|
#region Nested classes
|
|
|
|
|
|
2013-08-16 13:57:39 +02:00
|
|
|
|
public class DataGridViewActionRow : DataGridViewRow
|
2013-08-10 13:29:36 +02:00
|
|
|
|
{
|
|
|
|
|
private DataGridViewImageCell expanderCell = new DataGridViewImageCell();
|
|
|
|
|
private DataGridViewImageCell statusCell = new DataGridViewImageCell();
|
|
|
|
|
private DataGridViewTextBoxCell messageCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell locationCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewTextBoxCell dateCell = new DataGridViewTextBoxCell();
|
|
|
|
|
private DataGridViewDropDownSplitButtonCell actionCell = new DataGridViewDropDownSplitButtonCell();
|
|
|
|
|
|
2013-08-19 14:17:33 +02:00
|
|
|
|
private ToolStripMenuItem cancelItem = new ToolStripMenuItem(Messages.CANCEL);
|
|
|
|
|
private ToolStripMenuItem dismissItem = new ToolStripMenuItem(Messages.ALERT_DISMISS);
|
|
|
|
|
private ToolStripMenuItem goToItem = new ToolStripMenuItem(Messages.HISTORYPAGE_GOTO);
|
2013-12-10 12:29:31 +01:00
|
|
|
|
private ToolStripSeparator separatorItem = new ToolStripSeparator();
|
|
|
|
|
private ToolStripMenuItem copyItem = new ToolStripMenuItem(Messages.COPY);
|
2013-08-19 14:17:33 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
public event Action<DataGridViewActionRow> DismissalRequested;
|
|
|
|
|
public event Action<IXenObject> GoToXenObjectRequested;
|
|
|
|
|
|
|
|
|
|
public ActionBase Action { get; private set; }
|
|
|
|
|
public bool Expanded { get; set; }
|
|
|
|
|
|
|
|
|
|
public DataGridViewActionRow(ActionBase action)
|
|
|
|
|
{
|
|
|
|
|
Action = action;
|
2013-08-19 14:17:33 +02:00
|
|
|
|
|
|
|
|
|
cancelItem.Click += ToolStripMenuItemCancel_Click;
|
|
|
|
|
dismissItem.Click += ToolStripMenuItemDismiss_Click;
|
|
|
|
|
goToItem.Click += ToolStripMenuItemGoTo_Click;
|
2013-12-10 12:29:31 +01:00
|
|
|
|
copyItem.Click += ToolStripMenuItemCopy_Click;
|
2013-08-19 14:17:33 +02:00
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
MinimumHeight = DataGridViewDropDownSplitButtonCell.MIN_ROW_HEIGHT;
|
|
|
|
|
Cells.AddRange(expanderCell, statusCell, messageCell, locationCell, dateCell, actionCell);
|
|
|
|
|
RefreshSelf();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RefreshSelf()
|
|
|
|
|
{
|
2013-08-19 14:17:33 +02:00
|
|
|
|
var actionItems = new List<ToolStripItem>();
|
|
|
|
|
if (!Action.IsCompleted && Action.CanCancel)
|
|
|
|
|
actionItems.Add(cancelItem);
|
|
|
|
|
|
|
|
|
|
if (Action.IsCompleted)
|
|
|
|
|
actionItems.Add(dismissItem);
|
|
|
|
|
|
|
|
|
|
var obj = Action.GetRelevantXenObject();
|
|
|
|
|
if (obj != null)
|
|
|
|
|
actionItems.Add(goToItem);
|
|
|
|
|
|
2013-12-10 12:29:31 +01:00
|
|
|
|
if (actionItems.Count > 0)
|
|
|
|
|
actionItems.Add(separatorItem);
|
|
|
|
|
|
|
|
|
|
actionItems.Add(copyItem);
|
|
|
|
|
|
2013-08-10 13:29:36 +02:00
|
|
|
|
actionCell.RefreshItems(actionItems.ToArray());
|
|
|
|
|
|
|
|
|
|
statusCell.Value = Action.GetImage();
|
|
|
|
|
|
|
|
|
|
if (Expanded)
|
|
|
|
|
{
|
2017-01-11 14:54:56 +01:00
|
|
|
|
expanderCell.Value = Images.StaticImages.expanded_triangle;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
messageCell.Value = Action.GetDetails();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-01-11 14:54:56 +01:00
|
|
|
|
expanderCell.Value = Images.StaticImages.contracted_triangle;
|
2013-08-10 13:29:36 +02:00
|
|
|
|
messageCell.Value = Action.GetTitle();
|
|
|
|
|
}
|
|
|
|
|
locationCell.Value = Action.GetLocation();
|
|
|
|
|
dateCell.Value = HelpersGUI.DateTimeToString(Action.Started.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolStripMenuItemCancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Action.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolStripMenuItemDismiss_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (DismissalRequested != null)
|
|
|
|
|
DismissalRequested(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ToolStripMenuItemGoTo_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (GoToXenObjectRequested != null)
|
|
|
|
|
GoToXenObjectRequested(Action.GetRelevantXenObject());
|
|
|
|
|
}
|
2013-12-10 12:29:31 +01:00
|
|
|
|
|
|
|
|
|
private void ToolStripMenuItemCopy_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string text = string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\"",
|
|
|
|
|
Action.GetStatusString(), messageCell.Value,
|
|
|
|
|
locationCell.Value, dateCell.Value);
|
|
|
|
|
|
2016-10-13 17:16:16 +02:00
|
|
|
|
Clip.SetClipboardText(text);
|
2013-12-10 12:29:31 +01:00
|
|
|
|
}
|
2013-08-10 13:29:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class CustomToolStripRenderer : ToolStripProfessionalRenderer
|
|
|
|
|
{
|
|
|
|
|
public CustomToolStripRenderer()
|
|
|
|
|
: base(new CustomToolstripColourTable())
|
|
|
|
|
{
|
|
|
|
|
RoundedEdges = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class CustomToolstripColourTable : ProfessionalColorTable
|
|
|
|
|
{
|
|
|
|
|
public override Color ToolStripBorder
|
|
|
|
|
{
|
|
|
|
|
get { return Color.Gainsboro; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|