X-Git-Url: https://code.grnet.gr/git/pithos-ms-client/blobdiff_plain/6f03d6e1b8b682db85b9515d423a57ad89d1fd93..cfb091032c1ea51d109dccf68322ce2ee63eaab5:/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs?ds=inline diff --git a/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs b/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs index 426fc36..2036ac8 100644 --- a/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs +++ b/trunk/Pithos.Client.WPF/Configuration/PithosSettings.cs @@ -1,290 +1,313 @@ -#region -/* ----------------------------------------------------------------------- - * - * - * Copyright 2011-2012 GRNET S.A. All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * - * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and - * documentation are those of the authors and should not be - * interpreted as representing official policies, either expressed - * or implied, of GRNET S.A. - * - * ----------------------------------------------------------------------- - */ -#endregion -using System.ComponentModel.Composition; -using System.Diagnostics; -using System.IO; -using System.Linq; -using Pithos.Client.WPF.Properties; -using Pithos.Interfaces; -using log4net.Appender; -using log4net.Core; -using log4net.Repository.Hierarchy; - -namespace Pithos.Client.WPF.Configuration -{ - using System; - - [Export(typeof(IPithosSettings))] - [Export] - public class PithosSettings : IPithosSettings - { - private readonly Settings _settings = Settings.Default; - - public PithosSettings() - { - //Settings should already be upgraded by the time we reach this point - Debug.Assert(!_settings.MustUpgrade); - //_settings.Upgrade(); - } - - public bool UseDefaultProxy - { - get { return _settings.UseDefaultProxy; } - set { _settings.UseDefaultProxy = value; } - } - - public bool UseManualProxy - { - get { return _settings.UseManualProxy; } - set { _settings.UseManualProxy = value; } - } - - public bool UseNoProxy - { - get { return _settings.UseNoProxy; } - set { _settings.UseNoProxy = value; } - } - - public string PithosPath - { - get { return _settings.PithosPath; } - set { _settings.PithosPath = value; } - } - - /* public string PithosSite - { - get { return _settings.PithosSite; } - }*/ - - public string PithosLoginUrl - { - get { return _settings.PithosLoginUrl; } - } - - public string IconsPath - { - get { return _settings.IconPath; } - set { _settings.IconPath = value; } - } - - public string UserName - { - get { return _settings.UserName; } - set { _settings.UserName = value; } - } - - public string ApiKey - { - get { return _settings.ApiKey; } - set { _settings.ApiKey = value; } - } - - public AccountsCollection Accounts - { - get { return _settings.Accounts ?? (_settings.Accounts = new AccountsCollection()); } - set { _settings.Accounts = value; } - } - - public string ProxyServer - { - get { return _settings.ProxyServer; } - set { _settings.ProxyServer = value; } - } - - public int ProxyPort - { - get { return _settings.ProxyPort; } - set { _settings.ProxyPort = value; } - } - - public string ProxyUsername - { - get { return _settings.ProxyUsername; } - set { _settings.ProxyUsername = value; } - } - - - public string ProxyPassword - { - get { return _settings.ProxyPassword; } - set { _settings.ProxyPassword = value; } - } - - public string ProxyDomain - { - get { return _settings.ProxyDomain; } - set { _settings.ProxyDomain = value; } - } - - public bool ProxyAuthentication - { - - get { return _settings.ProxyAuthentication; } - set { _settings.ProxyAuthentication = value; } - } - - - - public bool ExtensionsActivated - { - - get { return _settings.ExtensionsActivated; } - set { _settings.ExtensionsActivated = value; } - } - - public bool ShowDesktopNotifications - { - get { return _settings.ShowDesktopNotifications; } - set { _settings.ShowDesktopNotifications = value; } - } - - - public int PollingInterval - { - get { return _settings.PollingInterval; } - set - { - if (value <= 0) - throw new ArgumentOutOfRangeException(); - _settings.PollingInterval = value; - } - } - - public TimeSpan StartupDelay - { - get { return _settings.StartupDelay; } - set - { - if (value < TimeSpan.Zero) - throw new ArgumentOutOfRangeException(); - _settings.StartupDelay = value; - } - } - - - public bool StartOnSystemStartup - { - get { return _settings.StartOnSystemStartup; } - set - { - _settings.StartOnSystemStartup = value; - } - } - - public byte HashingParallelism - { - get { return _settings.HashingParallelism; } - set { _settings.HashingParallelism = value; } - } - - public string UpdateUrl - { - get { return _settings.UpdateUrl; } - } - - public bool UpdateDiagnostics - { - get { return _settings.UpdateDiagnostics; } - } - - public TimeSpan UpdateCheckInterval - { - get { return _settings.UpdateCheckInterval; } - } - - public TimeSpan FileIdleTimeout - { - get { return _settings.FileIdleTimeout; } - } - - public bool UpdateForceCheck - { - get { return _settings.UpdateForceCheck; } - } - - public bool DebugLoggingEnabled - { - get { return _settings.DebugLoggingEnabled; } - set - { - _settings.DebugLoggingEnabled = value; - - SetDebugLevel(); - } - } - - private static void SetDebugLevel() - { - var loggerRepository = (Hierarchy) log4net.LogManager.GetRepository(); - - var appenders = loggerRepository.GetAppenders(); - - var debugAppender = appenders.OfType() - .FirstOrDefault(a => a.Name == "DebugFileAppender"); - if (debugAppender != null) - { - var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - var pithosDataPath = Path.Combine(appDataPath, "GRNET"); - debugAppender.File = Path.Combine(pithosDataPath, "debuglog.xml"); - debugAppender.Threshold = !Settings.Default.DebugLoggingEnabled ? Level.Off : Level.All; - debugAppender.ActivateOptions(); - } - } - - public void Save() - { - _settings.Save(); - Proxy.SetFromSettings(this); - } - - public void Reload() - { - _settings.Reload(); - } - - public void Reset() - { - _settings.Reset(); - _settings.Save(); - } - } -} +#region +/* ----------------------------------------------------------------------- + * + * + * Copyright 2011-2012 GRNET S.A. All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * + * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and + * documentation are those of the authors and should not be + * interpreted as representing official policies, either expressed + * or implied, of GRNET S.A. + * + * ----------------------------------------------------------------------- + */ +#endregion +using System.ComponentModel.Composition; +using System.Diagnostics; +using System.IO; +using System.Linq; +using Pithos.Client.WPF.Properties; +using Pithos.Interfaces; +using log4net.Appender; +using log4net.Core; +using log4net.Repository.Hierarchy; + +namespace Pithos.Client.WPF.Configuration +{ + using System; + + [Export(typeof(IPithosSettings))] + [Export] + public class PithosSettings : IPithosSettings + { + private readonly Settings _settings = Settings.Default; + + public PithosSettings() + { + //Settings should already be upgraded by the time we reach this point + Debug.Assert(!_settings.MustUpgrade); + //_settings.Upgrade(); + } + + public bool UseDefaultProxy + { + get { return _settings.UseDefaultProxy; } + set { _settings.UseDefaultProxy = value; } + } + + public bool UseManualProxy + { + get { return _settings.UseManualProxy; } + set { _settings.UseManualProxy = value; } + } + + public bool UseNoProxy + { + get { return _settings.UseNoProxy; } + set { _settings.UseNoProxy = value; } + } + + public string PithosPath + { + get { return _settings.PithosPath; } + set { _settings.PithosPath = value; } + } + + /* public string PithosSite + { + get { return _settings.PithosSite; } + }*/ + + + public string IconsPath + { + get { return _settings.IconPath; } + set { _settings.IconPath = value; } + } + + public string UserName + { + get { return _settings.UserName; } + set { _settings.UserName = value; } + } + + public string ApiKey + { + get { return _settings.ApiKey; } + set { _settings.ApiKey = value; } + } + + public AccountsCollection Accounts + { + get { return _settings.Accounts ?? (_settings.Accounts = new AccountsCollection()); } + set { _settings.Accounts = value; } + } + + public string ProxyServer + { + get { return _settings.ProxyServer; } + set { _settings.ProxyServer = value; } + } + + public int ProxyPort + { + get { return _settings.ProxyPort; } + set { _settings.ProxyPort = value; } + } + + public string ProxyUsername + { + get { return _settings.ProxyUsername; } + set { _settings.ProxyUsername = value; } + } + + + public string ProxyPassword + { + get { return _settings.ProxyPassword; } + set { _settings.ProxyPassword = value; } + } + + public string ProxyDomain + { + get { return _settings.ProxyDomain; } + set { _settings.ProxyDomain = value; } + } + + public bool ProxyAuthentication + { + + get { return _settings.ProxyAuthentication; } + set { _settings.ProxyAuthentication = value; } + } + + + + public bool ExtensionsActivated + { + + get { return _settings.ExtensionsActivated; } + set { _settings.ExtensionsActivated = value; } + } + + public bool ShowDesktopNotifications + { + get { return _settings.ShowDesktopNotifications; } + set { _settings.ShowDesktopNotifications = value; } + } + + + public int PollingInterval + { + get { return _settings.PollingInterval; } + set + { + if (value <= 0) + throw new ArgumentOutOfRangeException(); + _settings.PollingInterval = value; + } + } + + public TimeSpan StartupDelay + { + get { return _settings.StartupDelay; } + set + { + if (value < TimeSpan.Zero) + throw new ArgumentOutOfRangeException(); + _settings.StartupDelay = value; + } + } + + + public bool StartOnSystemStartup + { + get { return _settings.StartOnSystemStartup; } + set + { + _settings.StartOnSystemStartup = value; + } + } + + public byte HashingParallelism + { + get { return _settings.HashingParallelism; } + set { _settings.HashingParallelism = value; } + } + + public string UpdateUrl + { + get { return _settings.UpdateUrl; } + } + + public bool UpdateDiagnostics + { + get { return _settings.UpdateDiagnostics; } + } + + public TimeSpan UpdateCheckInterval + { + get { return _settings.UpdateCheckInterval; } + } + + public TimeSpan FileIdleTimeout + { + get { return _settings.FileIdleTimeout; } + } + + public bool UpdateForceCheck + { + get { return _settings.UpdateForceCheck; } + } + + public bool DebugLoggingEnabled + { + get { return _settings.DebugLoggingEnabled; } + set + { + _settings.DebugLoggingEnabled = value; + + SetDebugLevel(); + } + } + + public bool IgnoreCertificateErrors + { + get { return _settings.IgnoreCertificateErrors; } + set + { + _settings.IgnoreCertificateErrors = value; + + } + } + + private static void SetDebugLevel() + { + var loggerRepository = (Hierarchy) log4net.LogManager.GetRepository(); + + var appenders = loggerRepository.GetAppenders(); + + var debugAppender = appenders.OfType() + .FirstOrDefault(a => a.Name == "DebugFileAppender"); + if (debugAppender != null) + { + var pithosDataPath = PithosDataPath; + debugAppender.File = Path.Combine(pithosDataPath, "debuglog.xml"); + debugAppender.Threshold = !Settings.Default.DebugLoggingEnabled ? Level.Off : Level.All; + debugAppender.ActivateOptions(); + } + } + + public static string PithosDataPath + { + get + { + var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + var pithosDataPath = Path.Combine(appDataPath, "GRNET\\PITHOS"); + return pithosDataPath; + } + } + + public void Save() + { + LockedSave(); + Proxy.SetFromSettings(this); + } + + private void LockedSave() + { + lock (this) + { + _settings.Save(); + } + } + + public void Reload() + { + _settings.Reload(); + } + + public void Reset() + { + _settings.Reset(); + LockedSave(); + } + } +}