Merge lp:~mandel/ubuntuone-windows-installer/manage_devices into lp:ubuntuone-windows-installer/beta
- manage_devices
- Merge into beta
Proposed by
Manuel de la Peña
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | John Lenton | ||||
Approved revision: | 178 | ||||
Merged at revision: | 136 | ||||
Proposed branch: | lp:~mandel/ubuntuone-windows-installer/manage_devices | ||||
Merge into: | lp:ubuntuone-windows-installer/beta | ||||
Diff against target: |
1565 lines (+1025/-55) 33 files modified
src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs (+0/-1) src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj (+0/-2) src/Canonical.Ubuntu.SSO/IKeyring.cs (+7/-0) src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs (+16/-0) src/Canonical.Ubuntu.SSO/Keyring.cs (+21/-0) src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs (+65/-0) src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs (+1/-30) src/Canonical.Ubuntu.SSO/objects.xml (+0/-3) src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj (+5/-0) src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs (+92/-0) src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj (+7/-0) src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml (+23/-0) src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs (+51/-0) src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml (+4/-4) src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs (+31/-0) src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml (+11/-10) src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs (+42/-1) src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj (+10/-0) src/Canonical.UbuntuOne.Client/Device.cs (+38/-0) src/Canonical.UbuntuOne.Client/DeviceFactory.cs (+57/-0) src/Canonical.UbuntuOne.Client/DeviceManager.cs (+157/-0) src/Canonical.UbuntuOne.Client/DeviceManagerException.cs (+57/-0) src/Canonical.UbuntuOne.Client/IDevice.cs (+57/-0) src/Canonical.UbuntuOne.Client/IDeviceFactory.cs (+35/-0) src/Canonical.UbuntuOne.Client/IDeviceManager.cs (+48/-0) src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs (+7/-0) src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs (+22/-0) src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs (+78/-1) src/Canonical.UbuntuOne.Client/objects.xml (+7/-0) src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj (+3/-0) src/Canonical.UbuntuOne.Common/Net/IOAuth.cs (+17/-1) src/Canonical.UbuntuOne.Common/Net/OAuth.cs (+52/-2) src/Canonical.UbuntuOne.Common/objects.xml (+4/-0) |
||||
To merge this branch: | bzr merge lp:~mandel/ubuntuone-windows-installer/manage_devices | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
John Lenton (community) | Approve | ||
Review via email:
|
Commit message
Description of the change
Allows to remove the current machine from ubuntu one by adding a way to manage your devices.
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
John Lenton (chipaca) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs' | |||
2 | --- src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs 2010-10-05 09:49:29 +0000 | |||
3 | +++ src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs 2010-11-14 21:31:15 +0000 | |||
4 | @@ -54,7 +54,6 @@ | |||
5 | 54 | _processor = new SSOLoginProcessor | 54 | _processor = new SSOLoginProcessor |
6 | 55 | { | 55 | { |
7 | 56 | Authentications = _auth, | 56 | Authentications = _auth, |
8 | 57 | HttpWebRequestFactory = _requestFactory, | ||
9 | 58 | Keyring = _keyring, | 57 | Keyring = _keyring, |
10 | 59 | OAuth = _oauth, | 58 | OAuth = _oauth, |
11 | 60 | SSOCredentialsEncoder = _encode | 59 | SSOCredentialsEncoder = _encode |
12 | 61 | 60 | ||
13 | === modified file 'src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj' | |||
14 | --- src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj 2010-10-12 13:07:02 +0000 | |||
15 | +++ src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj 2010-11-14 21:31:15 +0000 | |||
16 | @@ -89,13 +89,11 @@ | |||
17 | 89 | <Compile Include="IDataProtector.cs" /> | 89 | <Compile Include="IDataProtector.cs" /> |
18 | 90 | <Compile Include="ILoginOrRegisterView.cs" /> | 90 | <Compile Include="ILoginOrRegisterView.cs" /> |
19 | 91 | <Compile Include="ILoginView.cs" /> | 91 | <Compile Include="ILoginView.cs" /> |
20 | 92 | <Compile Include="IOAuth.cs" /> | ||
21 | 93 | <Compile Include="ISSOCredentialsEncoder.cs" /> | 92 | <Compile Include="ISSOCredentialsEncoder.cs" /> |
22 | 94 | <Compile Include="ISSOLoginProcessor.cs" /> | 93 | <Compile Include="ISSOLoginProcessor.cs" /> |
23 | 95 | <Compile Include="JsonSSOCredentialsEncoder.cs" /> | 94 | <Compile Include="JsonSSOCredentialsEncoder.cs" /> |
24 | 96 | <Compile Include="Keyring.cs" /> | 95 | <Compile Include="Keyring.cs" /> |
25 | 97 | <Compile Include="LoginCredentialsEventArgs.cs" /> | 96 | <Compile Include="LoginCredentialsEventArgs.cs" /> |
26 | 98 | <Compile Include="OAuth.cs" /> | ||
27 | 99 | <Compile Include="Service\Account.cs" /> | 97 | <Compile Include="Service\Account.cs" /> |
28 | 100 | <Compile Include="Service\AccountDiff.cs" /> | 98 | <Compile Include="Service\AccountDiff.cs" /> |
29 | 101 | <Compile Include="Service\AccountFull.cs" /> | 99 | <Compile Include="Service\AccountFull.cs" /> |
30 | 102 | 100 | ||
31 | === modified file 'src/Canonical.Ubuntu.SSO/IKeyring.cs' | |||
32 | --- src/Canonical.Ubuntu.SSO/IKeyring.cs 2010-09-16 16:18:56 +0000 | |||
33 | +++ src/Canonical.Ubuntu.SSO/IKeyring.cs 2010-11-14 21:31:15 +0000 | |||
34 | @@ -37,6 +37,13 @@ | |||
35 | 37 | void CreateSecret(string keyringName, string applicationName, string secret); | 37 | void CreateSecret(string keyringName, string applicationName, string secret); |
36 | 38 | 38 | ||
37 | 39 | /// <summary> | 39 | /// <summary> |
38 | 40 | /// Removes the given secret from the keyring. | ||
39 | 41 | /// </summary> | ||
40 | 42 | /// <param name="keyring">The keyring where th esecret is found.</param> | ||
41 | 43 | /// <param name="applicationName">The name of the application.</param> | ||
42 | 44 | void RemoveSecret(string keyring, string applicationName); | ||
43 | 45 | |||
44 | 46 | /// <summary> | ||
45 | 40 | /// Gets the secret froma keyring using the name of the application that stored it. | 47 | /// Gets the secret froma keyring using the name of the application that stored it. |
46 | 41 | /// </summary> | 48 | /// </summary> |
47 | 42 | /// <param name="keyringName">The name of the keyring where the secret was stored.</param> | 49 | /// <param name="keyringName">The name of the keyring where the secret was stored.</param> |
48 | 43 | 50 | ||
49 | === modified file 'src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs' | |||
50 | --- src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs 2010-10-18 10:53:55 +0000 | |||
51 | +++ src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs 2010-11-14 21:31:15 +0000 | |||
52 | @@ -72,6 +72,22 @@ | |||
53 | 72 | /// </summary> | 72 | /// </summary> |
54 | 73 | void LoginOrRegisterToGetCredentials(); | 73 | void LoginOrRegisterToGetCredentials(); |
55 | 74 | 74 | ||
56 | 75 | /// <summary> | ||
57 | 76 | /// Returns the credentials of the user and requests a login if necesary. | ||
58 | 77 | /// </summary> | ||
59 | 78 | /// <param name="applicationName">The name of the application requesting the info.</param> | ||
60 | 79 | /// <param name="token">The token part of the oauth.</param> | ||
61 | 80 | /// <param name="tokenSecret">The token secret of the part of the oauth.</param> | ||
62 | 81 | /// <param name="consumerKey">The consumer key of the oauth.</param> | ||
63 | 82 | /// <param name="consumerSecret">The consumer secret of the oauth.</param> | ||
64 | 83 | void LoginToGetCredentials(string applicationName, out string token, out string tokenSecret, out string consumerKey, out string consumerSecret); | ||
65 | 84 | |||
66 | 85 | /// <summary> | ||
67 | 86 | /// Removes the credentials for the given application name in the machine. | ||
68 | 87 | /// </summary> | ||
69 | 88 | /// <param name="applicationName">The name of the applications whose credentials we want to remove.</param> | ||
70 | 89 | void RemoveCredentials(string applicationName); | ||
71 | 90 | |||
72 | 75 | #endregion | 91 | #endregion |
73 | 76 | 92 | ||
74 | 77 | } | 93 | } |
75 | 78 | 94 | ||
76 | === modified file 'src/Canonical.Ubuntu.SSO/Keyring.cs' | |||
77 | --- src/Canonical.Ubuntu.SSO/Keyring.cs 2010-10-06 18:29:07 +0000 | |||
78 | +++ src/Canonical.Ubuntu.SSO/Keyring.cs 2010-11-14 21:31:15 +0000 | |||
79 | @@ -17,6 +17,7 @@ | |||
80 | 17 | * | 17 | * |
81 | 18 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | 18 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
82 | 19 | */ | 19 | */ |
83 | 20 | using System; | ||
84 | 20 | using System.Collections.Generic; | 21 | using System.Collections.Generic; |
85 | 21 | using System.Linq; | 22 | using System.Linq; |
86 | 22 | using System.Security.Cryptography; | 23 | using System.Security.Cryptography; |
87 | @@ -272,6 +273,26 @@ | |||
88 | 272 | } | 273 | } |
89 | 273 | 274 | ||
90 | 274 | /// <summary> | 275 | /// <summary> |
91 | 276 | /// Removes the given secret from the keyring. | ||
92 | 277 | /// </summary> | ||
93 | 278 | /// <param name="keyringName">The keyring where th esecret is found.</param> | ||
94 | 279 | /// <param name="applicationName">The name of the application.</param> | ||
95 | 280 | public void RemoveSecret(string keyringName, string applicationName) | ||
96 | 281 | { | ||
97 | 282 | ValidateArgs.Begin() | ||
98 | 283 | .IsNotNullOrEmpty(keyringName, "keyringName") | ||
99 | 284 | .IsNotNullOrEmpty(applicationName, "applicationName") | ||
100 | 285 | .Check(); | ||
101 | 286 | if(KeyringExist(keyringName)) | ||
102 | 287 | { | ||
103 | 288 | using(var keyring = OpenKeyring(keyringName)) | ||
104 | 289 | { | ||
105 | 290 | keyring.DeleteValue(applicationName); | ||
106 | 291 | } | ||
107 | 292 | } | ||
108 | 293 | } | ||
109 | 294 | |||
110 | 295 | /// <summary> | ||
111 | 275 | /// Gets the secret froma keyring using the name of the application that stored it. | 296 | /// Gets the secret froma keyring using the name of the application that stored it. |
112 | 276 | /// </summary> | 297 | /// </summary> |
113 | 277 | /// <param name="keyringName">The name of the keyring where the secret was stored.</param> | 298 | /// <param name="keyringName">The name of the keyring where the secret was stored.</param> |
114 | 278 | 299 | ||
115 | === modified file 'src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs' | |||
116 | --- src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-20 11:32:24 +0000 | |||
117 | +++ src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-11-14 21:31:15 +0000 | |||
118 | @@ -157,6 +157,71 @@ | |||
119 | 157 | throw new NotImplementedException(); | 157 | throw new NotImplementedException(); |
120 | 158 | } | 158 | } |
121 | 159 | 159 | ||
122 | 160 | /// <summary> | ||
123 | 161 | /// Returns the credentials of the user and requests a login if necesary. | ||
124 | 162 | /// </summary> | ||
125 | 163 | /// <param name="token">The token part of the oauth.</param> | ||
126 | 164 | /// <param name="tokenSecret">The token secret of the part of the oauth.</param> | ||
127 | 165 | /// <param name="consumerKey">The consumer key of the oauth.</param> | ||
128 | 166 | /// <param name="consumerSecret">The consumer secret of the oauth.</param> | ||
129 | 167 | public void LoginToGetCredentials(string applicationName, out string token, out string tokenSecret, out string consumerKey, out string consumerSecret) | ||
130 | 168 | { | ||
131 | 169 | token = null; | ||
132 | 170 | tokenSecret = null; | ||
133 | 171 | consumerKey = null; | ||
134 | 172 | consumerSecret = null; | ||
135 | 173 | try | ||
136 | 174 | { | ||
137 | 175 | // try to get the credentials from the keyring | ||
138 | 176 | var secret = Keyring.GetSecretByName(KeyringName, ApplicationName); | ||
139 | 177 | if (secret == null) | ||
140 | 178 | { | ||
141 | 179 | // we need to use the processor to get the login info | ||
142 | 180 | if (LoginView.ViewDispatcher.Dispatch(() => LoginView.IsShown)) | ||
143 | 181 | return; | ||
144 | 182 | |||
145 | 183 | if (LoginView.ViewDispatcher.Dispatch(() => LoginView.ShowDialog() != MessageBoxResult.Cancel)) | ||
146 | 184 | { | ||
147 | 185 | var tokenName = string.Format(ApplicationTokenName, Environment.MachineName); | ||
148 | 186 | secret = SSOLoginProcessor.Login( | ||
149 | 187 | LoginView.ViewDispatcher.Dispatch(() => LoginView.EmailAddress), | ||
150 | 188 | LoginView.ViewDispatcher.Dispatch(() => LoginView.Password), | ||
151 | 189 | tokenName); | ||
152 | 190 | // save the credentials in the keyring | ||
153 | 191 | // TODO: We have an issue here since we have more than one listening for the same credntials of Ubuntu One | ||
154 | 192 | Keyring.CreateSecret(KeyringName, applicationName, secret); | ||
155 | 193 | } | ||
156 | 194 | else | ||
157 | 195 | { | ||
158 | 196 | return; | ||
159 | 197 | } | ||
160 | 198 | } | ||
161 | 199 | // we execute the credentials found event | ||
162 | 200 | if (!string.IsNullOrEmpty(secret) && OnCredentialsFound != null) | ||
163 | 201 | { | ||
164 | 202 | SSOLoginProcessor.SSOCredentialsEncoder.Decode(secret, out token, out tokenSecret, out consumerKey, out consumerSecret); | ||
165 | 203 | } | ||
166 | 204 | } | ||
167 | 205 | catch (SSOLoginException e) | ||
168 | 206 | { | ||
169 | 207 | // TODO: Show message! | ||
170 | 208 | } | ||
171 | 209 | catch (Exception e) | ||
172 | 210 | { | ||
173 | 211 | // TODO: Show message! | ||
174 | 212 | } | ||
175 | 213 | } | ||
176 | 214 | |||
177 | 215 | /// <summary> | ||
178 | 216 | /// Removes the credentials for the given application name in the machine. | ||
179 | 217 | /// </summary> | ||
180 | 218 | /// <param name="applicationName">The name of the applications whose credentials we want to remove.</param> | ||
181 | 219 | public void RemoveCredentials(string applicationName) | ||
182 | 220 | { | ||
183 | 221 | // TODO: Currently the application name is hardcoded! | ||
184 | 222 | Keyring.RemoveSecret(KeyringName, ApplicationName); | ||
185 | 223 | } | ||
186 | 224 | |||
187 | 160 | #endregion | 225 | #endregion |
188 | 161 | } | 226 | } |
189 | 162 | } | 227 | } |
190 | 163 | 228 | ||
191 | === modified file 'src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs' | |||
192 | --- src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs 2010-10-05 15:20:36 +0000 | |||
193 | +++ src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs 2010-11-14 21:31:15 +0000 | |||
194 | @@ -58,40 +58,11 @@ | |||
195 | 58 | /// </summary> | 58 | /// </summary> |
196 | 59 | public IOAuth OAuth { get; set; } | 59 | public IOAuth OAuth { get; set; } |
197 | 60 | 60 | ||
198 | 61 | public IHttpWebRequestFactory HttpWebRequestFactory { get; set; } | ||
199 | 62 | |||
200 | 63 | #endregion | 61 | #endregion |
201 | 64 | 62 | ||
202 | 65 | #region Helper methods} | 63 | #region Helper methods} |
203 | 66 | 64 | ||
204 | 67 | /// <summary> | 65 | /// <summary> |
205 | 68 | /// Creates an oauth request that can access a protected web resource. | ||
206 | 69 | /// </summary> | ||
207 | 70 | /// <param name="uri">The uri where the resource is found.</param> | ||
208 | 71 | /// <param name="httpMethod">The request berb to be used.</param> | ||
209 | 72 | /// <param name="consumerKey">Consumer key from oauth.</param> | ||
210 | 73 | /// <param name="consumerSecret">Consumer secret from oauth.</param> | ||
211 | 74 | /// <param name="token">Token from oauth.</param> | ||
212 | 75 | /// <param name="tokenSecret">Token secret from oauth.</param> | ||
213 | 76 | /// <returns>A webrequest that can be used to access the resource.</returns> | ||
214 | 77 | public IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret, string token, string tokenSecret) | ||
215 | 78 | { | ||
216 | 79 | // Form the full REST request url | ||
217 | 80 | var url = new Uri(uri); | ||
218 | 81 | string normUrl; | ||
219 | 82 | string normParams; | ||
220 | 83 | |||
221 | 84 | // get oauth header | ||
222 | 85 | var authHeader = OAuth.GenerateHeaderWithSignature(url, string.Empty, consumerKey, consumerSecret, | ||
223 | 86 | token, tokenSecret, httpMethod, OAuth.GenerateTimeStamp(), OAuth.GenerateNonce(), SSO.OAuth.SignatureTypes.HMACSHA1, | ||
224 | 87 | out normUrl, out normParams); | ||
225 | 88 | |||
226 | 89 | var request = HttpWebRequestFactory.Create(url); | ||
227 | 90 | request.Headers.Add(authHeader.Key, authHeader.Value); | ||
228 | 91 | return request; | ||
229 | 92 | } | ||
230 | 93 | |||
231 | 94 | /// <summary> | ||
232 | 95 | /// Pings the Ubuntu One server so that the SSO tokens are added to them and they know how to identify the user. | 66 | /// Pings the Ubuntu One server so that the SSO tokens are added to them and they know how to identify the user. |
233 | 96 | /// </summary> | 67 | /// </summary> |
234 | 97 | /// <param name="email">The email used by the user to register to u1.</param> | 68 | /// <param name="email">The email used by the user to register to u1.</param> |
235 | @@ -102,7 +73,7 @@ | |||
236 | 102 | private void PingUbuntuOneServer(string email, string consumerKey, string consumerSecret, string token, string tokenSecret) | 73 | private void PingUbuntuOneServer(string email, string consumerKey, string consumerSecret, string token, string tokenSecret) |
237 | 103 | { | 74 | { |
238 | 104 | // ping the service to make it download the tokens | 75 | // ping the service to make it download the tokens |
240 | 105 | var pingRequest = MakeRequest(Constants.PingUrl + email, "GET", consumerKey, consumerSecret, | 76 | var pingRequest = OAuth.MakeRequest(Constants.PingUrl + email, "GET", consumerKey, consumerSecret, |
241 | 106 | token, tokenSecret); | 77 | token, tokenSecret); |
242 | 107 | try | 78 | try |
243 | 108 | { | 79 | { |
244 | 109 | 80 | ||
245 | === modified file 'src/Canonical.Ubuntu.SSO/objects.xml' | |||
246 | --- src/Canonical.Ubuntu.SSO/objects.xml 2010-10-05 15:20:36 +0000 | |||
247 | +++ src/Canonical.Ubuntu.SSO/objects.xml 2010-11-14 21:31:15 +0000 | |||
248 | @@ -19,9 +19,6 @@ | |||
249 | 19 | type="Canonical.Ubuntu.SSO.JsonSSOCredentialsEncoder , Canonical.Ubuntu.SSO" | 19 | type="Canonical.Ubuntu.SSO.JsonSSOCredentialsEncoder , Canonical.Ubuntu.SSO" |
250 | 20 | autowire="autodetect"/> | 20 | autowire="autodetect"/> |
251 | 21 | 21 | ||
252 | 22 | <object id="OAuth" | ||
253 | 23 | type="Canonical.Ubuntu.SSO.OAuth , Canonical.Ubuntu.SSO" | ||
254 | 24 | autowire="autodetect"/> | ||
255 | 25 | 22 | ||
256 | 26 | <!-- The actual interesting objects to perform the SSO --> | 23 | <!-- The actual interesting objects to perform the SSO --> |
257 | 27 | 24 | ||
258 | 28 | 25 | ||
259 | === modified file 'src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj' | |||
260 | --- src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj 2010-10-12 13:07:02 +0000 | |||
261 | +++ src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj 2010-11-14 21:31:15 +0000 | |||
262 | @@ -82,6 +82,7 @@ | |||
263 | 82 | <Compile Include="..\Version.cs"> | 82 | <Compile Include="..\Version.cs"> |
264 | 83 | <Link>Properties\Version.cs</Link> | 83 | <Link>Properties\Version.cs</Link> |
265 | 84 | </Compile> | 84 | </Compile> |
266 | 85 | <Compile Include="DeviceFactoryFixture.cs" /> | ||
267 | 85 | <Compile Include="Notification\NotificationEventArgsFixture.cs" /> | 86 | <Compile Include="Notification\NotificationEventArgsFixture.cs" /> |
268 | 86 | <Compile Include="Notification\NotificationPresenterFixture.cs" /> | 87 | <Compile Include="Notification\NotificationPresenterFixture.cs" /> |
269 | 87 | <Compile Include="Notification\OperationCompletenessEventArgsFixture.cs" /> | 88 | <Compile Include="Notification\OperationCompletenessEventArgsFixture.cs" /> |
270 | @@ -90,6 +91,10 @@ | |||
271 | 90 | <Compile Include="Properties\AssemblyInfo.cs" /> | 91 | <Compile Include="Properties\AssemblyInfo.cs" /> |
272 | 91 | </ItemGroup> | 92 | </ItemGroup> |
273 | 92 | <ItemGroup> | 93 | <ItemGroup> |
274 | 94 | <ProjectReference Include="..\Canonical.Ubuntu.SSO\Canonical.Ubuntu.SSO.csproj"> | ||
275 | 95 | <Project>{9460A771-2589-45DA-9618-9FE8BB7D16E8}</Project> | ||
276 | 96 | <Name>Canonical.Ubuntu.SSO</Name> | ||
277 | 97 | </ProjectReference> | ||
278 | 93 | <ProjectReference Include="..\Canonical.UbuntuOne.Client\Canonical.UbuntuOne.Client.csproj"> | 98 | <ProjectReference Include="..\Canonical.UbuntuOne.Client\Canonical.UbuntuOne.Client.csproj"> |
279 | 94 | <Project>{7467483A-D6D5-4362-8DF4-57A7254EB569}</Project> | 99 | <Project>{7467483A-D6D5-4362-8DF4-57A7254EB569}</Project> |
280 | 95 | <Name>Canonical.UbuntuOne.Client</Name> | 100 | <Name>Canonical.UbuntuOne.Client</Name> |
281 | 96 | 101 | ||
282 | === added file 'src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs' | |||
283 | --- src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs 1970-01-01 00:00:00 +0000 | |||
284 | +++ src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs 2010-11-14 21:31:15 +0000 | |||
285 | @@ -0,0 +1,92 @@ | |||
286 | 1 | /* Copyright 2010 Canonical Ltd. | ||
287 | 2 | * | ||
288 | 3 | * This file is part of UbuntuOne on Windows. | ||
289 | 4 | * | ||
290 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
291 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
292 | 7 | * as published by the Free Software Foundation. | ||
293 | 8 | * | ||
294 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
295 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
296 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
297 | 12 | * GNU Lesser General Public License for more details. | ||
298 | 13 | * | ||
299 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
300 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
301 | 16 | * | ||
302 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
303 | 18 | */ | ||
304 | 19 | using NUnit.Framework; | ||
305 | 20 | using Rhino.Mocks; | ||
306 | 21 | |||
307 | 22 | namespace Canonical.UbuntuOne.Client.Test | ||
308 | 23 | { | ||
309 | 24 | [TestFixture] | ||
310 | 25 | public class DeviceFactoryFixture | ||
311 | 26 | { | ||
312 | 27 | #region Variables | ||
313 | 28 | |||
314 | 29 | private IDeviceManager _deviceManager; | ||
315 | 30 | private MockRepository _mocks; | ||
316 | 31 | private DeviceFactory _factory; | ||
317 | 32 | |||
318 | 33 | #endregion | ||
319 | 34 | |||
320 | 35 | #region Setup | ||
321 | 36 | |||
322 | 37 | [SetUp] | ||
323 | 38 | public void SetUp() | ||
324 | 39 | { | ||
325 | 40 | _mocks = new MockRepository(); | ||
326 | 41 | _deviceManager = _mocks.StrictMock<IDeviceManager>(); | ||
327 | 42 | _factory = new DeviceFactory {DeviceManager = _deviceManager}; | ||
328 | 43 | } | ||
329 | 44 | |||
330 | 45 | #endregion | ||
331 | 46 | |||
332 | 47 | #region Tests | ||
333 | 48 | |||
334 | 49 | [TestCase("firstToken", "batman", "computer")] | ||
335 | 50 | [TestCase("secondToken", "robin", "computer")] | ||
336 | 51 | [TestCase("thirdToken", "blah blah", "phone")] | ||
337 | 52 | public void CreateCurrentDeviceTest(string token, string description, string kind) | ||
338 | 53 | { | ||
339 | 54 | using (_mocks.Record()) | ||
340 | 55 | { | ||
341 | 56 | Expect.Call(_deviceManager.IsCurrentMachine(token)) | ||
342 | 57 | .Repeat.Once() | ||
343 | 58 | .Return(true); | ||
344 | 59 | } | ||
345 | 60 | using(_mocks.Playback()) | ||
346 | 61 | { | ||
347 | 62 | var device = _factory.Create(description, token, kind); | ||
348 | 63 | Assert.AreEqual(token, device.Token); | ||
349 | 64 | Assert.AreEqual(DeviceFactory.CurrentMachine, device.Description); | ||
350 | 65 | Assert.AreEqual(kind == "computer" ? DeviceType.COMPUTER : DeviceType.PHONE, device.Type); | ||
351 | 66 | } | ||
352 | 67 | } | ||
353 | 68 | |||
354 | 69 | [TestCase("firstToken", "batman", "computer")] | ||
355 | 70 | [TestCase("secondToken", "robin", "computer")] | ||
356 | 71 | [TestCase("thirdToken", "blah blah", "phone")] | ||
357 | 72 | public void CreateOtherDeviceTest(string token, string description, string kind) | ||
358 | 73 | { | ||
359 | 74 | using (_mocks.Record()) | ||
360 | 75 | { | ||
361 | 76 | Expect.Call(_deviceManager.IsCurrentMachine(token)) | ||
362 | 77 | .Repeat.Once() | ||
363 | 78 | .Return(false); | ||
364 | 79 | } | ||
365 | 80 | using (_mocks.Playback()) | ||
366 | 81 | { | ||
367 | 82 | var device = _factory.Create(description, token, kind); | ||
368 | 83 | Assert.AreEqual(token, device.Token); | ||
369 | 84 | Assert.AreEqual(description, device.Description); | ||
370 | 85 | Assert.AreEqual(kind == "computer" ? DeviceType.COMPUTER : DeviceType.PHONE, device.Type); | ||
371 | 86 | } | ||
372 | 87 | } | ||
373 | 88 | |||
374 | 89 | #endregion | ||
375 | 90 | |||
376 | 91 | } | ||
377 | 92 | } | ||
378 | 0 | 93 | ||
379 | === modified file 'src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj' | |||
380 | --- src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj 2010-11-02 23:28:01 +0000 | |||
381 | +++ src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj 2010-11-14 21:31:15 +0000 | |||
382 | @@ -86,6 +86,9 @@ | |||
383 | 86 | <Compile Include="BetaView.xaml.cs"> | 86 | <Compile Include="BetaView.xaml.cs"> |
384 | 87 | <DependentUpon>BetaView.xaml</DependentUpon> | 87 | <DependentUpon>BetaView.xaml</DependentUpon> |
385 | 88 | </Compile> | 88 | </Compile> |
386 | 89 | <Compile Include="DeviceControl.xaml.cs"> | ||
387 | 90 | <DependentUpon>DeviceControl.xaml</DependentUpon> | ||
388 | 91 | </Compile> | ||
389 | 89 | <Compile Include="WindowsSettingsView.xaml.cs"> | 92 | <Compile Include="WindowsSettingsView.xaml.cs"> |
390 | 90 | <DependentUpon>WindowsSettingsView.xaml</DependentUpon> | 93 | <DependentUpon>WindowsSettingsView.xaml</DependentUpon> |
391 | 91 | </Compile> | 94 | </Compile> |
392 | @@ -97,6 +100,10 @@ | |||
393 | 97 | <SubType>Designer</SubType> | 100 | <SubType>Designer</SubType> |
394 | 98 | <Generator>MSBuild:Compile</Generator> | 101 | <Generator>MSBuild:Compile</Generator> |
395 | 99 | </Page> | 102 | </Page> |
396 | 103 | <Page Include="DeviceControl.xaml"> | ||
397 | 104 | <SubType>Designer</SubType> | ||
398 | 105 | <Generator>MSBuild:Compile</Generator> | ||
399 | 106 | </Page> | ||
400 | 100 | <Page Include="DevicesView.xaml"> | 107 | <Page Include="DevicesView.xaml"> |
401 | 101 | <SubType>Designer</SubType> | 108 | <SubType>Designer</SubType> |
402 | 102 | <Generator>MSBuild:Compile</Generator> | 109 | <Generator>MSBuild:Compile</Generator> |
403 | 103 | 110 | ||
404 | === added file 'src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml' | |||
405 | --- src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml 1970-01-01 00:00:00 +0000 | |||
406 | +++ src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml 2010-11-14 21:31:15 +0000 | |||
407 | @@ -0,0 +1,23 @@ | |||
408 | 1 | <UserControl x:Class="Canonical.UbuntuOne.Client.Views.DeviceControl" | ||
409 | 2 | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
410 | 3 | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
411 | 4 | xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
412 | 5 | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
413 | 6 | mc:Ignorable="d" | ||
414 | 7 | d:DesignHeight="64" d:DesignWidth="300" BorderThickness="2 1 2 1"> | ||
415 | 8 | <Grid> | ||
416 | 9 | <Grid.ColumnDefinitions> | ||
417 | 10 | <ColumnDefinition Width="64"/> | ||
418 | 11 | <ColumnDefinition Width="*"/> | ||
419 | 12 | </Grid.ColumnDefinitions> | ||
420 | 13 | <Image Name="DeviceTypeImage" Grid.Column="0" /> | ||
421 | 14 | <Grid Grid.Column="1"> | ||
422 | 15 | <Grid.RowDefinitions> | ||
423 | 16 | <RowDefinition Height="Auto"/> | ||
424 | 17 | <RowDefinition Height="Auto"/> | ||
425 | 18 | </Grid.RowDefinitions> | ||
426 | 19 | <Label Name="DescriptionLabel" Grid.Row="0" Margin="3" HorizontalAlignment="Center">Description</Label> | ||
427 | 20 | <Button Name="RemoveButton" Grid.Row="1" Margin="3" Width="Auto" HorizontalAlignment="Center" Click="OnRemoveButtonClick">Remove</Button> | ||
428 | 21 | </Grid> | ||
429 | 22 | </Grid> | ||
430 | 23 | </UserControl> | ||
431 | 0 | 24 | ||
432 | === added file 'src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs' | |||
433 | --- src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs 1970-01-01 00:00:00 +0000 | |||
434 | +++ src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs 2010-11-14 21:31:15 +0000 | |||
435 | @@ -0,0 +1,51 @@ | |||
436 | 1 | using System.Windows.Input; | ||
437 | 2 | using Canonical.UbuntuOne.Client.Preferences; | ||
438 | 3 | |||
439 | 4 | namespace Canonical.UbuntuOne.Client.Views | ||
440 | 5 | { | ||
441 | 6 | /// <summary> | ||
442 | 7 | /// Interaction logic for DeviceControl.xaml | ||
443 | 8 | /// </summary> | ||
444 | 9 | public partial class DeviceControl | ||
445 | 10 | { | ||
446 | 11 | #region Variables | ||
447 | 12 | |||
448 | 13 | private IDevice _device; | ||
449 | 14 | |||
450 | 15 | #endregion | ||
451 | 16 | |||
452 | 17 | #region Properties | ||
453 | 18 | |||
454 | 19 | public IDevice Device | ||
455 | 20 | { | ||
456 | 21 | get { return _device; } | ||
457 | 22 | set | ||
458 | 23 | { | ||
459 | 24 | _device = value; | ||
460 | 25 | DescriptionLabel.Content = _device.Description; | ||
461 | 26 | } | ||
462 | 27 | } | ||
463 | 28 | |||
464 | 29 | /// <summary> | ||
465 | 30 | /// Gets and sets the presenter used to manage the user preferences. | ||
466 | 31 | /// </summary> | ||
467 | 32 | public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; } | ||
468 | 33 | |||
469 | 34 | #endregion | ||
470 | 35 | |||
471 | 36 | public DeviceControl() | ||
472 | 37 | { | ||
473 | 38 | InitializeComponent(); | ||
474 | 39 | } | ||
475 | 40 | |||
476 | 41 | private void OnRemoveButtonClick(object sender, System.Windows.RoutedEventArgs e) | ||
477 | 42 | { | ||
478 | 43 | if (PreferencesDialogPresenter == null) return; | ||
479 | 44 | Mouse.OverrideCursor = Cursors.Wait; | ||
480 | 45 | var removed = PreferencesDialogPresenter.RemoveDevice(Device.Type, Device.Token); | ||
481 | 46 | Mouse.OverrideCursor = null; | ||
482 | 47 | if(removed) | ||
483 | 48 | Visibility = System.Windows.Visibility.Collapsed; | ||
484 | 49 | } | ||
485 | 50 | } | ||
486 | 51 | } | ||
487 | 0 | 52 | ||
488 | === modified file 'src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml' | |||
489 | --- src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml 2010-10-13 09:56:20 +0000 | |||
490 | +++ src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml 2010-11-14 21:31:15 +0000 | |||
491 | @@ -24,15 +24,15 @@ | |||
492 | 24 | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | 24 | xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
493 | 25 | xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources" | 25 | xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources" |
494 | 26 | mc:Ignorable="d" | 26 | mc:Ignorable="d" |
496 | 27 | d:DesignHeight="300" d:DesignWidth="300"> | 27 | d:DesignHeight="298" d:DesignWidth="300"> |
497 | 28 | <Grid> | 28 | <Grid> |
498 | 29 | <Grid.RowDefinitions> | 29 | <Grid.RowDefinitions> |
500 | 30 | <RowDefinition Height="75" /> | 30 | <RowDefinition Height="Auto" /> |
501 | 31 | <RowDefinition Height="*" /> | 31 | <RowDefinition Height="*" /> |
502 | 32 | </Grid.RowDefinitions> | 32 | </Grid.RowDefinitions> |
503 | 33 | <TextBlock Name="MessageText" Grid.Row="0" Margin="3" TextWrapping="Wrap" Text="{x:Static resx:Resources.DevicesViewMessageTextBlock}"/> | 33 | <TextBlock Name="MessageText" Grid.Row="0" Margin="3" TextWrapping="Wrap" Text="{x:Static resx:Resources.DevicesViewMessageTextBlock}"/> |
506 | 34 | <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"> | 34 | <ScrollViewer Grid.Row="1" Height="Auto" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="6" BorderThickness="3" BorderBrush="Black"> |
507 | 35 | <StackPanel Name="MachinesContent"> | 35 | <StackPanel Name="MachinesContent" Margin="3"> |
508 | 36 | 36 | ||
509 | 37 | </StackPanel> | 37 | </StackPanel> |
510 | 38 | </ScrollViewer> | 38 | </ScrollViewer> |
511 | 39 | 39 | ||
512 | === modified file 'src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs' | |||
513 | --- src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs 2010-10-20 23:09:36 +0000 | |||
514 | +++ src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs 2010-11-14 21:31:15 +0000 | |||
515 | @@ -17,7 +17,9 @@ | |||
516 | 17 | * | 17 | * |
517 | 18 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | 18 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
518 | 19 | */ | 19 | */ |
519 | 20 | using System.Collections.Generic; | ||
520 | 20 | using System.Windows.Controls; | 21 | using System.Windows.Controls; |
521 | 22 | using Canonical.UbuntuOne.Client.Preferences; | ||
522 | 21 | 23 | ||
523 | 22 | namespace Canonical.UbuntuOne.Client.Views | 24 | namespace Canonical.UbuntuOne.Client.Views |
524 | 23 | { | 25 | { |
525 | @@ -28,6 +30,34 @@ | |||
526 | 28 | { | 30 | { |
527 | 29 | #region Properties | 31 | #region Properties |
528 | 30 | 32 | ||
529 | 33 | private IList<IDevice> _devices; | ||
530 | 34 | |||
531 | 35 | #endregion | ||
532 | 36 | |||
533 | 37 | #region Properties | ||
534 | 38 | |||
535 | 39 | /// <summary> | ||
536 | 40 | /// Gets and sets the presenter used to manage the user preferences. | ||
537 | 41 | /// </summary> | ||
538 | 42 | public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; } | ||
539 | 43 | |||
540 | 44 | ///<summary> | ||
541 | 45 | /// Gets and sets the devices shown in the dialog. | ||
542 | 46 | ///</summary> | ||
543 | 47 | public IList<IDevice> Devices | ||
544 | 48 | { | ||
545 | 49 | get { return _devices; } | ||
546 | 50 | set | ||
547 | 51 | { | ||
548 | 52 | _devices = value; | ||
549 | 53 | MachinesContent.Children.RemoveRange(0, MachinesContent.Children.Count); | ||
550 | 54 | foreach (var currentDevice in value) | ||
551 | 55 | { | ||
552 | 56 | var newControl = new DeviceControl {Device = currentDevice, PreferencesDialogPresenter = PreferencesDialogPresenter}; | ||
553 | 57 | MachinesContent.Children.Add(newControl); | ||
554 | 58 | } | ||
555 | 59 | } | ||
556 | 60 | } | ||
557 | 31 | 61 | ||
558 | 32 | #endregion | 62 | #endregion |
559 | 33 | 63 | ||
560 | @@ -38,5 +68,6 @@ | |||
561 | 38 | { | 68 | { |
562 | 39 | InitializeComponent(); | 69 | InitializeComponent(); |
563 | 40 | } | 70 | } |
564 | 71 | |||
565 | 41 | } | 72 | } |
566 | 42 | } | 73 | } |
567 | 43 | 74 | ||
568 | === modified file 'src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml' | |||
569 | --- src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml 2010-11-02 23:28:01 +0000 | |||
570 | +++ src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml 2010-11-14 21:31:15 +0000 | |||
571 | @@ -22,7 +22,7 @@ | |||
572 | 22 | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | 22 | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
573 | 23 | xmlns:Views="clr-namespace:Canonical.UbuntuOne.Client.Views" | 23 | xmlns:Views="clr-namespace:Canonical.UbuntuOne.Client.Views" |
574 | 24 | xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources" | 24 | xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources" |
576 | 25 | Title="{x:Static resx:Resources.PreferencesDialogTitle}" Height="450" Width="400"> | 25 | Title="{x:Static resx:Resources.PreferencesDialogTitle}" Height="450" Width="400" ResizeMode="NoResize"> |
577 | 26 | <Grid Margin="3"> | 26 | <Grid Margin="3"> |
578 | 27 | <Grid.RowDefinitions> | 27 | <Grid.RowDefinitions> |
579 | 28 | <RowDefinition Height="50" /> | 28 | <RowDefinition Height="50" /> |
580 | @@ -39,25 +39,26 @@ | |||
581 | 39 | <ColumnDefinition Width="*" /> | 39 | <ColumnDefinition Width="*" /> |
582 | 40 | <ColumnDefinition Width="*" /> | 40 | <ColumnDefinition Width="*" /> |
583 | 41 | </Grid.ColumnDefinitions> | 41 | </Grid.ColumnDefinitions> |
585 | 42 | <ProgressBar Name="Progressbar" Grid.Column="0" HorizontalAlignment="Stretch" Margin="3" /> | 42 | <ProgressBar Name="ConsumptionProgressbar" Grid.Column="0" HorizontalAlignment="Stretch" Margin="3" Minimum="0" Maximum="100"/> |
586 | 43 | <Label Name="ConsumptionLabel" Grid.Column="1">Unknown</Label> | 43 | <Label Name="ConsumptionLabel" Grid.Column="1">Unknown</Label> |
587 | 44 | </Grid> | 44 | </Grid> |
588 | 45 | <Label Name="StatusLabel" Grid.Row="1">Disconnected</Label> | 45 | <Label Name="StatusLabel" Grid.Row="1">Disconnected</Label> |
589 | 46 | </Grid> | 46 | </Grid> |
591 | 47 | <TabControl Margin="3" Grid.Row="1"> | 47 | <TabControl Margin="3" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> |
592 | 48 | <TabItem Header="{x:Static resx:Resources.PreferencesDialogDevicesTabHeader}" > | ||
593 | 49 | <Views:DevicesView x:Name="DevicesTab" Height="300" HorizontalAlignment="Stretch"/> | ||
594 | 50 | </TabItem> | ||
595 | 51 | <TabItem Header="{x:Static resx:Resources.PreferencesDialogWindowsTabHeader}"> | ||
596 | 52 | <Views:WindowsSettingsView x:Name="WindowsTab" Height="300" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> | ||
597 | 53 | </TabItem> | ||
598 | 48 | <TabItem Header="Beta" > | 54 | <TabItem Header="Beta" > |
603 | 49 | <Views:BetaView x:Name="BetaTab" Height="300" IsEnabled="False"/> | 55 | <Views:BetaView x:Name="BetaTab" Height="300" IsEnabled="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> |
600 | 50 | </TabItem> | ||
601 | 51 | <TabItem Header="{x:Static resx:Resources.PreferencesDialogWindowsTabHeader}"> | ||
602 | 52 | <Views:WindowsSettingsView x:Name="WindowsTab" Height="300" /> | ||
604 | 53 | </TabItem> | 56 | </TabItem> |
605 | 54 | <!-- | 57 | <!-- |
606 | 55 | <TabItem Header="{x:Static resx:Resources.PreferencesDialogAccountTabHeader}" > | 58 | <TabItem Header="{x:Static resx:Resources.PreferencesDialogAccountTabHeader}" > |
607 | 56 | <Views:AccountView x:Name="AccountsTab" Height="300" IsEnabled="False"/> | 59 | <Views:AccountView x:Name="AccountsTab" Height="300" IsEnabled="False"/> |
608 | 57 | </TabItem> | 60 | </TabItem> |
612 | 58 | <TabItem Header="{x:Static resx:Resources.PreferencesDialogDevicesTabHeader}" > | 61 | |
610 | 59 | <Views:DevicesView x:Name="DevicesTab" Height="300" IsEnabled="False"/> | ||
611 | 60 | </TabItem> | ||
613 | 61 | <TabItem Header="{x:Static resx:Resources.PreferencesDialogServicesTabHeader}" > | 62 | <TabItem Header="{x:Static resx:Resources.PreferencesDialogServicesTabHeader}" > |
614 | 62 | <Views:ServicesView x:Name="ServicesTab" Height="300" IsEnabled="False"/> | 63 | <Views:ServicesView x:Name="ServicesTab" Height="300" IsEnabled="False"/> |
615 | 63 | </TabItem> | 64 | </TabItem> |
616 | 64 | 65 | ||
617 | === modified file 'src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs' | |||
618 | --- src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs 2010-11-02 23:28:01 +0000 | |||
619 | +++ src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs 2010-11-14 21:31:15 +0000 | |||
620 | @@ -16,6 +16,8 @@ | |||
621 | 16 | * | 16 | * |
622 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
623 | 18 | */ | 18 | */ |
624 | 19 | using System; | ||
625 | 20 | using System.Collections.Generic; | ||
626 | 19 | using System.Windows; | 21 | using System.Windows; |
627 | 20 | using Canonical.UbuntuOne.Client.Preferences; | 22 | using Canonical.UbuntuOne.Client.Preferences; |
628 | 21 | 23 | ||
629 | @@ -26,12 +28,26 @@ | |||
630 | 26 | /// </summary> | 28 | /// </summary> |
631 | 27 | public partial class PreferencesDialog : Window, IPreferencesView | 29 | public partial class PreferencesDialog : Window, IPreferencesView |
632 | 28 | { | 30 | { |
633 | 31 | #region Variables | ||
634 | 32 | |||
635 | 33 | private IPreferencesDialogPresenter _presenter; | ||
636 | 34 | |||
637 | 35 | #endregion | ||
638 | 36 | |||
639 | 29 | #region DI properties | 37 | #region DI properties |
640 | 30 | 38 | ||
641 | 31 | /// <summary> | 39 | /// <summary> |
642 | 32 | /// Gets and sets the presenter that will be used by the view. | 40 | /// Gets and sets the presenter that will be used by the view. |
643 | 33 | /// </summary> | 41 | /// </summary> |
645 | 34 | public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; } | 42 | public IPreferencesDialogPresenter PreferencesDialogPresenter |
646 | 43 | { | ||
647 | 44 | get { return _presenter; } | ||
648 | 45 | set | ||
649 | 46 | { | ||
650 | 47 | _presenter = value; | ||
651 | 48 | DevicesTab.PreferencesDialogPresenter = value; | ||
652 | 49 | } | ||
653 | 50 | } | ||
654 | 35 | 51 | ||
655 | 36 | #endregion | 52 | #endregion |
656 | 37 | 53 | ||
657 | @@ -88,6 +104,31 @@ | |||
658 | 88 | // set { ServicesTab.IsMusicSynced = value; } | 104 | // set { ServicesTab.IsMusicSynced = value; } |
659 | 89 | //} | 105 | //} |
660 | 90 | 106 | ||
661 | 107 | /// <summary> | ||
662 | 108 | /// Sets the consumption of the plan so far. The value should be between 0 and 100. | ||
663 | 109 | /// </summary> | ||
664 | 110 | public double Consumption | ||
665 | 111 | { | ||
666 | 112 | set { ConsumptionProgressbar.Value = value; } | ||
667 | 113 | } | ||
668 | 114 | |||
669 | 115 | /// <summary> | ||
670 | 116 | /// Sets the text used next the consumption. | ||
671 | 117 | /// </summary> | ||
672 | 118 | public string ConsumptionText | ||
673 | 119 | { | ||
674 | 120 | set { ConsumptionLabel.Content = value; } | ||
675 | 121 | } | ||
676 | 122 | |||
677 | 123 | /// <summary> | ||
678 | 124 | /// Gets and sets the devices shown in the app. | ||
679 | 125 | /// </summary> | ||
680 | 126 | public IList<IDevice> Devices | ||
681 | 127 | { | ||
682 | 128 | get { return DevicesTab.Devices; } | ||
683 | 129 | set { DevicesTab.Devices = value; } | ||
684 | 130 | } | ||
685 | 131 | |||
686 | 91 | public string UserName | 132 | public string UserName |
687 | 92 | { | 133 | { |
688 | 93 | set { } | 134 | set { } |
689 | 94 | 135 | ||
690 | === modified file 'src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj' | |||
691 | --- src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj 2010-11-11 11:44:38 +0000 | |||
692 | +++ src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj 2010-11-14 21:31:15 +0000 | |||
693 | @@ -74,6 +74,13 @@ | |||
694 | 74 | <Compile Include="..\Version.cs"> | 74 | <Compile Include="..\Version.cs"> |
695 | 75 | <Link>Properties\Version.cs</Link> | 75 | <Link>Properties\Version.cs</Link> |
696 | 76 | </Compile> | 76 | </Compile> |
697 | 77 | <Compile Include="Device.cs" /> | ||
698 | 78 | <Compile Include="DeviceFactory.cs" /> | ||
699 | 79 | <Compile Include="DeviceManager.cs" /> | ||
700 | 80 | <Compile Include="DeviceManagerException.cs" /> | ||
701 | 81 | <Compile Include="IDevice.cs" /> | ||
702 | 82 | <Compile Include="IDeviceFactory.cs" /> | ||
703 | 83 | <Compile Include="IDeviceManager.cs" /> | ||
704 | 77 | <Compile Include="Notification\Enums.cs" /> | 84 | <Compile Include="Notification\Enums.cs" /> |
705 | 78 | <Compile Include="Notification\INotificationIconView.cs" /> | 85 | <Compile Include="Notification\INotificationIconView.cs" /> |
706 | 79 | <Compile Include="Notification\IStateMapper.cs" /> | 86 | <Compile Include="Notification\IStateMapper.cs" /> |
707 | @@ -176,5 +183,8 @@ | |||
708 | 176 | <Install>true</Install> | 183 | <Install>true</Install> |
709 | 177 | </BootstrapperPackage> | 184 | </BootstrapperPackage> |
710 | 178 | </ItemGroup> | 185 | </ItemGroup> |
711 | 186 | <ItemGroup> | ||
712 | 187 | <Folder Include="Devices\" /> | ||
713 | 188 | </ItemGroup> | ||
714 | 179 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | 189 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
715 | 180 | </Project> | 190 | </Project> |
716 | 181 | \ No newline at end of file | 191 | \ No newline at end of file |
717 | 182 | 192 | ||
718 | === added file 'src/Canonical.UbuntuOne.Client/Device.cs' | |||
719 | --- src/Canonical.UbuntuOne.Client/Device.cs 1970-01-01 00:00:00 +0000 | |||
720 | +++ src/Canonical.UbuntuOne.Client/Device.cs 2010-11-14 21:31:15 +0000 | |||
721 | @@ -0,0 +1,38 @@ | |||
722 | 1 | /* Copyright 2010 Canonical Ltd. | ||
723 | 2 | * | ||
724 | 3 | * This file is part of UbuntuOne on Windows. | ||
725 | 4 | * | ||
726 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
727 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
728 | 7 | * as published by the Free Software Foundation. | ||
729 | 8 | * | ||
730 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
731 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
732 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
733 | 12 | * GNU Lesser General Public License for more details. | ||
734 | 13 | * | ||
735 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
736 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
737 | 16 | * | ||
738 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
739 | 18 | */ | ||
740 | 19 | namespace Canonical.UbuntuOne.Client | ||
741 | 20 | { | ||
742 | 21 | internal class Device : IDevice | ||
743 | 22 | { | ||
744 | 23 | /// <summary> | ||
745 | 24 | /// Gets and sets a descriptin of the device. | ||
746 | 25 | /// </summary> | ||
747 | 26 | public string Description { get; set; } | ||
748 | 27 | |||
749 | 28 | /// <summary> | ||
750 | 29 | /// The token that identifies the device. | ||
751 | 30 | /// </summary> | ||
752 | 31 | public string Token { get; set; } | ||
753 | 32 | |||
754 | 33 | /// <summary> | ||
755 | 34 | /// Gets and sets the type of device. | ||
756 | 35 | /// </summary> | ||
757 | 36 | public DeviceType Type { get; set; } | ||
758 | 37 | } | ||
759 | 38 | } | ||
760 | 0 | 39 | ||
761 | === added file 'src/Canonical.UbuntuOne.Client/DeviceFactory.cs' | |||
762 | --- src/Canonical.UbuntuOne.Client/DeviceFactory.cs 1970-01-01 00:00:00 +0000 | |||
763 | +++ src/Canonical.UbuntuOne.Client/DeviceFactory.cs 2010-11-14 21:31:15 +0000 | |||
764 | @@ -0,0 +1,57 @@ | |||
765 | 1 | /* Copyright 2010 Canonical Ltd. | ||
766 | 2 | * | ||
767 | 3 | * This file is part of UbuntuOne on Windows. | ||
768 | 4 | * | ||
769 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
770 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
771 | 7 | * as published by the Free Software Foundation. | ||
772 | 8 | * | ||
773 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
774 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
775 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
776 | 12 | * GNU Lesser General Public License for more details. | ||
777 | 13 | * | ||
778 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
779 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
780 | 16 | * | ||
781 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
782 | 18 | */ | ||
783 | 19 | namespace Canonical.UbuntuOne.Client | ||
784 | 20 | { | ||
785 | 21 | internal class DeviceFactory : IDeviceFactory | ||
786 | 22 | { | ||
787 | 23 | #region Variables | ||
788 | 24 | |||
789 | 25 | internal const string ComputerType = "computer"; | ||
790 | 26 | internal const string PhoneType = "phone"; | ||
791 | 27 | internal const string CurrentMachine = "Current machine"; | ||
792 | 28 | |||
793 | 29 | #endregion | ||
794 | 30 | |||
795 | 31 | #region Di Properties | ||
796 | 32 | |||
797 | 33 | /// <summary> | ||
798 | 34 | /// Gets and sets the device manager used to access device info. | ||
799 | 35 | /// </summary> | ||
800 | 36 | public IDeviceManager DeviceManager { get; set; } | ||
801 | 37 | |||
802 | 38 | #endregion | ||
803 | 39 | |||
804 | 40 | /// <summary> | ||
805 | 41 | /// Creates a new device from the given data. | ||
806 | 42 | /// </summary> | ||
807 | 43 | /// <param name="description">A string with the description of the machine.</param> | ||
808 | 44 | /// <param name="token">The token that identifies the device.</param> | ||
809 | 45 | /// <param name="type">The type of device.</param> | ||
810 | 46 | /// <returns>A device with the given data.</returns> | ||
811 | 47 | public IDevice Create(string description, string token, string type) | ||
812 | 48 | { | ||
813 | 49 | return new Device | ||
814 | 50 | { | ||
815 | 51 | Description = (DeviceManager.IsCurrentMachine(token))?CurrentMachine:description, | ||
816 | 52 | Token = token, | ||
817 | 53 | Type = string.Compare(type, ComputerType, true) == 0 ? DeviceType.COMPUTER : DeviceType.PHONE | ||
818 | 54 | }; | ||
819 | 55 | } | ||
820 | 56 | } | ||
821 | 57 | } | ||
822 | 0 | 58 | ||
823 | === added file 'src/Canonical.UbuntuOne.Client/DeviceManager.cs' | |||
824 | --- src/Canonical.UbuntuOne.Client/DeviceManager.cs 1970-01-01 00:00:00 +0000 | |||
825 | +++ src/Canonical.UbuntuOne.Client/DeviceManager.cs 2010-11-14 21:31:15 +0000 | |||
826 | @@ -0,0 +1,157 @@ | |||
827 | 1 | /* Copyright 2010 Canonical Ltd. | ||
828 | 2 | * | ||
829 | 3 | * This file is part of UbuntuOne on Windows. | ||
830 | 4 | * | ||
831 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
832 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
833 | 7 | * as published by the Free Software Foundation. | ||
834 | 8 | * | ||
835 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
836 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
837 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
838 | 12 | * GNU Lesser General Public License for more details. | ||
839 | 13 | * | ||
840 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
841 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
842 | 16 | * | ||
843 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
844 | 18 | */ | ||
845 | 19 | using System; | ||
846 | 20 | using System.Collections.Generic; | ||
847 | 21 | using System.IO; | ||
848 | 22 | using System.Linq; | ||
849 | 23 | using Canonical.Ubuntu.SSO; | ||
850 | 24 | using Canonical.UbuntuOne.Common.Net; | ||
851 | 25 | using log4net; | ||
852 | 26 | using Newtonsoft.Json.Linq; | ||
853 | 27 | |||
854 | 28 | namespace Canonical.UbuntuOne.Client | ||
855 | 29 | { | ||
856 | 30 | internal class DeviceManager : IDeviceManager | ||
857 | 31 | { | ||
858 | 32 | |||
859 | 33 | #region Variables | ||
860 | 34 | |||
861 | 35 | private const string DevicesUrl = "https://one.ubuntu.com/api/1.0/devices/"; | ||
862 | 36 | private const string RemoveUrl = "https://one.ubuntu.com/api/1.0/devices/remove/{0}/{1}"; | ||
863 | 37 | private ILog _logger; | ||
864 | 38 | private readonly object _loggerLock = new object(); | ||
865 | 39 | |||
866 | 40 | #endregion | ||
867 | 41 | |||
868 | 42 | #region Di properties | ||
869 | 43 | |||
870 | 44 | /// <summary> | ||
871 | 45 | /// Gets and sets the object used to perform the secure requests. | ||
872 | 46 | /// </summary> | ||
873 | 47 | public IOAuth OAuth { get; set; } | ||
874 | 48 | |||
875 | 49 | /// <summary> | ||
876 | 50 | /// Gets and sets the credentials provider used to get the user credentials. | ||
877 | 51 | /// </summary> | ||
878 | 52 | public ISSOCredentialsProvider SSOCredentialsProvider { get; set; } | ||
879 | 53 | |||
880 | 54 | /// <summary> | ||
881 | 55 | /// Gets and sets the factory that creates devices. | ||
882 | 56 | /// </summary> | ||
883 | 57 | public IDeviceFactory DeviceFactory { get; set; } | ||
884 | 58 | |||
885 | 59 | /// <summary> | ||
886 | 60 | /// Gets and sets the logger used by the class. | ||
887 | 61 | /// </summary> | ||
888 | 62 | internal ILog Logger | ||
889 | 63 | { | ||
890 | 64 | get | ||
891 | 65 | { | ||
892 | 66 | if (_logger == null) | ||
893 | 67 | { | ||
894 | 68 | lock (_loggerLock) | ||
895 | 69 | { | ||
896 | 70 | _logger = LogManager.GetLogger(typeof(DeviceManager)); | ||
897 | 71 | } | ||
898 | 72 | } | ||
899 | 73 | return _logger; | ||
900 | 74 | } | ||
901 | 75 | set { _logger = value; } | ||
902 | 76 | } | ||
903 | 77 | |||
904 | 78 | #endregion | ||
905 | 79 | |||
906 | 80 | /// <summary> | ||
907 | 81 | /// Returns if the machine with the given token is th current machine. | ||
908 | 82 | /// </summary> | ||
909 | 83 | /// <param name="token">The token of the machine.</param> | ||
910 | 84 | /// <returns>A bool stating if th token represents the current machine.</returns> | ||
911 | 85 | public bool IsCurrentMachine(string token) | ||
912 | 86 | { | ||
913 | 87 | string currentToken; | ||
914 | 88 | string currentTokenSecret; | ||
915 | 89 | string currentConsumerKey; | ||
916 | 90 | string currentConsumerSecret; | ||
917 | 91 | |||
918 | 92 | // get the credentials | ||
919 | 93 | SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out currentToken, out currentTokenSecret, out currentConsumerKey, | ||
920 | 94 | out currentConsumerSecret); | ||
921 | 95 | return string.Compare(currentToken, token) == 0; | ||
922 | 96 | } | ||
923 | 97 | |||
924 | 98 | /// <summary> | ||
925 | 99 | /// Removes a machine with the given token from the machines synced with ubuntu one. | ||
926 | 100 | /// </summary> | ||
927 | 101 | /// <param name="kind"></param> | ||
928 | 102 | /// <param name="tokenToRemove"></param> | ||
929 | 103 | public void RemoveDevice(string kind, string tokenToRemove) | ||
930 | 104 | { | ||
931 | 105 | string token; | ||
932 | 106 | string tokenSecret; | ||
933 | 107 | string consumerKey; | ||
934 | 108 | string consumerSecret; | ||
935 | 109 | |||
936 | 110 | // get the credentials | ||
937 | 111 | SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey, | ||
938 | 112 | out consumerSecret); | ||
939 | 113 | var uri = string.Format(RemoveUrl, kind, tokenToRemove); | ||
940 | 114 | var request = OAuth.MakeRequest(uri, "GET", consumerKey, consumerSecret, token, tokenSecret); | ||
941 | 115 | try | ||
942 | 116 | { | ||
943 | 117 | var response = request.GetResponse(); | ||
944 | 118 | } | ||
945 | 119 | catch (Exception e) | ||
946 | 120 | { | ||
947 | 121 | throw new DeviceManagerException("Machine could not be removed.", e); | ||
948 | 122 | } | ||
949 | 123 | } | ||
950 | 124 | |||
951 | 125 | /// <summary> | ||
952 | 126 | /// Returns a list with the current machines synced in the account. | ||
953 | 127 | /// </summary> | ||
954 | 128 | public IList<IDevice> GetSyncedDevices() | ||
955 | 129 | { | ||
956 | 130 | string token; | ||
957 | 131 | string tokenSecret; | ||
958 | 132 | string consumerKey; | ||
959 | 133 | string consumerSecret; | ||
960 | 134 | |||
961 | 135 | // get the credentials | ||
962 | 136 | SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey, | ||
963 | 137 | out consumerSecret); | ||
964 | 138 | var request = OAuth.MakeRequest(DevicesUrl, "GET", consumerKey, consumerSecret, token, tokenSecret); | ||
965 | 139 | try | ||
966 | 140 | { | ||
967 | 141 | var response = request.GetResponse(); | ||
968 | 142 | var data = new StreamReader(response.GetResponseStream()).ReadToEnd(); | ||
969 | 143 | // parse the json string | ||
970 | 144 | var devicesArray = JArray.Parse(data); | ||
971 | 145 | return devicesArray.Select(currentJDevice => | ||
972 | 146 | DeviceFactory.Create( | ||
973 | 147 | (string) currentJDevice["description"], | ||
974 | 148 | (string) currentJDevice["token"], | ||
975 | 149 | (string) currentJDevice["kind"])).ToList(); | ||
976 | 150 | } | ||
977 | 151 | catch (Exception e) | ||
978 | 152 | { | ||
979 | 153 | throw new DeviceManagerException("Machine could not be removed.", e); | ||
980 | 154 | } | ||
981 | 155 | } | ||
982 | 156 | } | ||
983 | 157 | } | ||
984 | 0 | 158 | ||
985 | === added file 'src/Canonical.UbuntuOne.Client/DeviceManagerException.cs' | |||
986 | --- src/Canonical.UbuntuOne.Client/DeviceManagerException.cs 1970-01-01 00:00:00 +0000 | |||
987 | +++ src/Canonical.UbuntuOne.Client/DeviceManagerException.cs 2010-11-14 21:31:15 +0000 | |||
988 | @@ -0,0 +1,57 @@ | |||
989 | 1 | /* Copyright 2010 Canonical Ltd. | ||
990 | 2 | * | ||
991 | 3 | * This file is part of UbuntuOne on Windows. | ||
992 | 4 | * | ||
993 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
994 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
995 | 7 | * as published by the Free Software Foundation. | ||
996 | 8 | * | ||
997 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
998 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
999 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1000 | 12 | * GNU Lesser General Public License for more details. | ||
1001 | 13 | * | ||
1002 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
1003 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
1004 | 16 | * | ||
1005 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
1006 | 18 | */ | ||
1007 | 19 | using System; | ||
1008 | 20 | |||
1009 | 21 | namespace Canonical.UbuntuOne.Client | ||
1010 | 22 | { | ||
1011 | 23 | ///<summary> | ||
1012 | 24 | /// Exception thrown when there was an issue managing the devices of the account. | ||
1013 | 25 | ///</summary> | ||
1014 | 26 | public class DeviceManagerException : Exception | ||
1015 | 27 | { | ||
1016 | 28 | ///<summary> | ||
1017 | 29 | /// Creates a new instance of the class. | ||
1018 | 30 | ///</summary> | ||
1019 | 31 | public DeviceManagerException() | ||
1020 | 32 | { | ||
1021 | 33 | |||
1022 | 34 | } | ||
1023 | 35 | |||
1024 | 36 | /// <summary> | ||
1025 | 37 | /// Creates a new instance of the exception. | ||
1026 | 38 | /// </summary> | ||
1027 | 39 | /// <param name="message">The message to be carried by the exception.</param> | ||
1028 | 40 | public DeviceManagerException(string message) | ||
1029 | 41 | : base(message) | ||
1030 | 42 | { | ||
1031 | 43 | |||
1032 | 44 | } | ||
1033 | 45 | |||
1034 | 46 | /// <summary> | ||
1035 | 47 | /// Creates a new instance of the exception. | ||
1036 | 48 | /// </summary> | ||
1037 | 49 | /// <param name="message">The message to be carried by the exception.</param> | ||
1038 | 50 | /// <param name="inner">The inner exception to be carried by the exception.</param> | ||
1039 | 51 | public DeviceManagerException(string message, Exception inner) | ||
1040 | 52 | : base(message, inner) | ||
1041 | 53 | { | ||
1042 | 54 | |||
1043 | 55 | } | ||
1044 | 56 | } | ||
1045 | 57 | } | ||
1046 | 0 | 58 | ||
1047 | === added file 'src/Canonical.UbuntuOne.Client/IDevice.cs' | |||
1048 | --- src/Canonical.UbuntuOne.Client/IDevice.cs 1970-01-01 00:00:00 +0000 | |||
1049 | +++ src/Canonical.UbuntuOne.Client/IDevice.cs 2010-11-14 21:31:15 +0000 | |||
1050 | @@ -0,0 +1,57 @@ | |||
1051 | 1 | /* Copyright 2010 Canonical Ltd. | ||
1052 | 2 | * | ||
1053 | 3 | * This file is part of UbuntuOne on Windows. | ||
1054 | 4 | * | ||
1055 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
1056 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
1057 | 7 | * as published by the Free Software Foundation. | ||
1058 | 8 | * | ||
1059 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
1060 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1061 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1062 | 12 | * GNU Lesser General Public License for more details. | ||
1063 | 13 | * | ||
1064 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
1065 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
1066 | 16 | * | ||
1067 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
1068 | 18 | */ | ||
1069 | 19 | namespace Canonical.UbuntuOne.Client | ||
1070 | 20 | { | ||
1071 | 21 | /// <summary> | ||
1072 | 22 | /// Enumerator that describes the different types of devices. | ||
1073 | 23 | /// </summary> | ||
1074 | 24 | public enum DeviceType | ||
1075 | 25 | { | ||
1076 | 26 | ///<summary> | ||
1077 | 27 | /// The device is a computer. | ||
1078 | 28 | ///</summary> | ||
1079 | 29 | COMPUTER, | ||
1080 | 30 | ///<summary> | ||
1081 | 31 | /// The device is a phone. | ||
1082 | 32 | ///</summary> | ||
1083 | 33 | PHONE | ||
1084 | 34 | } | ||
1085 | 35 | |||
1086 | 36 | /// <summary> | ||
1087 | 37 | /// Interface that represents a device in the system. | ||
1088 | 38 | /// </summary> | ||
1089 | 39 | public interface IDevice | ||
1090 | 40 | { | ||
1091 | 41 | /// <summary> | ||
1092 | 42 | /// Gets and sets a descriptin of the device. | ||
1093 | 43 | /// </summary> | ||
1094 | 44 | string Description { get; set; } | ||
1095 | 45 | |||
1096 | 46 | /// <summary> | ||
1097 | 47 | /// The token that identifies the device. | ||
1098 | 48 | /// </summary> | ||
1099 | 49 | string Token { get; set; } | ||
1100 | 50 | |||
1101 | 51 | /// <summary> | ||
1102 | 52 | /// Gets and sets the type of device. | ||
1103 | 53 | /// </summary> | ||
1104 | 54 | DeviceType Type { get; set; } | ||
1105 | 55 | |||
1106 | 56 | } | ||
1107 | 57 | } | ||
1108 | 0 | 58 | ||
1109 | === added file 'src/Canonical.UbuntuOne.Client/IDeviceFactory.cs' | |||
1110 | --- src/Canonical.UbuntuOne.Client/IDeviceFactory.cs 1970-01-01 00:00:00 +0000 | |||
1111 | +++ src/Canonical.UbuntuOne.Client/IDeviceFactory.cs 2010-11-14 21:31:15 +0000 | |||
1112 | @@ -0,0 +1,35 @@ | |||
1113 | 1 | /* Copyright 2010 Canonical Ltd. | ||
1114 | 2 | * | ||
1115 | 3 | * This file is part of UbuntuOne on Windows. | ||
1116 | 4 | * | ||
1117 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
1118 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
1119 | 7 | * as published by the Free Software Foundation. | ||
1120 | 8 | * | ||
1121 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
1122 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1123 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1124 | 12 | * GNU Lesser General Public License for more details. | ||
1125 | 13 | * | ||
1126 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
1127 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
1128 | 16 | * | ||
1129 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
1130 | 18 | */ | ||
1131 | 19 | namespace Canonical.UbuntuOne.Client | ||
1132 | 20 | { | ||
1133 | 21 | /// <summary> | ||
1134 | 22 | /// A factory that can create devices. | ||
1135 | 23 | /// </summary> | ||
1136 | 24 | public interface IDeviceFactory | ||
1137 | 25 | { | ||
1138 | 26 | /// <summary> | ||
1139 | 27 | /// Creates a new device from the given data. | ||
1140 | 28 | /// </summary> | ||
1141 | 29 | /// <param name="description">A string with the description of the machine.</param> | ||
1142 | 30 | /// <param name="token">The token that identifies the device.</param> | ||
1143 | 31 | /// <param name="type">The type of device.</param> | ||
1144 | 32 | /// <returns>A device with the given data.</returns> | ||
1145 | 33 | IDevice Create(string description, string token, string type); | ||
1146 | 34 | } | ||
1147 | 35 | } | ||
1148 | 0 | 36 | ||
1149 | === added file 'src/Canonical.UbuntuOne.Client/IDeviceManager.cs' | |||
1150 | --- src/Canonical.UbuntuOne.Client/IDeviceManager.cs 1970-01-01 00:00:00 +0000 | |||
1151 | +++ src/Canonical.UbuntuOne.Client/IDeviceManager.cs 2010-11-14 21:31:15 +0000 | |||
1152 | @@ -0,0 +1,48 @@ | |||
1153 | 1 | /* Copyright 2010 Canonical Ltd. | ||
1154 | 2 | * | ||
1155 | 3 | * This file is part of UbuntuOne on Windows. | ||
1156 | 4 | * | ||
1157 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
1158 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
1159 | 7 | * as published by the Free Software Foundation. | ||
1160 | 8 | * | ||
1161 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
1162 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1163 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1164 | 12 | * GNU Lesser General Public License for more details. | ||
1165 | 13 | * | ||
1166 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
1167 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
1168 | 16 | * | ||
1169 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
1170 | 18 | */ | ||
1171 | 19 | using System.Collections.Generic; | ||
1172 | 20 | |||
1173 | 21 | namespace Canonical.UbuntuOne.Client | ||
1174 | 22 | { | ||
1175 | 23 | /// <summary> | ||
1176 | 24 | /// Interface to be implemented by those objects that can manage the different devices | ||
1177 | 25 | /// found in the Ubuntu One account. | ||
1178 | 26 | /// </summary> | ||
1179 | 27 | public interface IDeviceManager | ||
1180 | 28 | { | ||
1181 | 29 | /// <summary> | ||
1182 | 30 | /// Returns if the machine with the given token is th current machine. | ||
1183 | 31 | /// </summary> | ||
1184 | 32 | /// <param name="token">The token of the machine.</param> | ||
1185 | 33 | /// <returns>A bool stating if th token represents the current machine.</returns> | ||
1186 | 34 | bool IsCurrentMachine(string token); | ||
1187 | 35 | |||
1188 | 36 | /// <summary> | ||
1189 | 37 | /// Removes a machine with the given token from the machines synced with ubuntu one. | ||
1190 | 38 | /// </summary> | ||
1191 | 39 | /// <param name="king"></param> | ||
1192 | 40 | /// <param name="token"></param> | ||
1193 | 41 | void RemoveDevice(string king, string token); | ||
1194 | 42 | |||
1195 | 43 | /// <summary> | ||
1196 | 44 | /// Returns a list with the current machines synced in the account. | ||
1197 | 45 | /// </summary> | ||
1198 | 46 | IList<IDevice> GetSyncedDevices(); | ||
1199 | 47 | } | ||
1200 | 48 | } | ||
1201 | 0 | 49 | ||
1202 | === modified file 'src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs' | |||
1203 | === modified file 'src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs' | |||
1204 | --- src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs 2010-10-19 12:34:50 +0000 | |||
1205 | +++ src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs 2010-11-14 21:31:15 +0000 | |||
1206 | @@ -31,5 +31,12 @@ | |||
1207 | 31 | /// Updates the preferences that the user will use in the application. | 31 | /// Updates the preferences that the user will use in the application. |
1208 | 32 | /// </summary> | 32 | /// </summary> |
1209 | 33 | void UpdatePreferences(); | 33 | void UpdatePreferences(); |
1210 | 34 | |||
1211 | 35 | /// <summary> | ||
1212 | 36 | /// Removes the device with the given token from the system. | ||
1213 | 37 | /// </summary> | ||
1214 | 38 | /// <param name="deviceType">The type of the device to remove.</param> | ||
1215 | 39 | /// <param name="token">The token of the device to remove.</param> | ||
1216 | 40 | bool RemoveDevice(DeviceType deviceType, string token); | ||
1217 | 34 | } | 41 | } |
1218 | 35 | } | 42 | } |
1219 | 36 | 43 | ||
1220 | === modified file 'src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs' | |||
1221 | --- src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs 2010-10-13 10:38:57 +0000 | |||
1222 | +++ src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs 2010-11-14 21:31:15 +0000 | |||
1223 | @@ -17,6 +17,8 @@ | |||
1224 | 17 | * | 17 | * |
1225 | 18 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | 18 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1226 | 19 | */ | 19 | */ |
1227 | 20 | using System.Collections.Generic; | ||
1228 | 21 | |||
1229 | 20 | namespace Canonical.UbuntuOne.Client.Preferences | 22 | namespace Canonical.UbuntuOne.Client.Preferences |
1230 | 21 | { | 23 | { |
1231 | 22 | /// <summary> | 24 | /// <summary> |
1232 | @@ -26,6 +28,21 @@ | |||
1233 | 26 | public interface IPreferencesView | 28 | public interface IPreferencesView |
1234 | 27 | { | 29 | { |
1235 | 28 | /// <summary> | 30 | /// <summary> |
1236 | 31 | /// Sets the consumption of the plan so far. The value should be between 0 and 100. | ||
1237 | 32 | /// </summary> | ||
1238 | 33 | double Consumption { set; } | ||
1239 | 34 | |||
1240 | 35 | /// <summary> | ||
1241 | 36 | /// Sets the text used next the consumption. | ||
1242 | 37 | /// </summary> | ||
1243 | 38 | string ConsumptionText { set; } | ||
1244 | 39 | |||
1245 | 40 | /// <summary> | ||
1246 | 41 | /// Gets and sets the devices shown in the app. | ||
1247 | 42 | /// </summary> | ||
1248 | 43 | IList<IDevice> Devices { get; set; } | ||
1249 | 44 | |||
1250 | 45 | /// <summary> | ||
1251 | 29 | /// Allows to set the name that will be displayed in the UI. | 46 | /// Allows to set the name that will be displayed in the UI. |
1252 | 30 | /// </summary> | 47 | /// </summary> |
1253 | 31 | string UserName { set; } | 48 | string UserName { set; } |
1254 | @@ -79,5 +96,10 @@ | |||
1255 | 79 | /// Tell the view to show itself as a dialog. | 96 | /// Tell the view to show itself as a dialog. |
1256 | 80 | /// </summary> | 97 | /// </summary> |
1257 | 81 | void ShowDialog(); | 98 | void ShowDialog(); |
1258 | 99 | |||
1259 | 100 | /// <summary> | ||
1260 | 101 | /// Hides the dialog. | ||
1261 | 102 | /// </summary> | ||
1262 | 103 | void Hide(); | ||
1263 | 82 | } | 104 | } |
1264 | 83 | } | 105 | } |
1265 | 84 | 106 | ||
1266 | === modified file 'src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs' | |||
1267 | --- src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-11-11 11:43:38 +0000 | |||
1268 | +++ src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-11-14 21:31:15 +0000 | |||
1269 | @@ -18,9 +18,12 @@ | |||
1270 | 18 | */ | 18 | */ |
1271 | 19 | using System; | 19 | using System; |
1272 | 20 | using System.IO; | 20 | using System.IO; |
1273 | 21 | using System.Windows; | ||
1274 | 21 | using Canonical.Ubuntu.SSO; | 22 | using Canonical.Ubuntu.SSO; |
1275 | 22 | using Canonical.UbuntuOne.Common; | 23 | using Canonical.UbuntuOne.Common; |
1276 | 24 | using Canonical.UbuntuOne.Common.Net; | ||
1277 | 23 | using log4net; | 25 | using log4net; |
1278 | 26 | using Newtonsoft.Json.Linq; | ||
1279 | 24 | 27 | ||
1280 | 25 | namespace Canonical.UbuntuOne.Client.Preferences | 28 | namespace Canonical.UbuntuOne.Client.Preferences |
1281 | 26 | { | 29 | { |
1282 | @@ -36,6 +39,7 @@ | |||
1283 | 36 | private readonly object _loggerLock = new object(); | 39 | private readonly object _loggerLock = new object(); |
1284 | 37 | private const string EventName = "UbuntuOneAutoManualSync"; | 40 | private const string EventName = "UbuntuOneAutoManualSync"; |
1285 | 38 | private const string ApplicationName = "UbuntuOne"; | 41 | private const string ApplicationName = "UbuntuOne"; |
1286 | 42 | private const string ConsumptionUrl = "https://one.ubuntu.com/api/quota/"; | ||
1287 | 39 | 43 | ||
1288 | 40 | #endregion | 44 | #endregion |
1289 | 41 | 45 | ||
1290 | @@ -64,6 +68,11 @@ | |||
1291 | 64 | #region DI Properties | 68 | #region DI Properties |
1292 | 65 | 69 | ||
1293 | 66 | /// <summary> | 70 | /// <summary> |
1294 | 71 | /// Gets and sets the object that allows to mange the devices of the Ubuntu One. | ||
1295 | 72 | /// </summary> | ||
1296 | 73 | public IDeviceManager DeviceManager { get; set; } | ||
1297 | 74 | |||
1298 | 75 | /// <summary> | ||
1299 | 67 | /// Gets and sets the view used by this presenter. | 76 | /// Gets and sets the view used by this presenter. |
1300 | 68 | /// </summary> | 77 | /// </summary> |
1301 | 69 | public IPreferencesView PreferencesView { get; set; } | 78 | public IPreferencesView PreferencesView { get; set; } |
1302 | @@ -100,6 +109,11 @@ | |||
1303 | 100 | /// </summary> | 109 | /// </summary> |
1304 | 101 | public IMessageBox MessageBox { get; set; } | 110 | public IMessageBox MessageBox { get; set; } |
1305 | 102 | 111 | ||
1306 | 112 | /// <summary> | ||
1307 | 113 | /// Gets and sets the oauth used to access secure resources. | ||
1308 | 114 | /// </summary> | ||
1309 | 115 | public IOAuth OAuth { get; set; } | ||
1310 | 116 | |||
1311 | 103 | #endregion | 117 | #endregion |
1312 | 104 | 118 | ||
1313 | 105 | #region Helpers | 119 | #region Helpers |
1314 | @@ -142,14 +156,49 @@ | |||
1315 | 142 | MessageBox.ShowError("An error courred when trying to retrieve your credentials."); | 156 | MessageBox.ShowError("An error courred when trying to retrieve your credentials."); |
1316 | 143 | } | 157 | } |
1317 | 144 | 158 | ||
1318 | 159 | /// <summary> | ||
1319 | 160 | /// Returns the comsumption so far. | ||
1320 | 161 | /// </summary> | ||
1321 | 162 | /// <returns></returns> | ||
1322 | 163 | private double GetConsumption() | ||
1323 | 164 | { | ||
1324 | 165 | string token; | ||
1325 | 166 | string tokenSecret; | ||
1326 | 167 | string consumerKey; | ||
1327 | 168 | string consumerSecret; | ||
1328 | 169 | |||
1329 | 170 | // get the credentials | ||
1330 | 171 | SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey, | ||
1331 | 172 | out consumerSecret); | ||
1332 | 173 | var request = OAuth.MakeRequest(ConsumptionUrl, "GET", consumerKey, consumerSecret, token, tokenSecret); | ||
1333 | 174 | try | ||
1334 | 175 | { | ||
1335 | 176 | var response = request.GetResponse(); | ||
1336 | 177 | var data = new StreamReader(response.GetResponseStream()).ReadToEnd(); | ||
1337 | 178 | // parse the json string | ||
1338 | 179 | var consumption = JObject.Parse(data); | ||
1339 | 180 | return ((Int64)consumption["used"] * 100) / (Int64)consumption["total"]; | ||
1340 | 181 | } | ||
1341 | 182 | catch (Exception e) | ||
1342 | 183 | { | ||
1343 | 184 | throw new DeviceManagerException("Machine could not be listed.", e); | ||
1344 | 185 | } | ||
1345 | 186 | } | ||
1346 | 187 | |||
1347 | 145 | #endregion | 188 | #endregion |
1348 | 146 | 189 | ||
1349 | 147 | public void Show() | 190 | public void Show() |
1350 | 148 | { | 191 | { |
1351 | 149 | // set the preferences to be shown in the UI. | 192 | // set the preferences to be shown in the UI. |
1352 | 150 | PreferencesView.IsAutoSyncEnable = PreferencesManager.IsAutoSyncEnable; | 193 | PreferencesView.IsAutoSyncEnable = PreferencesManager.IsAutoSyncEnable; |
1353 | 194 | // set consumption | ||
1354 | 195 | var consumption = GetConsumption(); | ||
1355 | 196 | PreferencesView.Consumption = consumption; | ||
1356 | 197 | PreferencesView.ConsumptionText = string.Format("{0}% used", consumption); | ||
1357 | 198 | PreferencesView.Devices = DeviceManager.GetSyncedDevices(); | ||
1358 | 199 | |||
1359 | 151 | if (PreferencesManager.IsAutoSyncEnable) | 200 | if (PreferencesManager.IsAutoSyncEnable) |
1361 | 152 | PreferencesView.AutoSyncFrequency = PreferencesManager.AutoSyncFrequency; | 201 | PreferencesView.AutoSyncFrequency = PreferencesManager.AutoSyncFrequency; |
1362 | 153 | PreferencesView.ShowDialog(); | 202 | PreferencesView.ShowDialog(); |
1363 | 154 | } | 203 | } |
1364 | 155 | 204 | ||
1365 | @@ -170,5 +219,33 @@ | |||
1366 | 170 | PreferencesManager.Save(); | 219 | PreferencesManager.Save(); |
1367 | 171 | } | 220 | } |
1368 | 172 | 221 | ||
1369 | 222 | /// <summary> | ||
1370 | 223 | /// Removes the device with the given token from the system. | ||
1371 | 224 | /// </summary> | ||
1372 | 225 | /// <param name="deviceType">The type of the device to remove.</param> | ||
1373 | 226 | /// <param name="token">The token of the device to remove.</param> | ||
1374 | 227 | public bool RemoveDevice(DeviceType deviceType, string token) | ||
1375 | 228 | { | ||
1376 | 229 | var currentMachine = DeviceManager.IsCurrentMachine(token); | ||
1377 | 230 | if(currentMachine) | ||
1378 | 231 | { | ||
1379 | 232 | // we need to remove the current machine, we should tell the user | ||
1380 | 233 | if(MessageBox.ShowYesNo("Are you sure you want to remove this machine?",MessageBoxImage.Question) == MessageBoxResult.No) | ||
1381 | 234 | { | ||
1382 | 235 | return false; | ||
1383 | 236 | } | ||
1384 | 237 | } | ||
1385 | 238 | // just use the device manager for thise | ||
1386 | 239 | DeviceManager.RemoveDevice(deviceType == DeviceType.COMPUTER ? "computer" : "phone", token); | ||
1387 | 240 | // we remove the tokens in our machine | ||
1388 | 241 | if (currentMachine) | ||
1389 | 242 | { | ||
1390 | 243 | SSOCredentialsProvider.RemoveCredentials("UbuntuOne"); | ||
1391 | 244 | // we tell the user we will close the preferences since the | ||
1392 | 245 | MessageBox.ShowInformation("Preferences dialog will be closed because your removed the machine."); | ||
1393 | 246 | PreferencesView.Hide(); | ||
1394 | 247 | } | ||
1395 | 248 | return true; | ||
1396 | 249 | } | ||
1397 | 173 | } | 250 | } |
1398 | 174 | } | 251 | } |
1399 | 175 | 252 | ||
1400 | === modified file 'src/Canonical.UbuntuOne.Client/objects.xml' | |||
1401 | --- src/Canonical.UbuntuOne.Client/objects.xml 2010-10-19 12:34:50 +0000 | |||
1402 | +++ src/Canonical.UbuntuOne.Client/objects.xml 2010-11-14 21:31:15 +0000 | |||
1403 | @@ -14,4 +14,11 @@ | |||
1404 | 14 | type="Canonical.UbuntuOne.Client.Preferences.LoadPreferencesStartupTask, Canonical.UbuntuOne.Client" | 14 | type="Canonical.UbuntuOne.Client.Preferences.LoadPreferencesStartupTask, Canonical.UbuntuOne.Client" |
1405 | 15 | autowire="autodetect"/> | 15 | autowire="autodetect"/> |
1406 | 16 | 16 | ||
1407 | 17 | <object id="DeviceManager" | ||
1408 | 18 | type="Canonical.UbuntuOne.Client.DeviceManager, Canonical.UbuntuOne.Client" | ||
1409 | 19 | autowire="autodetect"/> | ||
1410 | 20 | |||
1411 | 21 | <object id="DeviceFactory" | ||
1412 | 22 | type="Canonical.UbuntuOne.Client.DeviceFactory, Canonical.UbuntuOne.Client" | ||
1413 | 23 | autowire="autodetect"/> | ||
1414 | 17 | </objects> | 24 | </objects> |
1415 | 18 | \ No newline at end of file | 25 | \ No newline at end of file |
1416 | 19 | 26 | ||
1417 | === modified file 'src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj' | |||
1418 | --- src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj 2010-10-21 10:17:18 +0000 | |||
1419 | +++ src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj 2010-11-14 21:31:15 +0000 | |||
1420 | @@ -106,7 +106,9 @@ | |||
1421 | 106 | <Compile Include="Net\HttpWebRequestFactory.cs" /> | 106 | <Compile Include="Net\HttpWebRequestFactory.cs" /> |
1422 | 107 | <Compile Include="Net\IHttpWebRequestFactory.cs" /> | 107 | <Compile Include="Net\IHttpWebRequestFactory.cs" /> |
1423 | 108 | <Compile Include="Net\IHttpWebRequest.cs" /> | 108 | <Compile Include="Net\IHttpWebRequest.cs" /> |
1424 | 109 | <Compile Include="Net\IOAuth.cs" /> | ||
1425 | 109 | <Compile Include="Net\IServiceCaller.cs" /> | 110 | <Compile Include="Net\IServiceCaller.cs" /> |
1426 | 111 | <Compile Include="Net\OAuth.cs" /> | ||
1427 | 110 | <Compile Include="Net\ServiceCaller.cs" /> | 112 | <Compile Include="Net\ServiceCaller.cs" /> |
1428 | 111 | <Compile Include="OperationContracts\IEventNotifier.cs" /> | 113 | <Compile Include="OperationContracts\IEventNotifier.cs" /> |
1429 | 112 | <Compile Include="OperationContracts\IPostInitDirectoryTask.cs" /> | 114 | <Compile Include="OperationContracts\IPostInitDirectoryTask.cs" /> |
1430 | @@ -213,6 +215,7 @@ | |||
1431 | 213 | <Reference Include="System" /> | 215 | <Reference Include="System" /> |
1432 | 214 | <Reference Include="System.Runtime.Serialization"> | 216 | <Reference Include="System.Runtime.Serialization"> |
1433 | 215 | </Reference> | 217 | </Reference> |
1434 | 218 | <Reference Include="System.Web" /> | ||
1435 | 216 | <Reference Include="System.Xaml" /> | 219 | <Reference Include="System.Xaml" /> |
1436 | 217 | <Reference Include="System.Xml" /> | 220 | <Reference Include="System.Xml" /> |
1437 | 218 | <Reference Include="WindowsBase"> | 221 | <Reference Include="WindowsBase"> |
1438 | 219 | 222 | ||
1439 | === renamed file 'src/Canonical.Ubuntu.SSO/IOAuth.cs' => 'src/Canonical.UbuntuOne.Common/Net/IOAuth.cs' | |||
1440 | --- src/Canonical.Ubuntu.SSO/IOAuth.cs 2010-10-05 09:49:29 +0000 | |||
1441 | +++ src/Canonical.UbuntuOne.Common/Net/IOAuth.cs 2010-11-14 21:31:15 +0000 | |||
1442 | @@ -20,8 +20,11 @@ | |||
1443 | 20 | using System.Collections.Generic; | 20 | using System.Collections.Generic; |
1444 | 21 | using System.Security.Cryptography; | 21 | using System.Security.Cryptography; |
1445 | 22 | 22 | ||
1447 | 23 | namespace Canonical.Ubuntu.SSO | 23 | namespace Canonical.UbuntuOne.Common.Net |
1448 | 24 | { | 24 | { |
1449 | 25 | ///<summary> | ||
1450 | 26 | /// Interface to be implemented by those objects that allows to perform Oauth operations. | ||
1451 | 27 | ///</summary> | ||
1452 | 25 | public interface IOAuth | 28 | public interface IOAuth |
1453 | 26 | { | 29 | { |
1454 | 27 | /// <summary> | 30 | /// <summary> |
1455 | @@ -118,5 +121,18 @@ | |||
1456 | 118 | /// </summary> | 121 | /// </summary> |
1457 | 119 | /// <returns></returns> | 122 | /// <returns></returns> |
1458 | 120 | string GenerateNonce(); | 123 | string GenerateNonce(); |
1459 | 124 | |||
1460 | 125 | /// <summary> | ||
1461 | 126 | /// Returns a request with an Oauth header that can be used to acess a secured resource. | ||
1462 | 127 | /// </summary> | ||
1463 | 128 | /// <param name="uri">The uri to be accessed.</param> | ||
1464 | 129 | /// <param name="httpMethod">The http method of the request.</param> | ||
1465 | 130 | /// <param name="consumerKey">The consumer key of the oauth.</param> | ||
1466 | 131 | /// <param name="consumerSecret">The consumer secret of the oauth.</param> | ||
1467 | 132 | /// <param name="token">The token of the oauth,</param> | ||
1468 | 133 | /// <param name="tokenSecret">The token secret of the oauth.</param> | ||
1469 | 134 | /// <returns>Returns a request that can be used to access a secure resource.</returns> | ||
1470 | 135 | IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret, | ||
1471 | 136 | string token, string tokenSecret); | ||
1472 | 121 | } | 137 | } |
1473 | 122 | } | 138 | } |
1474 | 123 | \ No newline at end of file | 139 | \ No newline at end of file |
1475 | 124 | 140 | ||
1476 | === renamed file 'src/Canonical.Ubuntu.SSO/OAuth.cs' => 'src/Canonical.UbuntuOne.Common/Net/OAuth.cs' | |||
1477 | --- src/Canonical.Ubuntu.SSO/OAuth.cs 2010-10-05 09:49:29 +0000 | |||
1478 | +++ src/Canonical.UbuntuOne.Common/Net/OAuth.cs 2010-11-14 21:31:15 +0000 | |||
1479 | @@ -1,13 +1,36 @@ | |||
1481 | 1 | using System; | 1 | /* Copyright 2010 Canonical Ltd. |
1482 | 2 | * | ||
1483 | 3 | * This file is part of UbuntuOne on Windows. | ||
1484 | 4 | * | ||
1485 | 5 | * UbuntuOne on Windows is free software: you can redistribute it and/or modify | ||
1486 | 6 | * it under the terms of the GNU Lesser General Public License version | ||
1487 | 7 | * as published by the Free Software Foundation. | ||
1488 | 8 | * | ||
1489 | 9 | * Ubuntu One on Windows is distributed in the hope that it will be useful, | ||
1490 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1491 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1492 | 12 | * GNU Lesser General Public License for more details. | ||
1493 | 13 | * | ||
1494 | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
1495 | 15 | * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. | ||
1496 | 16 | * | ||
1497 | 17 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> | ||
1498 | 18 | */ | ||
1499 | 19 | using System; | ||
1500 | 2 | using System.Security.Cryptography; | 20 | using System.Security.Cryptography; |
1501 | 3 | using System.Collections.Generic; | 21 | using System.Collections.Generic; |
1502 | 4 | using System.Text; | 22 | using System.Text; |
1503 | 5 | using System.Web; | 23 | using System.Web; |
1504 | 6 | 24 | ||
1506 | 7 | namespace Canonical.Ubuntu.SSO | 25 | namespace Canonical.UbuntuOne.Common.Net |
1507 | 8 | { | 26 | { |
1508 | 9 | public class OAuth : IOAuth | 27 | public class OAuth : IOAuth |
1509 | 10 | { | 28 | { |
1510 | 29 | #region Di properties | ||
1511 | 30 | |||
1512 | 31 | public IHttpWebRequestFactory HttpWebRequestFactory { get; set; } | ||
1513 | 32 | |||
1514 | 33 | #endregion | ||
1515 | 11 | 34 | ||
1516 | 12 | /// <summary> | 35 | /// <summary> |
1517 | 13 | /// Provides a predefined set of algorithms that are supported officially by the protocol | 36 | /// Provides a predefined set of algorithms that are supported officially by the protocol |
1518 | @@ -387,5 +410,32 @@ | |||
1519 | 387 | return Random.Next(123400, 9999999).ToString(); | 410 | return Random.Next(123400, 9999999).ToString(); |
1520 | 388 | } | 411 | } |
1521 | 389 | 412 | ||
1522 | 413 | |||
1523 | 414 | /// <summary> | ||
1524 | 415 | /// Creates an oauth request that can access a protected web resource. | ||
1525 | 416 | /// </summary> | ||
1526 | 417 | /// <param name="uri">The uri where the resource is found.</param> | ||
1527 | 418 | /// <param name="httpMethod">The request berb to be used.</param> | ||
1528 | 419 | /// <param name="consumerKey">Consumer key from oauth.</param> | ||
1529 | 420 | /// <param name="consumerSecret">Consumer secret from oauth.</param> | ||
1530 | 421 | /// <param name="token">Token from oauth.</param> | ||
1531 | 422 | /// <param name="tokenSecret">Token secret from oauth.</param> | ||
1532 | 423 | /// <returns>A webrequest that can be used to access the resource.</returns> | ||
1533 | 424 | public IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret, string token, string tokenSecret) | ||
1534 | 425 | { | ||
1535 | 426 | // Form the full REST request url | ||
1536 | 427 | var url = new Uri(uri); | ||
1537 | 428 | string normUrl; | ||
1538 | 429 | string normParams; | ||
1539 | 430 | |||
1540 | 431 | // get oauth header | ||
1541 | 432 | var authHeader = GenerateHeaderWithSignature(url, string.Empty, consumerKey, consumerSecret, | ||
1542 | 433 | token, tokenSecret, httpMethod, GenerateTimeStamp(), GenerateNonce(), SignatureTypes.HMACSHA1, | ||
1543 | 434 | out normUrl, out normParams); | ||
1544 | 435 | |||
1545 | 436 | var request = HttpWebRequestFactory.Create(url); | ||
1546 | 437 | request.Headers.Add(authHeader.Key, authHeader.Value); | ||
1547 | 438 | return request; | ||
1548 | 439 | } | ||
1549 | 390 | } | 440 | } |
1550 | 391 | } | 441 | } |
1551 | 392 | \ No newline at end of file | 442 | \ No newline at end of file |
1552 | 393 | 443 | ||
1553 | === modified file 'src/Canonical.UbuntuOne.Common/objects.xml' | |||
1554 | --- src/Canonical.UbuntuOne.Common/objects.xml 2010-10-21 10:17:18 +0000 | |||
1555 | +++ src/Canonical.UbuntuOne.Common/objects.xml 2010-11-14 21:31:15 +0000 | |||
1556 | @@ -56,6 +56,10 @@ | |||
1557 | 56 | <!-- Net Objects --> | 56 | <!-- Net Objects --> |
1558 | 57 | <!-- ######################################################################################## --> | 57 | <!-- ######################################################################################## --> |
1559 | 58 | 58 | ||
1560 | 59 | <object id="OAuth" | ||
1561 | 60 | type="Canonical.UbuntuOne.Common.Net.OAuth , Canonical.UbuntuOne.Common" | ||
1562 | 61 | autowire="autodetect"/> | ||
1563 | 62 | |||
1564 | 59 | <object id="HttpWebRequestFactory" | 63 | <object id="HttpWebRequestFactory" |
1565 | 60 | type="Canonical.UbuntuOne.Common.Net.HttpWebRequestFactory, Canonical.UbuntuOne.Common" /> | 64 | type="Canonical.UbuntuOne.Common.Net.HttpWebRequestFactory, Canonical.UbuntuOne.Common" /> |
1566 | 61 | 65 |