Statistics
| Branch: | Revision:

root / trunk / Pithos.ShellExtensions / ShellSettings.cs @ db8a9589

History | View | Annotate | Download (6.3 kB)

1
#region
2
/* -----------------------------------------------------------------------
3
 * <copyright file="ShellSettings.cs" company="GRNet">
4
 * 
5
 * Copyright 2011-2012 GRNET S.A. All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or
8
 * without modification, are permitted provided that the following
9
 * conditions are met:
10
 *
11
 *   1. Redistributions of source code must retain the above
12
 *      copyright notice, this list of conditions and the following
13
 *      disclaimer.
14
 *
15
 *   2. Redistributions in binary form must reproduce the above
16
 *      copyright notice, this list of conditions and the following
17
 *      disclaimer in the documentation and/or other materials
18
 *      provided with the distribution.
19
 *
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
22
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
 * POSSIBILITY OF SUCH DAMAGE.
33
 *
34
 * The views and conclusions contained in the software and
35
 * documentation are those of the authors and should not be
36
 * interpreted as representing official policies, either expressed
37
 * or implied, of GRNET S.A.
38
 * </copyright>
39
 * -----------------------------------------------------------------------
40
 */
41
#endregion
42
using System.ComponentModel.Composition;
43
using System.Diagnostics;
44
using System.Reflection;
45
using System.ServiceModel;
46
using Microsoft.Win32;
47
using Pithos.Interfaces;
48

    
49
namespace Pithos.ShellExtensions
50
{
51
    using System;
52
    using System.Collections.Generic;
53
    using System.Linq;
54
    using System.Text;
55

    
56
    /// <summary>
57
    /// TODO: Update summary.
58
    /// </summary>
59
    [Export(typeof(IPithosSettings))]
60
    public class ShellSettings:IPithosSettings
61
    {
62
        private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
63

    
64
        private Lazy<IPithosSettings> _settings;
65
        public ShellSettings()
66
        {
67
            _settings = new Lazy<IPithosSettings>(LoadSettings);
68
        }
69

    
70
        public bool UseDefaultProxy
71
        {
72
            get { return _settings.Value.UseDefaultProxy; }
73
            set { _settings.Value.UseDefaultProxy = value; }
74
        }
75

    
76
        public bool UseManualProxy
77
        {
78
            get { return _settings.Value.UseManualProxy; }
79
            set { _settings.Value.UseManualProxy = value; }
80
        }
81

    
82
        public bool UseNoProxy
83
        {
84
            get { return _settings.Value.UseNoProxy; }
85
            set { _settings.Value.UseNoProxy = value; }
86
        }
87

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

    
94
/*
95
        public string PithosSite
96
        {
97
            get { return _settings.Value.PithosSite; }
98
        }
99
*/
100

    
101
        public string IconsPath
102
        {
103
            get { return _settings.Value.IconsPath; }
104
            set { _settings.Value.IconsPath = value; }
105
        }
106

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

    
113
        public string ApiKey
114
        {
115
            get { return _settings.Value.ApiKey; }
116
            set { _settings.Value.ApiKey = value; }
117
        }
118

    
119
        public AccountsCollection Accounts
120
        {
121
            get { return _settings.Value.Accounts; }
122
            set { _settings.Value.Accounts = value; }
123
        }
124

    
125
        public string ProxyServer
126
        {
127
            get { return _settings.Value.ProxyServer; }
128
            set { _settings.Value.ProxyServer = value; }
129
        }
130

    
131
        public int ProxyPort
132
        {
133
            get { return _settings.Value.ProxyPort; }
134
            set { _settings.Value.ProxyPort = value; }
135
        }
136

    
137
        public string ProxyUsername
138
        {
139
            get { return _settings.Value.ProxyUsername; }
140
            set { _settings.Value.ProxyUsername = value; }
141
        }
142

    
143

    
144
        public string ProxyPassword
145
        {
146
            get { return _settings.Value.ProxyPassword; }
147
            set { _settings.Value.ProxyPassword = value; }
148
        }
149

    
150
        public string ProxyDomain
151
        {
152
            get { return _settings.Value.ProxyDomain; }
153
            set { _settings.Value.ProxyDomain = value; }
154
        }
155

    
156
        public bool ProxyAuthentication
157
        {
158

    
159
            get { return _settings.Value.ProxyAuthentication; }
160
            set { _settings.Value.ProxyAuthentication = value; }
161
        }
162

    
163
        public bool ExtensionsActivated
164
        {
165

    
166
            get { return _settings.Value.ExtensionsActivated; }
167
            set { _settings.Value.ExtensionsActivated = value; }
168
        }
169

    
170
        public int PollingInterval
171
        {
172
            get { return _settings.Value.PollingInterval; }
173
            set { _settings.Value.PollingInterval = value; }
174
        }
175

    
176
        public TimeSpan StartupDelay
177
        {
178
            get { return _settings.Value.StartupDelay; }
179
            set { _settings.Value.StartupDelay = value; }
180
        }
181

    
182
        public byte HashingParallelism
183
        {
184
            get { return _settings.Value.HashingParallelism; }
185
            set { _settings.Value.HashingParallelism = value; }
186
        }
187
        public void Save()
188
        {
189
           
190
        }
191

    
192
        public void Reload()
193
        {
194
            _settings=new Lazy<IPithosSettings>(LoadSettings);
195
        }
196

    
197
        private  IPithosSettings LoadSettings()
198
        {
199

    
200
            try
201
            {
202
                using (var client = PithosHost.GetSettingsClient())
203
                {
204
                    return client.GetSettings();
205
                }
206
            }
207
            catch (Exception exc)
208
            {
209
                Log.ErrorFormat("[ERROR] while loading settings:\r{0}",exc);
210
                _settings = new Lazy<IPithosSettings>(LoadSettings);
211
            }
212
            return null;
213
        }
214
    }
215
}