-// -----------------------------------------------------------------------
-// <copyright file="PithosSettings.cs" company="GRNET">
-// Copyright 2011 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.
-// </copyright>
-// -----------------------------------------------------------------------
-
+#region
+/* -----------------------------------------------------------------------
+ * <copyright file="PithosSettings.cs" company="GRNet">
+ *
+ * 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.
+ * </copyright>
+ * -----------------------------------------------------------------------
+ */
+#endregion
using System.ComponentModel.Composition;
-using System.Configuration;
-using System.Dynamic;
+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;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
[Export(typeof(IPithosSettings))]
[Export]
public PithosSettings()
{
- _settings.Upgrade();
+ //Settings should already be upgraded by the time we reach this point
+ Debug.Assert(!_settings.MustUpgrade);
+ //_settings.Upgrade();
}
public bool UseDefaultProxy
get { return _settings.PithosSite; }
}*/
- public string PithosLoginUrl
- {
- get { return _settings.PithosLoginUrl; }
- }
public string IconsPath
{
public AccountsCollection Accounts
{
- get
- {
- if (_settings.Accounts==null)
- _settings.Accounts=new AccountsCollection();
- return _settings.Accounts;
- }
+ get { return _settings.Accounts ?? (_settings.Accounts = new AccountsCollection()); }
set { _settings.Accounts = value; }
}
set { _settings.ProxyPassword = value; }
}
+ public string ProxyDomain
+ {
+ get { return _settings.ProxyDomain; }
+ set { _settings.ProxyDomain = value; }
+ }
+
public bool ProxyAuthentication
{
get { return _settings.ShowDesktopNotifications; }
set { _settings.ShowDesktopNotifications = value; }
}
-/*
- public override IEnumerable<string> GetDynamicMemberNames()
+
+
+ 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
{
- return (from SettingsProperty property in _settings.Properties
- select property.Name);
+ get { return _settings.DebugLoggingEnabled; }
+ set
+ {
+ _settings.DebugLoggingEnabled = value;
+
+ SetDebugLevel();
+ }
}
+ private static void SetDebugLevel()
+ {
+ var loggerRepository = (Hierarchy) log4net.LogManager.GetRepository();
+
+ var appenders = loggerRepository.GetAppenders();
- private Lazy<ILookup<string, SettingsProperty>> _propertyNames = new Lazy<ILookup<string, SettingsProperty>>(
- () => (from SettingsProperty property in
- _settings.Properties
- select property).ToLookup(property => property.Name));
+ var debugAppender = appenders.OfType<RollingFileAppender>()
+ .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 override bool TryGetMember(GetMemberBinder binder, out object result)
+ public static string PithosDataPath
{
- result = null;
- if (!_propertyNames.Value.Contains(binder.Name))
- return false;
- result=_settings.Properties[binder.Name];
- return true;
+ get
+ {
+ var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
+ var pithosDataPath = Path.Combine(appDataPath, "GRNET\\PITHOS");
+ return pithosDataPath;
+ }
}
-*/
public void Save()
{
_settings.Save();
+ Proxy.SetFromSettings(this);
}
public void Reload()
{
_settings.Reload();
}
+
+ public void Reset()
+ {
+ _settings.Reset();
+ _settings.Save();
+ }
}
}