1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
// Copyright (C) 2015, The Duplicati Team
// http://www.duplicati.com, info@duplicati.com
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections.Generic;
using Duplicati.Library.Main;
namespace Duplicati.CommandLine
{
public class ConsoleOutput : Library.Main.IMessageSink
{
private object m_lock = new object();
public bool QuietConsole { get; private set; }
public bool VerboseOutput { get; private set; }
public bool VerboseErrors { get; private set; }
public ConsoleOutput(Dictionary<string, string> options)
{
this.QuietConsole = Library.Utility.Utility.ParseBoolOption(options, "quiet-console");
this.VerboseOutput = Library.Utility.Utility.ParseBoolOption(options, "verbose");
this.VerboseErrors = Library.Utility.Utility.ParseBoolOption(options, "debug-output");
}
#region IMessageSink implementation
public IBackendProgress BackendProgress { get; set; }
private IOperationProgress m_operationProgress;
public IOperationProgress OperationProgress
{
get { return m_operationProgress; }
set
{
if (m_operationProgress != null)
m_operationProgress.PhaseChanged -= InvokePhaseChanged;
m_operationProgress = value;
if (value != null)
m_operationProgress.PhaseChanged += InvokePhaseChanged;
}
}
private void InvokePhaseChanged(OperationPhase p1, OperationPhase p2)
{
if (PhaseChanged != null)
PhaseChanged(p1, p2);
}
public event PhaseChangedDelegate PhaseChanged;
public void BackendEvent(BackendActionType action, BackendEventType type, string path, long size)
{
lock(m_lock)
if (type == BackendEventType.Started)
{
if (action == BackendActionType.Put)
Console.WriteLine(" Uploading file ({0}) ...", Library.Utility.Utility.FormatSizeString(size));
else if (action == BackendActionType.Get)
Console.WriteLine(" Downloading file ({0}) ...", size < 0 ? "unknown" : Library.Utility.Utility.FormatSizeString(size));
else if (action == BackendActionType.List)
Console.WriteLine(" Listing remote folder ...");
else if (action == BackendActionType.CreateFolder)
Console.WriteLine(" Creating remote folder ...");
else if (action == BackendActionType.Delete)
Console.WriteLine(" Deleting file {0}{1} ...", path, size < 0 ? "" : (" (" + Library.Utility.Utility.FormatSizeString(size) + ")"));
}
}
public void VerboseEvent(string message, object[] args)
{
if (VerboseOutput)
lock(m_lock)
Console.WriteLine(message, args);
}
public void MessageEvent(string message)
{
if (!QuietConsole)
lock(m_lock)
Console.WriteLine(message);
}
public void RetryEvent(string message, Exception ex)
{
if (!QuietConsole)
lock(m_lock)
Console.WriteLine(ex == null ? message : string.Format("{0} => {1}", message, VerboseErrors ? ex.ToString() : ex.Message));
}
public void WarningEvent(string message, Exception ex)
{
if (!QuietConsole)
lock(m_lock)
Console.WriteLine(ex == null ? message : string.Format("{0} => {1}", message, VerboseErrors ? ex.ToString() : ex.Message));
}
public void ErrorEvent(string message, Exception ex)
{
if (!QuietConsole)
lock(m_lock)
Console.WriteLine(ex == null ? message : string.Format("{0} => {1}", message, VerboseErrors ? ex.ToString() : ex.Message));
}
public void DryrunEvent(string message)
{
lock(m_lock)
Console.WriteLine(string.Format("[Dryrun]: {0}", message));
}
#endregion
}
}
|