Merge lp:~mandel/ubuntuone-windows-installer/implement_ipc into lp:ubuntuone-windows-installer/beta
- implement_ipc
- Merge into beta
Proposed by
Manuel de la Peña
Status: | Merged |
---|---|
Approved by: | Rick McBride |
Approved revision: | 43 |
Merged at revision: | 62 |
Proposed branch: | lp:~mandel/ubuntuone-windows-installer/implement_ipc |
Merge into: | lp:ubuntuone-windows-installer/beta |
Prerequisite: | lp:~mandel/ubuntuone-windows-installer/add_interaction_documentation |
Diff against target: |
2558 lines (+1574/-189) 34 files modified
.bzrignore (+1/-0) src/Canonical.UbuntuOne.Common/OperationContracts/ISyncConfiguration.cs (+0/-7) src/Canonical.UbuntuOne.Common/OperationContracts/ISyncDaemon.cs (+8/-7) src/Canonical.UbuntuOne.Common/OperationContracts/ISyncFileManager.cs (+0/-6) src/Canonical.UbuntuOne.Common/OperationContracts/ISyncFolders.cs (+0/-6) src/Canonical.UbuntuOne.Common/OperationContracts/ISyncShares.cs (+0/-6) src/Canonical.UbuntuOne.Common/Validation/EqualityValidationExtensions.cs (+1/-1) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Canonical.UbuntuOne.ProcessDispatcher.Tests.csproj (+16/-0) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientCommunicatorFixture.cs (+131/-0) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/ConvertFixture.cs (+1/-1) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/SyncDaemonMessageFactoryFixture.cs (+32/-0) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/SyncFolderMessageFactoryFixture.cs (+1/-1) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncConfigurationServiceFixture.cs (+180/-0) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncDaemonServiceFixture.cs (+238/-41) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncFoldersServiceFixture.cs (+200/-0) src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncSharesServiceFixture.cs (+167/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj (+6/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClient.cs (+42/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientCommunicator.cs (+48/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientFactory.cs (+36/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientCommunicator.cs (+88/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Properties/AssemblyInfo.cs (+1/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/Convert.cs (+2/-1) src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/IProtobufSerializer.cs (+46/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ISyncDaemonMessageFactory.cs (+27/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ISyncFolderMessageFactory.cs (+2/-2) src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ProtobufSerializer.cs (+56/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/SyncDaemonMessageFactory.cs (+66/-2) src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/SyncFolderMessageFactory.cs (+1/-1) src/Canonical.UbuntuOne.ProcessDispatcher/SyncConfigurationService.cs (+34/-17) src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs (+53/-30) src/Canonical.UbuntuOne.ProcessDispatcher/SyncFileManagerService.cs (+4/-9) src/Canonical.UbuntuOne.ProcessDispatcher/SyncFoldersService.cs (+34/-18) src/Canonical.UbuntuOne.ProcessDispatcher/SyncSharesService.cs (+52/-33) |
To merge this branch: | bzr merge lp:~mandel/ubuntuone-windows-installer/implement_ipc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rick McBride (community) | Approve | ||
John O'Brien (community) | Approve | ||
Review via email: mp+32305@code.launchpad.net |
Commit message
Description of the change
Implements the first part of the IPC. This branch contains the code that will communicate with python by requesting a TcpClient to a TcpClient factory which will be implemented in an other branch.
To post a comment you must log in.
Revision history for this message
Rick McBride (rmcbride) wrote : | # |
Tests pass. Looks good.
I second jdo's comment regarding the diff limit. Makes branch approvals happen a lot faster :)
review:
Approve
Revision history for this message
Manuel de la Peña (mandel) wrote : | # |
I agree with the merge sizes, but most of the time is the bloody windows devel enviroment that keeps adding bloody xml everywhere....
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' |
2 | --- .bzrignore 2010-08-02 17:57:48 +0000 |
3 | +++ .bzrignore 2010-08-11 10:35:55 +0000 |
4 | @@ -26,3 +26,4 @@ |
5 | src/UbuntuOneClient/obj |
6 | src/UbuntuOneClient.Tests/bin |
7 | src/UbuntuOneClient.Tests/obj |
8 | +*.ReSharper |
9 | |
10 | === modified file 'src/Canonical.UbuntuOne.Common/OperationContracts/ISyncConfiguration.cs' |
11 | --- src/Canonical.UbuntuOne.Common/OperationContracts/ISyncConfiguration.cs 2010-08-05 07:13:28 +0000 |
12 | +++ src/Canonical.UbuntuOne.Common/OperationContracts/ISyncConfiguration.cs 2010-08-11 10:35:55 +0000 |
13 | @@ -33,13 +33,6 @@ |
14 | public interface ISyncConfiguration |
15 | { |
16 | /// <summary> |
17 | - /// Provides a way that the client can use to register itself to be notified about events |
18 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
19 | - /// </summary> |
20 | - [OperationContract(IsOneWay = true)] |
21 | - void RegisterClient(); |
22 | - |
23 | - /// <summary> |
24 | /// Returns the throttling limits that have been set up for the daemon. |
25 | /// </summary> |
26 | /// <returns>The upload and downloads limits that the daemon has.</returns> |
27 | |
28 | === modified file 'src/Canonical.UbuntuOne.Common/OperationContracts/ISyncDaemon.cs' |
29 | --- src/Canonical.UbuntuOne.Common/OperationContracts/ISyncDaemon.cs 2010-08-05 07:13:28 +0000 |
30 | +++ src/Canonical.UbuntuOne.Common/OperationContracts/ISyncDaemon.cs 2010-08-11 10:35:55 +0000 |
31 | @@ -1,4 +1,4 @@ |
32 | -/** |
33 | +/* |
34 | * Copyright 2010 Canonical Ltd. |
35 | * |
36 | * This file is part of UbuntuOne on Windows. |
37 | @@ -33,12 +33,6 @@ |
38 | SessionMode = SessionMode.Required)] |
39 | public interface ISyncDaemon |
40 | { |
41 | - /// <summary> |
42 | - /// Provides a way that the client can use to register itself to be notified about events |
43 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
44 | - /// </summary> |
45 | - [OperationContract(IsOneWay = true)] |
46 | - void RegisterClient(); |
47 | |
48 | /// <summary> |
49 | /// Allows to start the daemon by a client. |
50 | @@ -67,6 +61,13 @@ |
51 | bool TryStop(); |
52 | |
53 | /// <summary> |
54 | + /// Returns the port number of the socket that the synd daemo is listening to for communication. |
55 | + /// </summary> |
56 | + /// <returns></returns> |
57 | + [OperationContract] |
58 | + int GetListeningSocket(); |
59 | + |
60 | + /// <summary> |
61 | /// Allows to query the service about the current status of the daemon. |
62 | /// </summary> |
63 | /// <returns>A data contract that contains the current status of the daemon.</returns> |
64 | |
65 | === modified file 'src/Canonical.UbuntuOne.Common/OperationContracts/ISyncFileManager.cs' |
66 | --- src/Canonical.UbuntuOne.Common/OperationContracts/ISyncFileManager.cs 2010-08-02 10:07:10 +0000 |
67 | +++ src/Canonical.UbuntuOne.Common/OperationContracts/ISyncFileManager.cs 2010-08-11 10:35:55 +0000 |
68 | @@ -32,12 +32,6 @@ |
69 | SessionMode = SessionMode.Required)] |
70 | public interface ISyncFileManager |
71 | { |
72 | - /// <summary> |
73 | - /// Provides a way that the client can use to register itself to be notified about events |
74 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
75 | - /// </summary> |
76 | - [OperationContract(IsOneWay = true)] |
77 | - void RegisterClient(); |
78 | |
79 | /// <summary> |
80 | /// Returns the metadata |
81 | |
82 | === modified file 'src/Canonical.UbuntuOne.Common/OperationContracts/ISyncFolders.cs' |
83 | --- src/Canonical.UbuntuOne.Common/OperationContracts/ISyncFolders.cs 2010-08-05 08:01:59 +0000 |
84 | +++ src/Canonical.UbuntuOne.Common/OperationContracts/ISyncFolders.cs 2010-08-11 10:35:55 +0000 |
85 | @@ -33,12 +33,6 @@ |
86 | SessionMode = SessionMode.Required)] |
87 | public interface ISyncFolders |
88 | { |
89 | - /// <summary> |
90 | - /// Provides a way that the client can use to register itself to be notified about events |
91 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
92 | - /// </summary> |
93 | - [OperationContract(IsOneWay = true)] |
94 | - void RegisterClient(); |
95 | |
96 | /// <summary> |
97 | /// Creates a new udf for the given path. |
98 | |
99 | === modified file 'src/Canonical.UbuntuOne.Common/OperationContracts/ISyncShares.cs' |
100 | --- src/Canonical.UbuntuOne.Common/OperationContracts/ISyncShares.cs 2010-08-05 07:13:28 +0000 |
101 | +++ src/Canonical.UbuntuOne.Common/OperationContracts/ISyncShares.cs 2010-08-11 10:35:55 +0000 |
102 | @@ -33,12 +33,6 @@ |
103 | SessionMode = SessionMode.Required)] |
104 | public interface ISyncShares |
105 | { |
106 | - /// <summary> |
107 | - /// Provides a way that the client can use to register itself to be notified about events |
108 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
109 | - /// </summary> |
110 | - [OperationContract(IsOneWay = true)] |
111 | - void RegisterClient(); |
112 | |
113 | /// <summary> |
114 | /// Allows the client to query and get all the different shares that the user has. |
115 | |
116 | === modified file 'src/Canonical.UbuntuOne.Common/Validation/EqualityValidationExtensions.cs' |
117 | --- src/Canonical.UbuntuOne.Common/Validation/EqualityValidationExtensions.cs 2010-08-05 07:13:28 +0000 |
118 | +++ src/Canonical.UbuntuOne.Common/Validation/EqualityValidationExtensions.cs 2010-08-11 10:35:55 +0000 |
119 | @@ -1,4 +1,4 @@ |
120 | -/** |
121 | +/* |
122 | * Copyright 2010 Canonical Ltd. |
123 | * |
124 | * This file is part of UbuntuOne on Windows. |
125 | |
126 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Canonical.UbuntuOne.ProcessDispatcher.Tests.csproj' |
127 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Canonical.UbuntuOne.ProcessDispatcher.Tests.csproj 2010-07-30 09:33:20 +0000 |
128 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Canonical.UbuntuOne.ProcessDispatcher.Tests.csproj 2010-08-11 10:35:55 +0000 |
129 | @@ -55,12 +55,17 @@ |
130 | <Compile Include="..\Version.cs"> |
131 | <Link>Properties\Version.cs</Link> |
132 | </Compile> |
133 | + <Compile Include="Net\TcpClientCommunicatorFixture.cs" /> |
134 | <Compile Include="Properties\AssemblyInfo.cs" /> |
135 | <Compile Include="Protobuf\ConvertFixture.cs" /> |
136 | <Compile Include="Protobuf\SyncConfigurationMessageFactoryFixture.cs" /> |
137 | <Compile Include="Protobuf\SyncDaemonMessageFactoryFixture.cs" /> |
138 | <Compile Include="Protobuf\SyncFolderMessageFactoryFixture.cs" /> |
139 | <Compile Include="Protobuf\SyncShareMessageFactoryFixture.cs" /> |
140 | + <Compile Include="SyncConfigurationServiceFixture.cs" /> |
141 | + <Compile Include="SyncDaemonServiceFixture.cs" /> |
142 | + <Compile Include="SyncFoldersServiceFixture.cs" /> |
143 | + <Compile Include="SyncSharesServiceFixture.cs" /> |
144 | </ItemGroup> |
145 | <ItemGroup> |
146 | <ProjectReference Include="..\Canonical.UbuntuOne.Common\Canonical.UbuntuOne.Common.csproj"> |
147 | @@ -73,6 +78,10 @@ |
148 | </ProjectReference> |
149 | </ItemGroup> |
150 | <ItemGroup> |
151 | + <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL"> |
152 | + <SpecificVersion>False</SpecificVersion> |
153 | + <HintPath>..\..\lib\log4net\log4net.dll</HintPath> |
154 | + </Reference> |
155 | <Reference Include="nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> |
156 | <SpecificVersion>False</SpecificVersion> |
157 | <HintPath>..\..\lib\Nunit\nunit.framework.dll</HintPath> |
158 | @@ -81,9 +90,16 @@ |
159 | <SpecificVersion>False</SpecificVersion> |
160 | <HintPath>..\..\lib\Protobuf-net\protobuf-net.dll</HintPath> |
161 | </Reference> |
162 | + <Reference Include="Rhino.Mocks, Version=3.6.0.0, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL"> |
163 | + <SpecificVersion>False</SpecificVersion> |
164 | + <HintPath>..\..\lib\RhinoMocks\Rhino.Mocks.dll</HintPath> |
165 | + </Reference> |
166 | + <Reference Include="System" /> |
167 | <Reference Include="System.Core"> |
168 | <RequiredTargetFramework>3.5</RequiredTargetFramework> |
169 | </Reference> |
170 | + <Reference Include="System.Data" /> |
171 | + <Reference Include="System.Xml" /> |
172 | </ItemGroup> |
173 | <ItemGroup> |
174 | <BootstrapperPackage Include="Microsoft.Net.Framework.2.0"> |
175 | |
176 | === added directory 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net' |
177 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientCommunicatorFixture.cs' |
178 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientCommunicatorFixture.cs 1970-01-01 00:00:00 +0000 |
179 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientCommunicatorFixture.cs 2010-08-11 10:35:55 +0000 |
180 | @@ -0,0 +1,131 @@ |
181 | +/* |
182 | + * Copyright 2010 Canonical Ltd. |
183 | + * |
184 | + * This file is part of UbuntuOne on Windows. |
185 | + * |
186 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
187 | + * it under the terms of the GNU Lesser General Public License version |
188 | + * as published by the Free Software Foundation. |
189 | + * |
190 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
191 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
192 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
193 | + * GNU Lesser General Public License for more details. |
194 | + * |
195 | + * You should have received a copy of the GNU Lesser General Public License |
196 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
197 | + * |
198 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
199 | + */ |
200 | +using System.Net.Sockets; |
201 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
202 | +using NUnit.Framework; |
203 | +using Rhino.Mocks; |
204 | + |
205 | +namespace Canonical.UbuntuOne.ProcessDispatcher.Tests.Net |
206 | +{ |
207 | + [TestFixture] |
208 | + public class TcpClientCommunicatorFixture |
209 | + { |
210 | + #region Variables |
211 | + |
212 | + private ITcpClientFactory _clientFactory; |
213 | + private ITcpClient _client; |
214 | + private IProtobufSerializer _serializer; |
215 | + private NetworkStream _stream; |
216 | + private bool _wasCalled; |
217 | + private MockRepository _mocks; |
218 | + private ConfigurationMessage _message; |
219 | + private TcpClientCommunicator<ConfigurationMessage> _communitcator; |
220 | + |
221 | + #endregion |
222 | + |
223 | + #region Setup & TearDown |
224 | + |
225 | + [SetUp] |
226 | + public void Setup() |
227 | + { |
228 | + _mocks = new MockRepository(); |
229 | + _clientFactory = _mocks.StrictMock<ITcpClientFactory>(); |
230 | + _client = _mocks.StrictMock<ITcpClient>(); |
231 | + _serializer = _mocks.StrictMock<IProtobufSerializer>(); |
232 | + _message = _mocks.Stub<ConfigurationMessage>(); |
233 | + _stream = _mocks.StrictMock<NetworkStream>(); |
234 | + _wasCalled = false; |
235 | + _communitcator = new TcpClientCommunicator<ConfigurationMessage> |
236 | + { |
237 | + ProtobufSerializer = _serializer, |
238 | + TcpClientFactory = _clientFactory |
239 | + }; |
240 | + } |
241 | + |
242 | + #endregion |
243 | + |
244 | + #region Helpers |
245 | + |
246 | + private string ConvertCallback(ConfigurationMessage message) |
247 | + { |
248 | + _wasCalled = true; |
249 | + return "mandel"; |
250 | + } |
251 | + |
252 | + #endregion |
253 | + |
254 | + #region Tests |
255 | + |
256 | + [Test] |
257 | + public void SendMessageTest() |
258 | + { |
259 | + using(_mocks.Record()) |
260 | + { |
261 | + Expect.Call(_clientFactory.GetClient()) |
262 | + .Return(_client) |
263 | + .Repeat.Once(); |
264 | + Expect.Call(_client.GetStream()) |
265 | + .Return(_stream) |
266 | + .Repeat.Once(); |
267 | + Expect.Call(() => _serializer.Serialize(_stream, _message)) |
268 | + .Repeat.Once(); |
269 | + Expect.Call(() => _client.Close()) |
270 | + .Repeat.Once(); |
271 | + Expect.Call(() => _stream.Close()) |
272 | + .Repeat.Once(); |
273 | + } |
274 | + using(_mocks.Playback()) |
275 | + { |
276 | + _communitcator.SendMessage(_message); |
277 | + } |
278 | + } |
279 | + |
280 | + [Test] |
281 | + public void SendReceiveMessage() |
282 | + { |
283 | + using (_mocks.Record()) |
284 | + { |
285 | + Expect.Call(_clientFactory.GetClient()) |
286 | + .Return(_client) |
287 | + .Repeat.Once(); |
288 | + Expect.Call(_client.GetStream()) |
289 | + .Return(_stream) |
290 | + .Repeat.Once(); |
291 | + Expect.Call(() => _serializer.Serialize(_stream, _message)) |
292 | + .Repeat.Once(); |
293 | + Expect.Call(_serializer.Deserialize<ConfigurationMessage>(_stream)) |
294 | + .Return(_message) |
295 | + .Repeat.Once(); |
296 | + Expect.Call(() => _client.Close()) |
297 | + .Repeat.Once(); |
298 | + Expect.Call(() => _stream.Close()) |
299 | + .Repeat.Once(); |
300 | + } |
301 | + using (_mocks.Playback()) |
302 | + { |
303 | + _communitcator.SendReceiveMessage<string>(_message, ConvertCallback); |
304 | + Assert.IsTrue(_wasCalled, "The convert callback was not called."); |
305 | + } |
306 | + } |
307 | + |
308 | + #endregion |
309 | + |
310 | + } |
311 | +} |
312 | |
313 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/ConvertFixture.cs' |
314 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/ConvertFixture.cs 2010-07-13 09:12:00 +0000 |
315 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/ConvertFixture.cs 2010-08-11 10:35:55 +0000 |
316 | @@ -1,4 +1,4 @@ |
317 | -/** |
318 | +/* |
319 | * Copyright 2010 Canonical Ltd. |
320 | * |
321 | * This file is part of UbuntuOne on Windows. |
322 | |
323 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/SyncDaemonMessageFactoryFixture.cs' |
324 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/SyncDaemonMessageFactoryFixture.cs 2010-07-13 09:12:00 +0000 |
325 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/SyncDaemonMessageFactoryFixture.cs 2010-08-11 10:35:55 +0000 |
326 | @@ -71,5 +71,37 @@ |
327 | var message = _factory.QueryUploads(); |
328 | Assert.AreEqual(SyncDaemonMessage.MessageType.QUERYUPLOADS, message.Type); |
329 | } |
330 | + |
331 | + [TestCase("NodeId1", "ShareId1")] |
332 | + [TestCase("NodeId2", "ShareId2")] |
333 | + [TestCase("NodeId3", "ShareId3")] |
334 | + public void ScheduleAsNextTest(string shareId, string nodeId) |
335 | + { |
336 | + var message = _factory.ScheduleAsNext(shareId, nodeId); |
337 | + Assert.AreEqual(SyncDaemonMessage.MessageType.SCHEDULENEXT, message.Type); |
338 | + Assert.AreEqual(nodeId, message.NextNodeId); |
339 | + Assert.AreEqual(shareId, message.NextShareId); |
340 | + } |
341 | + |
342 | + [Test] |
343 | + public void ConnectTest() |
344 | + { |
345 | + var message = _factory.Connect(); |
346 | + Assert.AreEqual(SyncDaemonMessage.MessageType.CONNECT, message.Type); |
347 | + } |
348 | + |
349 | + [Test] |
350 | + public void DisconnectTest() |
351 | + { |
352 | + var message = _factory.Disconnect(); |
353 | + Assert.AreEqual(SyncDaemonMessage.MessageType.DISCONNECT, message.Type); |
354 | + } |
355 | + |
356 | + [Test] |
357 | + public void QuitTest() |
358 | + { |
359 | + var message = _factory.Quit(); |
360 | + Assert.AreEqual(SyncDaemonMessage.MessageType.QUIT, message.Type); |
361 | + } |
362 | } |
363 | } |
364 | |
365 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/SyncFolderMessageFactoryFixture.cs' |
366 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/SyncFolderMessageFactoryFixture.cs 2010-07-13 09:12:00 +0000 |
367 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Protobuf/SyncFolderMessageFactoryFixture.cs 2010-08-11 10:35:55 +0000 |
368 | @@ -119,7 +119,7 @@ |
369 | [Test] |
370 | public void RefreshFolders() |
371 | { |
372 | - var message = _factory.RefreshFolders(); |
373 | + var message = _factory.RefreshVolumes(); |
374 | Assert.AreEqual(FolderMessage.MessageType.REFRESH, message.Type); |
375 | } |
376 | |
377 | |
378 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncConfigurationServiceFixture.cs' |
379 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncConfigurationServiceFixture.cs 1970-01-01 00:00:00 +0000 |
380 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncConfigurationServiceFixture.cs 2010-08-11 10:35:55 +0000 |
381 | @@ -0,0 +1,180 @@ |
382 | +/* |
383 | + * Copyright 2010 Canonical Ltd. |
384 | + * |
385 | + * This file is part of UbuntuOne on Windows. |
386 | + * |
387 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
388 | + * it under the terms of the GNU Lesser General Public License version |
389 | + * as published by the Free Software Foundation. |
390 | + * |
391 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
392 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
393 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
394 | + * GNU Lesser General Public License for more details. |
395 | + * |
396 | + * You should have received a copy of the GNU Lesser General Public License |
397 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
398 | + * |
399 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
400 | + */ |
401 | +using Canonical.UbuntuOne.Common; |
402 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
403 | +using NUnit.Framework; |
404 | +using Rhino.Mocks; |
405 | + |
406 | +namespace Canonical.UbuntuOne.ProcessDispatcher.Tests |
407 | +{ |
408 | + [TestFixture] |
409 | + public class SyncConfigurationServiceFixture |
410 | + { |
411 | + #region Variables |
412 | + |
413 | + private ISyncConfigurationMessageFactory _messageFactory; |
414 | + private ITcpClientCommunicator<ConfigurationMessage> _communicator; |
415 | + private ConfigurationMessage _message; |
416 | + private MockRepository _mocks; |
417 | + private SyncConfigurationService _service; |
418 | + |
419 | + #endregion |
420 | + |
421 | + #region Setup |
422 | + |
423 | + [SetUp] |
424 | + public void Setup() |
425 | + { |
426 | + _mocks = new MockRepository(); |
427 | + _messageFactory = _mocks.StrictMock<ISyncConfigurationMessageFactory>(); |
428 | + _communicator = _mocks.StrictMock<ITcpClientCommunicator<ConfigurationMessage>>(); |
429 | + _message = _mocks.StrictMock<ConfigurationMessage>(); |
430 | + _service = new SyncConfigurationService |
431 | + { |
432 | + SyncConfigurationMessageFactory = _messageFactory, |
433 | + TcpClientCommunicator = _communicator |
434 | + }; |
435 | + } |
436 | + |
437 | + #endregion |
438 | + |
439 | + #region Tests |
440 | + |
441 | + [Test] |
442 | + public void GetThrottlingLimitsCorrectMessageTest() |
443 | + { |
444 | + _message.Type = ConfigurationMessage.MessageType.THROTTLING; |
445 | + _message.Throttling = new ConfigurationMessage.ThrottlingLimitsMessage(); |
446 | + _mocks.BackToRecord(_message); |
447 | + using (_mocks.Record()) |
448 | + { |
449 | + Expect.Call(_messageFactory.QueryThrottling()) |
450 | + .Return(_message) |
451 | + .Repeat.Once(); |
452 | + Expect.Call(_communicator.SendReceiveMessage<ThrottlingData>(_message, Convert.ToThrottlingData)) |
453 | + .Return(new ThrottlingData()) |
454 | + .Repeat.Once(); |
455 | + } |
456 | + using (_mocks.Playback()) |
457 | + { |
458 | + _service.GetThrottlingLimits(); |
459 | + } |
460 | + } |
461 | + |
462 | + [TestCase(3, 4)] |
463 | + [TestCase(34, 56)] |
464 | + public void SetThrottlingLimitsCorrectMessageTest(int download, int upload) |
465 | + { |
466 | + var data = new ThrottlingData |
467 | + { |
468 | + Download = download, |
469 | + Upload = upload |
470 | + }; |
471 | + using (_mocks.Record()) |
472 | + { |
473 | + Expect.Call(_messageFactory.SetThrottlingLimits(data)) |
474 | + .Return(_message) |
475 | + .Repeat.Once(); |
476 | + Expect.Call(() => _communicator.SendMessage(_message)) |
477 | + .Repeat.Once(); |
478 | + } |
479 | + using (_mocks.Playback()) |
480 | + { |
481 | + _service.SetThrottlingLimits(data); |
482 | + } |
483 | + } |
484 | + |
485 | + [TestCase(true)] |
486 | + [TestCase(false)] |
487 | + public void EnableThrottlingLimitsCorrectMessageTest(bool isEnabled) |
488 | + { |
489 | + using (_mocks.Record()) |
490 | + { |
491 | + Expect.Call(_messageFactory.EnableThrottling(isEnabled)) |
492 | + .Return(_message); |
493 | + Expect.Call(() => _communicator.SendMessage(_message)) |
494 | + .Repeat.Once(); |
495 | + } |
496 | + using (_mocks.Playback()) |
497 | + { |
498 | + _service.EnableThrottlingLimits(isEnabled); |
499 | + } |
500 | + } |
501 | + |
502 | + [Test] |
503 | + public void IsEnabledThrottlingLimitsCorrectMessageTest() |
504 | + { |
505 | + _message.Type = ConfigurationMessage.MessageType.ENABLETHROTTLING; |
506 | + _mocks.BackToRecord(_message); |
507 | + using (_mocks.Record()) |
508 | + { |
509 | + Expect.Call(_messageFactory.QueryThrottling()) |
510 | + .Return(_message) |
511 | + .Repeat.Once(); |
512 | + Expect.Call(_communicator.SendReceiveMessage<bool>(_message, Convert.ToIsEnabledThrottling)) |
513 | + .Return(true) |
514 | + .Repeat.Once(); |
515 | + } |
516 | + using (_mocks.Playback()) |
517 | + { |
518 | + _service.IsEnabledThrottlingLimits(); |
519 | + } |
520 | + } |
521 | + |
522 | + [TestCase(true)] |
523 | + [TestCase(false)] |
524 | + public void EnableUdfAutosubscribeCorrectMessageTest(bool isEnabled) |
525 | + { |
526 | + using (_mocks.Record()) |
527 | + { |
528 | + Expect.Call(_messageFactory.EnablesAutosubscribe(isEnabled)) |
529 | + .Return(_message); |
530 | + Expect.Call(() => _communicator.SendMessage(_message)) |
531 | + .Repeat.Once(); |
532 | + } |
533 | + using (_mocks.Playback()) |
534 | + { |
535 | + _service.EnableUdfAutosubscribe(isEnabled); |
536 | + } |
537 | + } |
538 | + |
539 | + [Test] |
540 | + public void IsEnabledUdfAutosubscribeCorrectMessageTest() |
541 | + { |
542 | + _message.Type = ConfigurationMessage.MessageType.ENABLEAUTOSUBSCRIBE; |
543 | + _mocks.BackToRecord(_message); |
544 | + using (_mocks.Record()) |
545 | + { |
546 | + Expect.Call(_messageFactory.QueryThrottling()) |
547 | + .Return(_message) |
548 | + .Repeat.Once(); |
549 | + Expect.Call(_communicator.SendReceiveMessage<bool>(_message, Convert.ToIsAutosubscribe)) |
550 | + .Return(false) |
551 | + .Repeat.Once(); |
552 | + } |
553 | + using (_mocks.Playback()) |
554 | + { |
555 | + _service.IsEnabledUdfAutosubscribe(); |
556 | + } |
557 | + } |
558 | + |
559 | + #endregion |
560 | + } |
561 | +} |
562 | |
563 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncDaemonServiceFixture.cs' |
564 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncDaemonServiceFixture.cs 2010-07-07 10:41:49 +0000 |
565 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncDaemonServiceFixture.cs 2010-08-11 10:35:55 +0000 |
566 | @@ -1,4 +1,4 @@ |
567 | -/** |
568 | +/* |
569 | * Copyright 2010 Canonical Ltd. |
570 | * |
571 | * This file is part of UbuntuOne on Windows. |
572 | @@ -17,7 +17,9 @@ |
573 | * |
574 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
575 | */ |
576 | +using System.Collections.Generic; |
577 | using Canonical.UbuntuOne.Common; |
578 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
579 | using log4net; |
580 | using NUnit.Framework; |
581 | using Rhino.Mocks; |
582 | @@ -27,31 +29,44 @@ |
583 | [TestFixture] |
584 | public class SyncDaemonServiceFixture |
585 | { |
586 | - #region Setup |
587 | + #region Variables |
588 | |
589 | + private ISyncDaemonMessageFactory _messageFactory; |
590 | + private SyncDaemonMessage _message; |
591 | private MockRepository _mocks; |
592 | - private IAuthentication _auth; |
593 | - private IProcessManagerFactory _managerFactory; |
594 | - private IProcessManager _processManager; |
595 | private SyncDaemonService _service; |
596 | + private IAuthentication _authentication; |
597 | private ILog _logger; |
598 | + private IProcessManagerFactory _processManagerFactory; |
599 | + private IProcessManager _processManager; |
600 | + private ITcpClientCommunicator<SyncDaemonMessage> _communicator; |
601 | + |
602 | + #endregion |
603 | + |
604 | + #region Setup |
605 | |
606 | [SetUp] |
607 | public void Setup() |
608 | { |
609 | _mocks = new MockRepository(); |
610 | - _auth = _mocks.DynamicMock<IAuthentication>(); |
611 | - _managerFactory = _mocks.DynamicMock<IProcessManagerFactory>(); |
612 | - _processManager = _mocks.DynamicMock<IProcessManager>(); |
613 | + _messageFactory = _mocks.StrictMock<ISyncDaemonMessageFactory>(); |
614 | + _message = _mocks.StrictMock<SyncDaemonMessage>(); |
615 | _logger = _mocks.DynamicMock<ILog>(); |
616 | + _authentication = _mocks.StrictMock<IAuthentication>(); |
617 | + _processManagerFactory = _mocks.StrictMock<IProcessManagerFactory>(); |
618 | + _processManager = _mocks.StrictMock<IProcessManager>(); |
619 | + _communicator = _mocks.StrictMock<ITcpClientCommunicator<SyncDaemonMessage>>(); |
620 | _service = new SyncDaemonService |
621 | { |
622 | + SyncDaemonMessageFactory = _messageFactory, |
623 | + Authentication = _authentication, |
624 | Logger = _logger, |
625 | - ProcessManagerFactory = _managerFactory, |
626 | - Authentication = _auth |
627 | + ProcessManagerFactory = _processManagerFactory, |
628 | + TcpClientCommunicator = _communicator |
629 | }; |
630 | } |
631 | |
632 | + |
633 | #endregion |
634 | |
635 | #region Tests |
636 | @@ -67,21 +82,21 @@ |
637 | { |
638 | // expect to call the authentication class as well as |
639 | // the factory and the manager. |
640 | - SetupResult.For(_auth.IsAuthenticated) |
641 | + SetupResult.For(_authentication.IsAuthenticated) |
642 | .Return(true) |
643 | .Repeat.Once(); |
644 | |
645 | - SetupResult.For(_auth.Username) |
646 | + SetupResult.For(_authentication.Username) |
647 | .Return("mandel") |
648 | .Repeat.Once(); |
649 | |
650 | - Expect.Call(_managerFactory.GetManager()) |
651 | + Expect.Call(_processManagerFactory.GetManager()) |
652 | .Return(_processManager) |
653 | .Repeat.Once(); |
654 | |
655 | Expect.Call(() => _processManager.Start()) |
656 | .Repeat.Once(); |
657 | - |
658 | + |
659 | } |
660 | using (_mocks.Playback()) |
661 | { |
662 | @@ -100,15 +115,15 @@ |
663 | { |
664 | // expect to call the authentication class as well as |
665 | // the factory and the manager. |
666 | - SetupResult.For(_auth.IsAuthenticated) |
667 | + SetupResult.For(_authentication.IsAuthenticated) |
668 | .Return(true) |
669 | .Repeat.Once(); |
670 | |
671 | - SetupResult.For(_auth.Username) |
672 | + SetupResult.For(_authentication.Username) |
673 | .Return("mandel") |
674 | .Repeat.Once(); |
675 | |
676 | - Expect.Call(_managerFactory.GetManager()) |
677 | + Expect.Call(_processManagerFactory.GetManager()) |
678 | .Return(_processManager) |
679 | .Repeat.Once(); |
680 | |
681 | @@ -134,15 +149,15 @@ |
682 | { |
683 | // we try to run the process but we will throw an exception when |
684 | // trying to start the process |
685 | - SetupResult.For(_auth.IsAuthenticated) |
686 | + SetupResult.For(_authentication.IsAuthenticated) |
687 | .Return(true) |
688 | .Repeat.Once(); |
689 | |
690 | - SetupResult.For(_auth.Username) |
691 | + SetupResult.For(_authentication.Username) |
692 | .Return("mandel") |
693 | .Repeat.Once(); |
694 | |
695 | - Expect.Call(_managerFactory.GetManager()) |
696 | + Expect.Call(_processManagerFactory.GetManager()) |
697 | .Return(_processManager) |
698 | .Repeat.Once(); |
699 | |
700 | @@ -167,15 +182,15 @@ |
701 | { |
702 | // we try to run the process but we will throw an exception when |
703 | // trying to start the process |
704 | - SetupResult.For(_auth.IsAuthenticated) |
705 | + SetupResult.For(_authentication.IsAuthenticated) |
706 | .Return(true) |
707 | .Repeat.Once(); |
708 | |
709 | - SetupResult.For(_auth.Username) |
710 | + SetupResult.For(_authentication.Username) |
711 | .Return("mandel") |
712 | .Repeat.Once(); |
713 | |
714 | - Expect.Call(_managerFactory.GetManager()) |
715 | + Expect.Call(_processManagerFactory.GetManager()) |
716 | .Return(_processManager) |
717 | .Repeat.Once(); |
718 | |
719 | @@ -197,11 +212,11 @@ |
720 | { |
721 | using (_mocks.Record()) |
722 | { |
723 | - SetupResult.For(_auth.IsAuthenticated) |
724 | + SetupResult.For(_authentication.IsAuthenticated) |
725 | .Return(false) |
726 | .Repeat.Once(); |
727 | |
728 | - Expect.Call(_managerFactory.GetManager()) |
729 | + Expect.Call(_processManagerFactory.GetManager()) |
730 | .Repeat.Never(); |
731 | |
732 | Expect.Call(() => _processManager.Start()) |
733 | @@ -219,21 +234,23 @@ |
734 | [Test] |
735 | public void StopTest() |
736 | { |
737 | - using(_mocks.Record()) |
738 | + using (_mocks.Record()) |
739 | { |
740 | // set basic set up to be able to start and stop |
741 | - SetupResult.For(_auth.IsAuthenticated) |
742 | + SetupResult.For(_authentication.IsAuthenticated) |
743 | .Return(true) |
744 | .Repeat.Once(); |
745 | |
746 | - SetupResult.For(_auth.Username) |
747 | + SetupResult.For(_authentication.Username) |
748 | .Return("mandel") |
749 | .Repeat.Once(); |
750 | |
751 | - Expect.Call(_managerFactory.GetManager()) |
752 | + Expect.Call(_processManagerFactory.GetManager()) |
753 | .Return(_processManager) |
754 | .Repeat.Once(); |
755 | |
756 | + Expect.Call(() => _processManager.Start()) |
757 | + .Repeat.Once(); |
758 | Expect.Call(() => _processManager.Stop()) |
759 | .Repeat.Once(); |
760 | } |
761 | @@ -254,18 +271,21 @@ |
762 | using (_mocks.Record()) |
763 | { |
764 | // set basic set up to be able to start and stop |
765 | - SetupResult.For(_auth.IsAuthenticated) |
766 | + SetupResult.For(_authentication.IsAuthenticated) |
767 | .Return(true) |
768 | .Repeat.Once(); |
769 | |
770 | - SetupResult.For(_auth.Username) |
771 | + SetupResult.For(_authentication.Username) |
772 | .Return("mandel") |
773 | .Repeat.Once(); |
774 | |
775 | - Expect.Call(_managerFactory.GetManager()) |
776 | + Expect.Call(_processManagerFactory.GetManager()) |
777 | .Return(_processManager) |
778 | .Repeat.Once(); |
779 | |
780 | + Expect.Call(() => _processManager.Start()) |
781 | + .Repeat.Once(); |
782 | + |
783 | Expect.Call(() => _processManager.Stop()) |
784 | .Repeat.Once(); |
785 | } |
786 | @@ -286,11 +306,11 @@ |
787 | { |
788 | using (_mocks.Record()) |
789 | { |
790 | - SetupResult.For(_auth.IsAuthenticated) |
791 | + SetupResult.For(_authentication.IsAuthenticated) |
792 | .Return(true) |
793 | .Repeat.Once(); |
794 | |
795 | - SetupResult.For(_auth.Username) |
796 | + SetupResult.For(_authentication.Username) |
797 | .Return("mandel") |
798 | .Repeat.Once(); |
799 | } |
800 | @@ -310,18 +330,21 @@ |
801 | { |
802 | using (_mocks.Record()) |
803 | { |
804 | - SetupResult.For(_auth.IsAuthenticated) |
805 | + SetupResult.For(_authentication.IsAuthenticated) |
806 | .Return(true) |
807 | .Repeat.Once(); |
808 | |
809 | - SetupResult.For(_auth.Username) |
810 | + SetupResult.For(_authentication.Username) |
811 | .Return("mandel") |
812 | .Repeat.Once(); |
813 | |
814 | - Expect.Call(_managerFactory.GetManager()) |
815 | + Expect.Call(_processManagerFactory.GetManager()) |
816 | .Return(_processManager) |
817 | .Repeat.Once(); |
818 | |
819 | + Expect.Call(() => _processManager.Start()) |
820 | + .Repeat.Once(); |
821 | + |
822 | Expect.Call(() => _processManager.Stop()) |
823 | .Throw(new ProcessManagementException()); |
824 | } |
825 | @@ -342,18 +365,21 @@ |
826 | |
827 | using (_mocks.Record()) |
828 | { |
829 | - SetupResult.For(_auth.IsAuthenticated) |
830 | + SetupResult.For(_authentication.IsAuthenticated) |
831 | .Return(true) |
832 | .Repeat.Once(); |
833 | |
834 | - SetupResult.For(_auth.Username) |
835 | + SetupResult.For(_authentication.Username) |
836 | .Return("mandel") |
837 | .Repeat.Once(); |
838 | |
839 | - Expect.Call(_managerFactory.GetManager()) |
840 | + Expect.Call(_processManagerFactory.GetManager()) |
841 | .Return(_processManager) |
842 | .Repeat.Once(); |
843 | |
844 | + Expect.Call(() => _processManager.Start()) |
845 | + .Repeat.Once(); |
846 | + |
847 | Expect.Call(() => _processManager.Stop()) |
848 | .Throw(new ProcessManagementException()); |
849 | } |
850 | @@ -365,7 +391,178 @@ |
851 | } |
852 | } |
853 | |
854 | + [Test] |
855 | + public void GetListeningSocketTest() |
856 | + { |
857 | + Assert.Ignore("To be implemented."); |
858 | + } |
859 | + |
860 | + [Test] |
861 | + public void GetCurrentStatusCorrectMessageTest() |
862 | + { |
863 | + _message.Type = SyncDaemonMessage.MessageType.STATUS; |
864 | + _message.State = new SyncDaemonMessage.StateMessage(); |
865 | + _mocks.BackToRecord(_message); |
866 | + using(_mocks.Record()) |
867 | + { |
868 | + Expect.Call(_messageFactory.QueryState()) |
869 | + .Return(_message) |
870 | + .Repeat.Once(); |
871 | + Expect.Call(_communicator.SendReceiveMessage<StateData>(_message, Convert.ToStateData)) |
872 | + .Repeat.Once(); |
873 | + } |
874 | + using(_mocks.Playback()) |
875 | + { |
876 | + _service.GetCurrentStatus(); |
877 | + } |
878 | + } |
879 | + |
880 | + [Test] |
881 | + public void GetCurrentDownloadsCorrectMessageTest() |
882 | + { |
883 | + _message.Type = SyncDaemonMessage.MessageType.DOWNLOADS; |
884 | + _mocks.BackToRecord(_message); |
885 | + using (_mocks.Record()) |
886 | + { |
887 | + Expect.Call(_messageFactory.QueryDownloads()) |
888 | + .Return(_message) |
889 | + .Repeat.Once(); |
890 | + Expect.Call(_communicator.SendReceiveMessage<IList<DownloadData>>(_message, Convert.ToCurrentDownloads)) |
891 | + .Repeat.Once(); |
892 | + } |
893 | + using (_mocks.Playback()) |
894 | + { |
895 | + _service.GetCurrentDownloads(); |
896 | + } |
897 | + } |
898 | + |
899 | + [Test] |
900 | + public void GetWaitingContentCorrectMessageTest() |
901 | + { |
902 | + _message.Type = SyncDaemonMessage.MessageType.WAITING; |
903 | + _mocks.BackToRecord(_message); |
904 | + using (_mocks.Record()) |
905 | + { |
906 | + Expect.Call(_messageFactory.QueryWaiting()) |
907 | + .Return(_message) |
908 | + .Repeat.Once(); |
909 | + Expect.Call(_communicator.SendReceiveMessage<IList<QueueItemData>>(_message, Convert.ToCurrentWaiting)) |
910 | + .Repeat.Once(); |
911 | + } |
912 | + using (_mocks.Playback()) |
913 | + { |
914 | + _service.GetWaitingContent(); |
915 | + } |
916 | + } |
917 | + |
918 | + [TestCase("ShareId", "NodeId")] |
919 | + [TestCase("Share", "Node")] |
920 | + public void ScheduleAsNextTest(string shareId, string nodeId) |
921 | + { |
922 | + using (_mocks.Record()) |
923 | + { |
924 | + Expect.Call(_messageFactory.ScheduleAsNext(shareId, nodeId)) |
925 | + .Return(_message) |
926 | + .Repeat.Once(); |
927 | + Expect.Call(() => _communicator.SendMessage(_message)) |
928 | + .Repeat.Once(); |
929 | + } |
930 | + using (_mocks.Playback()) |
931 | + { |
932 | + _service.ScheduleAsNext(shareId, nodeId); |
933 | + } |
934 | + } |
935 | + |
936 | + [Test] |
937 | + public void GetCurrentUploadsCorrectMessageTest() |
938 | + { |
939 | + _message.Type = SyncDaemonMessage.MessageType.UPLOADS; |
940 | + _mocks.BackToRecord(_message); |
941 | + using (_mocks.Record()) |
942 | + { |
943 | + Expect.Call(_messageFactory.QueryUploads()) |
944 | + .Return(_message) |
945 | + .Repeat.Once(); |
946 | + Expect.Call(_communicator.SendReceiveMessage<IList<UploadData>>(_message, Convert.ToCurrentUploads)) |
947 | + .Repeat.Once(); |
948 | + } |
949 | + using (_mocks.Playback()) |
950 | + { |
951 | + _service.GetCurrentUploads(); |
952 | + } |
953 | + } |
954 | + |
955 | + [Test] |
956 | + public void ConnectTest() |
957 | + { |
958 | + using (_mocks.Record()) |
959 | + { |
960 | + Expect.Call(_messageFactory.Connect()) |
961 | + .Return(_message) |
962 | + .Repeat.Once(); |
963 | + Expect.Call(() => _communicator.SendMessage(_message)) |
964 | + .Repeat.Once(); |
965 | + } |
966 | + using (_mocks.Playback()) |
967 | + { |
968 | + _service.Connect(); |
969 | + } |
970 | + } |
971 | + |
972 | + [Test] |
973 | + public void DisconnectTest() |
974 | + { |
975 | + using (_mocks.Record()) |
976 | + { |
977 | + Expect.Call(_messageFactory.Disconnect()) |
978 | + .Return(_message) |
979 | + .Repeat.Once(); |
980 | + Expect.Call(() => _communicator.SendMessage(_message)) |
981 | + .Repeat.Once(); |
982 | + } |
983 | + using (_mocks.Playback()) |
984 | + { |
985 | + _service.Disconnect(); |
986 | + } |
987 | + } |
988 | + |
989 | + [Test] |
990 | + public void GetRootDirectoryTest() |
991 | + { |
992 | + _message.Type = SyncDaemonMessage.MessageType.ROOT; |
993 | + _mocks.BackToRecord(_message); |
994 | + using (_mocks.Record()) |
995 | + { |
996 | + Expect.Call(_messageFactory.QueryRoot()) |
997 | + .Return(_message) |
998 | + .Repeat.Once(); |
999 | + Expect.Call(_communicator.SendReceiveMessage<string>(_message, Convert.ToRootDirectory)) |
1000 | + .Return("test") |
1001 | + .Repeat.Once(); |
1002 | + } |
1003 | + using (_mocks.Playback()) |
1004 | + { |
1005 | + _service.GetRootDirectory(); |
1006 | + } |
1007 | + } |
1008 | + |
1009 | + [Test] |
1010 | + public void QuitTest() |
1011 | + { |
1012 | + using (_mocks.Record()) |
1013 | + { |
1014 | + Expect.Call(_messageFactory.Quit()) |
1015 | + .Return(_message) |
1016 | + .Repeat.Once(); |
1017 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1018 | + .Repeat.Once(); |
1019 | + } |
1020 | + using (_mocks.Playback()) |
1021 | + { |
1022 | + _service.Quit(); |
1023 | + } |
1024 | + } |
1025 | + |
1026 | #endregion |
1027 | - |
1028 | } |
1029 | } |
1030 | |
1031 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncFoldersServiceFixture.cs' |
1032 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncFoldersServiceFixture.cs 1970-01-01 00:00:00 +0000 |
1033 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncFoldersServiceFixture.cs 2010-08-11 10:35:55 +0000 |
1034 | @@ -0,0 +1,200 @@ |
1035 | +/* |
1036 | + * Copyright 2010 Canonical Ltd. |
1037 | + * |
1038 | + * This file is part of UbuntuOne on Windows. |
1039 | + * |
1040 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1041 | + * it under the terms of the GNU Lesser General Public License version |
1042 | + * as published by the Free Software Foundation. |
1043 | + * |
1044 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1045 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1046 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1047 | + * GNU Lesser General Public License for more details. |
1048 | + * |
1049 | + * You should have received a copy of the GNU Lesser General Public License |
1050 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1051 | + * |
1052 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1053 | + */ |
1054 | +using System.Collections.Generic; |
1055 | +using Canonical.UbuntuOne.Common; |
1056 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
1057 | +using NUnit.Framework; |
1058 | +using Rhino.Mocks; |
1059 | + |
1060 | +namespace Canonical.UbuntuOne.ProcessDispatcher.Tests |
1061 | +{ |
1062 | + [TestFixture] |
1063 | + public class SyncFoldersServiceFixture |
1064 | + { |
1065 | + #region Variables |
1066 | + |
1067 | + private ISyncFolderMessageFactory _messageFactory; |
1068 | + private FolderMessage _message; |
1069 | + private MockRepository _mocks; |
1070 | + private SyncFoldersService _service; |
1071 | + private ITcpClientCommunicator<FolderMessage> _communicator; |
1072 | + |
1073 | + #endregion |
1074 | + |
1075 | + #region Setup & Tear downs |
1076 | + |
1077 | + [SetUp] |
1078 | + public void Setup() |
1079 | + { |
1080 | + _mocks = new MockRepository(); |
1081 | + _messageFactory = _mocks.StrictMock<ISyncFolderMessageFactory>(); |
1082 | + _message = _mocks.StrictMock<FolderMessage>(); |
1083 | + _communicator = _mocks.StrictMock<ITcpClientCommunicator<FolderMessage>>(); |
1084 | + _service = new SyncFoldersService |
1085 | + { |
1086 | + SyncFolderMessageFactory = _messageFactory, |
1087 | + TcpClientCommunicator = _communicator |
1088 | + }; |
1089 | + } |
1090 | + |
1091 | + #endregion |
1092 | + |
1093 | + #region Tests |
1094 | + |
1095 | + [TestCase("path1")] |
1096 | + [TestCase("path to new location")] |
1097 | + public void CreateFolderUdfTest(string path) |
1098 | + { |
1099 | + using (_mocks.Record()) |
1100 | + { |
1101 | + Expect.Call(_messageFactory.CreateFolder(path)) |
1102 | + .Return(_message); |
1103 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1104 | + .Repeat.Once(); |
1105 | + } |
1106 | + using (_mocks.Playback()) |
1107 | + { |
1108 | + _service.CreateFolderUdf(path); |
1109 | + } |
1110 | + } |
1111 | + |
1112 | + [TestCase("path1")] |
1113 | + [TestCase("path to old location")] |
1114 | + public void DeleteFolderUdfTest(string path) |
1115 | + { |
1116 | + using (_mocks.Record()) |
1117 | + { |
1118 | + Expect.Call(_messageFactory.DeleteFolder(path)) |
1119 | + .Return(_message); |
1120 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1121 | + .Repeat.Once(); |
1122 | + } |
1123 | + using (_mocks.Playback()) |
1124 | + { |
1125 | + _service.DeleteFolderUdf(path); |
1126 | + } |
1127 | + } |
1128 | + |
1129 | + [Test] |
1130 | + public void GetFoldersCorrectMessageTest() |
1131 | + { |
1132 | + var data = new FolderMessage.UdfDataMessage |
1133 | + { |
1134 | + Node = new FolderMessage.NodeMessage() |
1135 | + }; |
1136 | + _message = new FolderMessage(new List<FolderMessage.UdfDataMessage>()) |
1137 | + { |
1138 | + Type = FolderMessage.MessageType.FOLDERS |
1139 | + }; |
1140 | + _message.Udfs.Add(data); |
1141 | + using (_mocks.Record()) |
1142 | + { |
1143 | + Expect.Call(_messageFactory.QueryFolders()) |
1144 | + .Return(_message) |
1145 | + .Repeat.Once(); |
1146 | + Expect.Call(_communicator.SendReceiveMessage<IList<UdfData>>(_message, Convert.ToAllFolders)) |
1147 | + .Repeat.Once(); |
1148 | + } |
1149 | + using (_mocks.Playback()) |
1150 | + { |
1151 | + _service.GetFolders(); |
1152 | + } |
1153 | + } |
1154 | + |
1155 | + [TestCase("firstId")] |
1156 | + [TestCase("secondId")] |
1157 | + public void SubscribeTest(string folderId) |
1158 | + { |
1159 | + using (_mocks.Record()) |
1160 | + { |
1161 | + Expect.Call(_messageFactory.Subscribe(folderId)) |
1162 | + .Return(_message); |
1163 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1164 | + .Repeat.Once(); |
1165 | + } |
1166 | + using (_mocks.Playback()) |
1167 | + { |
1168 | + _service.Subscribe(folderId); |
1169 | + } |
1170 | + } |
1171 | + |
1172 | + [TestCase("firstId")] |
1173 | + [TestCase("secondId")] |
1174 | + public void UnsubscribeTest(string folderId) |
1175 | + { |
1176 | + using (_mocks.Record()) |
1177 | + { |
1178 | + Expect.Call(_messageFactory.Unsubscribe(folderId)) |
1179 | + .Return(_message); |
1180 | + Expect.Call(() => _communicator.SendMessage((_message))) |
1181 | + .Repeat.Once(); |
1182 | + } |
1183 | + using (_mocks.Playback()) |
1184 | + { |
1185 | + _service.Unsubscribe(folderId); |
1186 | + } |
1187 | + } |
1188 | + |
1189 | + [TestCase("FirstPath")] |
1190 | + [TestCase("secondPath")] |
1191 | + public void GetInfoCorrectMessageTest(string path) |
1192 | + { |
1193 | + var data = new FolderMessage.UdfDataMessage |
1194 | + { |
1195 | + Node = new FolderMessage.NodeMessage() |
1196 | + }; |
1197 | + _message = new FolderMessage(new List<FolderMessage.UdfDataMessage>()) |
1198 | + { |
1199 | + Type = FolderMessage.MessageType.INFO |
1200 | + }; |
1201 | + _message.Udfs.Add(data); |
1202 | + using (_mocks.Record()) |
1203 | + { |
1204 | + Expect.Call(_messageFactory.QueryInfo(path)) |
1205 | + .Return(_message) |
1206 | + .Repeat.Once(); |
1207 | + Expect.Call(_communicator.SendReceiveMessage<UdfData>(_message, Convert.ToUdfData)) |
1208 | + .Repeat.Once(); |
1209 | + } |
1210 | + using (_mocks.Playback()) |
1211 | + { |
1212 | + _service.GetInfo(path); |
1213 | + } |
1214 | + } |
1215 | + |
1216 | + [Test] |
1217 | + public void RefreshVolumes() |
1218 | + { |
1219 | + using (_mocks.Record()) |
1220 | + { |
1221 | + Expect.Call(_messageFactory.RefreshVolumes()) |
1222 | + .Return(_message); |
1223 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1224 | + .Repeat.Once(); |
1225 | + } |
1226 | + using (_mocks.Playback()) |
1227 | + { |
1228 | + _service.RefreshVolumes(); |
1229 | + } |
1230 | + } |
1231 | + |
1232 | + #endregion |
1233 | + } |
1234 | +} |
1235 | |
1236 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncSharesServiceFixture.cs' |
1237 | --- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncSharesServiceFixture.cs 1970-01-01 00:00:00 +0000 |
1238 | +++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncSharesServiceFixture.cs 2010-08-11 10:35:55 +0000 |
1239 | @@ -0,0 +1,167 @@ |
1240 | +/* |
1241 | + * Copyright 2010 Canonical Ltd. |
1242 | + * |
1243 | + * This file is part of UbuntuOne on Windows. |
1244 | + * |
1245 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1246 | + * it under the terms of the GNU Lesser General Public License version |
1247 | + * as published by the Free Software Foundation. |
1248 | + * |
1249 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1250 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1251 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1252 | + * GNU Lesser General Public License for more details. |
1253 | + * |
1254 | + * You should have received a copy of the GNU Lesser General Public License |
1255 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1256 | + * |
1257 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1258 | + */ |
1259 | +using System.Collections.Generic; |
1260 | +using Canonical.UbuntuOne.Common; |
1261 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
1262 | +using NUnit.Framework; |
1263 | +using Rhino.Mocks; |
1264 | + |
1265 | +namespace Canonical.UbuntuOne.ProcessDispatcher.Tests |
1266 | +{ |
1267 | + [TestFixture] |
1268 | + public class SyncSharesServiceFixture |
1269 | + { |
1270 | + #region Variables |
1271 | + |
1272 | + private ISyncShareMessageFactory _messageFactory; |
1273 | + private ShareMessage _message; |
1274 | + private MockRepository _mocks; |
1275 | + private SyncSharesService _service; |
1276 | + private ITcpClientCommunicator<ShareMessage> _communicator; |
1277 | + |
1278 | + #endregion |
1279 | + |
1280 | + #region Setup & Tear down |
1281 | + |
1282 | + [SetUp] |
1283 | + public void Setup() |
1284 | + { |
1285 | + _mocks = new MockRepository(); |
1286 | + _messageFactory = _mocks.StrictMock<ISyncShareMessageFactory>(); |
1287 | + _message = _mocks.StrictMock<ShareMessage>(); |
1288 | + _communicator = _mocks.StrictMock<ITcpClientCommunicator<ShareMessage>>(); |
1289 | + _service = new SyncSharesService |
1290 | + { |
1291 | + SyncShareMessageFactory = _messageFactory, |
1292 | + TcpClientCommunicator = _communicator |
1293 | + }; |
1294 | + } |
1295 | + |
1296 | + #endregion |
1297 | + |
1298 | + #region Tests |
1299 | + |
1300 | + [Test] |
1301 | + public void GetSharesTest() |
1302 | + { |
1303 | + using(_mocks.Record()) |
1304 | + { |
1305 | + Expect.Call(_messageFactory.QueryShares()) |
1306 | + .Return(_message) |
1307 | + .Repeat.Once(); |
1308 | + Expect.Call(_communicator.SendReceiveMessage<IList<ShareData>>(_message, Convert.ToGetShares)) |
1309 | + .Return(new List<ShareData>()) |
1310 | + .Repeat.Once(); |
1311 | + } |
1312 | + using(_mocks.Playback()) |
1313 | + { |
1314 | + _service.GetShares(); |
1315 | + } |
1316 | + } |
1317 | + |
1318 | + [TestCase("ShareId")] |
1319 | + public void AcceptShare(string shareId) |
1320 | + { |
1321 | + using (_mocks.Record()) |
1322 | + { |
1323 | + Expect.Call(_messageFactory.AcceptShare(shareId)) |
1324 | + .Return(_message) |
1325 | + .Repeat.Once(); |
1326 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1327 | + .Repeat.Once(); |
1328 | + } |
1329 | + using (_mocks.Playback()) |
1330 | + { |
1331 | + _service.AcceptShare(shareId); |
1332 | + } |
1333 | + } |
1334 | + |
1335 | + [TestCase("ShareID")] |
1336 | + public void RejectShare(string shareId) |
1337 | + { |
1338 | + using (_mocks.Record()) |
1339 | + { |
1340 | + Expect.Call(_messageFactory.RejectShare(shareId)) |
1341 | + .Return(_message) |
1342 | + .Repeat.Once(); |
1343 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1344 | + .Repeat.Once(); |
1345 | + } |
1346 | + using (_mocks.Playback()) |
1347 | + { |
1348 | + _service.RejectShare(shareId); |
1349 | + } |
1350 | + } |
1351 | + |
1352 | + [TestCase("Path", "Username", "Name", AccessLevel.MODIFY)] |
1353 | + public void CreateShare(string path, string username, string name, AccessLevel accessLevel) |
1354 | + { |
1355 | + using (_mocks.Record()) |
1356 | + { |
1357 | + Expect.Call(_messageFactory.CreateShare(path, username, name, accessLevel)) |
1358 | + .Return(_message) |
1359 | + .Repeat.Once(); |
1360 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1361 | + .Repeat.Once(); |
1362 | + } |
1363 | + using (_mocks.Playback()) |
1364 | + { |
1365 | + _service.CreateShare(path, username, name, accessLevel); |
1366 | + } |
1367 | + } |
1368 | + |
1369 | + [Test] |
1370 | + public void UpdateShares() |
1371 | + { |
1372 | + using (_mocks.Record()) |
1373 | + { |
1374 | + Expect.Call(_messageFactory.UpdateShares()) |
1375 | + .Return(_message) |
1376 | + .Repeat.Once(); |
1377 | + Expect.Call(() => _communicator.SendMessage(_message)) |
1378 | + .Repeat.Once(); |
1379 | + } |
1380 | + using (_mocks.Playback()) |
1381 | + { |
1382 | + _service.UpdateShares(); |
1383 | + } |
1384 | + } |
1385 | + |
1386 | + [Test] |
1387 | + public void GetShared() |
1388 | + { |
1389 | + using (_mocks.Record()) |
1390 | + { |
1391 | + Expect.Call(_messageFactory.GetShared()) |
1392 | + .Return(_message) |
1393 | + .Repeat.Once(); |
1394 | + Expect.Call(_communicator.SendReceiveMessage<IList<ShareData>>(_message, Convert.ToGetShared)) |
1395 | + .Return(new List<ShareData>()) |
1396 | + .Repeat.Once(); |
1397 | + } |
1398 | + using (_mocks.Playback()) |
1399 | + { |
1400 | + _service.GetShared(); |
1401 | + } |
1402 | + } |
1403 | + |
1404 | + #endregion |
1405 | + } |
1406 | +} |
1407 | |
1408 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj' |
1409 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj 2010-08-03 15:34:47 +0000 |
1410 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj 2010-08-11 10:35:55 +0000 |
1411 | @@ -71,11 +71,17 @@ |
1412 | <Compile Include="..\Version.cs"> |
1413 | <Link>Properties\Version.cs</Link> |
1414 | </Compile> |
1415 | + <Compile Include="Net\ITcpClient.cs" /> |
1416 | + <Compile Include="Net\ITcpClientCommunicator.cs" /> |
1417 | + <Compile Include="Net\ITcpClientFactory.cs" /> |
1418 | + <Compile Include="Net\TcpClientCommunicator.cs" /> |
1419 | <Compile Include="Program.cs" /> |
1420 | <Compile Include="ProjectInstaller.cs"> |
1421 | <SubType>Component</SubType> |
1422 | </Compile> |
1423 | <Compile Include="Protobuf\FolderMessageExtensions.cs" /> |
1424 | + <Compile Include="Protobuf\IProtobufSerializer.cs" /> |
1425 | + <Compile Include="Protobuf\ProtobufSerializer.cs" /> |
1426 | <Compile Include="Protobuf\ShareMessageExtensions.cs" /> |
1427 | <Compile Include="SyncConfigurationService.cs" /> |
1428 | <Compile Include="SyncDaemonService.cs" /> |
1429 | |
1430 | === added directory 'src/Canonical.UbuntuOne.ProcessDispatcher/Net' |
1431 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClient.cs' |
1432 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClient.cs 1970-01-01 00:00:00 +0000 |
1433 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClient.cs 2010-08-11 10:35:55 +0000 |
1434 | @@ -0,0 +1,42 @@ |
1435 | +/* |
1436 | + * Copyright 2010 Canonical Ltd. |
1437 | + * |
1438 | + * This file is part of UbuntuOne on Windows. |
1439 | + * |
1440 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1441 | + * it under the terms of the GNU Lesser General Public License version |
1442 | + * as published by the Free Software Foundation. |
1443 | + * |
1444 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1445 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1446 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1447 | + * GNU Lesser General Public License for more details. |
1448 | + * |
1449 | + * You should have received a copy of the GNU Lesser General Public License |
1450 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1451 | + * |
1452 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1453 | + */ |
1454 | +using System.Net.Sockets; |
1455 | + |
1456 | +namespace Canonical.UbuntuOne.ProcessDispatcher.Net |
1457 | +{ |
1458 | + /// <summary> |
1459 | + /// Interface to be implemented by a TcpClient that allows to communicate with the |
1460 | + /// python code. |
1461 | + /// </summary> |
1462 | + internal interface ITcpClient |
1463 | + { |
1464 | + /// <summary> |
1465 | + /// Returns the stream that is used by the tcp client to communicate with |
1466 | + /// the python code. |
1467 | + /// </summary> |
1468 | + /// <returns>A stream that can send data to the python process.</returns> |
1469 | + NetworkStream GetStream(); |
1470 | + |
1471 | + /// <summary> |
1472 | + /// Closes the TcpClient release the different used resources. |
1473 | + /// </summary> |
1474 | + void Close(); |
1475 | + } |
1476 | +} |
1477 | |
1478 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientCommunicator.cs' |
1479 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientCommunicator.cs 1970-01-01 00:00:00 +0000 |
1480 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientCommunicator.cs 2010-08-11 10:35:55 +0000 |
1481 | @@ -0,0 +1,48 @@ |
1482 | +/* |
1483 | + * Copyright 2010 Canonical Ltd. |
1484 | + * |
1485 | + * This file is part of UbuntuOne on Windows. |
1486 | + * |
1487 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1488 | + * it under the terms of the GNU Lesser General Public License version |
1489 | + * as published by the Free Software Foundation. |
1490 | + * |
1491 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1492 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1493 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1494 | + * GNU Lesser General Public License for more details. |
1495 | + * |
1496 | + * You should have received a copy of the GNU Lesser General Public License |
1497 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1498 | + * |
1499 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1500 | + */ |
1501 | +using System; |
1502 | + |
1503 | +namespace Canonical.UbuntuOne.ProcessDispatcher.Net |
1504 | +{ |
1505 | + /// <summary> |
1506 | + /// Interface to be implemented by a class that allows to send an receive |
1507 | + /// protobuf messages using sockets and a tcp client. |
1508 | + /// </summary> |
1509 | + internal interface ITcpClientCommunicator<TMessage> |
1510 | + { |
1511 | + /// <summary> |
1512 | + /// Sends a message to the python code but does not expecte and answer |
1513 | + /// back. |
1514 | + /// </summary> |
1515 | + /// <param name="message">The message to be sent to the python code.</param> |
1516 | + void SendMessage(TMessage message); |
1517 | + |
1518 | + /// <summary> |
1519 | + /// Sends a message to the python code and expects and answer back. |
1520 | + /// </summary> |
1521 | + /// <typeparam name="TResult">The type of object that is expected to be in the return from the |
1522 | + /// python code.</typeparam> |
1523 | + /// <param name="message">The message to be sent to the python code.</param> |
1524 | + /// <param name="conversion">A function that can convert the message type from the python code to |
1525 | + /// the expected result type.</param> |
1526 | + /// <returns>The resposne that the python returned once the message has been processed.</returns> |
1527 | + TResult SendReceiveMessage<TResult>(TMessage message, Func<TMessage, TResult> conversion); |
1528 | + } |
1529 | +} |
1530 | |
1531 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientFactory.cs' |
1532 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientFactory.cs 1970-01-01 00:00:00 +0000 |
1533 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientFactory.cs 2010-08-11 10:35:55 +0000 |
1534 | @@ -0,0 +1,36 @@ |
1535 | +/* |
1536 | + * Copyright 2010 Canonical Ltd. |
1537 | + * |
1538 | + * This file is part of UbuntuOne on Windows. |
1539 | + * |
1540 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1541 | + * it under the terms of the GNU Lesser General Public License version |
1542 | + * as published by the Free Software Foundation. |
1543 | + * |
1544 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1545 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1546 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1547 | + * GNU Lesser General Public License for more details. |
1548 | + * |
1549 | + * You should have received a copy of the GNU Lesser General Public License |
1550 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1551 | + * |
1552 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1553 | + */ |
1554 | +using System.Net.Sockets; |
1555 | + |
1556 | +namespace Canonical.UbuntuOne.ProcessDispatcher.Net |
1557 | +{ |
1558 | + /// <summary> |
1559 | + /// Interface to be implemented by a factory that will return TcpClients that are configured ready |
1560 | + /// to communicate with the python code. |
1561 | + /// </summary> |
1562 | + internal interface ITcpClientFactory |
1563 | + { |
1564 | + /// <summary> |
1565 | + /// Returns a client that allows to communicate with the python code. |
1566 | + /// </summary> |
1567 | + /// <returns>A TcpClient configured to talk with the python code through sockets.</returns> |
1568 | + ITcpClient GetClient(); |
1569 | + } |
1570 | +} |
1571 | |
1572 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientCommunicator.cs' |
1573 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientCommunicator.cs 1970-01-01 00:00:00 +0000 |
1574 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientCommunicator.cs 2010-08-11 10:35:55 +0000 |
1575 | @@ -0,0 +1,88 @@ |
1576 | +/* |
1577 | + * Copyright 2010 Canonical Ltd. |
1578 | + * |
1579 | + * This file is part of UbuntuOne on Windows. |
1580 | + * |
1581 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1582 | + * it under the terms of the GNU Lesser General Public License version |
1583 | + * as published by the Free Software Foundation. |
1584 | + * |
1585 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1586 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1587 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1588 | + * GNU Lesser General Public License for more details. |
1589 | + * |
1590 | + * You should have received a copy of the GNU Lesser General Public License |
1591 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1592 | + * |
1593 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1594 | + */ |
1595 | +using System; |
1596 | + |
1597 | +namespace Canonical.UbuntuOne.ProcessDispatcher.Net |
1598 | +{ |
1599 | + /// <summary> |
1600 | + /// Implementation of ITcpClientCommunicator that allows to send and receive |
1601 | + /// messages from the python code. |
1602 | + /// </summary> |
1603 | + internal class TcpClientCommunicator<TMessage> : ITcpClientCommunicator<TMessage> |
1604 | + { |
1605 | + #region DI properties |
1606 | + |
1607 | + /// <summary> |
1608 | + /// Gets and sets the factory that is used to crete a tcp client that will communicate with |
1609 | + /// the python code. |
1610 | + /// </summary> |
1611 | + internal ITcpClientFactory TcpClientFactory { get; set; } |
1612 | + |
1613 | + /// <summary> |
1614 | + /// Gets and sets the serializer that is used to serialize the protobuf messages that |
1615 | + /// are used to communicate with the python code. |
1616 | + /// </summary> |
1617 | + internal IProtobufSerializer ProtobufSerializer { get; set; } |
1618 | + |
1619 | + #endregion |
1620 | + |
1621 | + #region Implementation of ITcpClientCommunicator<TMessage> |
1622 | + |
1623 | + /// <summary> |
1624 | + /// Sends a message to the python code but does not expecte and answer |
1625 | + /// back. |
1626 | + /// </summary> |
1627 | + /// <param name="message">The message to be sent to the python code.</param> |
1628 | + public void SendMessage(TMessage message) |
1629 | + { |
1630 | + // get the tcp client that will be used to communicate with python |
1631 | + var client = TcpClientFactory.GetClient(); |
1632 | + var stream = client.GetStream(); |
1633 | + ProtobufSerializer.Serialize(stream, message); |
1634 | + stream.Close(); |
1635 | + client.Close(); |
1636 | + } |
1637 | + |
1638 | + /// <summary> |
1639 | + /// Sends a message to the python code and expects and answer back. |
1640 | + /// </summary> |
1641 | + /// <typeparam name="TResult">The type of object that is expected to be in the return from the |
1642 | + /// python code.</typeparam> |
1643 | + /// <param name="message">The message to be sent to the python code.</param> |
1644 | + /// <param name="conversion">A function that can convert the message type from the python code to |
1645 | + /// the expected result type.</param> |
1646 | + /// <returns>The resposne that the python returned once the message has been processed.</returns> |
1647 | + public TResult SendReceiveMessage<TResult>(TMessage message, Func<TMessage, TResult> conversion) |
1648 | + { |
1649 | + // get the tcp client that will be used to communicate with python |
1650 | + var client = TcpClientFactory.GetClient(); |
1651 | + var stream = client.GetStream(); |
1652 | + ProtobufSerializer.Serialize(stream, message); |
1653 | + var response = ProtobufSerializer.Deserialize<TMessage>(stream); |
1654 | + var result = conversion(response); |
1655 | + // close resources |
1656 | + stream.Close(); |
1657 | + client.Close(); |
1658 | + return result; |
1659 | + } |
1660 | + |
1661 | + #endregion |
1662 | + } |
1663 | +} |
1664 | |
1665 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Properties/AssemblyInfo.cs' |
1666 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Properties/AssemblyInfo.cs 2010-07-30 09:33:20 +0000 |
1667 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Properties/AssemblyInfo.cs 2010-08-11 10:35:55 +0000 |
1668 | @@ -23,3 +23,4 @@ |
1669 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. |
1670 | [assembly: ComVisible(false)] |
1671 | [assembly: InternalsVisibleTo("Canonical.UbuntuOne.ProcessDispatcher.Tests")] |
1672 | +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] |
1673 | |
1674 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/Convert.cs' |
1675 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/Convert.cs 2010-07-13 10:45:23 +0000 |
1676 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/Convert.cs 2010-08-11 10:35:55 +0000 |
1677 | @@ -1,4 +1,4 @@ |
1678 | -/** |
1679 | +/* |
1680 | * Copyright 2010 Canonical Ltd. |
1681 | * |
1682 | * This file is part of UbuntuOne on Windows. |
1683 | @@ -255,6 +255,7 @@ |
1684 | { |
1685 | ValidateArgs.Begin() |
1686 | .IsNotNull(udfProto) |
1687 | + .IsNotNull(udfProto.Node) |
1688 | .Check(); |
1689 | return new UdfData |
1690 | { |
1691 | |
1692 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/IProtobufSerializer.cs' |
1693 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/IProtobufSerializer.cs 1970-01-01 00:00:00 +0000 |
1694 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/IProtobufSerializer.cs 2010-08-11 10:35:55 +0000 |
1695 | @@ -0,0 +1,46 @@ |
1696 | +/* |
1697 | + * Copyright 2010 Canonical Ltd. |
1698 | + * |
1699 | + * This file is part of UbuntuOne on Windows. |
1700 | + * |
1701 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1702 | + * it under the terms of the GNU Lesser General Public License version |
1703 | + * as published by the Free Software Foundation. |
1704 | + * |
1705 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1706 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1707 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1708 | + * GNU Lesser General Public License for more details. |
1709 | + * |
1710 | + * You should have received a copy of the GNU Lesser General Public License |
1711 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1712 | + * |
1713 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1714 | + */ |
1715 | +using System.IO; |
1716 | + |
1717 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
1718 | +{ |
1719 | + /// <summary> |
1720 | + /// Interface to be implemented by a serializer that can serialize and deserialize the protobuf |
1721 | + /// messages that are used in the application for IPC. |
1722 | + /// </summary> |
1723 | + interface IProtobufSerializer |
1724 | + { |
1725 | + /// <summary> |
1726 | + /// Method that serializes a given message to the provided destination stream. |
1727 | + /// </summary> |
1728 | + /// <typeparam name="TMessage">A message type to serialize.</typeparam> |
1729 | + /// <param name="destinationStream">The destination stream that will contain the serialized version of the message.</param> |
1730 | + /// <param name="message">The message that will be serialize to its binary format.</param> |
1731 | + void Serialize<TMessage>(Stream destinationStream, TMessage message); |
1732 | + |
1733 | + /// <summary> |
1734 | + /// Method that deserializes an object from the given source stream. |
1735 | + /// </summary> |
1736 | + /// <typeparam name="TMessage">The type of the message that should be deserialized.</typeparam> |
1737 | + /// <param name="sourceStream">The source stream that contains the binary representation of the message.</param> |
1738 | + TMessage Deserialize<TMessage>(Stream sourceStream); |
1739 | + |
1740 | + } |
1741 | +} |
1742 | |
1743 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ISyncDaemonMessageFactory.cs' |
1744 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ISyncDaemonMessageFactory.cs 2010-07-07 17:06:36 +0000 |
1745 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ISyncDaemonMessageFactory.cs 2010-08-11 10:35:55 +0000 |
1746 | @@ -56,5 +56,32 @@ |
1747 | /// </summary> |
1748 | /// <returns>A message that queries the current uploads in the daemon.</returns> |
1749 | SyncDaemonMessage QueryUploads(); |
1750 | + |
1751 | + /// <summary> |
1752 | + /// Creates a new message that can be used to place an specific share id with a node id as the |
1753 | + /// next node to be processed. |
1754 | + /// </summary> |
1755 | + /// <param name="shareId">The id of the share.</param> |
1756 | + /// <param name="nodeId">The node id.</param> |
1757 | + /// <returns>A message that can be used to schedule the nex share to be processed.</returns> |
1758 | + SyncDaemonMessage ScheduleAsNext(string shareId, string nodeId); |
1759 | + |
1760 | + /// <summary> |
1761 | + /// Creates a message that will tell the daemon to connect to the UbuntuOne server. |
1762 | + /// </summary> |
1763 | + /// <returns>A message that will tell the python code to connect to the Ubuntu One server.</returns> |
1764 | + SyncDaemonMessage Connect(); |
1765 | + |
1766 | + /// <summary> |
1767 | + /// Creates a message that will tell the daemon to disconnect from the UbuntuOne server. |
1768 | + /// </summary> |
1769 | + /// <returns>A message that will tell the python code to disconnect from the UbuntuOne server. </returns> |
1770 | + SyncDaemonMessage Disconnect(); |
1771 | + |
1772 | + /// <summary> |
1773 | + /// Creates a new message that will tell the daemon to quit. |
1774 | + /// </summary> |
1775 | + /// <returns>A message that will tell the python code to quit the sync daemon.</returns> |
1776 | + SyncDaemonMessage Quit(); |
1777 | } |
1778 | } |
1779 | \ No newline at end of file |
1780 | |
1781 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ISyncFolderMessageFactory.cs' |
1782 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ISyncFolderMessageFactory.cs 2010-07-13 09:12:00 +0000 |
1783 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ISyncFolderMessageFactory.cs 2010-08-11 10:35:55 +0000 |
1784 | @@ -1,4 +1,4 @@ |
1785 | -/** |
1786 | +/* |
1787 | * Copyright 2010 Canonical Ltd. |
1788 | * |
1789 | * This file is part of UbuntuOne on Windows. |
1790 | @@ -66,6 +66,6 @@ |
1791 | /// Creates a message that tells the daemon to refresh the folders. |
1792 | /// </summary> |
1793 | /// <returns>A message that tells the daemon to refresh the folders.</returns> |
1794 | - FolderMessage RefreshFolders(); |
1795 | + FolderMessage RefreshVolumes(); |
1796 | } |
1797 | } |
1798 | \ No newline at end of file |
1799 | |
1800 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ProtobufSerializer.cs' |
1801 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ProtobufSerializer.cs 1970-01-01 00:00:00 +0000 |
1802 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/ProtobufSerializer.cs 2010-08-11 10:35:55 +0000 |
1803 | @@ -0,0 +1,56 @@ |
1804 | +/* |
1805 | + * Copyright 2010 Canonical Ltd. |
1806 | + * |
1807 | + * This file is part of UbuntuOne on Windows. |
1808 | + * |
1809 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1810 | + * it under the terms of the GNU Lesser General Public License version |
1811 | + * as published by the Free Software Foundation. |
1812 | + * |
1813 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1814 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1815 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1816 | + * GNU Lesser General Public License for more details. |
1817 | + * |
1818 | + * You should have received a copy of the GNU Lesser General Public License |
1819 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1820 | + * |
1821 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1822 | + */ |
1823 | +using System.IO; |
1824 | +using ProtoBuf; |
1825 | + |
1826 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
1827 | +{ |
1828 | + /// <summary> |
1829 | + /// Convenience class that wraps the static Serializer class that is used to serialize and |
1830 | + /// deserialize protobuf messages. |
1831 | + /// </summary> |
1832 | + internal class ProtobufSerializer : IProtobufSerializer |
1833 | + { |
1834 | + #region Implementation of IProtobufSerializer |
1835 | + |
1836 | + /// <summary> |
1837 | + /// Method that serializes a given message to the provided destination stream. |
1838 | + /// </summary> |
1839 | + /// <typeparam name="TMessage">A message type to serialize.</typeparam> |
1840 | + /// <param name="destinationStream">The destination stream that will contain the serialized version of the message.</param> |
1841 | + /// <param name="message">The message that will be serialize to its binary format.</param> |
1842 | + public void Serialize<TMessage>(Stream destinationStream, TMessage message) |
1843 | + { |
1844 | + Serializer.Serialize(destinationStream, message); |
1845 | + } |
1846 | + |
1847 | + /// <summary> |
1848 | + /// Method that deserializes an object from the given source stream. |
1849 | + /// </summary> |
1850 | + /// <typeparam name="TMessage">The type of the message that should be deserialized.</typeparam> |
1851 | + /// <param name="sourceStream">The source stream that contains the binary representation of the message.</param> |
1852 | + public TMessage Deserialize<TMessage>(Stream sourceStream) |
1853 | + { |
1854 | + return Serializer.Deserialize<TMessage>(sourceStream); |
1855 | + } |
1856 | + |
1857 | + #endregion |
1858 | + } |
1859 | +} |
1860 | |
1861 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/SyncDaemonMessageFactory.cs' |
1862 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/SyncDaemonMessageFactory.cs 2010-07-13 09:12:00 +0000 |
1863 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/SyncDaemonMessageFactory.cs 2010-08-11 10:35:55 +0000 |
1864 | @@ -1,4 +1,4 @@ |
1865 | -/** |
1866 | +/* |
1867 | * Copyright 2010 Canonical Ltd. |
1868 | * |
1869 | * This file is part of UbuntuOne on Windows. |
1870 | @@ -19,32 +19,96 @@ |
1871 | */ |
1872 | namespace Canonical.UbuntuOne.ProcessDispatcher |
1873 | { |
1874 | + /// <summary> |
1875 | + /// Implementation of the ISyncDaemonMessageFactory that generates the message to be sent to python. |
1876 | + /// </summary> |
1877 | internal class SyncDaemonMessageFactory : ISyncDaemonMessageFactory |
1878 | { |
1879 | - |
1880 | + /// <summary> |
1881 | + /// Creates a message that can be used to query the root of used by the sync daemon. |
1882 | + /// </summary> |
1883 | + /// <returns>A message that can be used to query the root of the daemon.</returns> |
1884 | public SyncDaemonMessage QueryRoot() |
1885 | { |
1886 | return new SyncDaemonMessage { Type = SyncDaemonMessage.MessageType.QUERYROOT }; |
1887 | } |
1888 | |
1889 | + /// <summary> |
1890 | + /// Creates a message that can be used to query the state of the sync daemon. |
1891 | + /// </summary> |
1892 | + /// <returns>A message that can be used to query the sync daemon about its state.</returns> |
1893 | public SyncDaemonMessage QueryState() |
1894 | { |
1895 | return new SyncDaemonMessage { Type = SyncDaemonMessage.MessageType.QUERYSTATUS }; |
1896 | } |
1897 | |
1898 | + /// <summary> |
1899 | + /// Creates a message that can be used to query the downloads that are currently in process |
1900 | + /// in the sycn daemon. |
1901 | + /// </summary> |
1902 | + /// <returns>A message that can be used to query the sync daemon about the current downloads.</returns> |
1903 | public SyncDaemonMessage QueryDownloads() |
1904 | { |
1905 | return new SyncDaemonMessage { Type = SyncDaemonMessage.MessageType.QUERYDOWNLOADS }; |
1906 | } |
1907 | |
1908 | + /// <summary> |
1909 | + /// Creates a message that can be used to query the sync daemon about the items that are in the |
1910 | + /// queue to be processed. |
1911 | + /// </summary> |
1912 | + /// <returns>A message to query the queue of the daemon.</returns> |
1913 | public SyncDaemonMessage QueryWaiting() |
1914 | { |
1915 | return new SyncDaemonMessage { Type = SyncDaemonMessage.MessageType.QUERYWAITING }; |
1916 | } |
1917 | |
1918 | + /// <summary> |
1919 | + /// Creates a message that can be used to query the sync daemon about the items that are currently |
1920 | + /// being uploaded. |
1921 | + /// </summary> |
1922 | + /// <returns>A message that queries the current uploads in the daemon.</returns> |
1923 | public SyncDaemonMessage QueryUploads() |
1924 | { |
1925 | return new SyncDaemonMessage { Type = SyncDaemonMessage.MessageType.QUERYUPLOADS }; |
1926 | } |
1927 | + |
1928 | + /// <summary> |
1929 | + /// Creates a new message that can be used to place an specific share id with a node id as the |
1930 | + /// next node to be processed. |
1931 | + /// </summary> |
1932 | + /// <param name="shareId">The id of the share.</param> |
1933 | + /// <param name="nodeId">The node id.</param> |
1934 | + /// <returns>A message that can be used to schedule the nex share to be processed.</returns> |
1935 | + public SyncDaemonMessage ScheduleAsNext(string shareId, string nodeId) |
1936 | + { |
1937 | + return new SyncDaemonMessage {NextShareId = shareId, NextNodeId = nodeId, Type = SyncDaemonMessage.MessageType.SCHEDULENEXT}; |
1938 | + } |
1939 | + |
1940 | + /// <summary> |
1941 | + /// Creates a message that will tell the daemon to connect to the UbuntuOne server. |
1942 | + /// </summary> |
1943 | + /// <returns>A message that will tell the python code to connect to the UbuntuOne server.</returns> |
1944 | + public SyncDaemonMessage Connect() |
1945 | + { |
1946 | + return new SyncDaemonMessage {Type = SyncDaemonMessage.MessageType.CONNECT}; |
1947 | + } |
1948 | + |
1949 | + /// <summary> |
1950 | + /// Creates a message that will tell the daemon to disconnect from the UbuntuOne server. |
1951 | + /// </summary> |
1952 | + /// <returns>A message that will tell the python code to disconnect from the UbuntuOne server. </returns> |
1953 | + public SyncDaemonMessage Disconnect() |
1954 | + { |
1955 | + return new SyncDaemonMessage { Type = SyncDaemonMessage.MessageType.DISCONNECT}; |
1956 | + } |
1957 | + |
1958 | + /// <summary> |
1959 | + /// Creates a new message that will tell the daemon to quit. |
1960 | + /// </summary> |
1961 | + /// <returns>A message that will tell the python code to quit the sync daemon.</returns> |
1962 | + public SyncDaemonMessage Quit() |
1963 | + { |
1964 | + return new SyncDaemonMessage{Type = SyncDaemonMessage.MessageType.QUIT}; |
1965 | + } |
1966 | } |
1967 | } |
1968 | |
1969 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/SyncFolderMessageFactory.cs' |
1970 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/SyncFolderMessageFactory.cs 2010-08-09 16:40:28 +0000 |
1971 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Protobuf/SyncFolderMessageFactory.cs 2010-08-11 10:35:55 +0000 |
1972 | @@ -82,7 +82,7 @@ |
1973 | }; |
1974 | } |
1975 | |
1976 | - public FolderMessage RefreshFolders() |
1977 | + public FolderMessage RefreshVolumes() |
1978 | { |
1979 | return new FolderMessage { Type = FolderMessage.MessageType.REFRESH }; |
1980 | } |
1981 | |
1982 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncConfigurationService.cs' |
1983 | --- src/Canonical.UbuntuOne.ProcessDispatcher/SyncConfigurationService.cs 2010-08-02 10:07:10 +0000 |
1984 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncConfigurationService.cs 2010-08-11 10:35:55 +0000 |
1985 | @@ -1,4 +1,4 @@ |
1986 | -/** |
1987 | +/* |
1988 | * Copyright 2010 Canonical Ltd. |
1989 | * |
1990 | * This file is part of UbuntuOne on Windows. |
1991 | @@ -17,22 +17,32 @@ |
1992 | * |
1993 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1994 | */ |
1995 | -using System; |
1996 | using Canonical.UbuntuOne.Common; |
1997 | using Canonical.UbuntuOne.Common.Aop; |
1998 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
1999 | |
2000 | namespace Canonical.UbuntuOne.ProcessDispatcher |
2001 | { |
2002 | - class SyncConfigurationService : ISyncConfiguration |
2003 | + /// <summary> |
2004 | + /// Implementation of the ISyncConfiguration contract that fowards the required operations to the |
2005 | + /// python code which will perform the appropiate operations. |
2006 | + /// </summary> |
2007 | + internal class SyncConfigurationService : ISyncConfiguration |
2008 | { |
2009 | - /// <summary> |
2010 | - /// Provides a way that the client can use to register itself to be notified about events |
2011 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
2012 | - /// </summary> |
2013 | - public void RegisterClient() |
2014 | - { |
2015 | - throw new NotImplementedException(); |
2016 | - } |
2017 | + #region DI properties |
2018 | + |
2019 | + /// <summary> |
2020 | + /// Gets and sets the message factory that can be used to generate the appropiate messages to |
2021 | + /// communicate with the python process that manages the configuration. |
2022 | + /// </summary> |
2023 | + internal ISyncConfigurationMessageFactory SyncConfigurationMessageFactory { get; set; } |
2024 | + |
2025 | + /// <summary> |
2026 | + /// Gets and sets the communicator that is used to send and receive messages to the socket. |
2027 | + /// </summary> |
2028 | + internal ITcpClientCommunicator<ConfigurationMessage> TcpClientCommunicator { get; set; } |
2029 | + |
2030 | + #endregion |
2031 | |
2032 | /// <summary> |
2033 | /// Returns the throttling limits that have been set up for the daemon. |
2034 | @@ -41,7 +51,9 @@ |
2035 | [DebugLogged] |
2036 | public ThrottlingData GetThrottlingLimits() |
2037 | { |
2038 | - throw new NotImplementedException(); |
2039 | + // create a message that will be used to query the thorttling limits to the python process |
2040 | + var message = SyncConfigurationMessageFactory.QueryThrottling(); |
2041 | + return TcpClientCommunicator.SendReceiveMessage<ThrottlingData>(message, Convert.ToThrottlingData); |
2042 | } |
2043 | |
2044 | /// <summary> |
2045 | @@ -51,7 +63,8 @@ |
2046 | [DebugLogged] |
2047 | public void SetThrottlingLimits(ThrottlingData limits) |
2048 | { |
2049 | - throw new NotImplementedException(); |
2050 | + var message = SyncConfigurationMessageFactory.SetThrottlingLimits(limits); |
2051 | + TcpClientCommunicator.SendMessage(message); |
2052 | } |
2053 | |
2054 | /// <summary> |
2055 | @@ -61,7 +74,8 @@ |
2056 | [DebugLogged] |
2057 | public void EnableThrottlingLimits(bool isEnabled) |
2058 | { |
2059 | - throw new NotImplementedException(); |
2060 | + var message = SyncConfigurationMessageFactory.EnableThrottling(isEnabled); |
2061 | + TcpClientCommunicator.SendMessage(message); |
2062 | } |
2063 | |
2064 | /// <summary> |
2065 | @@ -71,7 +85,8 @@ |
2066 | [DebugLogged] |
2067 | public bool IsEnabledThrottlingLimits() |
2068 | { |
2069 | - throw new NotImplementedException(); |
2070 | + var message = SyncConfigurationMessageFactory.QueryThrottling(); |
2071 | + return TcpClientCommunicator.SendReceiveMessage<bool>(message, Convert.ToIsEnabledThrottling); |
2072 | } |
2073 | |
2074 | /// <summary> |
2075 | @@ -81,7 +96,8 @@ |
2076 | [DebugLogged] |
2077 | public void EnableUdfAutosubscribe(bool isEnable) |
2078 | { |
2079 | - throw new NotImplementedException(); |
2080 | + var message = SyncConfigurationMessageFactory.EnablesAutosubscribe(isEnable); |
2081 | + TcpClientCommunicator.SendMessage(message); |
2082 | } |
2083 | |
2084 | /// <summary> |
2085 | @@ -91,7 +107,8 @@ |
2086 | [DebugLogged] |
2087 | public bool IsEnabledUdfAutosubscribe() |
2088 | { |
2089 | - throw new NotImplementedException(); |
2090 | + var message = SyncConfigurationMessageFactory.QueryThrottling(); |
2091 | + return TcpClientCommunicator.SendReceiveMessage<bool>(message, Convert.ToIsAutosubscribe); |
2092 | } |
2093 | } |
2094 | } |
2095 | |
2096 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs' |
2097 | --- src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-08-05 08:15:00 +0000 |
2098 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-08-11 10:35:55 +0000 |
2099 | @@ -1,25 +1,28 @@ |
2100 | -// Copyright 2010 Canonical Ltd. |
2101 | -// |
2102 | -// This file is part of UbuntuOne on Windows. |
2103 | -// |
2104 | -// UbuntuOne on Windows is free software: you can redistribute it and/or modify |
2105 | -// it under the terms of the GNU Lesser General Public License version |
2106 | -// as published by the Free Software Foundation. |
2107 | -// |
2108 | -// Ubuntu One on Windows is distributed in the hope that it will be useful, |
2109 | -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
2110 | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2111 | -// GNU Lesser General Public License for more details. |
2112 | -// |
2113 | -// You should have received a copy of the GNU Lesser General Public License |
2114 | -// along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
2115 | -// |
2116 | -// Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
2117 | +/* |
2118 | + * Copyright 2010 Canonical Ltd. |
2119 | + * |
2120 | + * This file is part of UbuntuOne on Windows. |
2121 | + * |
2122 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
2123 | + * it under the terms of the GNU Lesser General Public License version |
2124 | + * as published by the Free Software Foundation. |
2125 | + * |
2126 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
2127 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2128 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2129 | + * GNU Lesser General Public License for more details. |
2130 | + * |
2131 | + * You should have received a copy of the GNU Lesser General Public License |
2132 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
2133 | + * |
2134 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
2135 | + */ |
2136 | using System; |
2137 | using System.Collections.Generic; |
2138 | using Canonical.UbuntuOne.Common; |
2139 | using Canonical.UbuntuOne.Common.Aop; |
2140 | using Canonical.UbuntuOne.Common.Validation; |
2141 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
2142 | using log4net; |
2143 | |
2144 | namespace Canonical.UbuntuOne.ProcessDispatcher |
2145 | @@ -73,6 +76,17 @@ |
2146 | /// </summary> |
2147 | internal IAuthentication Authentication { get; set; } |
2148 | |
2149 | + /// <summary> |
2150 | + /// Allows to get and set the factory that is used to generate the different messages that are sent |
2151 | + /// to the python code. |
2152 | + /// </summary> |
2153 | + internal ISyncDaemonMessageFactory SyncDaemonMessageFactory { get; set; } |
2154 | + |
2155 | + /// <summary> |
2156 | + /// Gets and sets the communicator that is used to send and receive messages to the socket. |
2157 | + /// </summary> |
2158 | + internal ITcpClientCommunicator<SyncDaemonMessage> TcpClientCommunicator { get; set; } |
2159 | + |
2160 | #endregion |
2161 | |
2162 | public SyncDaemonService() |
2163 | @@ -193,10 +207,10 @@ |
2164 | } |
2165 | |
2166 | /// <summary> |
2167 | - /// Provides a way that the client can use to register itself to be notified about events |
2168 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
2169 | + /// Returns the port number of the socket that the synd daemo is listening to for communication. |
2170 | /// </summary> |
2171 | - public void RegisterClient() |
2172 | + /// <returns></returns> |
2173 | + public int GetListeningSocket() |
2174 | { |
2175 | throw new NotImplementedException(); |
2176 | } |
2177 | @@ -208,7 +222,8 @@ |
2178 | [DebugLogged] |
2179 | public StateData GetCurrentStatus() |
2180 | { |
2181 | - throw new NotImplementedException(); |
2182 | + var message = SyncDaemonMessageFactory.QueryState(); |
2183 | + return TcpClientCommunicator.SendReceiveMessage<StateData>(message, Convert.ToStateData); |
2184 | } |
2185 | |
2186 | /// <summary> |
2187 | @@ -218,7 +233,8 @@ |
2188 | [DebugLogged] |
2189 | public IList<DownloadData> GetCurrentDownloads() |
2190 | { |
2191 | - throw new NotImplementedException(); |
2192 | + var message = SyncDaemonMessageFactory.QueryDownloads(); |
2193 | + return TcpClientCommunicator.SendReceiveMessage<IList<DownloadData>>(message, Convert.ToCurrentDownloads); |
2194 | } |
2195 | |
2196 | /// <summary> |
2197 | @@ -228,7 +244,8 @@ |
2198 | [DebugLogged] |
2199 | public IList<QueueItemData> GetWaitingContent() |
2200 | { |
2201 | - throw new NotImplementedException(); |
2202 | + var message = SyncDaemonMessageFactory.QueryWaiting(); |
2203 | + return TcpClientCommunicator.SendReceiveMessage<IList<QueueItemData>>(message, Convert.ToCurrentWaiting); |
2204 | } |
2205 | |
2206 | /// <summary> |
2207 | @@ -240,7 +257,8 @@ |
2208 | [DebugLogged] |
2209 | public void ScheduleAsNext(string shareId, string nodeId) |
2210 | { |
2211 | - throw new NotImplementedException(); |
2212 | + var message = SyncDaemonMessageFactory.ScheduleAsNext(shareId, nodeId); |
2213 | + TcpClientCommunicator.SendMessage(message); |
2214 | } |
2215 | |
2216 | /// <summary> |
2217 | @@ -250,7 +268,8 @@ |
2218 | [DebugLogged] |
2219 | public IList<UploadData> GetCurrentUploads() |
2220 | { |
2221 | - throw new NotImplementedException(); |
2222 | + var message = SyncDaemonMessageFactory.QueryUploads(); |
2223 | + return TcpClientCommunicator.SendReceiveMessage<IList<UploadData>>(message, Convert.ToCurrentUploads); |
2224 | } |
2225 | |
2226 | /// <summary> |
2227 | @@ -260,7 +279,8 @@ |
2228 | [DebugLogged] |
2229 | public void Connect() |
2230 | { |
2231 | - throw new NotImplementedException(); |
2232 | + var message = SyncDaemonMessageFactory.Connect(); |
2233 | + TcpClientCommunicator.SendMessage(message); |
2234 | } |
2235 | |
2236 | /// <summary> |
2237 | @@ -269,7 +289,8 @@ |
2238 | [DebugLogged] |
2239 | public void Disconnect() |
2240 | { |
2241 | - throw new NotImplementedException(); |
2242 | + var message = SyncDaemonMessageFactory.Disconnect(); |
2243 | + TcpClientCommunicator.SendMessage(message); |
2244 | } |
2245 | |
2246 | /// <summary> |
2247 | @@ -279,17 +300,19 @@ |
2248 | [DebugLogged] |
2249 | public string GetRootDirectory() |
2250 | { |
2251 | - throw new NotImplementedException(); |
2252 | + var message = SyncDaemonMessageFactory.QueryRoot(); |
2253 | + return TcpClientCommunicator.SendReceiveMessage<string>(message, Convert.ToRootDirectory); |
2254 | } |
2255 | |
2256 | /// <summary> |
2257 | - /// Allows client to tell the sync daemon to quit. Discomment allows the daemon toquee the event |
2258 | + /// Allows client to tell the sync daemon to quit. Discomment allows the daemon to quee the event |
2259 | /// for the next time it connects, quit completelly closes the service and stops listening the IO changes. |
2260 | /// </summary> |
2261 | [DebugLogged] |
2262 | public void Quit() |
2263 | { |
2264 | - throw new NotImplementedException(); |
2265 | + var message = SyncDaemonMessageFactory.Quit(); |
2266 | + TcpClientCommunicator.SendMessage(message); |
2267 | } |
2268 | } |
2269 | } |
2270 | |
2271 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncFileManagerService.cs' |
2272 | --- src/Canonical.UbuntuOne.ProcessDispatcher/SyncFileManagerService.cs 2010-08-09 16:40:28 +0000 |
2273 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncFileManagerService.cs 2010-08-11 10:35:55 +0000 |
2274 | @@ -24,16 +24,11 @@ |
2275 | |
2276 | namespace Canonical.UbuntuOne.ProcessDispatcher |
2277 | { |
2278 | - class SyncFileManagerService : ISyncFileManager |
2279 | + /// <summary> |
2280 | + /// Class that implements the ISyncFileManager bny fowarding the request to the python code. |
2281 | + /// </summary> |
2282 | + internal class SyncFileManagerService : ISyncFileManager |
2283 | { |
2284 | - /// <summary> |
2285 | - /// Provides a way that the client can use to register itself to be notified about events |
2286 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
2287 | - /// </summary> |
2288 | - public void RegisterClient() |
2289 | - { |
2290 | - throw new NotImplementedException(); |
2291 | - } |
2292 | |
2293 | [DebugLogged] |
2294 | public IDictionary<string, string> GetMetadata(string path) |
2295 | |
2296 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncFoldersService.cs' |
2297 | --- src/Canonical.UbuntuOne.ProcessDispatcher/SyncFoldersService.cs 2010-08-02 10:07:10 +0000 |
2298 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncFoldersService.cs 2010-08-11 10:35:55 +0000 |
2299 | @@ -1,4 +1,4 @@ |
2300 | -/** |
2301 | +/* |
2302 | * Copyright 2010 Canonical Ltd. |
2303 | * |
2304 | * This file is part of UbuntuOne on Windows. |
2305 | @@ -17,22 +17,31 @@ |
2306 | * |
2307 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
2308 | */ |
2309 | -using System; |
2310 | using System.Collections.Generic; |
2311 | using Canonical.UbuntuOne.Common; |
2312 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
2313 | |
2314 | namespace Canonical.UbuntuOne.ProcessDispatcher |
2315 | { |
2316 | - class SyncFoldersService : ISyncFolders |
2317 | + /// <summary> |
2318 | + /// Implementation of the ISyncFolders that fowards the request to the python code. |
2319 | + /// </summary> |
2320 | + internal class SyncFoldersService : ISyncFolders |
2321 | { |
2322 | - /// <summary> |
2323 | - /// Provides a way that the client can use to register itself to be notified about events |
2324 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
2325 | - /// </summary> |
2326 | - public void RegisterClient() |
2327 | - { |
2328 | - throw new NotImplementedException(); |
2329 | - } |
2330 | + #region DI properties |
2331 | + |
2332 | + /// <summary> |
2333 | + /// Gets and sets the factory that is used to generate the messages used to communicate with the |
2334 | + /// python process. |
2335 | + /// </summary> |
2336 | + internal ISyncFolderMessageFactory SyncFolderMessageFactory { get; set; } |
2337 | + |
2338 | + /// <summary> |
2339 | + /// Gets and sets the communicator that is used to send and receive messages to the socket. |
2340 | + /// </summary> |
2341 | + internal ITcpClientCommunicator<FolderMessage> TcpClientCommunicator { get; set; } |
2342 | + |
2343 | + #endregion |
2344 | |
2345 | /// <summary> |
2346 | /// Creates a new udf for the given path. |
2347 | @@ -40,7 +49,8 @@ |
2348 | /// <param name="path">The path to which the Udf will be created.</param> |
2349 | public void CreateFolderUdf(string path) |
2350 | { |
2351 | - throw new NotImplementedException(); |
2352 | + var message = SyncFolderMessageFactory.CreateFolder(path); |
2353 | + TcpClientCommunicator.SendMessage(message); |
2354 | } |
2355 | |
2356 | /// <summary> |
2357 | @@ -49,7 +59,8 @@ |
2358 | /// <param name="path">The path whose Udf we will remove.</param> |
2359 | public void DeleteFolderUdf(string path) |
2360 | { |
2361 | - throw new NotImplementedException(); |
2362 | + var message = SyncFolderMessageFactory.DeleteFolder(path); |
2363 | + TcpClientCommunicator.SendMessage(message); |
2364 | } |
2365 | |
2366 | /// <summary> |
2367 | @@ -58,7 +69,8 @@ |
2368 | /// <returns>A list with all the udfs.</returns> |
2369 | public IList<UdfData> GetFolders() |
2370 | { |
2371 | - throw new NotImplementedException(); |
2372 | + var message = SyncFolderMessageFactory.QueryFolders(); |
2373 | + return TcpClientCommunicator.SendReceiveMessage<IList<UdfData>>(message, Convert.ToAllFolders); |
2374 | } |
2375 | |
2376 | /// <summary> |
2377 | @@ -67,7 +79,8 @@ |
2378 | /// <param name="folderId">The id of the folder to subscribe to.</param> |
2379 | public void Subscribe(string folderId) |
2380 | { |
2381 | - throw new NotImplementedException(); |
2382 | + var message = SyncFolderMessageFactory.Subscribe(folderId); |
2383 | + TcpClientCommunicator.SendMessage(message); |
2384 | } |
2385 | |
2386 | /// <summary> |
2387 | @@ -76,7 +89,8 @@ |
2388 | /// <param name="folderId">The id of the folder to unsubscribe from.</param> |
2389 | public void Unsubscribe(string folderId) |
2390 | { |
2391 | - throw new NotImplementedException(); |
2392 | + var message = SyncFolderMessageFactory.Unsubscribe(folderId); |
2393 | + TcpClientCommunicator.SendMessage(message); |
2394 | } |
2395 | |
2396 | /// <summary> |
2397 | @@ -86,7 +100,8 @@ |
2398 | /// <returns>The udf data of the given path.</returns> |
2399 | public UdfData GetInfo(string path) |
2400 | { |
2401 | - throw new NotImplementedException(); |
2402 | + var message = SyncFolderMessageFactory.QueryInfo(path); |
2403 | + return TcpClientCommunicator.SendReceiveMessage<UdfData>(message, Convert.ToUdfData); |
2404 | } |
2405 | |
2406 | /// <summary> |
2407 | @@ -94,7 +109,8 @@ |
2408 | /// </summary> |
2409 | public void RefreshVolumes() |
2410 | { |
2411 | - throw new NotImplementedException(); |
2412 | + var message = SyncFolderMessageFactory.RefreshVolumes(); |
2413 | + TcpClientCommunicator.SendMessage(message); |
2414 | } |
2415 | } |
2416 | } |
2417 | |
2418 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncSharesService.cs' |
2419 | --- src/Canonical.UbuntuOne.ProcessDispatcher/SyncSharesService.cs 2010-08-05 08:15:00 +0000 |
2420 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncSharesService.cs 2010-08-11 10:35:55 +0000 |
2421 | @@ -1,37 +1,49 @@ |
2422 | -// Copyright 2010 Canonical Ltd. |
2423 | -// |
2424 | -// This file is part of UbuntuOne on Windows. |
2425 | -// |
2426 | -// UbuntuOne on Windows is free software: you can redistribute it and/or modify |
2427 | -// it under the terms of the GNU Lesser General Public License version |
2428 | -// as published by the Free Software Foundation. |
2429 | -// |
2430 | -// Ubuntu One on Windows is distributed in the hope that it will be useful, |
2431 | -// but WITHOUT ANY WARRANTY; without even the implied warranty of |
2432 | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2433 | -// GNU Lesser General Public License for more details. |
2434 | -// |
2435 | -// You should have received a copy of the GNU Lesser General Public License |
2436 | -// along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
2437 | -// |
2438 | -// Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
2439 | -using System; |
2440 | +/* |
2441 | + * Copyright 2010 Canonical Ltd. |
2442 | + * |
2443 | + * This file is part of UbuntuOne on Windows. |
2444 | + * |
2445 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
2446 | + * it under the terms of the GNU Lesser General Public License version |
2447 | + * as published by the Free Software Foundation. |
2448 | + * |
2449 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
2450 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2451 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2452 | + * GNU Lesser General Public License for more details. |
2453 | + * |
2454 | + * You should have received a copy of the GNU Lesser General Public License |
2455 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
2456 | + * |
2457 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
2458 | + */ |
2459 | using System.Collections.Generic; |
2460 | using Canonical.UbuntuOne.Common; |
2461 | using Canonical.UbuntuOne.Common.Aop; |
2462 | +using Canonical.UbuntuOne.ProcessDispatcher.Net; |
2463 | |
2464 | namespace Canonical.UbuntuOne.ProcessDispatcher |
2465 | { |
2466 | - class SyncSharesService : ISyncShares |
2467 | + /// <summary> |
2468 | + /// Implementation of the ISyncShares interface that will foward the request operations to the |
2469 | + /// python code. |
2470 | + /// </summary> |
2471 | + internal class SyncSharesService : ISyncShares |
2472 | { |
2473 | - /// <summary> |
2474 | - /// Provides a way that the client can use to register itself to be notified about events |
2475 | - /// through callbacks. The client should implemented the ISyncDaemonClient interface. |
2476 | - /// </summary> |
2477 | - public void RegisterClient() |
2478 | - { |
2479 | - throw new NotImplementedException(); |
2480 | - } |
2481 | + #region DI properties |
2482 | + |
2483 | + /// <summary> |
2484 | + /// Gets and sets the factory that is used to create the protobuf messages used |
2485 | + /// to communicate with the python code. |
2486 | + /// </summary> |
2487 | + internal ISyncShareMessageFactory SyncShareMessageFactory { get; set; } |
2488 | + |
2489 | + /// <summary> |
2490 | + /// Gets and sets the communicator that is used to send and receive messages to the socket. |
2491 | + /// </summary> |
2492 | + internal ITcpClientCommunicator<ShareMessage> TcpClientCommunicator { get; set; } |
2493 | + |
2494 | + #endregion |
2495 | |
2496 | /// <summary> |
2497 | /// Allows the client to query and get all the different shares that the user has. |
2498 | @@ -40,7 +52,9 @@ |
2499 | [DebugLogged] |
2500 | public IList<ShareData> GetShares() |
2501 | { |
2502 | - throw new NotImplementedException(); |
2503 | + var message = SyncShareMessageFactory.QueryShares(); |
2504 | + return TcpClientCommunicator.SendReceiveMessage<IList<ShareData>>(message, Convert.ToGetShares); |
2505 | + |
2506 | } |
2507 | |
2508 | /// <summary> |
2509 | @@ -51,7 +65,8 @@ |
2510 | [DebugLogged] |
2511 | public void AcceptShare(string shareId) |
2512 | { |
2513 | - throw new NotImplementedException(); |
2514 | + var message = SyncShareMessageFactory.AcceptShare(shareId); |
2515 | + TcpClientCommunicator.SendMessage(message); |
2516 | } |
2517 | |
2518 | /// <summary> |
2519 | @@ -62,7 +77,8 @@ |
2520 | [DebugLogged] |
2521 | public void RejectShare(string shareId) |
2522 | { |
2523 | - throw new NotImplementedException(); |
2524 | + var message = SyncShareMessageFactory.RejectShare(shareId); |
2525 | + TcpClientCommunicator.SendMessage(message); |
2526 | } |
2527 | |
2528 | /// <summary> |
2529 | @@ -76,7 +92,8 @@ |
2530 | [DebugLogged] |
2531 | public void CreateShare(string path, string username, string name, AccessLevel accessLevel) |
2532 | { |
2533 | - throw new NotImplementedException(); |
2534 | + var message = SyncShareMessageFactory.CreateShare(path, username, name, accessLevel); |
2535 | + TcpClientCommunicator.SendMessage(message); |
2536 | } |
2537 | |
2538 | /// <summary> |
2539 | @@ -85,7 +102,8 @@ |
2540 | [DebugLogged] |
2541 | public void UpdateShares() |
2542 | { |
2543 | - throw new NotImplementedException(); |
2544 | + var message = SyncShareMessageFactory.UpdateShares(); |
2545 | + TcpClientCommunicator.SendMessage(message); |
2546 | } |
2547 | |
2548 | /// <summary> |
2549 | @@ -95,7 +113,8 @@ |
2550 | [DebugLogged] |
2551 | public IList<ShareData> GetShared() |
2552 | { |
2553 | - throw new NotImplementedException(); |
2554 | + var message = SyncShareMessageFactory.GetShared(); |
2555 | + return TcpClientCommunicator.SendReceiveMessage<IList<ShareData>>(message, Convert.ToGetShared); |
2556 | } |
2557 | } |
2558 | } |
I'm sorry I still don't have my test environment setup to actually test this.
But I wanted to point out, due to a concern with the Ubuntu client, UDFs can only be created with the path starting with ~/. I think it's something the windows client is going to need to handle as it gets these back from the server.
This code looks good from a visual review.
PS. You may find it advantageous to keep branches smaller than 2k line diffs :)