2
// ConsoleProgressStatus.cs
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
/// An IProgressStatus class which writes output to the console.
37
public class ConsoleProgressStatus: MarshalByRefObject, IProgressStatus
43
/// Initializes a new instance
45
/// <param name="verboseLog">
46
/// Set to true to enabled verbose log
48
public ConsoleProgressStatus (bool verboseLog)
57
/// Initializes a new instance
59
/// <param name="logLevel">
60
/// Verbosity level. 0: not verbose, 1: normal, >1 extra verbose
62
public ConsoleProgressStatus (int logLevel)
64
this.logLevel = logLevel;
68
/// Sets the description of the current operation.
70
/// <param name="msg">
74
/// This method is called by the add-in engine to show a description of the operation being monitorized.
76
public void SetMessage (string msg)
81
/// Sets the progress of the operation.
83
/// <param name="progress">
84
/// A number between 0 and 1. 0 means no progress, 1 means operation completed.
87
/// This method is called by the add-in engine to show the progress of the operation being monitorized.
89
public void SetProgress (double progress)
94
/// Writes text to the log.
96
/// <param name="msg">
99
public void Log (string msg)
101
Console.WriteLine (msg);
105
/// Reports a warning.
107
/// <param name="message">
111
/// This method is called by the add-in engine to report a warning in the operation being monitorized.
113
public void ReportWarning (string message)
116
Console.WriteLine ("WARNING: " + message);
120
/// Reports an error.
122
/// <param name="message">
125
/// <param name="exception">
126
/// Exception that caused the error. It can be null.
129
/// This method is called by the add-in engine to report an error occurred while executing the operation being monitorized.
131
public void ReportError (string message, Exception exception)
135
Console.Write ("ERROR: ");
138
Console.WriteLine (message);
139
if (exception != null)
140
Console.WriteLine (exception);
142
if (message != null && exception != null)
143
Console.WriteLine (message + " (" + exception.Message + ")");
146
Console.WriteLine (message);
147
if (exception != null)
148
Console.WriteLine (exception.Message);
154
/// Returns True when the user requested to cancel this operation
156
public bool IsCanceled {
157
get { return canceled; }
161
/// Log level requested by the user: 0: no log, 1: normal log, >1 verbose log
163
public int LogLevel {
164
get { return logLevel; }
168
/// Cancels the operation being montorized.
170
public void Cancel ()