Added Polling interval property and setting
[pithos-ms-client] / trunk / Pithos.Client.WPF / Configuration / PithosSettings.cs
1 // -----------------------------------------------------------------------
2 // <copyright file="PithosSettings.cs" company="GRNET">
3 // Copyright 2011 GRNET S.A. All rights reserved.
4 // 
5 // Redistribution and use in source and binary forms, with or
6 // without modification, are permitted provided that the following
7 // conditions are met:
8 // 
9 //   1. Redistributions of source code must retain the above
10 //      copyright notice, this list of conditions and the following
11 //      disclaimer.
12 // 
13 //   2. Redistributions in binary form must reproduce the above
14 //      copyright notice, this list of conditions and the following
15 //      disclaimer in the documentation and/or other materials
16 //      provided with the distribution.
17 // 
18 // THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 // 
31 // The views and conclusions contained in the software and
32 // documentation are those of the authors and should not be
33 // interpreted as representing official policies, either expressed
34 // or implied, of GRNET S.A.
35 // </copyright>
36 // -----------------------------------------------------------------------
37
38 using System.ComponentModel.Composition;
39 using System.Configuration;
40 using System.Dynamic;
41 using Pithos.Client.WPF.Properties;
42 using Pithos.Interfaces;
43
44 namespace Pithos.Client.WPF.Configuration
45 {
46     using System;
47     using System.Collections.Generic;
48     using System.Linq;
49     using System.Text;
50
51     [Export(typeof(IPithosSettings))]
52     [Export]
53     public class PithosSettings :  IPithosSettings
54     {
55         private readonly Settings _settings = Settings.Default;
56
57         public PithosSettings()
58         {
59                 _settings.Upgrade();
60         }
61
62         public bool UseDefaultProxy
63         {
64             get { return _settings.UseDefaultProxy; }
65             set { _settings.UseDefaultProxy = value; }
66         }
67
68         public bool UseManualProxy
69         {
70             get { return _settings.UseManualProxy; }
71             set { _settings.UseManualProxy = value; }
72         }
73
74         public bool UseNoProxy
75         {
76             get { return _settings.UseNoProxy; }
77             set { _settings.UseNoProxy = value; }
78         }
79
80         public string PithosPath
81         {
82             get { return _settings.PithosPath; }
83             set { _settings.PithosPath = value; }
84         }
85
86       /*  public string PithosSite
87         {
88             get { return _settings.PithosSite; }
89         }*/
90
91         public string PithosLoginUrl
92         {
93             get { return _settings.PithosLoginUrl; }
94         }
95
96         public string IconsPath
97         {
98             get { return _settings.IconPath; }
99             set { _settings.IconPath = value; }
100         }
101
102         public string UserName
103         {
104             get { return _settings.UserName; }
105             set { _settings.UserName = value; }
106         }
107
108         public string ApiKey
109         {
110             get { return _settings.ApiKey; }
111             set { _settings.ApiKey = value; }
112         }
113
114         public AccountsCollection Accounts
115         {
116             get
117             {
118                 if (_settings.Accounts==null)
119                     _settings.Accounts=new AccountsCollection();
120                 return _settings.Accounts;
121             }
122             set { _settings.Accounts = value; }
123         }
124
125         public string ProxyServer
126         {
127             get { return _settings.ProxyServer; }
128             set { _settings.ProxyServer = value; }
129         }
130
131         public int ProxyPort
132         {
133             get { return _settings.ProxyPort; }
134             set { _settings.ProxyPort = value; }
135         }
136
137         public string ProxyUsername
138         {
139             get { return _settings.ProxyUsername; }
140             set { _settings.ProxyUsername = value; }
141         }
142
143
144         public string ProxyPassword
145         {
146             get { return _settings.ProxyPassword; }
147             set { _settings.ProxyPassword = value; }
148         }
149
150         public bool ProxyAuthentication
151         {
152
153             get { return _settings.ProxyAuthentication; }
154             set { _settings.ProxyAuthentication = value; }
155         }
156
157         
158         
159         public bool ExtensionsActivated
160         {
161
162             get { return _settings.ExtensionsActivated; }
163             set { _settings.ExtensionsActivated = value; }
164         }
165
166         public bool ShowDesktopNotifications
167         {
168             get { return _settings.ShowDesktopNotifications; }
169             set { _settings.ShowDesktopNotifications = value; }
170         }
171
172
173         public int PollingInterval
174         {
175             get { return _settings.PollingInterval; }
176             set
177             {
178                 if (value <= 0)
179                     throw new ArgumentOutOfRangeException();
180                 _settings.PollingInterval = value;
181             }
182         }
183 /*
184         public override IEnumerable<string> GetDynamicMemberNames()
185         {
186             return (from SettingsProperty property in _settings.Properties
187                         select property.Name);
188         }
189
190
191         private Lazy<ILookup<string, SettingsProperty>> _propertyNames = new Lazy<ILookup<string, SettingsProperty>>(
192             () => (from SettingsProperty property in
193                        _settings.Properties
194                    select property).ToLookup(property => property.Name));
195
196         public override bool TryGetMember(GetMemberBinder binder, out object result)
197         {
198             result = null;
199             if (!_propertyNames.Value.Contains(binder.Name))
200                 return false;
201             result=_settings.Properties[binder.Name];
202             return true;
203         }
204 */
205
206         public void Save()
207         {
208             _settings.Save();
209         }
210
211         public void Reload()
212         {
213             _settings.Reload();
214         }
215     }
216 }