Statistics
| Branch: | Revision:

root / trunk / Pithos.Client.WPF / Configuration / PithosSettings.cs @ 81c5c310

History | View | Annotate | Download (8.3 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

    
99
        public string IconsPath
100
        {
101
            get { return _settings.IconPath; }
102
            set { _settings.IconPath = value; }
103
        }
104

    
105
        public string UserName
106
        {
107
            get { return _settings.UserName; }
108
            set { _settings.UserName = value; }
109
        }
110

    
111
        public string ApiKey
112
        {
113
            get { return _settings.ApiKey; }
114
            set { _settings.ApiKey = value; }
115
        }
116

    
117
        public AccountsCollection Accounts
118
        {
119
            get { return _settings.Accounts ?? (_settings.Accounts = new AccountsCollection()); }
120
            set { _settings.Accounts = value; }
121
        }
122

    
123
        public string ProxyServer
124
        {
125
            get { return _settings.ProxyServer; }
126
            set { _settings.ProxyServer = value; }
127
        }
128

    
129
        public int ProxyPort
130
        {
131
            get { return _settings.ProxyPort; }
132
            set { _settings.ProxyPort = value; }
133
        }
134

    
135
        public string ProxyUsername
136
        {
137
            get { return _settings.ProxyUsername; }
138
            set { _settings.ProxyUsername = value; }
139
        }
140

    
141

    
142
        public string ProxyPassword
143
        {
144
            get { return _settings.ProxyPassword; }
145
            set { _settings.ProxyPassword = value; }
146
        }
147

    
148
        public string ProxyDomain
149
        {
150
            get { return _settings.ProxyDomain; }
151
            set { _settings.ProxyDomain = value; }
152
        }
153

    
154
        public bool ProxyAuthentication
155
        {
156

    
157
            get { return _settings.ProxyAuthentication; }
158
            set { _settings.ProxyAuthentication = value; }
159
        }
160

    
161
        
162
        
163
        public bool ExtensionsActivated
164
        {
165

    
166
            get { return _settings.ExtensionsActivated; }
167
            set { _settings.ExtensionsActivated = value; }
168
        }
169

    
170
        public bool ShowDesktopNotifications
171
        {
172
            get { return _settings.ShowDesktopNotifications; }
173
            set { _settings.ShowDesktopNotifications = value; }
174
        }
175

    
176

    
177
        public int PollingInterval
178
        {
179
            get { return _settings.PollingInterval; }
180
            set
181
            {
182
                if (value <= 0)
183
                    throw new ArgumentOutOfRangeException();
184
                _settings.PollingInterval = value;
185
            }
186
        }
187

    
188
        public TimeSpan StartupDelay
189
        {
190
            get { return _settings.StartupDelay; }
191
            set
192
            {
193
                if (value < TimeSpan.Zero)
194
                    throw new ArgumentOutOfRangeException();
195
                _settings.StartupDelay = value;
196
            }
197
        }
198

    
199

    
200
        public bool StartOnSystemStartup
201
        {
202
            get { return _settings.StartOnSystemStartup; }
203
            set
204
            {
205
                _settings.StartOnSystemStartup = value;
206
            }
207
        }
208

    
209
        public byte HashingParallelism
210
        {
211
            get { return _settings.HashingParallelism; }
212
            set { _settings.HashingParallelism = value; }
213
        }
214

    
215
        public string UpdateUrl
216
        {
217
            get { return _settings.UpdateUrl; }
218
        }
219

    
220
        public bool UpdateDiagnostics
221
        {
222
            get { return _settings.UpdateDiagnostics; }
223
        }
224

    
225
        public TimeSpan UpdateCheckInterval
226
        {
227
            get { return _settings.UpdateCheckInterval; }
228
        }
229

    
230
        public TimeSpan FileIdleTimeout
231
        {
232
            get { return _settings.FileIdleTimeout; }
233
        }
234

    
235
        public bool UpdateForceCheck
236
        {
237
            get { return _settings.UpdateForceCheck; }
238
        }
239

    
240
        public bool DebugLoggingEnabled
241
        {
242
            get { return _settings.DebugLoggingEnabled; }
243
            set
244
            {
245
                _settings.DebugLoggingEnabled = value;
246

    
247
                SetDebugLevel();
248
            }
249
        }
250

    
251
        private static void SetDebugLevel()
252
        {
253
            var loggerRepository = (Hierarchy) log4net.LogManager.GetRepository();
254

    
255
            var appenders = loggerRepository.GetAppenders();
256

    
257
            var debugAppender = appenders.OfType<RollingFileAppender>()
258
                .FirstOrDefault(a => a.Name == "DebugFileAppender");
259
            if (debugAppender != null)
260
            {
261
                var pithosDataPath = PithosDataPath;
262
                debugAppender.File = Path.Combine(pithosDataPath, "debuglog.xml");
263
                debugAppender.Threshold = !Settings.Default.DebugLoggingEnabled ? Level.Off : Level.All;
264
                debugAppender.ActivateOptions();
265
            }
266
        }
267

    
268
        public static string PithosDataPath
269
        {
270
            get
271
            {
272
                var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
273
                var pithosDataPath = Path.Combine(appDataPath, "GRNET\\PITHOS");
274
                return pithosDataPath;
275
            }
276
        }
277

    
278
        public void Save()
279
        {
280
            _settings.Save();
281
            Proxy.SetFromSettings(this);
282
        }
283

    
284
        public void Reload()
285
        {
286
            _settings.Reload();
287
        }
288

    
289
        public void Reset()
290
        {
291
            _settings.Reset();
292
            _settings.Save();
293
        }
294
    }
295
}