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 ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Windows.Forms ;
2013-07-18 14:56:40 +02:00
using XenAdmin.Controls ;
2013-06-24 13:41:48 +02:00
using XenAdmin.Core ;
2013-08-30 13:46:28 +02:00
using XenAdmin.Dialogs ;
2013-06-24 13:41:48 +02:00
using XenAdmin.Alerts ;
using XenAdmin.Help ;
using System.Threading ;
using XenAdmin.Actions ;
using System.IO ;
2013-08-30 13:46:28 +02:00
namespace XenAdmin.TabPages
2013-06-24 13:41:48 +02:00
{
2018-08-10 10:38:55 +02:00
public partial class AlertSummaryPage : NotificationsBasePage
2013-06-24 13:41:48 +02:00
{
private static readonly log4net . ILog log = log4net . LogManager . GetLogger ( System . Reflection . MethodBase . GetCurrentMethod ( ) . DeclaringType ) ;
private static readonly int ALERT_CAP = 1000 ;
2013-07-03 14:00:24 +02:00
private readonly CollectionChangeEventHandler m_alertCollectionChangedWithInvoke ;
Dictionary < string , bool > expandedState = new Dictionary < string , bool > ( ) ;
private bool inAlertBuild ;
private bool retryAlertBuild ;
2013-08-30 13:46:28 +02:00
public AlertSummaryPage ( )
2013-06-24 13:41:48 +02:00
{
InitializeComponent ( ) ;
GridViewAlerts . Sort ( ColumnDate , ListSortDirection . Descending ) ;
LabelCappingEntries . Text = String . Format ( Messages . ALERT_CAP_LABEL , ALERT_CAP ) ;
GridViewAlerts . ScrollBars = ScrollBars . Vertical ;
UpdateActionEnablement ( ) ;
2013-07-03 14:00:24 +02:00
m_alertCollectionChangedWithInvoke = Program . ProgramInvokeHandler ( AlertsCollectionChanged ) ;
2019-09-04 14:21:57 +02:00
RegisterCheckForUpdatesEvents ( ) ;
2013-07-03 14:00:24 +02:00
2013-07-11 19:20:18 +02:00
toolStripSplitButtonDismiss . DefaultItem = tsmiDismissAll ;
toolStripSplitButtonDismiss . Text = tsmiDismissAll . Text ;
2013-06-24 13:41:48 +02:00
}
2018-08-10 10:38:55 +02:00
#region NotificationPage overrides
protected override void RefreshPage ( )
2013-06-24 13:41:48 +02:00
{
2013-08-13 11:15:52 +02:00
toolStripDropDownButtonServerFilter . InitializeHostList ( ) ;
toolStripDropDownButtonServerFilter . BuildFilterList ( ) ;
2013-06-24 13:41:48 +02:00
Rebuild ( ) ;
}
2018-08-10 10:38:55 +02:00
protected override void RegisterEventHandlers ( )
{
Alert . RegisterAlertCollectionChanged ( m_alertCollectionChangedWithInvoke ) ;
}
protected override void DeregisterEventHandlers ( )
{
Alert . DeregisterAlertCollectionChanged ( m_alertCollectionChangedWithInvoke ) ;
}
2019-09-13 18:47:27 +02:00
public override string HelpID = > "AlertSummaryDialog" ;
2018-08-10 10:38:55 +02:00
#endregion
2019-09-13 18:47:27 +02:00
2013-07-03 12:10:21 +02:00
private void SetFilterLabel ( )
{
2013-08-14 17:59:25 +02:00
toolStripLabelFiltersOnOff . Text = FilterIsOn
2013-07-03 12:10:21 +02:00
? Messages . FILTERS_ON
: Messages . FILTERS_OFF ;
}
2013-06-24 13:41:48 +02:00
2013-08-14 17:59:25 +02:00
private bool FilterIsOn
{
get
{
return toolStripDropDownButtonDateFilter . FilterIsOn
| | toolStripDropDownButtonServerFilter . FilterIsOn
| | toolStripDropDownSeveritiesFilter . FilterIsOn ;
}
}
2013-06-24 13:41:48 +02:00
#region AlertListCode
private void Rebuild ( )
{
2014-04-28 16:04:23 +02:00
if ( ! Visible )
return ;
2013-06-24 13:41:48 +02:00
log . Debug ( "Rebuilding alertList" ) ;
Thread t = new Thread ( _Rebuild ) ;
t . Name = "Building alert list" ;
t . IsBackground = true ;
t . Start ( ) ;
}
private void _Rebuild ( )
{
log . Debug ( "Rebuilding alertList: Starting background thread" ) ;
Program . AssertOffEventThread ( ) ;
lock ( GridViewAlerts )
{
if ( inAlertBuild )
{
// queue up a rebuild after the current one has completed
log . Debug ( "Rebuilding alertList: In build already, exiting" ) ;
retryAlertBuild = true ;
return ;
}
inAlertBuild = true ;
log . Debug ( "Rebuilding alertList: taking inAlertBuild lock" ) ;
}
try
{
// 1) Add all the alerts that have not been filtered out to an array
// 2) Create rows for each of these
// 3) Sort them
// 4) Take the top n as set by the filters
// 5) Add them to the control using the optimized AddRange()
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 , SetFilterLabel ) ;
2013-07-03 12:10:21 +02:00
2013-06-24 13:41:48 +02:00
List < Alert > alerts = Alert . NonDismissingAlerts ;
2013-07-12 12:07:10 +02:00
alerts . RemoveAll ( FilterAlert ) ;
2013-06-24 13:41:48 +02:00
log . DebugFormat ( "Rebuilding alertList: there are {0} alerts in total. After filtering we have {1}" ,
Alert . AlertCount ,
alerts . Count ) ;
if ( GridViewAlerts . SortedColumn ! = null )
{
2013-07-12 12:07:10 +02:00
if ( GridViewAlerts . SortedColumn . Index = = ColumnMessage . Index )
2013-06-24 13:41:48 +02:00
{
2013-07-03 13:00:00 +02:00
alerts . Sort ( Alert . CompareOnTitle ) ;
2013-06-24 13:41:48 +02:00
}
else if ( GridViewAlerts . SortedColumn . Index = = ColumnDate . Index )
{
2013-07-03 13:00:00 +02:00
alerts . Sort ( Alert . CompareOnDate ) ;
2013-06-24 13:41:48 +02:00
}
2013-07-12 12:07:10 +02:00
else if ( GridViewAlerts . SortedColumn . Index = = ColumnLocation . Index )
2013-06-24 13:41:48 +02:00
{
2013-07-03 13:00:00 +02:00
alerts . Sort ( Alert . CompareOnAppliesTo ) ;
2013-06-24 13:41:48 +02:00
}
2013-07-12 12:07:10 +02:00
else if ( GridViewAlerts . SortedColumn . Index = = ColumnSeverity . Index )
2013-06-24 13:41:48 +02:00
{
2013-07-03 13:00:00 +02:00
alerts . Sort ( Alert . CompareOnPriority ) ;
2013-06-24 13:41:48 +02:00
}
if ( GridViewAlerts . SortOrder = = SortOrder . Descending )
{
alerts . Reverse ( ) ;
}
}
int alertsFound = alerts . Count ;
if ( ALERT_CAP < alerts . Count )
{
log . DebugFormat ( "Rebuilding alertList: hit alert cap, hiding {0} alerts" , alerts . Count - ALERT_CAP ) ;
alerts . RemoveRange ( ALERT_CAP , alerts . Count - ALERT_CAP ) ;
}
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 , delegate
2013-06-24 13:41:48 +02:00
{
List < DataGridViewRow > gridRows = new List < DataGridViewRow > ( ) ;
log . Debug ( "Rebuilding alertList: Adding alert rows" ) ;
foreach ( Alert alert in alerts )
gridRows . Add ( NewAlertRow ( alert ) ) ;
log . DebugFormat ( "Rebuilding alertList: Added {0} rows" , gridRows . Count ) ;
List < string > selection = ( GridViewAlerts . SelectedRows . Cast < DataGridViewRow > ( ) . Select (
selectedRow = > ( ( Alert ) selectedRow . Tag ) . uuid ) ) . ToList ( ) ;
GridViewAlerts . Rows . Clear ( ) ;
log . Debug ( "Rebuilding alertList: Cleared rows" ) ;
GridViewAlerts . Rows . AddRange ( gridRows . ToArray ( ) ) ;
log . DebugFormat ( "Rebuilding alertList: Added {0} rows to the grid" , GridViewAlerts . Rows . Count ) ;
2013-08-30 13:46:28 +02:00
tableLayoutPanel3 . Visible = alertsFound > ALERT_CAP ;
2013-06-24 13:41:48 +02:00
//restore selection
if ( selection . Count > 0 )
{
log . Debug ( "Rebuilding alertList: Restoring alert selection" ) ;
foreach ( DataGridViewRow alertRow in GridViewAlerts . Rows )
{
alertRow . Selected = selection . Contains ( ( ( Alert ) alertRow . Tag ) . uuid ) ;
}
if ( GridViewAlerts . SelectedRows . Count = = 0 & & GridViewAlerts . Rows . Count > 0 )
{
GridViewAlerts . Rows [ 0 ] . Selected = true ;
}
log . DebugFormat ( "Rebuilding alertList: Selected {0} alerts" , selection . Count ) ;
}
UpdateActionEnablement ( ) ;
} ) ;
}
catch ( Exception e )
{
2019-11-08 13:53:24 +01:00
log . Error ( "Encountered exception when building list." , e ) ;
2013-06-24 13:41:48 +02:00
}
finally
{
log . Debug ( "Rebuilding alertList: Waiting for lock to clear inAlertBuild" ) ;
lock ( GridViewAlerts )
{
inAlertBuild = false ;
log . Debug ( "Rebuilding alertList: cleared inAlertBuild" ) ;
if ( retryAlertBuild )
{
// we received a request to build while we were building, rebuild in case we missed something
retryAlertBuild = false ;
log . Debug ( "Rebuilding alertList: we received a request to build while we were building, rebuild in case we missed something" ) ;
_Rebuild ( ) ;
}
}
}
}
private DataGridViewRow NewAlertRow ( Alert alert )
{
2013-07-18 14:56:40 +02:00
var expanderCell = new DataGridViewImageCell ( ) ;
var imageCell = new DataGridViewImageCell ( ) ;
var appliesCell = new DataGridViewTextBoxCell ( ) ;
var detailCell = new DataGridViewTextBoxCell ( ) ;
var dateCell = new DataGridViewTextBoxCell ( ) ;
var actionItems = GetAlertActionItems ( alert ) ;
var actionCell = new DataGridViewDropDownSplitButtonCell ( actionItems . ToArray ( ) ) ;
var newRow = new DataGridViewRow { Tag = alert , MinimumHeight = DataGridViewDropDownSplitButtonCell . MIN_ROW_HEIGHT } ;
2013-06-24 13:41:48 +02:00
// Get the relevant image for the row depending on the type of the alert
2017-09-03 04:33:29 +02:00
var msgAlert = alert as MessageAlert ;
Image typeImage = msgAlert ! = null & & msgAlert . Message . ShowOnGraphs ( )
2013-06-24 13:41:48 +02:00
? Images . GetImage16For ( ( ( MessageAlert ) alert ) . Message . Type )
: Images . GetImage16For ( alert . Priority ) ;
imageCell . Value = typeImage ;
// Set the detail cell content and expanding arrow
if ( expandedState . ContainsKey ( alert . uuid ) )
{
// show the expanded arrow and the body detail
2017-01-11 14:54:56 +01:00
expanderCell . Value = Images . StaticImages . expanded_triangle ;
2013-06-24 13:41:48 +02:00
detailCell . Value = String . Format ( "{0}\n\n{1}" , alert . Title , alert . Description ) ;
}
else
{
// show the expand arrow and just the title
2017-01-11 14:54:56 +01:00
expanderCell . Value = Images . StaticImages . contracted_triangle ;
2013-06-24 13:41:48 +02:00
detailCell . Value = alert . Title ;
}
appliesCell . Value = alert . AppliesTo ;
dateCell . Value = HelpersGUI . DateTimeToString ( alert . Timestamp . ToLocalTime ( ) , Messages . DATEFORMAT_DMY_HM , true ) ;
2013-07-18 14:56:40 +02:00
newRow . Cells . AddRange ( expanderCell , imageCell , detailCell , appliesCell , dateCell , actionCell ) ;
2013-06-24 13:41:48 +02:00
return newRow ;
}
/// <summary>
/// Runs all the current filters on the alert to determine if it should be shown in the list or not.
/// </summary>
/// <param name="alert"></param>
2013-07-12 12:07:10 +02:00
private bool FilterAlert ( Alert alert )
2013-06-24 13:41:48 +02:00
{
2013-07-02 20:06:11 +02:00
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-07-02 20:06:11 +02:00
hide = toolStripDropDownButtonDateFilter . HideByDate ( alert . Timestamp . ToLocalTime ( ) )
2013-07-03 14:00:24 +02:00
| | toolStripDropDownButtonServerFilter . HideByLocation ( alert . HostUuid )
| | toolStripDropDownSeveritiesFilter . HideBySeverity ( alert . Priority ) ) ;
return hide ;
2013-06-24 13:41:48 +02:00
}
private void RemoveAlertRow ( Alert a )
{
for ( int i = 0 ; i < GridViewAlerts . Rows . Count ; i + + )
{
if ( ( ( Alert ) GridViewAlerts . Rows [ i ] . Tag ) . uuid = = a . uuid )
GridViewAlerts . Rows . RemoveAt ( i ) ;
}
if ( GridViewAlerts . Rows . Count < ALERT_CAP )
2013-08-30 13:46:28 +02:00
tableLayoutPanel3 . Visible = false ;
2013-06-24 13:41:48 +02:00
}
2013-07-15 07:41:54 +02:00
private void GridViewAlerts_CellClick ( object sender , DataGridViewCellEventArgs e )
2013-06-24 13:41:48 +02:00
{
// If you click on the headers you can get -1 as the index.
if ( e . ColumnIndex < 0 | | e . RowIndex < 0 | | e . ColumnIndex ! = ColumnExpand . Index )
return ;
2013-07-18 14:56:40 +02:00
ToggleExpandedState ( e . RowIndex ) ;
2013-06-24 13:41:48 +02:00
}
2013-07-15 07:41:54 +02:00
private void GridViewAlerts_CellDoubleClick ( object sender , DataGridViewCellEventArgs e )
2013-06-24 13:41:48 +02:00
{
// If you click on the headers you can get -1 as the index.
if ( e . ColumnIndex < 0 | | e . RowIndex < 0 )
return ;
2013-07-18 14:56:40 +02:00
if ( e . ColumnIndex ! = ColumnActions . Index )
ToggleExpandedState ( e . RowIndex ) ;
2013-06-24 13:41:48 +02:00
}
2013-07-15 07:41:54 +02:00
private void GridViewAlerts_KeyDown ( object sender , KeyEventArgs e )
2013-06-24 13:41:48 +02:00
{
2013-07-15 07:41:54 +02:00
if ( e . KeyCode = = Keys . Right ) // expand all selected rows
2013-06-24 13:41:48 +02:00
{
2013-07-15 07:41:54 +02:00
foreach ( DataGridViewBand row in GridViewAlerts . SelectedRows )
{
Alert alert = ( Alert ) GridViewAlerts . Rows [ row . Index ] . Tag ;
if ( ! expandedState . ContainsKey ( alert . uuid ) )
{
2013-07-18 14:56:40 +02:00
ToggleExpandedState ( row . Index ) ;
2013-07-15 07:41:54 +02:00
}
}
2013-06-24 13:41:48 +02:00
}
2013-07-15 07:41:54 +02:00
else if ( e . KeyCode = = Keys . Left ) // collapse all selected rows
2013-06-24 13:41:48 +02:00
{
2013-07-15 07:41:54 +02:00
foreach ( DataGridViewBand row in GridViewAlerts . SelectedRows )
{
Alert alert = ( Alert ) GridViewAlerts . Rows [ row . Index ] . Tag ;
if ( expandedState . ContainsKey ( alert . uuid ) )
{
2013-07-18 14:56:40 +02:00
ToggleExpandedState ( row . Index ) ;
2013-07-15 07:41:54 +02:00
}
}
}
else if ( e . KeyCode = = Keys . Enter ) // toggle expanded state for all selected rows
{
foreach ( DataGridViewBand row in GridViewAlerts . SelectedRows )
{
2013-07-18 14:56:40 +02:00
ToggleExpandedState ( row . Index ) ;
2013-07-15 07:41:54 +02:00
}
2013-06-24 13:41:48 +02:00
}
}
2013-07-15 07:41:54 +02:00
private void GridViewAlerts_ColumnHeaderMouseClick ( object sender , DataGridViewCellMouseEventArgs e )
{
if ( GridViewAlerts . Columns [ e . ColumnIndex ] . SortMode = = DataGridViewColumnSortMode . Automatic )
{
Rebuild ( ) ;
}
}
private void GridViewAlerts_SelectionChanged ( object sender , EventArgs e )
{
// stop the buttons getting enabled/disabled during refresh, the rebuild will set them once it's finished
if ( inAlertBuild )
return ;
UpdateActionEnablement ( ) ;
}
2013-06-24 13:41:48 +02:00
/// <summary>
/// Handles the automatic sorting of the AlertsGridView for the non-string columns
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2013-07-15 07:41:54 +02:00
private void GridViewAlerts_SortCompare ( object sender , DataGridViewSortCompareEventArgs e )
2013-06-24 13:41:48 +02:00
{
Alert alert1 = ( Alert ) GridViewAlerts . Rows [ e . RowIndex1 ] . Tag ;
Alert alert2 = ( Alert ) GridViewAlerts . Rows [ e . RowIndex2 ] . Tag ;
if ( e . Column . Index = = ColumnDate . Index )
{
int SortResult = DateTime . Compare ( alert1 . Timestamp , alert2 . Timestamp ) ;
e . SortResult = ( GridViewAlerts . SortOrder = = SortOrder . Descending ) ? SortResult * = - 1 : SortResult ;
e . Handled = true ;
}
2013-07-12 12:07:10 +02:00
else if ( e . Column . Index = = ColumnSeverity . Index )
2013-06-24 13:41:48 +02:00
{
2013-07-03 13:00:00 +02:00
e . SortResult = Alert . CompareOnPriority ( alert1 , alert2 ) ;
2013-06-24 13:41:48 +02:00
e . Handled = true ;
}
}
2013-07-18 14:56:40 +02:00
private void ToggleExpandedState ( int rowIndex )
2013-07-15 07:41:54 +02:00
{
2013-07-18 14:56:40 +02:00
var row = GridViewAlerts . Rows [ rowIndex ] ;
Alert alert = row . Tag as Alert ;
if ( alert = = null )
return ;
2013-07-15 07:41:54 +02:00
if ( expandedState . ContainsKey ( alert . uuid ) )
{
expandedState . Remove ( alert . uuid ) ;
2017-01-11 14:54:56 +01:00
row . Cells [ ColumnExpand . Index ] . Value = Images . StaticImages . contracted_triangle ;
2013-07-18 14:56:40 +02:00
row . Cells [ ColumnMessage . Index ] . Value = alert . Title ;
2013-07-15 07:41:54 +02:00
}
else
{
expandedState . Add ( alert . uuid , true ) ;
2017-01-11 14:54:56 +01:00
row . Cells [ ColumnExpand . Index ] . Value = Images . StaticImages . expanded_triangle ;
2013-07-18 14:56:40 +02:00
row . Cells [ ColumnMessage . Index ] . Value = string . Format ( "{0}\n\n{1}" , alert . Title , alert . Description ) ;
2013-07-15 07:41:54 +02:00
}
}
2013-06-24 13:41:48 +02:00
2014-06-30 15:49:16 +02:00
private DataGridViewRow FindAlertRow ( ToolStripMenuItem toolStripMenuItem )
{
if ( toolStripMenuItem = = null )
return null ;
return ( from DataGridViewRow row in GridViewAlerts . Rows
where row . Cells . Count > 0
let actionCell = row . Cells [ row . Cells . Count - 1 ] as DataGridViewDropDownSplitButtonCell
where actionCell ! = null & & actionCell . ContextMenu . Items . Cast < object > ( ) . Any ( item = > item is ToolStripMenuItem & & item = = toolStripMenuItem )
select row ) . FirstOrDefault ( ) ;
}
2017-07-14 19:08:54 +02:00
#endregion
2013-07-18 14:56:40 +02:00
private void ToolStripMenuItemHelp_Click ( object sender , EventArgs e )
2013-06-24 13:41:48 +02:00
{
// We should only be here if one item is selected, we dont do multi-help
if ( GridViewAlerts . SelectedRows . Count ! = 1 )
2014-07-02 14:13:37 +02:00
log . DebugFormat ( "Can only launch help for 1 alert at a time (Attempted to launch {0}). Launching for the clicked item." , GridViewAlerts . SelectedRows . Count ) ;
2014-06-30 15:49:16 +02:00
DataGridViewRow clickedRow = FindAlertRow ( sender as ToolStripMenuItem ) ;
if ( clickedRow = = null )
return ;
Alert alert = ( Alert ) clickedRow . Tag ;
if ( alert = = null )
return ;
2013-06-24 13:41:48 +02:00
if ( alert . HelpID = = null )
{
log . ErrorFormat ( "Attempted to launch help for alert {0} ({1}) but no helpID available. Not launching." , alert . Title , alert . uuid ) ;
return ;
}
HelpManager . Launch ( alert . HelpID ) ;
}
2013-07-18 14:56:40 +02:00
private void ToolStripMenuItemFix_Click ( object sender , EventArgs e )
2013-06-24 13:41:48 +02:00
{
// We should only be here if one item is selected, we dont do multi-fix
2014-06-30 15:49:16 +02:00
if ( GridViewAlerts . SelectedRows . Count ! = 1 )
2014-07-02 14:13:37 +02:00
log . DebugFormat ( "Only 1 alert can be fixed at a time (Attempted to fix {0}). Fixing the clicked item." , GridViewAlerts . SelectedRows . Count ) ;
2014-06-30 15:49:16 +02:00
DataGridViewRow clickedRow = FindAlertRow ( sender as ToolStripMenuItem ) ;
if ( clickedRow = = null )
2013-06-24 13:41:48 +02:00
{
2014-07-02 14:13:37 +02:00
log . Debug ( "Attempted to fix alert with no alert selected." ) ;
2013-06-24 13:41:48 +02:00
return ;
}
2014-06-30 15:49:16 +02:00
Alert alert = ( Alert ) clickedRow . Tag ;
if ( alert = = null )
return ;
2013-06-24 13:41:48 +02:00
if ( alert . FixLinkAction = = null )
{
log . ErrorFormat ( "Attempted to fix alert {0} ({1}) but no fix link action available. Not fixing." , alert . Title , alert . uuid ) ;
return ;
}
alert . FixLinkAction . Invoke ( ) ;
}
2013-07-18 14:56:40 +02:00
private void ToolStripMenuItemDismiss_Click ( object sender , EventArgs e )
2013-06-24 13:41:48 +02:00
{
2014-07-29 11:19:54 +02:00
if ( GridViewAlerts . SelectedRows . Count ! = 1 )
log . DebugFormat ( "Only 1 alert can be dismissed at a time (Attempted to dismiss {0}). Dismissing the clicked item." , GridViewAlerts . SelectedRows . Count ) ;
DataGridViewRow clickedRow = FindAlertRow ( sender as ToolStripMenuItem ) ;
if ( clickedRow = = null )
{
log . Debug ( "Attempted to dismiss alert with no alert selected." ) ;
return ;
}
Alert alert = ( Alert ) clickedRow . Tag ;
if ( alert = = null )
return ;
2016-11-17 14:35:31 +01:00
if ( ! Properties . Settings . Default . DoNotConfirmDismissAlerts )
{
2020-04-22 15:47:03 +02:00
using ( var dlog = new NoIconDialog ( Messages . ALERT_DISMISS_CONFIRM ,
ThreeButtonDialog . ButtonYes , ThreeButtonDialog . ButtonNo )
2016-11-17 14:35:31 +01:00
{
ShowCheckbox = true ,
CheckboxCaption = Messages . DO_NOT_SHOW_THIS_MESSAGE
} )
{
var result = dlog . ShowDialog ( this ) ;
Properties . Settings . Default . DoNotConfirmDismissAlerts = dlog . IsCheckBoxChecked ;
Settings . TrySaveSettings ( ) ;
if ( result ! = DialogResult . Yes )
return ;
}
2013-11-18 15:31:00 +01:00
}
2013-06-24 13:41:48 +02:00
2020-07-26 15:54:52 +02:00
DismissAlerts ( ( Alert ) clickedRow . Tag ) ;
2013-06-24 13:41:48 +02:00
}
2013-07-11 19:20:18 +02:00
private void tsmiDismissAll_Click ( object sender , EventArgs e )
2013-06-24 13:41:48 +02:00
{
2016-11-17 14:35:31 +01:00
DialogResult result = DialogResult . Yes ;
2013-08-14 17:59:25 +02:00
2016-11-17 14:35:31 +01:00
if ( FilterIsOn )
2013-08-14 17:59:25 +02:00
{
2020-04-22 15:47:03 +02:00
using ( var dlog = new NoIconDialog ( Messages . ALERT_DISMISS_ALL_CONTINUE ,
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 ) ,
2013-08-14 17:59:25 +02:00
ThreeButtonDialog . ButtonCancel ) )
{
result = dlog . ShowDialog ( this ) ;
}
}
2016-11-17 14:35:31 +01:00
else if ( ! Properties . Settings . Default . DoNotConfirmDismissAlerts )
2013-08-14 17:59:25 +02:00
{
2020-04-22 15:47:03 +02:00
using ( var dlog = new NoIconDialog ( Messages . ALERT_DISMISS_ALL_NO_FILTER_CONTINUE ,
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
} )
2013-08-14 17:59:25 +02:00
{
result = dlog . ShowDialog ( this ) ;
2016-11-17 14:35:31 +01:00
Properties . Settings . Default . DoNotConfirmDismissAlerts = dlog . IsCheckBoxChecked ;
Settings . TrySaveSettings ( ) ;
2013-08-14 17:59:25 +02:00
}
}
2013-06-24 13:41:48 +02:00
if ( result = = DialogResult . Cancel )
return ;
2014-01-09 14:57:41 +01:00
var alerts = result = = DialogResult . No
2020-07-26 15:54:52 +02:00
? ( from DataGridViewRow row in GridViewAlerts . Rows select row . Tag as Alert ) . ToArray ( )
2016-11-17 14:35:31 +01:00
: Alert . Alerts ;
2013-06-24 13:41:48 +02:00
2014-01-09 14:57:41 +01:00
DismissAlerts ( alerts ) ;
2013-06-24 13:41:48 +02:00
}
2014-07-29 11:19:54 +02:00
private void tsmiDismissSelected_Click ( object sender , EventArgs e )
{
2016-11-17 14:35:31 +01:00
if ( ! Properties . Settings . Default . DoNotConfirmDismissAlerts )
2014-07-29 11:19:54 +02:00
{
2020-04-22 15:47:03 +02:00
using ( var dlog = new NoIconDialog ( Messages . ALERT_DISMISS_SELECTED_CONFIRM ,
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 . DoNotConfirmDismissAlerts = dlog . IsCheckBoxChecked ;
Settings . TrySaveSettings ( ) ;
if ( result ! = DialogResult . Yes )
return ;
}
2014-07-29 11:19:54 +02:00
}
if ( GridViewAlerts . SelectedRows . Count > 0 )
{
var selectedAlerts = from DataGridViewRow row in GridViewAlerts . SelectedRows select row . Tag as Alert ;
2020-07-26 15:54:52 +02:00
DismissAlerts ( selectedAlerts . ToArray ( ) ) ;
2014-07-29 11:19:54 +02:00
}
}
2013-07-03 14:00:24 +02:00
private void AlertsCollectionChanged ( object sender , CollectionChangeEventArgs e )
2013-06-24 13:41:48 +02:00
{
Program . AssertOnEventThread ( ) ;
2017-07-14 19:08:54 +02:00
2013-06-24 13:41:48 +02:00
switch ( e . Action )
{
case CollectionChangeAction . Add :
2019-08-30 11:00:01 +02:00
case CollectionChangeAction . Refresh :
2013-06-24 13:41:48 +02:00
Rebuild ( ) ; // rebuild entire alert list to ensure filtering and sorting
break ;
case CollectionChangeAction . Remove :
2017-07-14 19:08:54 +02:00
var a = e . Element as Alert ;
if ( a ! = null )
RemoveAlertRow ( a ) ;
else
{
var range = e . Element as List < Alert > ;
if ( range ! = null )
Rebuild ( ) ;
}
2013-06-24 13:41:48 +02:00
break ;
}
}
2017-07-14 19:08:54 +02:00
2013-06-24 13:41:48 +02:00
private void UpdateActionEnablement ( )
{
2014-07-31 10:39:16 +02:00
toolStripButtonExportAll . Enabled = Alert . NonDismissingAlertCount > 0 ;
2013-06-24 13:41:48 +02:00
2020-07-26 15:54:52 +02:00
tsmiDismissAll . Enabled = Alert . Alerts . Any ( a = > a . AllowedToDismiss ( ) ) ;
2013-07-11 19:20:18 +02:00
tsmiDismissAll . AutoToolTip = ! tsmiDismissAll . Enabled ;
tsmiDismissAll . ToolTipText = tsmiDismissAll . Enabled
? string . Empty
: Alert . NonDismissingAlertCount > 0
? Messages . DELETE_ANY_MESSAGE_RBAC_BLOCKED
: Messages . NO_MESSAGES_TO_DISMISS ;
2020-07-26 15:54:52 +02:00
var selectedAlerts = ( from DataGridViewRow row in GridViewAlerts . SelectedRows
select row . Tag as Alert ) . ToArray ( ) ;
2014-01-09 14:57:41 +01:00
2020-07-26 15:54:52 +02:00
tsmiDismissSelected . Enabled = selectedAlerts . Any ( a = > a . AllowedToDismiss ( ) ) ;
2013-07-11 19:20:18 +02:00
tsmiDismissSelected . AutoToolTip = ! tsmiDismissSelected . Enabled ;
tsmiDismissSelected . ToolTipText = tsmiDismissSelected . Enabled
? string . Empty
: Messages . DELETE_MESSAGE_RBAC_BLOCKED ;
2013-08-14 17:59:25 +02:00
2014-01-09 14:57:41 +01:00
toolStripSplitButtonDismiss . Enabled = tsmiDismissAll . Enabled | | tsmiDismissSelected . Enabled ;
2020-07-26 15:54:52 +02:00
toolStripSplitButtonDismiss . AutoToolTip = tsmiDismissAll . AutoToolTip | | tsmiDismissSelected . AutoToolTip ;
if ( toolStripSplitButtonDismiss . AutoToolTip )
{
if ( ! string . IsNullOrEmpty ( tsmiDismissAll . ToolTipText ) )
toolStripSplitButtonDismiss . ToolTipText = tsmiDismissAll . ToolTipText ;
else if ( ! string . IsNullOrEmpty ( tsmiDismissSelected . ToolTipText ) )
toolStripSplitButtonDismiss . ToolTipText = tsmiDismissSelected . ToolTipText ;
}
2013-06-24 13:41:48 +02:00
2014-01-09 14:57:41 +01:00
if ( toolStripSplitButtonDismiss . DefaultItem ! = null & & ! toolStripSplitButtonDismiss . DefaultItem . Enabled )
2013-06-24 13:41:48 +02:00
{
2014-01-09 14:57:41 +01:00
foreach ( ToolStripItem item in toolStripSplitButtonDismiss . DropDownItems )
{
if ( item . Enabled )
{
toolStripSplitButtonDismiss . DefaultItem = item ;
toolStripSplitButtonDismiss . Text = item . Text ;
break ;
}
}
}
}
2013-06-24 13:41:48 +02:00
2014-01-09 14:57:41 +01:00
#region Alert dismissal
2013-06-24 13:41:48 +02:00
2020-07-26 15:54:52 +02:00
private void DismissAlerts ( params Alert [ ] alerts )
2014-01-09 14:57:41 +01:00
{
var groups = from Alert alert in alerts
2020-07-26 15:54:52 +02:00
where alert ! = null & & alert . AllowedToDismiss ( )
2014-01-09 14:57:41 +01:00
group alert by alert . Connection
into g
select new { Connection = g . Key , Alerts = g } ;
foreach ( var g in groups )
{
2020-07-26 15:54:52 +02:00
foreach ( var alert in g . Alerts )
alert . Dismissing = true ;
new DeleteAllAlertsAction ( g . Alerts . ToList ( ) , g . Connection ) . RunAsync ( ) ;
2014-01-09 14:57:41 +01:00
}
}
#endregion
2013-07-18 14:56:40 +02:00
private List < ToolStripItem > GetAlertActionItems ( Alert alert )
2013-06-24 13:41:48 +02:00
{
2013-07-18 14:56:40 +02:00
var items = new List < ToolStripItem > ( ) ;
2013-06-24 13:41:48 +02:00
2020-07-26 15:54:52 +02:00
if ( alert . AllowedToDismiss ( ) )
2013-07-18 14:56:40 +02:00
{
var dismiss = new ToolStripMenuItem ( Messages . ALERT_DISMISS ) ;
dismiss . Click + = ToolStripMenuItemDismiss_Click ;
items . Add ( dismiss ) ;
}
2013-06-24 13:41:48 +02:00
2013-07-18 14:56:40 +02:00
if ( ! string . IsNullOrEmpty ( alert . FixLinkText ) & & alert . FixLinkAction ! = null )
2013-06-24 13:41:48 +02:00
{
2013-07-18 14:56:40 +02:00
var fix = new ToolStripMenuItem ( alert . FixLinkText ) ;
fix . Click + = ToolStripMenuItemFix_Click ;
items . Add ( fix ) ;
}
2013-07-15 07:41:54 +02:00
2013-07-18 14:56:40 +02:00
if ( ! string . IsNullOrEmpty ( alert . HelpID ) )
{
var help = new ToolStripMenuItem ( alert . HelpLinkText ) ;
help . Click + = ToolStripMenuItemHelp_Click ;
items . Add ( help ) ;
}
2013-07-15 07:41:54 +02:00
2013-07-18 14:56:40 +02:00
if ( items . Count > 0 )
items . Add ( new ToolStripSeparator ( ) ) ;
2013-07-15 07:41:54 +02:00
2013-07-18 14:56:40 +02:00
var copy = new ToolStripMenuItem ( Messages . COPY ) ;
copy . Click + = copyToolStripMenuItem_Click ;
items . Add ( copy ) ;
2013-06-24 13:41:48 +02:00
2013-07-18 14:56:40 +02:00
return items ;
2013-06-24 13:41:48 +02:00
}
2013-07-11 19:20:18 +02:00
#region Top ToolStrip event handlers
2013-07-02 18:36:02 +02:00
private void toolStripDropDownButtonDateFilter_FilterChanged ( )
2013-06-24 13:41:48 +02:00
{
Rebuild ( ) ;
}
2013-07-02 20:06:11 +02:00
private void toolStripDropDownButtonServerFilter_FilterChanged ( )
{
Rebuild ( ) ;
}
2013-07-15 07:41:54 +02:00
private void toolStripDropDownSeveritiesFilter_FilterChanged ( )
{
Rebuild ( ) ;
}
2013-06-24 13:41:48 +02:00
2013-07-15 07:41:54 +02:00
private void toolStripButtonRefresh_Click ( object sender , EventArgs e )
{
Rebuild ( ) ;
}
2013-07-11 19:20:18 +02:00
2013-06-24 13:41:48 +02:00
private void toolStripButtonExportAll_Click ( object sender , EventArgs e )
{
2013-08-14 18:12:39 +02:00
bool exportAll = true ;
if ( FilterIsOn )
{
2020-04-22 15:47:03 +02:00
using ( var dlog = new NoIconDialog ( Messages . ALERT_EXPORT_ALL_OR_FILTERED ,
2019-08-22 11:47:43 +02:00
new ThreeButtonDialog . TBDButton ( Messages . EXPORT_ALL_BUTTON , DialogResult . Yes ) ,
new ThreeButtonDialog . TBDButton ( Messages . EXPORT_FILTERED_BUTTON , DialogResult . No , ThreeButtonDialog . ButtonType . NONE ) ,
2013-08-14 18:12:39 +02:00
ThreeButtonDialog . ButtonCancel ) )
{
var result = dlog . ShowDialog ( this ) ;
if ( result = = DialogResult . No )
exportAll = false ;
else if ( result = = DialogResult . Cancel )
return ;
}
}
string fileName ;
using ( SaveFileDialog dialog = new SaveFileDialog
{
AddExtension = true ,
Filter = string . Format ( "{0} (*.csv)|*.csv|{1} (*.*)|*.*" ,
Messages . CSV_DESCRIPTION , Messages . ALL_FILES ) ,
FilterIndex = 0 ,
Title = Messages . EXPORT_ALL ,
RestoreDirectory = true ,
DefaultExt = "csv" ,
CheckPathExists = false ,
OverwritePrompt = true
} )
{
if ( dialog . ShowDialog ( this ) ! = DialogResult . OK )
return ;
fileName = dialog . FileName ;
}
2013-06-24 13:41:48 +02:00
new DelegatedAsyncAction ( null ,
2013-08-14 18:12:39 +02:00
string . Format ( Messages . EXPORT_SYSTEM_ALERTS , fileName ) ,
string . Format ( Messages . EXPORTING_SYSTEM_ALERTS , fileName ) ,
string . Format ( Messages . EXPORTED_SYSTEM_ALERTS , fileName ) ,
2013-07-18 14:56:40 +02:00
delegate
2013-06-24 13:41:48 +02:00
{
2019-08-22 11:47:43 +02:00
using ( StreamWriter stream = new StreamWriter ( fileName , false , Encoding . UTF8 ) )
2013-06-24 13:41:48 +02:00
{
2013-07-12 12:07:10 +02:00
stream . WriteLine ( "{0},{1},{2},{3},{4}" , Messages . TITLE ,
2013-08-14 18:12:39 +02:00
Messages . SEVERITY , Messages . DESCRIPTION ,
Messages . APPLIES_TO , Messages . TIMESTAMP ) ;
if ( exportAll )
2013-06-24 13:41:48 +02:00
{
2013-08-14 18:12:39 +02:00
foreach ( Alert a in Alert . Alerts )
2014-01-09 14:57:41 +01:00
{
if ( ! a . Dismissing )
stream . WriteLine ( a . GetAlertDetailsCSVQuotes ( ) ) ;
}
2013-08-14 18:12:39 +02:00
}
else
{
foreach ( DataGridViewRow row in GridViewAlerts . Rows )
{
2020-07-26 15:54:52 +02:00
if ( row . Tag is Alert a & & ! a . Dismissing )
2013-11-23 15:04:15 +01:00
stream . WriteLine ( a . GetAlertDetailsCSVQuotes ( ) ) ;
2013-08-14 18:12:39 +02:00
}
2013-06-24 13:41:48 +02:00
}
}
} ) . RunAsync ( ) ;
}
2013-07-11 19:20:18 +02:00
private void toolStripSplitButtonDismiss_DropDownItemClicked ( object sender , ToolStripItemClickedEventArgs e )
2013-06-24 13:41:48 +02:00
{
2013-07-11 19:20:18 +02:00
toolStripSplitButtonDismiss . DefaultItem = e . ClickedItem ;
toolStripSplitButtonDismiss . Text = toolStripSplitButtonDismiss . DefaultItem . Text ;
2013-06-24 13:41:48 +02:00
}
2013-11-23 15:04:15 +01:00
#endregion
2013-06-24 13:41:48 +02:00
private void copyToolStripMenuItem_Click ( object sender , EventArgs e )
{
2014-07-29 11:19:54 +02:00
if ( GridViewAlerts . SelectedRows . Count ! = 1 )
log . DebugFormat ( "Only 1 alert can be copied at a time (Attempted to copy {0}). Copying the clicked item." , GridViewAlerts . SelectedRows . Count ) ;
2014-06-30 15:49:16 +02:00
DataGridViewRow clickedRow = FindAlertRow ( sender as ToolStripMenuItem ) ;
if ( clickedRow = = null )
2013-06-24 13:41:48 +02:00
{
2014-07-02 14:13:37 +02:00
log . Debug ( "Attempted to copy alert with no alert selected." ) ;
2013-06-24 13:41:48 +02:00
return ;
}
2014-07-29 11:19:54 +02:00
Alert alert = ( Alert ) clickedRow . Tag ;
if ( alert = = null )
return ;
2013-07-12 12:07:10 +02:00
2016-10-13 17:16:16 +02:00
Clip . SetClipboardText ( alert . GetUpdateDetailsCSVQuotes ( ) ) ;
2013-06-24 13:41:48 +02:00
}
2019-09-04 14:21:57 +02:00
#region CheckForUpdates events
private void RegisterCheckForUpdatesEvents ( )
{
Updates . CheckForUpdatesCompleted + = CheckForUpdatesCompleted ;
}
private void DeregisterCheckForUpdatesEvents ( )
{
Updates . CheckForUpdatesCompleted - = CheckForUpdatesCompleted ;
}
private void CheckForUpdatesCompleted ( bool succeeded , string errorMessage )
{
Updates . CheckHotfixEligibility ( ) ;
}
#endregion
2013-06-24 13:41:48 +02:00
}
}