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

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins.Setup/Mono.Addins.Setup.ProgressMonitoring/NullProgressMonitor.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
// NullProgressMonitor.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
using System.Collections;
 
32
using System.Threading;
 
33
using System.IO;
 
34
 
 
35
namespace Mono.Addins.Setup.ProgressMonitoring
 
36
{
 
37
        internal class NullProgressMonitor: MarshalByRefObject, IProgressMonitor
 
38
        {
 
39
                bool done, canceled;
 
40
                ArrayList errors;
 
41
                ArrayList warnings;
 
42
                ArrayList messages;
 
43
                
 
44
                public string[] Messages {
 
45
                        get {
 
46
                                if (messages != null)
 
47
                                        return (string[]) messages.ToArray (typeof(string));
 
48
                                else
 
49
                                        return new string [0];
 
50
                        }
 
51
                }
 
52
                
 
53
                public string[] Warnings {
 
54
                        get {
 
55
                                if (warnings != null)
 
56
                                        return (string[]) warnings.ToArray (typeof(string));
 
57
                                else
 
58
                                        return new string [0];
 
59
                        }
 
60
                }
 
61
                
 
62
                public ProgressError[] Errors {
 
63
                        get {
 
64
                                if (errors != null)
 
65
                                        return (ProgressError[]) errors.ToArray (typeof(ProgressError));
 
66
                                else
 
67
                                        return new ProgressError [0];
 
68
                        }
 
69
                }
 
70
                
 
71
                public virtual void BeginTask (string name, int totalWork)
 
72
                {
 
73
                }
 
74
                
 
75
                public virtual void EndTask ()
 
76
                {
 
77
                }
 
78
                
 
79
                public virtual void BeginStepTask (string name, int totalWork, int stepSize)
 
80
                {
 
81
                }
 
82
                
 
83
                public virtual void Step (int work)
 
84
                {
 
85
                }
 
86
                
 
87
                public virtual TextWriter Log {
 
88
                        get { return TextWriter.Null; }
 
89
                }
 
90
                
 
91
                public virtual void ReportSuccess (string message)
 
92
                {
 
93
                        if (messages == null)
 
94
                                messages = new ArrayList ();
 
95
                        messages.Add (message);
 
96
                }
 
97
                
 
98
                public virtual void ReportWarning (string message)
 
99
                {
 
100
                        if (warnings == null)
 
101
                                warnings = new ArrayList ();
 
102
                        messages.Add (message);
 
103
                }
 
104
                
 
105
                public virtual void ReportError (string message, Exception ex)
 
106
                {
 
107
                        if (errors == null)
 
108
                                errors = new ArrayList ();
 
109
                                
 
110
                        if (message == null && ex != null)
 
111
                                message = ex.Message;
 
112
                        else if (message != null && ex != null) {
 
113
                                if (!message.EndsWith (".")) message += ".";
 
114
                                message += " " + ex.Message;
 
115
                        }
 
116
                        
 
117
                        errors.Add (new ProgressError (message, ex));
 
118
                }
 
119
                
 
120
                public bool IsCancelRequested {
 
121
                        get { return canceled; }
 
122
                }
 
123
                
 
124
                public void Cancel ()
 
125
                {
 
126
                        canceled = true;
 
127
                }
 
128
                
 
129
                public virtual int LogLevel {
 
130
                        get { return 1; }
 
131
                }
 
132
                
 
133
                public virtual void Dispose ()
 
134
                {
 
135
                        lock (this) {
 
136
                                if (done) return;
 
137
                                done = true;
 
138
                        }
 
139
                        OnCompleted ();
 
140
                }
 
141
                
 
142
                protected virtual void OnCompleted ()
 
143
                {
 
144
                }
 
145
        }
 
146
        
 
147
        internal class ProgressError
 
148
        {
 
149
                Exception ex;
 
150
                string message;
 
151
                
 
152
                public ProgressError (string message, Exception ex)
 
153
                {
 
154
                        this.ex = ex;
 
155
                        this.message = message;
 
156
                }
 
157
                
 
158
                public string Message {
 
159
                        get { return message; }
 
160
                }
 
161
                
 
162
                public Exception Exception {
 
163
                        get { return ex; }              }
 
164
        }
 
165
}