Merge lp:~mandel/ubuntuone-windows-installer/manage_devices into lp:ubuntuone-windows-installer/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
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+40816@code.launchpad.net

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
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs'
--- src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs 2010-10-05 09:49:29 +0000
+++ src/Canonical.Ubuntu.SSO.Tests/SSOLoginProcessorFixture.cs 2010-11-14 21:31:15 +0000
@@ -54,7 +54,6 @@
54 _processor = new SSOLoginProcessor54 _processor = new SSOLoginProcessor
55 {55 {
56 Authentications = _auth,56 Authentications = _auth,
57 HttpWebRequestFactory = _requestFactory,
58 Keyring = _keyring,57 Keyring = _keyring,
59 OAuth = _oauth,58 OAuth = _oauth,
60 SSOCredentialsEncoder = _encode59 SSOCredentialsEncoder = _encode
6160
=== modified file 'src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj'
--- src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj 2010-10-12 13:07:02 +0000
+++ src/Canonical.Ubuntu.SSO/Canonical.Ubuntu.SSO.csproj 2010-11-14 21:31:15 +0000
@@ -89,13 +89,11 @@
89 <Compile Include="IDataProtector.cs" />89 <Compile Include="IDataProtector.cs" />
90 <Compile Include="ILoginOrRegisterView.cs" />90 <Compile Include="ILoginOrRegisterView.cs" />
91 <Compile Include="ILoginView.cs" />91 <Compile Include="ILoginView.cs" />
92 <Compile Include="IOAuth.cs" />
93 <Compile Include="ISSOCredentialsEncoder.cs" />92 <Compile Include="ISSOCredentialsEncoder.cs" />
94 <Compile Include="ISSOLoginProcessor.cs" />93 <Compile Include="ISSOLoginProcessor.cs" />
95 <Compile Include="JsonSSOCredentialsEncoder.cs" />94 <Compile Include="JsonSSOCredentialsEncoder.cs" />
96 <Compile Include="Keyring.cs" />95 <Compile Include="Keyring.cs" />
97 <Compile Include="LoginCredentialsEventArgs.cs" />96 <Compile Include="LoginCredentialsEventArgs.cs" />
98 <Compile Include="OAuth.cs" />
99 <Compile Include="Service\Account.cs" />97 <Compile Include="Service\Account.cs" />
100 <Compile Include="Service\AccountDiff.cs" />98 <Compile Include="Service\AccountDiff.cs" />
101 <Compile Include="Service\AccountFull.cs" />99 <Compile Include="Service\AccountFull.cs" />
102100
=== modified file 'src/Canonical.Ubuntu.SSO/IKeyring.cs'
--- src/Canonical.Ubuntu.SSO/IKeyring.cs 2010-09-16 16:18:56 +0000
+++ src/Canonical.Ubuntu.SSO/IKeyring.cs 2010-11-14 21:31:15 +0000
@@ -37,6 +37,13 @@
37 void CreateSecret(string keyringName, string applicationName, string secret);37 void CreateSecret(string keyringName, string applicationName, string secret);
3838
39 /// <summary>39 /// <summary>
40 /// Removes the given secret from the keyring.
41 /// </summary>
42 /// <param name="keyring">The keyring where th esecret is found.</param>
43 /// <param name="applicationName">The name of the application.</param>
44 void RemoveSecret(string keyring, string applicationName);
45
46 /// <summary>
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.
41 /// </summary>48 /// </summary>
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>
4350
=== modified file 'src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs'
--- src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs 2010-10-18 10:53:55 +0000
+++ src/Canonical.Ubuntu.SSO/ISSOCredentialsProvider.cs 2010-11-14 21:31:15 +0000
@@ -72,6 +72,22 @@
72 /// </summary>72 /// </summary>
73 void LoginOrRegisterToGetCredentials();73 void LoginOrRegisterToGetCredentials();
7474
75 /// <summary>
76 /// Returns the credentials of the user and requests a login if necesary.
77 /// </summary>
78 /// <param name="applicationName">The name of the application requesting the info.</param>
79 /// <param name="token">The token part of the oauth.</param>
80 /// <param name="tokenSecret">The token secret of the part of the oauth.</param>
81 /// <param name="consumerKey">The consumer key of the oauth.</param>
82 /// <param name="consumerSecret">The consumer secret of the oauth.</param>
83 void LoginToGetCredentials(string applicationName, out string token, out string tokenSecret, out string consumerKey, out string consumerSecret);
84
85 /// <summary>
86 /// Removes the credentials for the given application name in the machine.
87 /// </summary>
88 /// <param name="applicationName">The name of the applications whose credentials we want to remove.</param>
89 void RemoveCredentials(string applicationName);
90
75 #endregion91 #endregion
7692
77 }93 }
7894
=== modified file 'src/Canonical.Ubuntu.SSO/Keyring.cs'
--- src/Canonical.Ubuntu.SSO/Keyring.cs 2010-10-06 18:29:07 +0000
+++ src/Canonical.Ubuntu.SSO/Keyring.cs 2010-11-14 21:31:15 +0000
@@ -17,6 +17,7 @@
17 * 17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */19 */
20using System;
20using System.Collections.Generic;21using System.Collections.Generic;
21using System.Linq;22using System.Linq;
22using System.Security.Cryptography;23using System.Security.Cryptography;
@@ -272,6 +273,26 @@
272 }273 }
273274
274 /// <summary>275 /// <summary>
276 /// Removes the given secret from the keyring.
277 /// </summary>
278 /// <param name="keyringName">The keyring where th esecret is found.</param>
279 /// <param name="applicationName">The name of the application.</param>
280 public void RemoveSecret(string keyringName, string applicationName)
281 {
282 ValidateArgs.Begin()
283 .IsNotNullOrEmpty(keyringName, "keyringName")
284 .IsNotNullOrEmpty(applicationName, "applicationName")
285 .Check();
286 if(KeyringExist(keyringName))
287 {
288 using(var keyring = OpenKeyring(keyringName))
289 {
290 keyring.DeleteValue(applicationName);
291 }
292 }
293 }
294
295 /// <summary>
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.
276 /// </summary>297 /// </summary>
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>
278299
=== modified file 'src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs'
--- src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-20 11:32:24 +0000
+++ src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-11-14 21:31:15 +0000
@@ -157,6 +157,71 @@
157 throw new NotImplementedException();157 throw new NotImplementedException();
158 }158 }
159159
160 /// <summary>
161 /// Returns the credentials of the user and requests a login if necesary.
162 /// </summary>
163 /// <param name="token">The token part of the oauth.</param>
164 /// <param name="tokenSecret">The token secret of the part of the oauth.</param>
165 /// <param name="consumerKey">The consumer key of the oauth.</param>
166 /// <param name="consumerSecret">The consumer secret of the oauth.</param>
167 public void LoginToGetCredentials(string applicationName, out string token, out string tokenSecret, out string consumerKey, out string consumerSecret)
168 {
169 token = null;
170 tokenSecret = null;
171 consumerKey = null;
172 consumerSecret = null;
173 try
174 {
175 // try to get the credentials from the keyring
176 var secret = Keyring.GetSecretByName(KeyringName, ApplicationName);
177 if (secret == null)
178 {
179 // we need to use the processor to get the login info
180 if (LoginView.ViewDispatcher.Dispatch(() => LoginView.IsShown))
181 return;
182
183 if (LoginView.ViewDispatcher.Dispatch(() => LoginView.ShowDialog() != MessageBoxResult.Cancel))
184 {
185 var tokenName = string.Format(ApplicationTokenName, Environment.MachineName);
186 secret = SSOLoginProcessor.Login(
187 LoginView.ViewDispatcher.Dispatch(() => LoginView.EmailAddress),
188 LoginView.ViewDispatcher.Dispatch(() => LoginView.Password),
189 tokenName);
190 // save the credentials in the keyring
191 // TODO: We have an issue here since we have more than one listening for the same credntials of Ubuntu One
192 Keyring.CreateSecret(KeyringName, applicationName, secret);
193 }
194 else
195 {
196 return;
197 }
198 }
199 // we execute the credentials found event
200 if (!string.IsNullOrEmpty(secret) && OnCredentialsFound != null)
201 {
202 SSOLoginProcessor.SSOCredentialsEncoder.Decode(secret, out token, out tokenSecret, out consumerKey, out consumerSecret);
203 }
204 }
205 catch (SSOLoginException e)
206 {
207 // TODO: Show message!
208 }
209 catch (Exception e)
210 {
211 // TODO: Show message!
212 }
213 }
214
215 /// <summary>
216 /// Removes the credentials for the given application name in the machine.
217 /// </summary>
218 /// <param name="applicationName">The name of the applications whose credentials we want to remove.</param>
219 public void RemoveCredentials(string applicationName)
220 {
221 // TODO: Currently the application name is hardcoded!
222 Keyring.RemoveSecret(KeyringName, ApplicationName);
223 }
224
160 #endregion225 #endregion
161 }226 }
162}227}
163228
=== modified file 'src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs'
--- src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs 2010-10-05 15:20:36 +0000
+++ src/Canonical.Ubuntu.SSO/SSOLoginProcessor.cs 2010-11-14 21:31:15 +0000
@@ -58,40 +58,11 @@
58 /// </summary>58 /// </summary>
59 public IOAuth OAuth { get; set; }59 public IOAuth OAuth { get; set; }
6060
61 public IHttpWebRequestFactory HttpWebRequestFactory { get; set; }
62
63 #endregion61 #endregion
6462
65 #region Helper methods}63 #region Helper methods}
6664
67 /// <summary>65 /// <summary>
68 /// Creates an oauth request that can access a protected web resource.
69 /// </summary>
70 /// <param name="uri">The uri where the resource is found.</param>
71 /// <param name="httpMethod">The request berb to be used.</param>
72 /// <param name="consumerKey">Consumer key from oauth.</param>
73 /// <param name="consumerSecret">Consumer secret from oauth.</param>
74 /// <param name="token">Token from oauth.</param>
75 /// <param name="tokenSecret">Token secret from oauth.</param>
76 /// <returns>A webrequest that can be used to access the resource.</returns>
77 public IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret, string token, string tokenSecret)
78 {
79 // Form the full REST request url
80 var url = new Uri(uri);
81 string normUrl;
82 string normParams;
83
84 // get oauth header
85 var authHeader = OAuth.GenerateHeaderWithSignature(url, string.Empty, consumerKey, consumerSecret,
86 token, tokenSecret, httpMethod, OAuth.GenerateTimeStamp(), OAuth.GenerateNonce(), SSO.OAuth.SignatureTypes.HMACSHA1,
87 out normUrl, out normParams);
88
89 var request = HttpWebRequestFactory.Create(url);
90 request.Headers.Add(authHeader.Key, authHeader.Value);
91 return request;
92 }
93
94 /// <summary>
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.
96 /// </summary>67 /// </summary>
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>
@@ -102,7 +73,7 @@
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)
103 {74 {
104 // ping the service to make it download the tokens75 // ping the service to make it download the tokens
105 var pingRequest = MakeRequest(Constants.PingUrl + email, "GET", consumerKey, consumerSecret,76 var pingRequest = OAuth.MakeRequest(Constants.PingUrl + email, "GET", consumerKey, consumerSecret,
106 token, tokenSecret);77 token, tokenSecret);
107 try78 try
108 {79 {
10980
=== modified file 'src/Canonical.Ubuntu.SSO/objects.xml'
--- src/Canonical.Ubuntu.SSO/objects.xml 2010-10-05 15:20:36 +0000
+++ src/Canonical.Ubuntu.SSO/objects.xml 2010-11-14 21:31:15 +0000
@@ -19,9 +19,6 @@
19 type="Canonical.Ubuntu.SSO.JsonSSOCredentialsEncoder , Canonical.Ubuntu.SSO"19 type="Canonical.Ubuntu.SSO.JsonSSOCredentialsEncoder , Canonical.Ubuntu.SSO"
20 autowire="autodetect"/>20 autowire="autodetect"/>
2121
22 <object id="OAuth"
23 type="Canonical.Ubuntu.SSO.OAuth , Canonical.Ubuntu.SSO"
24 autowire="autodetect"/>
25 22
26 <!-- The actual interesting objects to perform the SSO -->23 <!-- The actual interesting objects to perform the SSO -->
2724
2825
=== modified file 'src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj'
--- src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj 2010-10-12 13:07:02 +0000
+++ src/Canonical.UbuntuOne.Client.Test/Canonical.UbuntuOne.Client.Test.csproj 2010-11-14 21:31:15 +0000
@@ -82,6 +82,7 @@
82 <Compile Include="..\Version.cs">82 <Compile Include="..\Version.cs">
83 <Link>Properties\Version.cs</Link>83 <Link>Properties\Version.cs</Link>
84 </Compile>84 </Compile>
85 <Compile Include="DeviceFactoryFixture.cs" />
85 <Compile Include="Notification\NotificationEventArgsFixture.cs" />86 <Compile Include="Notification\NotificationEventArgsFixture.cs" />
86 <Compile Include="Notification\NotificationPresenterFixture.cs" />87 <Compile Include="Notification\NotificationPresenterFixture.cs" />
87 <Compile Include="Notification\OperationCompletenessEventArgsFixture.cs" />88 <Compile Include="Notification\OperationCompletenessEventArgsFixture.cs" />
@@ -90,6 +91,10 @@
90 <Compile Include="Properties\AssemblyInfo.cs" />91 <Compile Include="Properties\AssemblyInfo.cs" />
91 </ItemGroup>92 </ItemGroup>
92 <ItemGroup>93 <ItemGroup>
94 <ProjectReference Include="..\Canonical.Ubuntu.SSO\Canonical.Ubuntu.SSO.csproj">
95 <Project>{9460A771-2589-45DA-9618-9FE8BB7D16E8}</Project>
96 <Name>Canonical.Ubuntu.SSO</Name>
97 </ProjectReference>
93 <ProjectReference Include="..\Canonical.UbuntuOne.Client\Canonical.UbuntuOne.Client.csproj">98 <ProjectReference Include="..\Canonical.UbuntuOne.Client\Canonical.UbuntuOne.Client.csproj">
94 <Project>{7467483A-D6D5-4362-8DF4-57A7254EB569}</Project>99 <Project>{7467483A-D6D5-4362-8DF4-57A7254EB569}</Project>
95 <Name>Canonical.UbuntuOne.Client</Name>100 <Name>Canonical.UbuntuOne.Client</Name>
96101
=== added file 'src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs'
--- src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client.Test/DeviceFactoryFixture.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,92 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19using NUnit.Framework;
20using Rhino.Mocks;
21
22namespace Canonical.UbuntuOne.Client.Test
23{
24 [TestFixture]
25 public class DeviceFactoryFixture
26 {
27 #region Variables
28
29 private IDeviceManager _deviceManager;
30 private MockRepository _mocks;
31 private DeviceFactory _factory;
32
33 #endregion
34
35 #region Setup
36
37 [SetUp]
38 public void SetUp()
39 {
40 _mocks = new MockRepository();
41 _deviceManager = _mocks.StrictMock<IDeviceManager>();
42 _factory = new DeviceFactory {DeviceManager = _deviceManager};
43 }
44
45 #endregion
46
47 #region Tests
48
49 [TestCase("firstToken", "batman", "computer")]
50 [TestCase("secondToken", "robin", "computer")]
51 [TestCase("thirdToken", "blah blah", "phone")]
52 public void CreateCurrentDeviceTest(string token, string description, string kind)
53 {
54 using (_mocks.Record())
55 {
56 Expect.Call(_deviceManager.IsCurrentMachine(token))
57 .Repeat.Once()
58 .Return(true);
59 }
60 using(_mocks.Playback())
61 {
62 var device = _factory.Create(description, token, kind);
63 Assert.AreEqual(token, device.Token);
64 Assert.AreEqual(DeviceFactory.CurrentMachine, device.Description);
65 Assert.AreEqual(kind == "computer" ? DeviceType.COMPUTER : DeviceType.PHONE, device.Type);
66 }
67 }
68
69 [TestCase("firstToken", "batman", "computer")]
70 [TestCase("secondToken", "robin", "computer")]
71 [TestCase("thirdToken", "blah blah", "phone")]
72 public void CreateOtherDeviceTest(string token, string description, string kind)
73 {
74 using (_mocks.Record())
75 {
76 Expect.Call(_deviceManager.IsCurrentMachine(token))
77 .Repeat.Once()
78 .Return(false);
79 }
80 using (_mocks.Playback())
81 {
82 var device = _factory.Create(description, token, kind);
83 Assert.AreEqual(token, device.Token);
84 Assert.AreEqual(description, device.Description);
85 Assert.AreEqual(kind == "computer" ? DeviceType.COMPUTER : DeviceType.PHONE, device.Type);
86 }
87 }
88
89 #endregion
90
91 }
92}
093
=== modified file 'src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj'
--- src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj 2010-11-02 23:28:01 +0000
+++ src/Canonical.UbuntuOne.Client.Views/Canonical.UbuntuOne.Client.Views.csproj 2010-11-14 21:31:15 +0000
@@ -86,6 +86,9 @@
86 <Compile Include="BetaView.xaml.cs">86 <Compile Include="BetaView.xaml.cs">
87 <DependentUpon>BetaView.xaml</DependentUpon>87 <DependentUpon>BetaView.xaml</DependentUpon>
88 </Compile>88 </Compile>
89 <Compile Include="DeviceControl.xaml.cs">
90 <DependentUpon>DeviceControl.xaml</DependentUpon>
91 </Compile>
89 <Compile Include="WindowsSettingsView.xaml.cs">92 <Compile Include="WindowsSettingsView.xaml.cs">
90 <DependentUpon>WindowsSettingsView.xaml</DependentUpon>93 <DependentUpon>WindowsSettingsView.xaml</DependentUpon>
91 </Compile>94 </Compile>
@@ -97,6 +100,10 @@
97 <SubType>Designer</SubType>100 <SubType>Designer</SubType>
98 <Generator>MSBuild:Compile</Generator>101 <Generator>MSBuild:Compile</Generator>
99 </Page>102 </Page>
103 <Page Include="DeviceControl.xaml">
104 <SubType>Designer</SubType>
105 <Generator>MSBuild:Compile</Generator>
106 </Page>
100 <Page Include="DevicesView.xaml">107 <Page Include="DevicesView.xaml">
101 <SubType>Designer</SubType>108 <SubType>Designer</SubType>
102 <Generator>MSBuild:Compile</Generator>109 <Generator>MSBuild:Compile</Generator>
103110
=== added file 'src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml'
--- src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml 2010-11-14 21:31:15 +0000
@@ -0,0 +1,23 @@
1<UserControl x:Class="Canonical.UbuntuOne.Client.Views.DeviceControl"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6 mc:Ignorable="d"
7 d:DesignHeight="64" d:DesignWidth="300" BorderThickness="2 1 2 1">
8 <Grid>
9 <Grid.ColumnDefinitions>
10 <ColumnDefinition Width="64"/>
11 <ColumnDefinition Width="*"/>
12 </Grid.ColumnDefinitions>
13 <Image Name="DeviceTypeImage" Grid.Column="0" />
14 <Grid Grid.Column="1">
15 <Grid.RowDefinitions>
16 <RowDefinition Height="Auto"/>
17 <RowDefinition Height="Auto"/>
18 </Grid.RowDefinitions>
19 <Label Name="DescriptionLabel" Grid.Row="0" Margin="3" HorizontalAlignment="Center">Description</Label>
20 <Button Name="RemoveButton" Grid.Row="1" Margin="3" Width="Auto" HorizontalAlignment="Center" Click="OnRemoveButtonClick">Remove</Button>
21 </Grid>
22 </Grid>
23</UserControl>
024
=== added file 'src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs'
--- src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client.Views/DeviceControl.xaml.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,51 @@
1using System.Windows.Input;
2using Canonical.UbuntuOne.Client.Preferences;
3
4namespace Canonical.UbuntuOne.Client.Views
5{
6 /// <summary>
7 /// Interaction logic for DeviceControl.xaml
8 /// </summary>
9 public partial class DeviceControl
10 {
11 #region Variables
12
13 private IDevice _device;
14
15 #endregion
16
17 #region Properties
18
19 public IDevice Device
20 {
21 get { return _device; }
22 set
23 {
24 _device = value;
25 DescriptionLabel.Content = _device.Description;
26 }
27 }
28
29 /// <summary>
30 /// Gets and sets the presenter used to manage the user preferences.
31 /// </summary>
32 public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; }
33
34 #endregion
35
36 public DeviceControl()
37 {
38 InitializeComponent();
39 }
40
41 private void OnRemoveButtonClick(object sender, System.Windows.RoutedEventArgs e)
42 {
43 if (PreferencesDialogPresenter == null) return;
44 Mouse.OverrideCursor = Cursors.Wait;
45 var removed = PreferencesDialogPresenter.RemoveDevice(Device.Type, Device.Token);
46 Mouse.OverrideCursor = null;
47 if(removed)
48 Visibility = System.Windows.Visibility.Collapsed;
49 }
50 }
51}
052
=== modified file 'src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml'
--- src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml 2010-10-13 09:56:20 +0000
+++ src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml 2010-11-14 21:31:15 +0000
@@ -24,15 +24,15 @@
24 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"24 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
25 xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources"25 xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources"
26 mc:Ignorable="d" 26 mc:Ignorable="d"
27 d:DesignHeight="300" d:DesignWidth="300">27 d:DesignHeight="298" d:DesignWidth="300">
28 <Grid>28 <Grid>
29 <Grid.RowDefinitions>29 <Grid.RowDefinitions>
30 <RowDefinition Height="75" />30 <RowDefinition Height="Auto" />
31 <RowDefinition Height="*" />31 <RowDefinition Height="*" />
32 </Grid.RowDefinitions>32 </Grid.RowDefinitions>
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}"/>
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">
35 <StackPanel Name="MachinesContent">35 <StackPanel Name="MachinesContent" Margin="3">
36 36
37 </StackPanel>37 </StackPanel>
38 </ScrollViewer>38 </ScrollViewer>
3939
=== modified file 'src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs'
--- src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs 2010-10-20 23:09:36 +0000
+++ src/Canonical.UbuntuOne.Client.Views/DevicesView.xaml.cs 2010-11-14 21:31:15 +0000
@@ -17,7 +17,9 @@
17 * 17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */19 */
20using System.Collections.Generic;
20using System.Windows.Controls;21using System.Windows.Controls;
22using Canonical.UbuntuOne.Client.Preferences;
2123
22namespace Canonical.UbuntuOne.Client.Views24namespace Canonical.UbuntuOne.Client.Views
23{25{
@@ -28,6 +30,34 @@
28 {30 {
29 #region Properties31 #region Properties
3032
33 private IList<IDevice> _devices;
34
35 #endregion
36
37 #region Properties
38
39 /// <summary>
40 /// Gets and sets the presenter used to manage the user preferences.
41 /// </summary>
42 public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; }
43
44 ///<summary>
45 /// Gets and sets the devices shown in the dialog.
46 ///</summary>
47 public IList<IDevice> Devices
48 {
49 get { return _devices; }
50 set
51 {
52 _devices = value;
53 MachinesContent.Children.RemoveRange(0, MachinesContent.Children.Count);
54 foreach (var currentDevice in value)
55 {
56 var newControl = new DeviceControl {Device = currentDevice, PreferencesDialogPresenter = PreferencesDialogPresenter};
57 MachinesContent.Children.Add(newControl);
58 }
59 }
60 }
3161
32 #endregion62 #endregion
3363
@@ -38,5 +68,6 @@
38 {68 {
39 InitializeComponent();69 InitializeComponent();
40 }70 }
71
41 }72 }
42}73}
4374
=== modified file 'src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml'
--- src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml 2010-11-02 23:28:01 +0000
+++ src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml 2010-11-14 21:31:15 +0000
@@ -22,7 +22,7 @@
22 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 22 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
23 xmlns:Views="clr-namespace:Canonical.UbuntuOne.Client.Views" 23 xmlns:Views="clr-namespace:Canonical.UbuntuOne.Client.Views"
24 xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources"24 xmlns:resx="clr-namespace:Canonical.UbuntuOne.Client.Views.Resources"
25 Title="{x:Static resx:Resources.PreferencesDialogTitle}" Height="450" Width="400">25 Title="{x:Static resx:Resources.PreferencesDialogTitle}" Height="450" Width="400" ResizeMode="NoResize">
26 <Grid Margin="3">26 <Grid Margin="3">
27 <Grid.RowDefinitions>27 <Grid.RowDefinitions>
28 <RowDefinition Height="50" />28 <RowDefinition Height="50" />
@@ -39,25 +39,26 @@
39 <ColumnDefinition Width="*" />39 <ColumnDefinition Width="*" />
40 <ColumnDefinition Width="*" />40 <ColumnDefinition Width="*" />
41 </Grid.ColumnDefinitions>41 </Grid.ColumnDefinitions>
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"/>
43 <Label Name="ConsumptionLabel" Grid.Column="1">Unknown</Label>43 <Label Name="ConsumptionLabel" Grid.Column="1">Unknown</Label>
44 </Grid>44 </Grid>
45 <Label Name="StatusLabel" Grid.Row="1">Disconnected</Label>45 <Label Name="StatusLabel" Grid.Row="1">Disconnected</Label>
46 </Grid>46 </Grid>
47 <TabControl Margin="3" Grid.Row="1">47 <TabControl Margin="3" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
48 <TabItem Header="{x:Static resx:Resources.PreferencesDialogDevicesTabHeader}" >
49 <Views:DevicesView x:Name="DevicesTab" Height="300" HorizontalAlignment="Stretch"/>
50 </TabItem>
51 <TabItem Header="{x:Static resx:Resources.PreferencesDialogWindowsTabHeader}">
52 <Views:WindowsSettingsView x:Name="WindowsTab" Height="300" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
53 </TabItem>
48 <TabItem Header="Beta" >54 <TabItem Header="Beta" >
49 <Views:BetaView x:Name="BetaTab" Height="300" IsEnabled="False"/>55 <Views:BetaView x:Name="BetaTab" Height="300" IsEnabled="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
50 </TabItem>
51 <TabItem Header="{x:Static resx:Resources.PreferencesDialogWindowsTabHeader}">
52 <Views:WindowsSettingsView x:Name="WindowsTab" Height="300" />
53 </TabItem>56 </TabItem>
54 <!--57 <!--
55 <TabItem Header="{x:Static resx:Resources.PreferencesDialogAccountTabHeader}" >58 <TabItem Header="{x:Static resx:Resources.PreferencesDialogAccountTabHeader}" >
56 <Views:AccountView x:Name="AccountsTab" Height="300" IsEnabled="False"/>59 <Views:AccountView x:Name="AccountsTab" Height="300" IsEnabled="False"/>
57 </TabItem>60 </TabItem>
58 <TabItem Header="{x:Static resx:Resources.PreferencesDialogDevicesTabHeader}" >61
59 <Views:DevicesView x:Name="DevicesTab" Height="300" IsEnabled="False"/>
60 </TabItem>
61 <TabItem Header="{x:Static resx:Resources.PreferencesDialogServicesTabHeader}" >62 <TabItem Header="{x:Static resx:Resources.PreferencesDialogServicesTabHeader}" >
62 <Views:ServicesView x:Name="ServicesTab" Height="300" IsEnabled="False"/>63 <Views:ServicesView x:Name="ServicesTab" Height="300" IsEnabled="False"/>
63 </TabItem> 64 </TabItem>
6465
=== modified file 'src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs'
--- src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs 2010-11-02 23:28:01 +0000
+++ src/Canonical.UbuntuOne.Client.Views/PreferencesDialog.xaml.cs 2010-11-14 21:31:15 +0000
@@ -16,6 +16,8 @@
16 * 16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */18 */
19using System;
20using System.Collections.Generic;
19using System.Windows;21using System.Windows;
20using Canonical.UbuntuOne.Client.Preferences;22using Canonical.UbuntuOne.Client.Preferences;
2123
@@ -26,12 +28,26 @@
26 /// </summary>28 /// </summary>
27 public partial class PreferencesDialog : Window, IPreferencesView29 public partial class PreferencesDialog : Window, IPreferencesView
28 {30 {
31 #region Variables
32
33 private IPreferencesDialogPresenter _presenter;
34
35 #endregion
36
29 #region DI properties37 #region DI properties
3038
31 /// <summary>39 /// <summary>
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.
33 /// </summary>41 /// </summary>
34 public IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; }42 public IPreferencesDialogPresenter PreferencesDialogPresenter
43 {
44 get { return _presenter; }
45 set
46 {
47 _presenter = value;
48 DevicesTab.PreferencesDialogPresenter = value;
49 }
50 }
3551
36 #endregion52 #endregion
3753
@@ -88,6 +104,31 @@
88 // set { ServicesTab.IsMusicSynced = value; }104 // set { ServicesTab.IsMusicSynced = value; }
89 //}105 //}
90106
107 /// <summary>
108 /// Sets the consumption of the plan so far. The value should be between 0 and 100.
109 /// </summary>
110 public double Consumption
111 {
112 set { ConsumptionProgressbar.Value = value; }
113 }
114
115 /// <summary>
116 /// Sets the text used next the consumption.
117 /// </summary>
118 public string ConsumptionText
119 {
120 set { ConsumptionLabel.Content = value; }
121 }
122
123 /// <summary>
124 /// Gets and sets the devices shown in the app.
125 /// </summary>
126 public IList<IDevice> Devices
127 {
128 get { return DevicesTab.Devices; }
129 set { DevicesTab.Devices = value; }
130 }
131
91 public string UserName132 public string UserName
92 {133 {
93 set { }134 set { }
94135
=== modified file 'src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj'
--- src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj 2010-11-11 11:44:38 +0000
+++ src/Canonical.UbuntuOne.Client/Canonical.UbuntuOne.Client.csproj 2010-11-14 21:31:15 +0000
@@ -74,6 +74,13 @@
74 <Compile Include="..\Version.cs">74 <Compile Include="..\Version.cs">
75 <Link>Properties\Version.cs</Link>75 <Link>Properties\Version.cs</Link>
76 </Compile>76 </Compile>
77 <Compile Include="Device.cs" />
78 <Compile Include="DeviceFactory.cs" />
79 <Compile Include="DeviceManager.cs" />
80 <Compile Include="DeviceManagerException.cs" />
81 <Compile Include="IDevice.cs" />
82 <Compile Include="IDeviceFactory.cs" />
83 <Compile Include="IDeviceManager.cs" />
77 <Compile Include="Notification\Enums.cs" />84 <Compile Include="Notification\Enums.cs" />
78 <Compile Include="Notification\INotificationIconView.cs" />85 <Compile Include="Notification\INotificationIconView.cs" />
79 <Compile Include="Notification\IStateMapper.cs" />86 <Compile Include="Notification\IStateMapper.cs" />
@@ -176,5 +183,8 @@
176 <Install>true</Install>183 <Install>true</Install>
177 </BootstrapperPackage>184 </BootstrapperPackage>
178 </ItemGroup>185 </ItemGroup>
186 <ItemGroup>
187 <Folder Include="Devices\" />
188 </ItemGroup>
179 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />189 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
180</Project>190</Project>
181\ No newline at end of file191\ No newline at end of file
182192
=== added file 'src/Canonical.UbuntuOne.Client/Device.cs'
--- src/Canonical.UbuntuOne.Client/Device.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client/Device.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,38 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19namespace Canonical.UbuntuOne.Client
20{
21 internal class Device : IDevice
22 {
23 /// <summary>
24 /// Gets and sets a descriptin of the device.
25 /// </summary>
26 public string Description { get; set; }
27
28 /// <summary>
29 /// The token that identifies the device.
30 /// </summary>
31 public string Token { get; set; }
32
33 /// <summary>
34 /// Gets and sets the type of device.
35 /// </summary>
36 public DeviceType Type { get; set; }
37 }
38}
039
=== added file 'src/Canonical.UbuntuOne.Client/DeviceFactory.cs'
--- src/Canonical.UbuntuOne.Client/DeviceFactory.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client/DeviceFactory.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,57 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19namespace Canonical.UbuntuOne.Client
20{
21 internal class DeviceFactory : IDeviceFactory
22 {
23 #region Variables
24
25 internal const string ComputerType = "computer";
26 internal const string PhoneType = "phone";
27 internal const string CurrentMachine = "Current machine";
28
29 #endregion
30
31 #region Di Properties
32
33 /// <summary>
34 /// Gets and sets the device manager used to access device info.
35 /// </summary>
36 public IDeviceManager DeviceManager { get; set; }
37
38 #endregion
39
40 /// <summary>
41 /// Creates a new device from the given data.
42 /// </summary>
43 /// <param name="description">A string with the description of the machine.</param>
44 /// <param name="token">The token that identifies the device.</param>
45 /// <param name="type">The type of device.</param>
46 /// <returns>A device with the given data.</returns>
47 public IDevice Create(string description, string token, string type)
48 {
49 return new Device
50 {
51 Description = (DeviceManager.IsCurrentMachine(token))?CurrentMachine:description,
52 Token = token,
53 Type = string.Compare(type, ComputerType, true) == 0 ? DeviceType.COMPUTER : DeviceType.PHONE
54 };
55 }
56 }
57}
058
=== added file 'src/Canonical.UbuntuOne.Client/DeviceManager.cs'
--- src/Canonical.UbuntuOne.Client/DeviceManager.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client/DeviceManager.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,157 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19using System;
20using System.Collections.Generic;
21using System.IO;
22using System.Linq;
23using Canonical.Ubuntu.SSO;
24using Canonical.UbuntuOne.Common.Net;
25using log4net;
26using Newtonsoft.Json.Linq;
27
28namespace Canonical.UbuntuOne.Client
29{
30 internal class DeviceManager : IDeviceManager
31 {
32
33 #region Variables
34
35 private const string DevicesUrl = "https://one.ubuntu.com/api/1.0/devices/";
36 private const string RemoveUrl = "https://one.ubuntu.com/api/1.0/devices/remove/{0}/{1}";
37 private ILog _logger;
38 private readonly object _loggerLock = new object();
39
40 #endregion
41
42 #region Di properties
43
44 /// <summary>
45 /// Gets and sets the object used to perform the secure requests.
46 /// </summary>
47 public IOAuth OAuth { get; set; }
48
49 /// <summary>
50 /// Gets and sets the credentials provider used to get the user credentials.
51 /// </summary>
52 public ISSOCredentialsProvider SSOCredentialsProvider { get; set; }
53
54 /// <summary>
55 /// Gets and sets the factory that creates devices.
56 /// </summary>
57 public IDeviceFactory DeviceFactory { get; set; }
58
59 /// <summary>
60 /// Gets and sets the logger used by the class.
61 /// </summary>
62 internal ILog Logger
63 {
64 get
65 {
66 if (_logger == null)
67 {
68 lock (_loggerLock)
69 {
70 _logger = LogManager.GetLogger(typeof(DeviceManager));
71 }
72 }
73 return _logger;
74 }
75 set { _logger = value; }
76 }
77
78 #endregion
79
80 /// <summary>
81 /// Returns if the machine with the given token is th current machine.
82 /// </summary>
83 /// <param name="token">The token of the machine.</param>
84 /// <returns>A bool stating if th token represents the current machine.</returns>
85 public bool IsCurrentMachine(string token)
86 {
87 string currentToken;
88 string currentTokenSecret;
89 string currentConsumerKey;
90 string currentConsumerSecret;
91
92 // get the credentials
93 SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out currentToken, out currentTokenSecret, out currentConsumerKey,
94 out currentConsumerSecret);
95 return string.Compare(currentToken, token) == 0;
96 }
97
98 /// <summary>
99 /// Removes a machine with the given token from the machines synced with ubuntu one.
100 /// </summary>
101 /// <param name="kind"></param>
102 /// <param name="tokenToRemove"></param>
103 public void RemoveDevice(string kind, string tokenToRemove)
104 {
105 string token;
106 string tokenSecret;
107 string consumerKey;
108 string consumerSecret;
109
110 // get the credentials
111 SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey,
112 out consumerSecret);
113 var uri = string.Format(RemoveUrl, kind, tokenToRemove);
114 var request = OAuth.MakeRequest(uri, "GET", consumerKey, consumerSecret, token, tokenSecret);
115 try
116 {
117 var response = request.GetResponse();
118 }
119 catch (Exception e)
120 {
121 throw new DeviceManagerException("Machine could not be removed.", e);
122 }
123 }
124
125 /// <summary>
126 /// Returns a list with the current machines synced in the account.
127 /// </summary>
128 public IList<IDevice> GetSyncedDevices()
129 {
130 string token;
131 string tokenSecret;
132 string consumerKey;
133 string consumerSecret;
134
135 // get the credentials
136 SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey,
137 out consumerSecret);
138 var request = OAuth.MakeRequest(DevicesUrl, "GET", consumerKey, consumerSecret, token, tokenSecret);
139 try
140 {
141 var response = request.GetResponse();
142 var data = new StreamReader(response.GetResponseStream()).ReadToEnd();
143 // parse the json string
144 var devicesArray = JArray.Parse(data);
145 return devicesArray.Select(currentJDevice =>
146 DeviceFactory.Create(
147 (string) currentJDevice["description"],
148 (string) currentJDevice["token"],
149 (string) currentJDevice["kind"])).ToList();
150 }
151 catch (Exception e)
152 {
153 throw new DeviceManagerException("Machine could not be removed.", e);
154 }
155 }
156 }
157}
0158
=== added file 'src/Canonical.UbuntuOne.Client/DeviceManagerException.cs'
--- src/Canonical.UbuntuOne.Client/DeviceManagerException.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client/DeviceManagerException.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,57 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19using System;
20
21namespace Canonical.UbuntuOne.Client
22{
23 ///<summary>
24 /// Exception thrown when there was an issue managing the devices of the account.
25 ///</summary>
26 public class DeviceManagerException : Exception
27 {
28 ///<summary>
29 /// Creates a new instance of the class.
30 ///</summary>
31 public DeviceManagerException()
32 {
33
34 }
35
36 /// <summary>
37 /// Creates a new instance of the exception.
38 /// </summary>
39 /// <param name="message">The message to be carried by the exception.</param>
40 public DeviceManagerException(string message)
41 : base(message)
42 {
43
44 }
45
46 /// <summary>
47 /// Creates a new instance of the exception.
48 /// </summary>
49 /// <param name="message">The message to be carried by the exception.</param>
50 /// <param name="inner">The inner exception to be carried by the exception.</param>
51 public DeviceManagerException(string message, Exception inner)
52 : base(message, inner)
53 {
54
55 }
56 }
57}
058
=== added file 'src/Canonical.UbuntuOne.Client/IDevice.cs'
--- src/Canonical.UbuntuOne.Client/IDevice.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client/IDevice.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,57 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19namespace Canonical.UbuntuOne.Client
20{
21 /// <summary>
22 /// Enumerator that describes the different types of devices.
23 /// </summary>
24 public enum DeviceType
25 {
26 ///<summary>
27 /// The device is a computer.
28 ///</summary>
29 COMPUTER,
30 ///<summary>
31 /// The device is a phone.
32 ///</summary>
33 PHONE
34 }
35
36 /// <summary>
37 /// Interface that represents a device in the system.
38 /// </summary>
39 public interface IDevice
40 {
41 /// <summary>
42 /// Gets and sets a descriptin of the device.
43 /// </summary>
44 string Description { get; set; }
45
46 /// <summary>
47 /// The token that identifies the device.
48 /// </summary>
49 string Token { get; set; }
50
51 /// <summary>
52 /// Gets and sets the type of device.
53 /// </summary>
54 DeviceType Type { get; set; }
55
56 }
57}
058
=== added file 'src/Canonical.UbuntuOne.Client/IDeviceFactory.cs'
--- src/Canonical.UbuntuOne.Client/IDeviceFactory.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client/IDeviceFactory.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,35 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19namespace Canonical.UbuntuOne.Client
20{
21 /// <summary>
22 /// A factory that can create devices.
23 /// </summary>
24 public interface IDeviceFactory
25 {
26 /// <summary>
27 /// Creates a new device from the given data.
28 /// </summary>
29 /// <param name="description">A string with the description of the machine.</param>
30 /// <param name="token">The token that identifies the device.</param>
31 /// <param name="type">The type of device.</param>
32 /// <returns>A device with the given data.</returns>
33 IDevice Create(string description, string token, string type);
34 }
35}
036
=== added file 'src/Canonical.UbuntuOne.Client/IDeviceManager.cs'
--- src/Canonical.UbuntuOne.Client/IDeviceManager.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.Client/IDeviceManager.cs 2010-11-14 21:31:15 +0000
@@ -0,0 +1,48 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19using System.Collections.Generic;
20
21namespace Canonical.UbuntuOne.Client
22{
23 /// <summary>
24 /// Interface to be implemented by those objects that can manage the different devices
25 /// found in the Ubuntu One account.
26 /// </summary>
27 public interface IDeviceManager
28 {
29 /// <summary>
30 /// Returns if the machine with the given token is th current machine.
31 /// </summary>
32 /// <param name="token">The token of the machine.</param>
33 /// <returns>A bool stating if th token represents the current machine.</returns>
34 bool IsCurrentMachine(string token);
35
36 /// <summary>
37 /// Removes a machine with the given token from the machines synced with ubuntu one.
38 /// </summary>
39 /// <param name="king"></param>
40 /// <param name="token"></param>
41 void RemoveDevice(string king, string token);
42
43 /// <summary>
44 /// Returns a list with the current machines synced in the account.
45 /// </summary>
46 IList<IDevice> GetSyncedDevices();
47 }
48}
049
=== modified file 'src/Canonical.UbuntuOne.Client/Notification/NotificationIconPresenter.cs'
=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs'
--- src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs 2010-10-19 12:34:50 +0000
+++ src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs 2010-11-14 21:31:15 +0000
@@ -31,5 +31,12 @@
31 /// Updates the preferences that the user will use in the application.31 /// Updates the preferences that the user will use in the application.
32 /// </summary>32 /// </summary>
33 void UpdatePreferences();33 void UpdatePreferences();
34
35 /// <summary>
36 /// Removes the device with the given token from the system.
37 /// </summary>
38 /// <param name="deviceType">The type of the device to remove.</param>
39 /// <param name="token">The token of the device to remove.</param>
40 bool RemoveDevice(DeviceType deviceType, string token);
34 }41 }
35}42}
3643
=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs'
--- src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs 2010-10-13 10:38:57 +0000
+++ src/Canonical.UbuntuOne.Client/Preferences/IPreferencesView.cs 2010-11-14 21:31:15 +0000
@@ -17,6 +17,8 @@
17 * 17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */19 */
20using System.Collections.Generic;
21
20namespace Canonical.UbuntuOne.Client.Preferences22namespace Canonical.UbuntuOne.Client.Preferences
21{23{
22 /// <summary>24 /// <summary>
@@ -26,6 +28,21 @@
26 public interface IPreferencesView28 public interface IPreferencesView
27 {29 {
28 /// <summary>30 /// <summary>
31 /// Sets the consumption of the plan so far. The value should be between 0 and 100.
32 /// </summary>
33 double Consumption { set; }
34
35 /// <summary>
36 /// Sets the text used next the consumption.
37 /// </summary>
38 string ConsumptionText { set; }
39
40 /// <summary>
41 /// Gets and sets the devices shown in the app.
42 /// </summary>
43 IList<IDevice> Devices { get; set; }
44
45 /// <summary>
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.
30 /// </summary>47 /// </summary>
31 string UserName { set; }48 string UserName { set; }
@@ -79,5 +96,10 @@
79 /// Tell the view to show itself as a dialog.96 /// Tell the view to show itself as a dialog.
80 /// </summary>97 /// </summary>
81 void ShowDialog();98 void ShowDialog();
99
100 /// <summary>
101 /// Hides the dialog.
102 /// </summary>
103 void Hide();
82 }104 }
83}105}
84106
=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs'
--- src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-11-11 11:43:38 +0000
+++ src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-11-14 21:31:15 +0000
@@ -18,9 +18,12 @@
18 */18 */
19using System;19using System;
20using System.IO;20using System.IO;
21using System.Windows;
21using Canonical.Ubuntu.SSO;22using Canonical.Ubuntu.SSO;
22using Canonical.UbuntuOne.Common;23using Canonical.UbuntuOne.Common;
24using Canonical.UbuntuOne.Common.Net;
23using log4net;25using log4net;
26using Newtonsoft.Json.Linq;
2427
25namespace Canonical.UbuntuOne.Client.Preferences28namespace Canonical.UbuntuOne.Client.Preferences
26{29{
@@ -36,6 +39,7 @@
36 private readonly object _loggerLock = new object();39 private readonly object _loggerLock = new object();
37 private const string EventName = "UbuntuOneAutoManualSync";40 private const string EventName = "UbuntuOneAutoManualSync";
38 private const string ApplicationName = "UbuntuOne";41 private const string ApplicationName = "UbuntuOne";
42 private const string ConsumptionUrl = "https://one.ubuntu.com/api/quota/";
3943
40 #endregion44 #endregion
4145
@@ -64,6 +68,11 @@
64 #region DI Properties68 #region DI Properties
6569
66 /// <summary>70 /// <summary>
71 /// Gets and sets the object that allows to mange the devices of the Ubuntu One.
72 /// </summary>
73 public IDeviceManager DeviceManager { get; set; }
74
75 /// <summary>
67 /// Gets and sets the view used by this presenter.76 /// Gets and sets the view used by this presenter.
68 /// </summary>77 /// </summary>
69 public IPreferencesView PreferencesView { get; set; }78 public IPreferencesView PreferencesView { get; set; }
@@ -100,6 +109,11 @@
100 /// </summary>109 /// </summary>
101 public IMessageBox MessageBox { get; set; }110 public IMessageBox MessageBox { get; set; }
102111
112 /// <summary>
113 /// Gets and sets the oauth used to access secure resources.
114 /// </summary>
115 public IOAuth OAuth { get; set; }
116
103 #endregion117 #endregion
104118
105 #region Helpers119 #region Helpers
@@ -142,14 +156,49 @@
142 MessageBox.ShowError("An error courred when trying to retrieve your credentials.");156 MessageBox.ShowError("An error courred when trying to retrieve your credentials.");
143 }157 }
144158
159 /// <summary>
160 /// Returns the comsumption so far.
161 /// </summary>
162 /// <returns></returns>
163 private double GetConsumption()
164 {
165 string token;
166 string tokenSecret;
167 string consumerKey;
168 string consumerSecret;
169
170 // get the credentials
171 SSOCredentialsProvider.LoginToGetCredentials("UbuntuOne", out token, out tokenSecret, out consumerKey,
172 out consumerSecret);
173 var request = OAuth.MakeRequest(ConsumptionUrl, "GET", consumerKey, consumerSecret, token, tokenSecret);
174 try
175 {
176 var response = request.GetResponse();
177 var data = new StreamReader(response.GetResponseStream()).ReadToEnd();
178 // parse the json string
179 var consumption = JObject.Parse(data);
180 return ((Int64)consumption["used"] * 100) / (Int64)consumption["total"];
181 }
182 catch (Exception e)
183 {
184 throw new DeviceManagerException("Machine could not be listed.", e);
185 }
186 }
187
145 #endregion188 #endregion
146189
147 public void Show()190 public void Show()
148 {191 {
149 // set the preferences to be shown in the UI.192 // set the preferences to be shown in the UI.
150 PreferencesView.IsAutoSyncEnable = PreferencesManager.IsAutoSyncEnable;193 PreferencesView.IsAutoSyncEnable = PreferencesManager.IsAutoSyncEnable;
194 // set consumption
195 var consumption = GetConsumption();
196 PreferencesView.Consumption = consumption;
197 PreferencesView.ConsumptionText = string.Format("{0}% used", consumption);
198 PreferencesView.Devices = DeviceManager.GetSyncedDevices();
199
151 if (PreferencesManager.IsAutoSyncEnable)200 if (PreferencesManager.IsAutoSyncEnable)
152 PreferencesView.AutoSyncFrequency = PreferencesManager.AutoSyncFrequency;201 PreferencesView.AutoSyncFrequency = PreferencesManager.AutoSyncFrequency;
153 PreferencesView.ShowDialog();202 PreferencesView.ShowDialog();
154 }203 }
155204
@@ -170,5 +219,33 @@
170 PreferencesManager.Save();219 PreferencesManager.Save();
171 }220 }
172221
222 /// <summary>
223 /// Removes the device with the given token from the system.
224 /// </summary>
225 /// <param name="deviceType">The type of the device to remove.</param>
226 /// <param name="token">The token of the device to remove.</param>
227 public bool RemoveDevice(DeviceType deviceType, string token)
228 {
229 var currentMachine = DeviceManager.IsCurrentMachine(token);
230 if(currentMachine)
231 {
232 // we need to remove the current machine, we should tell the user
233 if(MessageBox.ShowYesNo("Are you sure you want to remove this machine?",MessageBoxImage.Question) == MessageBoxResult.No)
234 {
235 return false;
236 }
237 }
238 // just use the device manager for thise
239 DeviceManager.RemoveDevice(deviceType == DeviceType.COMPUTER ? "computer" : "phone", token);
240 // we remove the tokens in our machine
241 if (currentMachine)
242 {
243 SSOCredentialsProvider.RemoveCredentials("UbuntuOne");
244 // we tell the user we will close the preferences since the
245 MessageBox.ShowInformation("Preferences dialog will be closed because your removed the machine.");
246 PreferencesView.Hide();
247 }
248 return true;
249 }
173 }250 }
174}251}
175252
=== modified file 'src/Canonical.UbuntuOne.Client/objects.xml'
--- src/Canonical.UbuntuOne.Client/objects.xml 2010-10-19 12:34:50 +0000
+++ src/Canonical.UbuntuOne.Client/objects.xml 2010-11-14 21:31:15 +0000
@@ -14,4 +14,11 @@
14 type="Canonical.UbuntuOne.Client.Preferences.LoadPreferencesStartupTask, Canonical.UbuntuOne.Client"14 type="Canonical.UbuntuOne.Client.Preferences.LoadPreferencesStartupTask, Canonical.UbuntuOne.Client"
15 autowire="autodetect"/>15 autowire="autodetect"/>
1616
17 <object id="DeviceManager"
18 type="Canonical.UbuntuOne.Client.DeviceManager, Canonical.UbuntuOne.Client"
19 autowire="autodetect"/>
20
21 <object id="DeviceFactory"
22 type="Canonical.UbuntuOne.Client.DeviceFactory, Canonical.UbuntuOne.Client"
23 autowire="autodetect"/>
17</objects>24</objects>
18\ No newline at end of file25\ No newline at end of file
1926
=== modified file 'src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj'
--- src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj 2010-10-21 10:17:18 +0000
+++ src/Canonical.UbuntuOne.Common/Canonical.UbuntuOne.Common.csproj 2010-11-14 21:31:15 +0000
@@ -106,7 +106,9 @@
106 <Compile Include="Net\HttpWebRequestFactory.cs" />106 <Compile Include="Net\HttpWebRequestFactory.cs" />
107 <Compile Include="Net\IHttpWebRequestFactory.cs" />107 <Compile Include="Net\IHttpWebRequestFactory.cs" />
108 <Compile Include="Net\IHttpWebRequest.cs" />108 <Compile Include="Net\IHttpWebRequest.cs" />
109 <Compile Include="Net\IOAuth.cs" />
109 <Compile Include="Net\IServiceCaller.cs" />110 <Compile Include="Net\IServiceCaller.cs" />
111 <Compile Include="Net\OAuth.cs" />
110 <Compile Include="Net\ServiceCaller.cs" />112 <Compile Include="Net\ServiceCaller.cs" />
111 <Compile Include="OperationContracts\IEventNotifier.cs" />113 <Compile Include="OperationContracts\IEventNotifier.cs" />
112 <Compile Include="OperationContracts\IPostInitDirectoryTask.cs" />114 <Compile Include="OperationContracts\IPostInitDirectoryTask.cs" />
@@ -213,6 +215,7 @@
213 <Reference Include="System" />215 <Reference Include="System" />
214 <Reference Include="System.Runtime.Serialization">216 <Reference Include="System.Runtime.Serialization">
215 </Reference>217 </Reference>
218 <Reference Include="System.Web" />
216 <Reference Include="System.Xaml" />219 <Reference Include="System.Xaml" />
217 <Reference Include="System.Xml" />220 <Reference Include="System.Xml" />
218 <Reference Include="WindowsBase">221 <Reference Include="WindowsBase">
219222
=== renamed file 'src/Canonical.Ubuntu.SSO/IOAuth.cs' => 'src/Canonical.UbuntuOne.Common/Net/IOAuth.cs'
--- src/Canonical.Ubuntu.SSO/IOAuth.cs 2010-10-05 09:49:29 +0000
+++ src/Canonical.UbuntuOne.Common/Net/IOAuth.cs 2010-11-14 21:31:15 +0000
@@ -20,8 +20,11 @@
20using System.Collections.Generic;20using System.Collections.Generic;
21using System.Security.Cryptography;21using System.Security.Cryptography;
2222
23namespace Canonical.Ubuntu.SSO23namespace Canonical.UbuntuOne.Common.Net
24{24{
25 ///<summary>
26 /// Interface to be implemented by those objects that allows to perform Oauth operations.
27 ///</summary>
25 public interface IOAuth28 public interface IOAuth
26 {29 {
27 /// <summary>30 /// <summary>
@@ -118,5 +121,18 @@
118 /// </summary>121 /// </summary>
119 /// <returns></returns>122 /// <returns></returns>
120 string GenerateNonce();123 string GenerateNonce();
124
125 /// <summary>
126 /// Returns a request with an Oauth header that can be used to acess a secured resource.
127 /// </summary>
128 /// <param name="uri">The uri to be accessed.</param>
129 /// <param name="httpMethod">The http method of the request.</param>
130 /// <param name="consumerKey">The consumer key of the oauth.</param>
131 /// <param name="consumerSecret">The consumer secret of the oauth.</param>
132 /// <param name="token">The token of the oauth,</param>
133 /// <param name="tokenSecret">The token secret of the oauth.</param>
134 /// <returns>Returns a request that can be used to access a secure resource.</returns>
135 IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret,
136 string token, string tokenSecret);
121 }137 }
122}138}
123\ No newline at end of file139\ No newline at end of file
124140
=== renamed file 'src/Canonical.Ubuntu.SSO/OAuth.cs' => 'src/Canonical.UbuntuOne.Common/Net/OAuth.cs'
--- src/Canonical.Ubuntu.SSO/OAuth.cs 2010-10-05 09:49:29 +0000
+++ src/Canonical.UbuntuOne.Common/Net/OAuth.cs 2010-11-14 21:31:15 +0000
@@ -1,13 +1,36 @@
1using System;1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19using System;
2using System.Security.Cryptography;20using System.Security.Cryptography;
3using System.Collections.Generic;21using System.Collections.Generic;
4using System.Text;22using System.Text;
5using System.Web;23using System.Web;
624
7namespace Canonical.Ubuntu.SSO25namespace Canonical.UbuntuOne.Common.Net
8{26{
9 public class OAuth : IOAuth27 public class OAuth : IOAuth
10 {28 {
29 #region Di properties
30
31 public IHttpWebRequestFactory HttpWebRequestFactory { get; set; }
32
33 #endregion
1134
12 /// <summary>35 /// <summary>
13 /// Provides a predefined set of algorithms that are supported officially by the protocol36 /// Provides a predefined set of algorithms that are supported officially by the protocol
@@ -387,5 +410,32 @@
387 return Random.Next(123400, 9999999).ToString();410 return Random.Next(123400, 9999999).ToString();
388 }411 }
389412
413
414 /// <summary>
415 /// Creates an oauth request that can access a protected web resource.
416 /// </summary>
417 /// <param name="uri">The uri where the resource is found.</param>
418 /// <param name="httpMethod">The request berb to be used.</param>
419 /// <param name="consumerKey">Consumer key from oauth.</param>
420 /// <param name="consumerSecret">Consumer secret from oauth.</param>
421 /// <param name="token">Token from oauth.</param>
422 /// <param name="tokenSecret">Token secret from oauth.</param>
423 /// <returns>A webrequest that can be used to access the resource.</returns>
424 public IHttpWebRequest MakeRequest(string uri, string httpMethod, string consumerKey, string consumerSecret, string token, string tokenSecret)
425 {
426 // Form the full REST request url
427 var url = new Uri(uri);
428 string normUrl;
429 string normParams;
430
431 // get oauth header
432 var authHeader = GenerateHeaderWithSignature(url, string.Empty, consumerKey, consumerSecret,
433 token, tokenSecret, httpMethod, GenerateTimeStamp(), GenerateNonce(), SignatureTypes.HMACSHA1,
434 out normUrl, out normParams);
435
436 var request = HttpWebRequestFactory.Create(url);
437 request.Headers.Add(authHeader.Key, authHeader.Value);
438 return request;
439 }
390 }440 }
391}441}
392\ No newline at end of file442\ No newline at end of file
393443
=== modified file 'src/Canonical.UbuntuOne.Common/objects.xml'
--- src/Canonical.UbuntuOne.Common/objects.xml 2010-10-21 10:17:18 +0000
+++ src/Canonical.UbuntuOne.Common/objects.xml 2010-11-14 21:31:15 +0000
@@ -56,6 +56,10 @@
56 <!-- Net Objects -->56 <!-- Net Objects -->
57 <!-- ######################################################################################## -->57 <!-- ######################################################################################## -->
5858
59 <object id="OAuth"
60 type="Canonical.UbuntuOne.Common.Net.OAuth , Canonical.UbuntuOne.Common"
61 autowire="autodetect"/>
62
59 <object id="HttpWebRequestFactory"63 <object id="HttpWebRequestFactory"
60 type="Canonical.UbuntuOne.Common.Net.HttpWebRequestFactory, Canonical.UbuntuOne.Common" />64 type="Canonical.UbuntuOne.Common.Net.HttpWebRequestFactory, Canonical.UbuntuOne.Common" />
6165

Subscribers

People subscribed via source and target branches

to all changes: