Statistics
| Branch: | Revision:

root / trunk / Pithos.ShellExtensions / ShellSettings.cs @ 5bcf6d70

History | View | Annotate | Download (4.2 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 Pithos.Interfaces;
11

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

    
19
    /// <summary>
20
    /// TODO: Update summary.
21
    /// </summary>
22
    [Export(typeof(IPithosSettings))]
23
    public class ShellSettings:IPithosSettings
24
    {
25
        private Lazy<IPithosSettings> _settings;
26
        public ShellSettings()
27
        {
28
            _settings = new Lazy<IPithosSettings>(LoadSettings);
29
        }
30

    
31
        public bool UseDefaultProxy
32
        {
33
            get { return _settings.Value.UseDefaultProxy; }
34
            set { _settings.Value.UseDefaultProxy = value; }
35
        }
36

    
37
        public bool UseManualProxy
38
        {
39
            get { return _settings.Value.UseManualProxy; }
40
            set { _settings.Value.UseManualProxy = value; }
41
        }
42

    
43
        public bool UseNoProxy
44
        {
45
            get { return _settings.Value.UseNoProxy; }
46
            set { _settings.Value.UseNoProxy = value; }
47
        }
48

    
49
        public string PithosPath
50
        {
51
            get { return _settings.Value.PithosPath; }
52
            set { _settings.Value.PithosPath = value; }
53
        }
54

    
55
        public string PithosSite
56
        {
57
            get { return _settings.Value.PithosSite; }
58
        }
59

    
60
        public string IconsPath
61
        {
62
            get { return _settings.Value.IconsPath; }
63
            set { _settings.Value.IconsPath = value; }
64
        }
65

    
66
        public string UserName
67
        {
68
            get { return _settings.Value.UserName; }
69
            set { _settings.Value.UserName = value; }
70
        }
71

    
72
        public string ApiKey
73
        {
74
            get { return _settings.Value.ApiKey; }
75
            set { _settings.Value.ApiKey = value; }
76
        }
77

    
78
        public AccountsCollection Accounts
79
        {
80
            get { return _settings.Value.Accounts; }
81
            set { _settings.Value.Accounts = value; }
82
        }
83

    
84
        public string ProxyServer
85
        {
86
            get { return _settings.Value.ProxyServer; }
87
            set { _settings.Value.ProxyServer = value; }
88
        }
89

    
90
        public int ProxyPort
91
        {
92
            get { return _settings.Value.ProxyPort; }
93
            set { _settings.Value.ProxyPort = value; }
94
        }
95

    
96
        public string ProxyUsername
97
        {
98
            get { return _settings.Value.ProxyUsername; }
99
            set { _settings.Value.ProxyUsername = value; }
100
        }
101

    
102

    
103
        public string ProxyPassword
104
        {
105
            get { return _settings.Value.ProxyPassword; }
106
            set { _settings.Value.ProxyPassword = value; }
107
        }
108

    
109
        public bool ProxyAuthentication
110
        {
111

    
112
            get { return _settings.Value.ProxyAuthentication; }
113
            set { _settings.Value.ProxyAuthentication = value; }
114
        }
115

    
116
        public bool ExtensionsActivated
117
        {
118

    
119
            get { return _settings.Value.ExtensionsActivated; }
120
            set { _settings.Value.ExtensionsActivated = value; }
121
        }
122
        public void Save()
123
        {
124
           
125
        }
126

    
127
        public void Reload()
128
        {
129
            _settings=new Lazy<IPithosSettings>(LoadSettings);
130
        }
131

    
132
        private  IPithosSettings LoadSettings()
133
        {
134
            try
135
            {
136
                var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
137

    
138
                var remoteAddress = new EndpointAddress("net.pipe://localhost/pithos/settings");
139
                using (var client = new PithosService.SettingsServiceClient(binding, remoteAddress))
140
                {
141
                    return client.GetSettings();
142
                }
143
            }
144
            catch (Exception exc)
145
            {
146
                Trace.WriteLine(exc.ToString());
147
                Trace.TraceError(exc.ToString());
148
                _settings = new Lazy<IPithosSettings>(LoadSettings);
149
            }
150
            return null;
151
        }
152
    }
153
}