Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / Configuration / PithosSettings.cs @ 6f03d6e1

History | View | Annotate | Download (8.2 kB)

1
#region
2
/* -----------------------------------------------------------------------
3
 * <copyright file="PithosSettings.cs" company="GRNet">
4
 * 
5
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or
8
 * without modification, are permitted provided that the following
9
 * conditions are met:
10
 *
11
 *   1. Redistributions of source code must retain the above
12
 *      copyright notice, this list of conditions and the following
13
 *      disclaimer.
14
 *
15
 *   2. Redistributions in binary form must reproduce the above
16
 *      copyright notice, this list of conditions and the following
17
 *      disclaimer in the documentation and/or other materials
18
 *      provided with the distribution.
19
 *
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
22
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 * POSSIBILITY OF SUCH DAMAGE.
33
 *
34
 * The views and conclusions contained in the software and
35
 * documentation are those of the authors and should not be
36
 * interpreted as representing official policies, either expressed
37
 * or implied, of GRNET S.A.
38
 * </copyright>
39
 * -----------------------------------------------------------------------
40
 */
41
#endregion
42
using System.ComponentModel.Composition;
43
using System.Diagnostics;
44
using System.IO;
45
using System.Linq;
46
using Pithos.Client.WPF.Properties;
47
using Pithos.Interfaces;
48
using log4net.Appender;
49
using log4net.Core;
50
using log4net.Repository.Hierarchy;
51

    
52
namespace Pithos.Client.WPF.Configuration
53
{
54
    using System;
55

    
56
    [Export(typeof(IPithosSettings))]
57
    [Export]
58
    public class PithosSettings :  IPithosSettings
59
    {
60
        private readonly Settings _settings = Settings.Default;
61

    
62
        public PithosSettings()
63
        {
64
            //Settings should already be upgraded by the time we reach this point
65
            Debug.Assert(!_settings.MustUpgrade);
66
            //_settings.Upgrade();
67
        }
68

    
69
        public bool UseDefaultProxy
70
        {
71
            get { return _settings.UseDefaultProxy; }
72
            set { _settings.UseDefaultProxy = value; }
73
        }
74

    
75
        public bool UseManualProxy
76
        {
77
            get { return _settings.UseManualProxy; }
78
            set { _settings.UseManualProxy = value; }
79
        }
80

    
81
        public bool UseNoProxy
82
        {
83
            get { return _settings.UseNoProxy; }
84
            set { _settings.UseNoProxy = value; }
85
        }
86

    
87
        public string PithosPath
88
        {
89
            get { return _settings.PithosPath; }
90
            set { _settings.PithosPath = value; }
91
        }
92

    
93
      /*  public string PithosSite
94
        {
95
            get { return _settings.PithosSite; }
96
        }*/
97

    
98
        public string PithosLoginUrl
99
        {
100
            get { return _settings.PithosLoginUrl; }
101
        }
102

    
103
        public string IconsPath
104
        {
105
            get { return _settings.IconPath; }
106
            set { _settings.IconPath = value; }
107
        }
108

    
109
        public string UserName
110
        {
111
            get { return _settings.UserName; }
112
            set { _settings.UserName = value; }
113
        }
114

    
115
        public string ApiKey
116
        {
117
            get { return _settings.ApiKey; }
118
            set { _settings.ApiKey = value; }
119
        }
120

    
121
        public AccountsCollection Accounts
122
        {
123
            get { return _settings.Accounts ?? (_settings.Accounts = new AccountsCollection()); }
124
            set { _settings.Accounts = value; }
125
        }
126

    
127
        public string ProxyServer
128
        {
129
            get { return _settings.ProxyServer; }
130
            set { _settings.ProxyServer = value; }
131
        }
132

    
133
        public int ProxyPort
134
        {
135
            get { return _settings.ProxyPort; }
136
            set { _settings.ProxyPort = value; }
137
        }
138

    
139
        public string ProxyUsername
140
        {
141
            get { return _settings.ProxyUsername; }
142
            set { _settings.ProxyUsername = value; }
143
        }
144

    
145

    
146
        public string ProxyPassword
147
        {
148
            get { return _settings.ProxyPassword; }
149
            set { _settings.ProxyPassword = value; }
150
        }
151

    
152
        public string ProxyDomain
153
        {
154
            get { return _settings.ProxyDomain; }
155
            set { _settings.ProxyDomain = value; }
156
        }
157

    
158
        public bool ProxyAuthentication
159
        {
160

    
161
            get { return _settings.ProxyAuthentication; }
162
            set { _settings.ProxyAuthentication = value; }
163
        }
164

    
165
        
166
        
167
        public bool ExtensionsActivated
168
        {
169

    
170
            get { return _settings.ExtensionsActivated; }
171
            set { _settings.ExtensionsActivated = value; }
172
        }
173

    
174
        public bool ShowDesktopNotifications
175
        {
176
            get { return _settings.ShowDesktopNotifications; }
177
            set { _settings.ShowDesktopNotifications = value; }
178
        }
179

    
180

    
181
        public int PollingInterval
182
        {
183
            get { return _settings.PollingInterval; }
184
            set
185
            {
186
                if (value <= 0)
187
                    throw new ArgumentOutOfRangeException();
188
                _settings.PollingInterval = value;
189
            }
190
        }
191

    
192
        public TimeSpan StartupDelay
193
        {
194
            get { return _settings.StartupDelay; }
195
            set
196
            {
197
                if (value < TimeSpan.Zero)
198
                    throw new ArgumentOutOfRangeException();
199
                _settings.StartupDelay = value;
200
            }
201
        }
202

    
203

    
204
        public bool StartOnSystemStartup
205
        {
206
            get { return _settings.StartOnSystemStartup; }
207
            set
208
            {
209
                _settings.StartOnSystemStartup = value;
210
            }
211
        }
212

    
213
        public byte HashingParallelism
214
        {
215
            get { return _settings.HashingParallelism; }
216
            set { _settings.HashingParallelism = value; }
217
        }
218

    
219
        public string UpdateUrl
220
        {
221
            get { return _settings.UpdateUrl; }
222
        }
223

    
224
        public bool UpdateDiagnostics
225
        {
226
            get { return _settings.UpdateDiagnostics; }
227
        }
228

    
229
        public TimeSpan UpdateCheckInterval
230
        {
231
            get { return _settings.UpdateCheckInterval; }
232
        }
233

    
234
        public TimeSpan FileIdleTimeout
235
        {
236
            get { return _settings.FileIdleTimeout; }
237
        }
238

    
239
        public bool UpdateForceCheck
240
        {
241
            get { return _settings.UpdateForceCheck; }
242
        }
243

    
244
        public bool DebugLoggingEnabled
245
        {
246
            get { return _settings.DebugLoggingEnabled; }
247
            set
248
            {
249
                _settings.DebugLoggingEnabled = value;
250

    
251
                SetDebugLevel();
252
            }
253
        }
254

    
255
        private static void SetDebugLevel()
256
        {
257
            var loggerRepository = (Hierarchy) log4net.LogManager.GetRepository();
258

    
259
            var appenders = loggerRepository.GetAppenders();
260

    
261
            var debugAppender = appenders.OfType<RollingFileAppender>()
262
                .FirstOrDefault(a => a.Name == "DebugFileAppender");
263
            if (debugAppender != null)
264
            {
265
                var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
266
                var pithosDataPath = Path.Combine(appDataPath, "GRNET");
267
                debugAppender.File = Path.Combine(pithosDataPath, "debuglog.xml");
268
                debugAppender.Threshold = !Settings.Default.DebugLoggingEnabled ? Level.Off : Level.All;
269
                debugAppender.ActivateOptions();
270
            }
271
        }
272

    
273
        public void Save()
274
        {
275
            _settings.Save();
276
            Proxy.SetFromSettings(this);
277
        }
278

    
279
        public void Reload()
280
        {
281
            _settings.Reload();
282
        }
283

    
284
        public void Reset()
285
        {
286
            _settings.Reset();
287
            _settings.Save();
288
        }
289
    }
290
}