Added fixes for v.0.7.20311
[pithos-ms-client] / trunk / Pithos.Client.WPF / Configuration / PithosSettings.cs
index c91d3d0..01866a4 100644 (file)
@@ -1,52 +1,57 @@
-// -----------------------------------------------------------------------
-// <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>
-// -----------------------------------------------------------------------
-
+#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]
@@ -56,7 +61,9 @@ namespace Pithos.Client.WPF.Configuration
 
         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
@@ -88,10 +95,6 @@ namespace Pithos.Client.WPF.Configuration
             get { return _settings.PithosSite; }
         }*/
 
-        public string PithosLoginUrl
-        {
-            get { return _settings.PithosLoginUrl; }
-        }
 
         public string IconsPath
         {
@@ -113,12 +116,7 @@ namespace Pithos.Client.WPF.Configuration
 
         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; }
         }
 
@@ -187,6 +185,18 @@ namespace Pithos.Client.WPF.Configuration
             }
         }
 
+        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; }
@@ -202,6 +212,69 @@ namespace Pithos.Client.WPF.Configuration
             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<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 static string PithosDataPath
+        {
+            get
+            {
+                var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
+                var pithosDataPath = Path.Combine(appDataPath, "GRNET\\PITHOS");
+                return pithosDataPath;
+            }
+        }
+
         public void Save()
         {
             _settings.Save();
@@ -212,5 +285,11 @@ namespace Pithos.Client.WPF.Configuration
         {
             _settings.Reload();
         }
+
+        public void Reset()
+        {
+            _settings.Reset();
+            _settings.Save();
+        }
     }
 }