diff options
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProgressMonitor.cs')
-rw-r--r-- | main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProgressMonitor.cs | 131 |
1 files changed, 29 insertions, 102 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProgressMonitor.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProgressMonitor.cs index 74076d6d47..6b73844a49 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProgressMonitor.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProgressMonitor.cs @@ -1,4 +1,4 @@ -//
+//
// PackageManagementProgressMonitor.cs
//
// Author:
@@ -26,21 +26,21 @@ using System;
using System.Collections.Generic;
+using System.IO;
+using System.Linq;
using MonoDevelop.Core;
using MonoDevelop.Core.Execution;
-using MonoDevelop.Core.ProgressMonitoring;
-using System.IO;
+using System.Threading;
namespace MonoDevelop.PackageManagement
{
- public class PackageManagementProgressMonitor : IProgressMonitor, IAsyncOperation
+ public class PackageManagementProgressMonitor : ProgressMonitor
{
- IProgressMonitor consoleMonitor;
- IProgressMonitor statusMonitor;
- List<string> warnings = new List<string> ();
- List<string> errors = new List<string> ();
+ ProgressMonitor consoleMonitor;
+ CancellationTokenRegistration consoleMonitorReg;
+ CancellationTokenRegistration statusMonitorReg;
- public IProgressMonitor ConsoleMonitor {
+ public ProgressMonitor ConsoleMonitor {
get { return consoleMonitor; }
}
@@ -48,146 +48,73 @@ namespace MonoDevelop.PackageManagement get { return (IConsole)this.consoleMonitor; }
}
- public PackageManagementProgressMonitor (IProgressMonitor consoleMonitor, IProgressMonitor statusMonitor)
+ public PackageManagementProgressMonitor (ProgressMonitor consoleMonitor, ProgressMonitor statusMonitor)
{
+ AddSlaveMonitor (statusMonitor);
this.consoleMonitor = consoleMonitor;
- this.statusMonitor = statusMonitor;
-
- consoleMonitor.CancelRequested += OnCancelRequested;
- statusMonitor.CancelRequested += OnCancelRequested;
- }
-
- public void BeginTask (string name, int totalWork)
- {
- statusMonitor.BeginTask (name, totalWork);
- }
-
- public void BeginStepTask (string name, int totalWork, int stepSize)
- {
- statusMonitor.BeginStepTask (name, totalWork, stepSize);
- }
- public void EndTask ()
- {
- statusMonitor.EndTask ();
+ consoleMonitorReg = consoleMonitor.CancellationToken.Register (OnCancelRequested);
+ statusMonitorReg = statusMonitor.CancellationToken.Register (OnCancelRequested);
}
- public void Step (int work)
+ protected override void OnWriteLog (string message)
{
- statusMonitor.Step (work);
+ consoleMonitor.Log.Write (message);
}
- public TextWriter Log
+ protected override void OnWriteErrorLog (string message)
{
- get { return consoleMonitor.Log; }
+ consoleMonitor.ErrorLog.Write (message);
}
- public void ReportSuccess (string message)
+ public override void Dispose ()
{
- consoleMonitor.ReportSuccess (message);
- statusMonitor.ReportSuccess (message);
- }
+ consoleMonitorReg.Dispose ();
+ statusMonitorReg.Dispose ();
- public void ReportWarning (string message)
- {
- warnings.Add (message);
- statusMonitor.ReportWarning (message);
- }
-
- public void ReportError (string message, Exception ex)
- {
- errors.Add (message);
- statusMonitor.ReportError (message, ex);
- }
-
- public void Dispose ()
- {
- consoleMonitor.CancelRequested -= OnCancelRequested;
- statusMonitor.CancelRequested -= OnCancelRequested;
+ foreach (var m in SuccessMessages)
+ consoleMonitor.ReportSuccess (m);
// Do not report warnings if there are errors otherwise the warnings will
// appear at the end of the Package Console and hide the error which
// should be the last line of text visible to the user.
- if (errors.Count == 0) {
+ if (Errors.Length == 0) {
ReportAllWarningsButLastToConsole ();
}
ReportAllErrorsButLastToConsole ();
consoleMonitor.Dispose ();
- statusMonitor.Dispose ();
}
void ReportAllWarningsButLastToConsole ()
{
+ var warnings = Warnings.Distinct ().ToList ();
RemoveLastItem (warnings);
warnings.ForEach (warning => consoleMonitor.ReportWarning (warning));
}
void ReportAllErrorsButLastToConsole ()
{
+ var errors = Errors.ToList ();
RemoveLastItem (errors);
- errors.ForEach (error => consoleMonitor.ReportError (error, null));
+ errors.ForEach (error => consoleMonitor.ReportError (error.Message, error.Exception));
}
- static void RemoveLastItem (List<string> items)
+ static void RemoveLastItem<T> (List<T> items)
{
if (items.Count > 0) {
items.RemoveAt (items.Count - 1);
}
}
- public bool IsCancelRequested
- {
- get {
- return consoleMonitor.IsCancelRequested || statusMonitor.IsCancelRequested;
- }
- }
-
public object SyncRoot {
get { return this; }
}
- void OnCancelRequested (IProgressMonitor sender)
- {
- AsyncOperation.Cancel ();
- }
-
- public IAsyncOperation AsyncOperation
- {
- get { return this; }
- }
-
- void IAsyncOperation.Cancel ()
- {
- consoleMonitor.AsyncOperation.Cancel ();
- }
-
- void IAsyncOperation.WaitForCompleted ()
+ void OnCancelRequested ()
{
- consoleMonitor.AsyncOperation.WaitForCompleted ();
- }
-
- public bool IsCompleted {
- get { return consoleMonitor.AsyncOperation.IsCompleted; }
- }
-
- bool IAsyncOperation.Success {
- get { return consoleMonitor.AsyncOperation.Success; }
- }
-
- bool IAsyncOperation.SuccessWithWarnings {
- get { return consoleMonitor.AsyncOperation.SuccessWithWarnings; }
- }
-
- public event MonitorHandler CancelRequested {
- add { consoleMonitor.CancelRequested += value; }
- remove { consoleMonitor.CancelRequested -= value; }
- }
-
- public event OperationHandler Completed {
- add { consoleMonitor.AsyncOperation.Completed += value; }
- remove { consoleMonitor.AsyncOperation.Completed -= value; }
+ CancellationTokenSource.Cancel ();
}
}
}
|