~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins/Mono.Addins/ConsoleProgressStatus.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ConsoleProgressStatus.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
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:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
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.
 
27
//
 
28
 
 
29
 
 
30
using System;
 
31
 
 
32
namespace Mono.Addins
 
33
{
 
34
        /// <summary>
 
35
        /// An IProgressStatus class which writes output to the console.
 
36
        /// </summary>
 
37
        public class ConsoleProgressStatus: MarshalByRefObject, IProgressStatus
 
38
        {
 
39
                bool canceled;
 
40
                int logLevel;
 
41
                
 
42
                /// <summary>
 
43
                /// Initializes a new instance
 
44
                /// </summary>
 
45
                /// <param name="verboseLog">
 
46
                /// Set to true to enabled verbose log
 
47
                /// </param>
 
48
                public ConsoleProgressStatus (bool verboseLog)
 
49
                {
 
50
                        if (verboseLog)
 
51
                                logLevel = 2;
 
52
                        else
 
53
                                logLevel = 1;
 
54
                }
 
55
                
 
56
                /// <summary>
 
57
                /// Initializes a new instance
 
58
                /// </summary>
 
59
                /// <param name="logLevel">
 
60
                /// Verbosity level. 0: not verbose, 1: normal, >1 extra verbose
 
61
                /// </param>
 
62
                public ConsoleProgressStatus (int logLevel)
 
63
                {
 
64
                        this.logLevel = logLevel;
 
65
                }
 
66
                
 
67
                /// <summary>
 
68
                /// Sets the description of the current operation.
 
69
                /// </summary>
 
70
                /// <param name="msg">
 
71
                /// A message
 
72
                /// </param>
 
73
                /// <remarks>
 
74
                /// This method is called by the add-in engine to show a description of the operation being monitorized.
 
75
                /// </remarks>
 
76
                public void SetMessage (string msg)
 
77
                {
 
78
                }
 
79
                
 
80
                /// <summary>
 
81
                /// Sets the progress of the operation.
 
82
                /// </summary>
 
83
                /// <param name="progress">
 
84
                /// A number between 0 and 1. 0 means no progress, 1 means operation completed.
 
85
                /// </param>
 
86
                /// <remarks>
 
87
                /// This method is called by the add-in engine to show the progress of the operation being monitorized.
 
88
                /// </remarks>
 
89
                public void SetProgress (double progress)
 
90
                {
 
91
                }
 
92
                
 
93
                /// <summary>
 
94
                /// Writes text to the log.
 
95
                /// </summary>
 
96
                /// <param name="msg">
 
97
                /// Message to write
 
98
                /// </param>
 
99
                public void Log (string msg)
 
100
                {
 
101
                        Console.WriteLine (msg);
 
102
                }
 
103
                
 
104
                /// <summary>
 
105
                /// Reports a warning.
 
106
                /// </summary>
 
107
                /// <param name="message">
 
108
                /// Warning message
 
109
                /// </param>
 
110
                /// <remarks>
 
111
                /// This method is called by the add-in engine to report a warning in the operation being monitorized.
 
112
                /// </remarks>
 
113
                public void ReportWarning (string message)
 
114
                {
 
115
                        if (logLevel > 0)
 
116
                                Console.WriteLine ("WARNING: " + message);
 
117
                }
 
118
                
 
119
                /// <summary>
 
120
                /// Reports an error.
 
121
                /// </summary>
 
122
                /// <param name="message">
 
123
                /// Error message
 
124
                /// </param>
 
125
                /// <param name="exception">
 
126
                /// Exception that caused the error. It can be null.
 
127
                /// </param>
 
128
                /// <remarks>
 
129
                /// This method is called by the add-in engine to report an error occurred while executing the operation being monitorized.
 
130
                /// </remarks>
 
131
                public void ReportError (string message, Exception exception)
 
132
                {
 
133
                        if (logLevel == 0)
 
134
                                return;
 
135
                        Console.Write ("ERROR: ");
 
136
                        if (logLevel > 1) {
 
137
                                if (message != null)
 
138
                                        Console.WriteLine (message);
 
139
                                if (exception != null)
 
140
                                        Console.WriteLine (exception);
 
141
                        } else {
 
142
                                if (message != null && exception != null)
 
143
                                        Console.WriteLine (message + " (" + exception.Message + ")");
 
144
                                else {
 
145
                                        if (message != null)
 
146
                                                Console.WriteLine (message);
 
147
                                        if (exception != null)
 
148
                                                Console.WriteLine (exception.Message);
 
149
                                }
 
150
                        }
 
151
                }
 
152
                
 
153
                /// <summary>
 
154
                /// Returns True when the user requested to cancel this operation
 
155
                /// </summary>
 
156
                public bool IsCanceled {
 
157
                        get { return canceled; }
 
158
                }
 
159
                
 
160
                /// <summary>
 
161
                /// Log level requested by the user: 0: no log, 1: normal log, >1 verbose log
 
162
                /// </summary>
 
163
                public int LogLevel {
 
164
                        get { return logLevel; }
 
165
                }
 
166
                
 
167
                /// <summary>
 
168
                /// Cancels the operation being montorized.
 
169
                /// </summary>
 
170
                public void Cancel ()
 
171
                {
 
172
                        canceled = true;
 
173
                }
 
174
        }
 
175
}
 
176