// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net)
// All rights reserved.
//
// This file is part of Regionerate.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
namespace Rauchy.Regionerate.Shared.Components
{
///
/// Provides quick access for user interface notifications.
///
public static class Output
{
#region Enums (1)
///
/// Describes the severity of a warning.
///
public enum WarningLevel
{
///
/// Indicates that an action that was chosen to perform might lead to undesirable results.
///
NonCritical = 0,
///
/// Indicates that an action failed to perform, which might lead to corrupt or lost code.
///
Critical
}
#endregion Enums
#region Delegates and Events (9)
// Delegates (3)
// [rgn] Delegates (3)
///
/// Occurs when new information is submitted.
///
/// The new information text.
public delegate void InformationSubmitted( string text );
///
/// Occurs when an operation's progress is increased.
///
/// The current progress value.
/// The maximum value that represents a complete operation.
public delegate void ProgressChanged( long value, long targetValue );
///
/// Occurs when a new warning is submitted.
///
/// The new warning text.
/// The level of warning (critical, non-critical etc.)
public delegate void WarningSubmitted( string text, WarningLevel level );
// Events (6)
// [rgn] Events (6)
private static event InformationSubmitted _onInformationSubmitted;
private static event ProgressChanged _onProgressChanged;
private static event WarningSubmitted _onWarningSubmitted;
///
/// Occurs when new information is submitted.
///
public static event InformationSubmitted OnInformationSubmitted
{
add
{
_onInformationSubmitted += value;
}
remove
{
_onInformationSubmitted -= value;
}
}
///
/// Occurs when an operation's progress is increased.
///
public static event ProgressChanged OnProgressChanged
{
add
{
_onProgressChanged += value;
}
remove
{
_onProgressChanged -= value;
}
}
///
/// Occurs when a new warning is submitted.
///
public static event WarningSubmitted OnWarningSubmitted
{
add
{
_onWarningSubmitted += value;
}
remove
{
_onWarningSubmitted -= value;
}
}
#endregion Delegates and Events
#region Methods (4)
// Public Methods (4)
// [rgn] Public Methods (4)
///
/// Disconnects all registered event handlers.
///
public static void Disconnect()
{
_onInformationSubmitted = null;
_onWarningSubmitted = null;
_onProgressChanged = null;
}
///
/// Informs about the specified text.
///
/// The text.
/// The parameters to include in the formatted information text.
public static void Inform( string text, params string[] parameters )
{
if ( _onInformationSubmitted != null )
{
string formattedText = string.Format( text, parameters );
_onInformationSubmitted( formattedText );
}
}
///
/// Sets the progress of an operation.
///
/// The value.
/// The target value.
public static void SetProgress( long value, long targetValue )
{
if ( _onProgressChanged != null )
{
_onProgressChanged( value, targetValue );
}
}
///
/// Warns about the specified text.
///
/// The text.
/// The warning level.
/// The parameters to include in the formatted warning text.
public static void Warn( string text, WarningLevel level, params string[] parameters )
{
if ( _onWarningSubmitted != null )
{
string formattedText = string.Format( text, parameters );
_onWarningSubmitted( formattedText, level );
}
}
#endregion Methods
}
}