2 /* -----------------------------------------------------------------------
3 * <copyright file="PithosSettings.cs" company="GRNet">
5 * Copyright 2011-2012 GRNET S.A. All rights reserved.
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
11 * 1. Redistributions of source code must retain the above
12 * copyright notice, this list of conditions and the following
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.
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.
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.
39 * -----------------------------------------------------------------------
42 using System.ComponentModel.Composition;
43 using System.Diagnostics;
46 using Pithos.Client.WPF.Properties;
47 using Pithos.Interfaces;
48 using log4net.Appender;
50 using log4net.Repository.Hierarchy;
52 namespace Pithos.Client.WPF.Configuration
56 [Export(typeof(IPithosSettings))]
58 public class PithosSettings : IPithosSettings
60 private readonly Settings _settings = Settings.Default;
62 public PithosSettings()
64 //Settings should already be upgraded by the time we reach this point
65 Debug.Assert(!_settings.MustUpgrade);
66 //_settings.Upgrade();
69 public bool UseDefaultProxy
71 get { return _settings.UseDefaultProxy; }
72 set { _settings.UseDefaultProxy = value; }
75 public bool UseManualProxy
77 get { return _settings.UseManualProxy; }
78 set { _settings.UseManualProxy = value; }
81 public bool UseNoProxy
83 get { return _settings.UseNoProxy; }
84 set { _settings.UseNoProxy = value; }
87 public string PithosPath
89 get { return _settings.PithosPath; }
90 set { _settings.PithosPath = value; }
93 /* public string PithosSite
95 get { return _settings.PithosSite; }
99 public string IconsPath
101 get { return _settings.IconPath; }
102 set { _settings.IconPath = value; }
105 public string UserName
107 get { return _settings.UserName; }
108 set { _settings.UserName = value; }
113 get { return _settings.ApiKey; }
114 set { _settings.ApiKey = value; }
117 public AccountsCollection Accounts
119 get { return _settings.Accounts ?? (_settings.Accounts = new AccountsCollection()); }
120 set { _settings.Accounts = value; }
123 public string ProxyServer
125 get { return _settings.ProxyServer; }
126 set { _settings.ProxyServer = value; }
131 get { return _settings.ProxyPort; }
132 set { _settings.ProxyPort = value; }
135 public string ProxyUsername
137 get { return _settings.ProxyUsername; }
138 set { _settings.ProxyUsername = value; }
142 public string ProxyPassword
144 get { return _settings.ProxyPassword; }
145 set { _settings.ProxyPassword = value; }
148 public string ProxyDomain
150 get { return _settings.ProxyDomain; }
151 set { _settings.ProxyDomain = value; }
154 public bool ProxyAuthentication
157 get { return _settings.ProxyAuthentication; }
158 set { _settings.ProxyAuthentication = value; }
163 public bool ExtensionsActivated
166 get { return _settings.ExtensionsActivated; }
167 set { _settings.ExtensionsActivated = value; }
170 public bool ShowDesktopNotifications
172 get { return _settings.ShowDesktopNotifications; }
173 set { _settings.ShowDesktopNotifications = value; }
177 public int PollingInterval
179 get { return _settings.PollingInterval; }
183 throw new ArgumentOutOfRangeException();
184 _settings.PollingInterval = value;
188 public TimeSpan StartupDelay
190 get { return _settings.StartupDelay; }
193 if (value < TimeSpan.Zero)
194 throw new ArgumentOutOfRangeException();
195 _settings.StartupDelay = value;
200 public bool StartOnSystemStartup
202 get { return _settings.StartOnSystemStartup; }
205 _settings.StartOnSystemStartup = value;
209 public byte HashingParallelism
211 get { return _settings.HashingParallelism; }
212 set { _settings.HashingParallelism = value; }
215 public string UpdateUrl
217 get { return _settings.UpdateUrl; }
220 public bool UpdateDiagnostics
222 get { return _settings.UpdateDiagnostics; }
225 public TimeSpan UpdateCheckInterval
227 get { return _settings.UpdateCheckInterval; }
230 public TimeSpan FileIdleTimeout
232 get { return _settings.FileIdleTimeout; }
235 public bool UpdateForceCheck
237 get { return _settings.UpdateForceCheck; }
240 public bool DebugLoggingEnabled
242 get { return _settings.DebugLoggingEnabled; }
245 _settings.DebugLoggingEnabled = value;
251 public bool IgnoreCertificateErrors
253 get { return _settings.IgnoreCertificateErrors; }
256 _settings.IgnoreCertificateErrors = value;
261 private static void SetDebugLevel()
263 var loggerRepository = (Hierarchy) log4net.LogManager.GetRepository();
265 var appenders = loggerRepository.GetAppenders();
267 var debugAppender = appenders.OfType<RollingFileAppender>()
268 .FirstOrDefault(a => a.Name == "DebugFileAppender");
269 if (debugAppender != null)
271 var pithosDataPath = PithosDataPath;
272 debugAppender.File = Path.Combine(pithosDataPath, "debuglog.xml");
273 debugAppender.Threshold = !Settings.Default.DebugLoggingEnabled ? Level.Off : Level.All;
274 debugAppender.ActivateOptions();
278 public static string PithosDataPath
282 var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
283 var pithosDataPath = Path.Combine(appDataPath, "GRNET\\PITHOS");
284 return pithosDataPath;
291 Proxy.SetFromSettings(this);