Statistics
| Branch: | Revision:

root / trunk / Pithos.ShellExtensions / ShellSettings.cs @ 7e26c075

History | View | Annotate | Download (4 kB)

1
// -----------------------------------------------------------------------
2
// <copyright file="ShellSettings.cs" company="Microsoft">
3
// TODO: Update copyright text.
4
// </copyright>
5
// -----------------------------------------------------------------------
6

    
7
using System.ComponentModel.Composition;
8
using System.Diagnostics;
9
using System.ServiceModel;
10
using Microsoft.Win32;
11
using Pithos.Interfaces;
12

    
13
namespace Pithos.ShellExtensions
14
{
15
    using System;
16
    using System.Collections.Generic;
17
    using System.Linq;
18
    using System.Text;
19

    
20
    /// <summary>
21
    /// TODO: Update summary.
22
    /// </summary>
23
    [Export(typeof(IPithosSettings))]
24
    public class ShellSettings:IPithosSettings
25
    {
26
        private static readonly log4net.ILog Log = log4net.LogManager.GetLogger("Pithos.ShellSettings");
27

    
28
        private Lazy<IPithosSettings> _settings;
29
        public ShellSettings()
30
        {
31
            _settings = new Lazy<IPithosSettings>(LoadSettings);
32
        }
33

    
34
        public bool UseDefaultProxy
35
        {
36
            get { return _settings.Value.UseDefaultProxy; }
37
            set { _settings.Value.UseDefaultProxy = value; }
38
        }
39

    
40
        public bool UseManualProxy
41
        {
42
            get { return _settings.Value.UseManualProxy; }
43
            set { _settings.Value.UseManualProxy = value; }
44
        }
45

    
46
        public bool UseNoProxy
47
        {
48
            get { return _settings.Value.UseNoProxy; }
49
            set { _settings.Value.UseNoProxy = value; }
50
        }
51

    
52
        public string PithosPath
53
        {
54
            get { return _settings.Value.PithosPath; }
55
            set { _settings.Value.PithosPath = value; }
56
        }
57

    
58
        public string PithosSite
59
        {
60
            get { return _settings.Value.PithosSite; }
61
        }
62

    
63
        public string IconsPath
64
        {
65
            get { return _settings.Value.IconsPath; }
66
            set { _settings.Value.IconsPath = value; }
67
        }
68

    
69
        public string UserName
70
        {
71
            get { return _settings.Value.UserName; }
72
            set { _settings.Value.UserName = value; }
73
        }
74

    
75
        public string ApiKey
76
        {
77
            get { return _settings.Value.ApiKey; }
78
            set { _settings.Value.ApiKey = value; }
79
        }
80

    
81
        public AccountsCollection Accounts
82
        {
83
            get { return _settings.Value.Accounts; }
84
            set { _settings.Value.Accounts = value; }
85
        }
86

    
87
        public string ProxyServer
88
        {
89
            get { return _settings.Value.ProxyServer; }
90
            set { _settings.Value.ProxyServer = value; }
91
        }
92

    
93
        public int ProxyPort
94
        {
95
            get { return _settings.Value.ProxyPort; }
96
            set { _settings.Value.ProxyPort = value; }
97
        }
98

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

    
105

    
106
        public string ProxyPassword
107
        {
108
            get { return _settings.Value.ProxyPassword; }
109
            set { _settings.Value.ProxyPassword = value; }
110
        }
111

    
112
        public bool ProxyAuthentication
113
        {
114

    
115
            get { return _settings.Value.ProxyAuthentication; }
116
            set { _settings.Value.ProxyAuthentication = value; }
117
        }
118

    
119
        public bool ExtensionsActivated
120
        {
121

    
122
            get { return _settings.Value.ExtensionsActivated; }
123
            set { _settings.Value.ExtensionsActivated = value; }
124
        }
125
        public void Save()
126
        {
127
           
128
        }
129

    
130
        public void Reload()
131
        {
132
            _settings=new Lazy<IPithosSettings>(LoadSettings);
133
        }
134

    
135
        private  IPithosSettings LoadSettings()
136
        {
137

    
138
            try
139
            {
140
                using (var client = PithosHost.GetSettingsClient())
141
                {
142
                    return client.GetSettings();
143
                }
144
            }
145
            catch (Exception exc)
146
            {
147
                Log.ErrorFormat("[ERROR] while loading settings:\r{0}",exc);
148
                _settings = new Lazy<IPithosSettings>(LoadSettings);
149
            }
150
            return null;
151
        }
152
    }
153
}