Merge lp:~mandel/ubuntuone-windows-installer/remove_syncdaemon_shit_the_first into lp:ubuntuone-windows-installer/beta

Proposed by Manuel de la Peña
Status: Merged
Approved by: Rick McBride
Approved revision: 55
Merged at revision: 68
Proposed branch: lp:~mandel/ubuntuone-windows-installer/remove_syncdaemon_shit_the_first
Merge into: lp:ubuntuone-windows-installer/beta
Prerequisite: lp:~mandel/ubuntuone-windows-installer/add_create_update_build
Diff against target: 3316 lines (+48/-2770)
25 files modified
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Canonical.UbuntuOne.ProcessDispatcher.Tests.csproj (+0/-3)
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/EventNotifierFixture.cs (+1/-211)
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/PortManagerFixture.cs (+0/-169)
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientCommunicatorFixture.cs (+0/-131)
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientFactoryFixture.cs (+0/-81)
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncConfigurationServiceFixture.cs (+2/-152)
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncDaemonServiceFixture.cs (+1/-540)
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncFoldersServiceFixture.cs (+1/-172)
src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncSharesServiceFixture.cs (+1/-139)
src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj (+0/-10)
src/Canonical.UbuntuOne.ProcessDispatcher/EventNotifier.cs (+6/-181)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/IPortFinder.cs (+0/-37)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/IPortManager.cs (+0/-41)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClient.cs (+0/-42)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientCommunicator.cs (+0/-48)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientFactory.cs (+0/-36)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/PortFinder.cs (+0/-107)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/PortManager.cs (+0/-331)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientCommunicator.cs (+0/-88)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientFactory.cs (+0/-74)
src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientWrapper.cs (+0/-63)
src/Canonical.UbuntuOne.ProcessDispatcher/SyncConfigurationService.cs (+12/-28)
src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs (+9/-30)
src/Canonical.UbuntuOne.ProcessDispatcher/SyncFoldersService.cs (+8/-29)
src/Canonical.UbuntuOne.ProcessDispatcher/SyncSharesService.cs (+7/-27)
To merge this branch: bzr merge lp:~mandel/ubuntuone-windows-installer/remove_syncdaemon_shit_the_first
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Vincenzo Di Somma (community) Approve
Review via email: mp+33535@code.launchpad.net

Description of the change

Adds some code that was added to talk with python using protobuf, what for now???

To post a comment you must log in.
Revision history for this message
Vincenzo Di Somma (vds) wrote :

Build and tests are passing! +1.

review: Approve
Revision history for this message
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Canonical.UbuntuOne.ProcessDispatcher.Tests.csproj'
2--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Canonical.UbuntuOne.ProcessDispatcher.Tests.csproj 2010-08-18 09:49:09 +0000
3+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Canonical.UbuntuOne.ProcessDispatcher.Tests.csproj 2010-08-24 15:21:43 +0000
4@@ -56,9 +56,6 @@
5 <Link>Properties\Version.cs</Link>
6 </Compile>
7 <Compile Include="EventNotifierFixture.cs" />
8- <Compile Include="Net\PortManagerFixture.cs" />
9- <Compile Include="Net\TcpClientCommunicatorFixture.cs" />
10- <Compile Include="Net\TcpClientFactoryFixture.cs" />
11 <Compile Include="Properties\AssemblyInfo.cs" />
12 <Compile Include="Protobuf\ConvertFixture.cs" />
13 <Compile Include="Protobuf\SyncConfigurationMessageFactoryFixture.cs" />
14
15=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/EventNotifierFixture.cs'
16--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/EventNotifierFixture.cs 2010-08-18 09:38:08 +0000
17+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/EventNotifierFixture.cs 2010-08-24 15:21:43 +0000
18@@ -17,223 +17,13 @@
19 *
20 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
21 */
22-using System;
23-using System.Net.Sockets;
24-using Canonical.UbuntuOne.Common;
25-using Canonical.UbuntuOne.ProcessDispatcher.Net;
26 using NUnit.Framework;
27-using Rhino.Mocks;
28
29 namespace Canonical.UbuntuOne.ProcessDispatcher.Tests
30 {
31 [TestFixture]
32 public class EventNotifierFixture
33 {
34- #region Vars
35-
36- private MockRepository _mocks;
37- private IEventDispatcher _eventDispatcher;
38- private ISyncDaemonClient _notifyIconClient;
39- private ICallerContext<ISyncDaemonClient> _callerContext;
40- private IPortManager _portManager;
41- private IProtobufSerializer _serilizer;
42- private TcpClient _client;
43- private EventNotifier _notifier;
44- private int _freePort;
45-
46- #endregion
47-
48- #region Setup
49-
50- [SetUp]
51- public void Setup()
52- {
53- _mocks = new MockRepository();
54- _eventDispatcher = _mocks.DynamicMock<IEventDispatcher>();
55- _notifyIconClient = _mocks.StrictMock<ISyncDaemonClient>();
56- _mocks.StrictMock<ISyncDaemonClient>();
57- _callerContext = _mocks.StrictMock<ICallerContext<ISyncDaemonClient>>();
58- _portManager = _mocks.StrictMock<IPortManager>();
59- _serilizer = _mocks.DynamicMock<IProtobufSerializer>();
60- _freePort = 50128;
61- _notifier = new EventNotifier
62- {
63- CallerContext = _callerContext,
64- EventDispatcher = _eventDispatcher,
65- PortManager = _portManager,
66- ProtobufSerializer = _serilizer
67- };
68- }
69-
70- [TearDown]
71- public void TearDown()
72- {
73- _notifier.KillListeningThread();
74- }
75-
76- #endregion
77-
78- #region Tests
79-
80- [Test]
81- public void RegisterClientTest()
82- {
83- using (_mocks.Record())
84- {
85- Expect.Call(_callerContext.GetCaller())
86- .Return(_notifyIconClient)
87- .Repeat.Once();
88- }
89- using(_mocks.Playback())
90- {
91- _notifier.RegisterClient();
92- }
93- }
94-
95- [Test]
96- public void UnregisterClientRegisteredTest()
97- {
98- using (_mocks.Record())
99- {
100- Expect.Call(_callerContext.GetCaller())
101- .Return(_notifyIconClient)
102- .Repeat.Once();
103- }
104- using (_mocks.Playback())
105- {
106- _notifier.UnregisterClient();
107- }
108- }
109-
110- [Test]
111- public void UnregisterClientNotRegisteredTest()
112- {
113- using (_mocks.Record())
114- {
115- Expect.Call(_callerContext.GetCaller())
116- .Return(_notifyIconClient)
117- .Repeat.Once();
118- }
119- using (_mocks.Playback())
120- {
121- _notifier.UnregisterClient();
122- }
123- }
124-
125- [Test]
126- public void StartListeningTest()
127- {
128- try
129- {
130- Assert.Ignore("This test is not reliable until RhinoMocks has multithread support.");
131- //using (_mocks.Record())
132- //{
133- // Expect.Call(_portManager.GetDotNetClientPort())
134- // .Return(_freePort)
135- // .Repeat.Any();
136- //}
137- //using (_mocks.Playback())
138- //{
139- // _notifier.StartListening();
140- // // create a client that will connect to the port
141- // while (!_notifier.IsListening)
142- // {
143- // // wait doing nothing :(
144- // }
145- // _client = new TcpClient("localhost", _freePort);
146- // // write data in the buffer to tell the the event notifier
147- // var stream = _client.GetStream();
148- // var data = System.Text.Encoding.ASCII.GetBytes("Test");
149- // stream.Write(data, 0, data.Length);
150- // stream.Flush();
151- // stream.Close();
152- //}
153- }
154- catch (SocketException)
155- {
156- Assert.Inconclusive(
157- "The test could not be performed due to a socket exception. You firewall is probably blocking connections to {0}",
158- _freePort);
159- }
160- }
161-
162- [Test]
163- [ExpectedException(typeof(InvalidOperationException))]
164- public void StartListeningAlreadyListeningTest()
165- {
166- try
167- {
168- using (_mocks.Record())
169- {
170- Expect.Call(_portManager.GetDotNetClientPort())
171- .Return(_freePort)
172- .Repeat.Once();
173- }
174- using (_mocks.Playback())
175- {
176- _notifier.StartListening();
177- _notifier.StartListening();
178- }
179- }
180- catch (SocketException)
181- {
182- Assert.Inconclusive(
183- "The test could not be performed due to a socket exception. You firewall is probably blocking connections to {0}",
184- _freePort);
185- }
186- }
187-
188- [Test]
189- public void StopListeningTest()
190- {
191- try
192- {
193- using (_mocks.Record())
194- {
195- Expect.Call(_portManager.GetDotNetClientPort())
196- .Return(_freePort)
197- .Repeat.Any();
198- }
199- using (_mocks.Playback())
200- {
201- _notifier.StartListening();
202- _notifier.StopListening();
203- }
204- }
205- catch (SocketException)
206- {
207- Assert.Inconclusive(
208- "The test could not be performed due to a socket exception. You firewall is probably blocking connections to {0}",
209- _freePort);
210- }
211- }
212-
213- [Test]
214- [ExpectedException(typeof(InvalidOperationException))]
215- public void StopListeningExceptionTest()
216- {
217- try
218- {
219- using (_mocks.Record())
220- {
221- Expect.Call(_portManager.GetDotNetClientPort())
222- .Return(_freePort)
223- .Repeat.Once();
224- }
225- using (_mocks.Playback())
226- {
227- _notifier.StopListening();
228- }
229- }
230- catch(SocketException)
231- {
232- Assert.Inconclusive(
233- "The test could not be performed due to a socket exception. You firewall is probably blocking connections to {0}",
234- _freePort);
235- }
236- }
237-
238- #endregion
239-
240+ //TODO :Implement whenever the new techinique is used.
241 }
242 }
243
244=== removed directory 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net'
245=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/PortManagerFixture.cs'
246--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/PortManagerFixture.cs 2010-08-18 09:49:09 +0000
247+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/PortManagerFixture.cs 1970-01-01 00:00:00 +0000
248@@ -1,169 +0,0 @@
249-/*
250- * Copyright 2010 Canonical Ltd.
251- *
252- * This file is part of UbuntuOne on Windows.
253- *
254- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
255- * it under the terms of the GNU Lesser General Public License version
256- * as published by the Free Software Foundation.
257- *
258- * Ubuntu One on Windows is distributed in the hope that it will be useful,
259- * but WITHOUT ANY WARRANTY; without even the implied warranty of
260- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
261- * GNU Lesser General Public License for more details.
262- *
263- * You should have received a copy of the GNU Lesser General Public License
264- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
265- *
266- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
267- */
268-using Canonical.UbuntuOne.Common;
269-using Canonical.UbuntuOne.Common.Container;
270-using Canonical.UbuntuOne.ProcessDispatcher.Net;
271-using NUnit.Framework;
272-using Rhino.Mocks;
273-using Spring.Data.Common;
274-using Spring.Data.Core;
275-
276-namespace Canonical.UbuntuOne.ProcessDispatcher.Tests.Net
277-{
278- [TestFixture]
279- public class PortManagerFixture
280- {
281- #region Vars
282-
283- private IPortFinder _portFinder;
284- private IAuthentication _auth;
285- private PortManager _portManager;
286- private MockRepository _mocks;
287- private IDbProvider _dbProvider;
288-
289- #endregion
290-
291- #region Setup
292-
293- [SetUp]
294- public void Setup()
295- {
296- _mocks = new MockRepository();
297- _portFinder = _mocks.StrictMock<IPortFinder>();
298- _auth = _mocks.StrictMock<IAuthentication>();
299- _dbProvider = ObjectsContainer.GetImplementationOf<IDbProvider>();
300- _portManager = PortManager.Instance;
301- _portManager.Authentication = _auth;
302- _portManager.PortFinder = _portFinder;
303- _portManager.DbProvider = _dbProvider;
304- }
305-
306- [TearDown]
307- public void TearDown()
308- {
309- _portManager.Clear();
310- // Clear the db
311- var template = new AdoTemplate(_dbProvider);
312- template.Execute(
313- command =>
314- {
315- command.CommandText = string.Format("DELETE FROM {0};", PortManager.UserPortsTableName);
316- return command.ExecuteScalar();
317- }
318- );
319- }
320-
321- #endregion
322-
323- #region Tests
324-
325- [TestCase(43)]
326- [TestCase(45)]
327- public void GetPythonPortFirstTimeTest(int portNumber)
328- {
329- using (_mocks.Record())
330- {
331- SetupResult.For(_auth.Username)
332- .Return("mandel");
333-
334- Expect.Call(_portFinder.GetFreePort())
335- .Return(portNumber)
336- .Repeat.Twice();
337-
338- }
339- using(_mocks.Playback())
340- {
341- var pythonPort = _portManager.GetPythonServerPort();
342- Assert.AreEqual(portNumber, pythonPort);
343- }
344- }
345-
346- [TestCase(43)]
347- [TestCase(45)]
348- public void GetPythonPortSecondTimeTest(int portNumber)
349- {
350- using (_mocks.Record())
351- {
352- SetupResult.For(_auth.Username)
353- .Return("mandel");
354-
355- Expect.Call(_portFinder.GetFreePort())
356- .Return(portNumber)
357- .Repeat.Twice();
358- }
359- using (_mocks.Playback())
360- {
361- var pythonPort = _portManager.GetPythonServerPort();
362- Assert.AreEqual(portNumber, pythonPort);
363- // we call the method again, we should get the same result
364- // and not extra calls to port finder should be made
365- var secondPort = _portManager.GetPythonServerPort();
366- Assert.AreEqual(portNumber, secondPort);
367- }
368- }
369-
370- [TestCase(43)]
371- [TestCase(45)]
372- public void GetDotNetPortFirstTimeTest(int portNumber)
373- {
374- using (_mocks.Record())
375- {
376- SetupResult.For(_auth.Username)
377- .Return("mandel");
378-
379- Expect.Call(_portFinder.GetFreePort())
380- .Return(portNumber)
381- .Repeat.Twice();
382-
383- }
384- using (_mocks.Playback())
385- {
386- var dotNetPort = _portManager.GetDotNetClientPort();
387- Assert.AreEqual(portNumber, dotNetPort);
388- }
389- }
390-
391- [TestCase(43)]
392- [TestCase(45)]
393- public void GetDotNetPortSecondTimeTest(int portNumber)
394- {
395- using (_mocks.Record())
396- {
397- SetupResult.For(_auth.Username)
398- .Return("mandel");
399-
400- Expect.Call(_portFinder.GetFreePort())
401- .Return(portNumber)
402- .Repeat.Twice();
403- }
404- using (_mocks.Playback())
405- {
406- var dotNetPort = _portManager.GetDotNetClientPort();
407- Assert.AreEqual(portNumber, dotNetPort);
408- // we call the method again, we should get the same result
409- // and not extra calls to port finder should be made
410- var secondPort = _portManager.GetDotNetClientPort();
411- Assert.AreEqual(portNumber, secondPort);
412- }
413- }
414-
415- #endregion
416- }
417-}
418
419=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientCommunicatorFixture.cs'
420--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientCommunicatorFixture.cs 2010-08-11 10:23:31 +0000
421+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientCommunicatorFixture.cs 1970-01-01 00:00:00 +0000
422@@ -1,131 +0,0 @@
423-/*
424- * Copyright 2010 Canonical Ltd.
425- *
426- * This file is part of UbuntuOne on Windows.
427- *
428- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
429- * it under the terms of the GNU Lesser General Public License version
430- * as published by the Free Software Foundation.
431- *
432- * Ubuntu One on Windows is distributed in the hope that it will be useful,
433- * but WITHOUT ANY WARRANTY; without even the implied warranty of
434- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
435- * GNU Lesser General Public License for more details.
436- *
437- * You should have received a copy of the GNU Lesser General Public License
438- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
439- *
440- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
441- */
442-using System.Net.Sockets;
443-using Canonical.UbuntuOne.ProcessDispatcher.Net;
444-using NUnit.Framework;
445-using Rhino.Mocks;
446-
447-namespace Canonical.UbuntuOne.ProcessDispatcher.Tests.Net
448-{
449- [TestFixture]
450- public class TcpClientCommunicatorFixture
451- {
452- #region Variables
453-
454- private ITcpClientFactory _clientFactory;
455- private ITcpClient _client;
456- private IProtobufSerializer _serializer;
457- private NetworkStream _stream;
458- private bool _wasCalled;
459- private MockRepository _mocks;
460- private ConfigurationMessage _message;
461- private TcpClientCommunicator<ConfigurationMessage> _communitcator;
462-
463- #endregion
464-
465- #region Setup & TearDown
466-
467- [SetUp]
468- public void Setup()
469- {
470- _mocks = new MockRepository();
471- _clientFactory = _mocks.StrictMock<ITcpClientFactory>();
472- _client = _mocks.StrictMock<ITcpClient>();
473- _serializer = _mocks.StrictMock<IProtobufSerializer>();
474- _message = _mocks.Stub<ConfigurationMessage>();
475- _stream = _mocks.StrictMock<NetworkStream>();
476- _wasCalled = false;
477- _communitcator = new TcpClientCommunicator<ConfigurationMessage>
478- {
479- ProtobufSerializer = _serializer,
480- TcpClientFactory = _clientFactory
481- };
482- }
483-
484- #endregion
485-
486- #region Helpers
487-
488- private string ConvertCallback(ConfigurationMessage message)
489- {
490- _wasCalled = true;
491- return "mandel";
492- }
493-
494- #endregion
495-
496- #region Tests
497-
498- [Test]
499- public void SendMessageTest()
500- {
501- using(_mocks.Record())
502- {
503- Expect.Call(_clientFactory.GetClient())
504- .Return(_client)
505- .Repeat.Once();
506- Expect.Call(_client.GetStream())
507- .Return(_stream)
508- .Repeat.Once();
509- Expect.Call(() => _serializer.Serialize(_stream, _message))
510- .Repeat.Once();
511- Expect.Call(() => _client.Close())
512- .Repeat.Once();
513- Expect.Call(() => _stream.Close())
514- .Repeat.Once();
515- }
516- using(_mocks.Playback())
517- {
518- _communitcator.SendMessage(_message);
519- }
520- }
521-
522- [Test]
523- public void SendReceiveMessage()
524- {
525- using (_mocks.Record())
526- {
527- Expect.Call(_clientFactory.GetClient())
528- .Return(_client)
529- .Repeat.Once();
530- Expect.Call(_client.GetStream())
531- .Return(_stream)
532- .Repeat.Once();
533- Expect.Call(() => _serializer.Serialize(_stream, _message))
534- .Repeat.Once();
535- Expect.Call(_serializer.Deserialize<ConfigurationMessage>(_stream))
536- .Return(_message)
537- .Repeat.Once();
538- Expect.Call(() => _client.Close())
539- .Repeat.Once();
540- Expect.Call(() => _stream.Close())
541- .Repeat.Once();
542- }
543- using (_mocks.Playback())
544- {
545- _communitcator.SendReceiveMessage<string>(_message, ConvertCallback);
546- Assert.IsTrue(_wasCalled, "The convert callback was not called.");
547- }
548- }
549-
550- #endregion
551-
552- }
553-}
554
555=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientFactoryFixture.cs'
556--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientFactoryFixture.cs 2010-08-16 09:55:12 +0000
557+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/Net/TcpClientFactoryFixture.cs 1970-01-01 00:00:00 +0000
558@@ -1,81 +0,0 @@
559-/*
560- * Copyright 2010 Canonical Ltd.
561- *
562- * This file is part of UbuntuOne on Windows.
563- *
564- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
565- * it under the terms of the GNU Lesser General Public License version
566- * as published by the Free Software Foundation.
567- *
568- * Ubuntu One on Windows is distributed in the hope that it will be useful,
569- * but WITHOUT ANY WARRANTY; without even the implied warranty of
570- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
571- * GNU Lesser General Public License for more details.
572- *
573- * You should have received a copy of the GNU Lesser General Public License
574- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
575- *
576- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
577- */
578-using System.Net.Sockets;
579-using Canonical.UbuntuOne.ProcessDispatcher.Net;
580-using NUnit.Framework;
581-using Rhino.Mocks;
582-
583-namespace Canonical.UbuntuOne.ProcessDispatcher.Tests.Net
584-{
585- [TestFixture]
586- public class TcpClientFactoryFixture
587- {
588- #region Varaibles
589-
590- private IPortManager _portManager;
591- private TcpClientFactory _clientFactory;
592- private MockRepository _mocks;
593- #endregion
594-
595- #region Setup
596-
597- [SetUp]
598- public void Setup()
599- {
600- _mocks = new MockRepository();
601- _portManager = _mocks.StrictMock<IPortManager>();
602- _clientFactory = new TcpClientFactory
603- {
604- PortManager = _portManager
605- };
606- }
607-
608- #endregion
609-
610- #region Tests
611-
612- [Test]
613- public void GetClientTest()
614- {
615- try
616- {
617- using (_mocks.Record())
618- {
619- Expect.Call(_portManager.GetPythonServerPort())
620- .Return(50128)
621- .Repeat.Once();
622- }
623- using (_mocks.Playback())
624- {
625- var client = _clientFactory.GetClient();
626- Assert.IsNotNull(client);
627- }
628- }
629- catch (SocketException e)
630- {
631- Assert.Inconclusive(
632- "The test could not be performed due to a socket exception. You firewall is probably blocking connections to {0}",
633- 50128);
634- }
635- }
636-
637- #endregion
638- }
639-}
640
641=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncConfigurationServiceFixture.cs'
642--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncConfigurationServiceFixture.cs 2010-08-11 10:23:31 +0000
643+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncConfigurationServiceFixture.cs 2010-08-24 15:21:43 +0000
644@@ -17,164 +17,14 @@
645 *
646 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
647 */
648-using Canonical.UbuntuOne.Common;
649-using Canonical.UbuntuOne.ProcessDispatcher.Net;
650 using NUnit.Framework;
651-using Rhino.Mocks;
652
653 namespace Canonical.UbuntuOne.ProcessDispatcher.Tests
654 {
655 [TestFixture]
656 public class SyncConfigurationServiceFixture
657 {
658- #region Variables
659-
660- private ISyncConfigurationMessageFactory _messageFactory;
661- private ITcpClientCommunicator<ConfigurationMessage> _communicator;
662- private ConfigurationMessage _message;
663- private MockRepository _mocks;
664- private SyncConfigurationService _service;
665-
666- #endregion
667-
668- #region Setup
669-
670- [SetUp]
671- public void Setup()
672- {
673- _mocks = new MockRepository();
674- _messageFactory = _mocks.StrictMock<ISyncConfigurationMessageFactory>();
675- _communicator = _mocks.StrictMock<ITcpClientCommunicator<ConfigurationMessage>>();
676- _message = _mocks.StrictMock<ConfigurationMessage>();
677- _service = new SyncConfigurationService
678- {
679- SyncConfigurationMessageFactory = _messageFactory,
680- TcpClientCommunicator = _communicator
681- };
682- }
683-
684- #endregion
685-
686- #region Tests
687-
688- [Test]
689- public void GetThrottlingLimitsCorrectMessageTest()
690- {
691- _message.Type = ConfigurationMessage.MessageType.THROTTLING;
692- _message.Throttling = new ConfigurationMessage.ThrottlingLimitsMessage();
693- _mocks.BackToRecord(_message);
694- using (_mocks.Record())
695- {
696- Expect.Call(_messageFactory.QueryThrottling())
697- .Return(_message)
698- .Repeat.Once();
699- Expect.Call(_communicator.SendReceiveMessage<ThrottlingData>(_message, Convert.ToThrottlingData))
700- .Return(new ThrottlingData())
701- .Repeat.Once();
702- }
703- using (_mocks.Playback())
704- {
705- _service.GetThrottlingLimits();
706- }
707- }
708-
709- [TestCase(3, 4)]
710- [TestCase(34, 56)]
711- public void SetThrottlingLimitsCorrectMessageTest(int download, int upload)
712- {
713- var data = new ThrottlingData
714- {
715- Download = download,
716- Upload = upload
717- };
718- using (_mocks.Record())
719- {
720- Expect.Call(_messageFactory.SetThrottlingLimits(data))
721- .Return(_message)
722- .Repeat.Once();
723- Expect.Call(() => _communicator.SendMessage(_message))
724- .Repeat.Once();
725- }
726- using (_mocks.Playback())
727- {
728- _service.SetThrottlingLimits(data);
729- }
730- }
731-
732- [TestCase(true)]
733- [TestCase(false)]
734- public void EnableThrottlingLimitsCorrectMessageTest(bool isEnabled)
735- {
736- using (_mocks.Record())
737- {
738- Expect.Call(_messageFactory.EnableThrottling(isEnabled))
739- .Return(_message);
740- Expect.Call(() => _communicator.SendMessage(_message))
741- .Repeat.Once();
742- }
743- using (_mocks.Playback())
744- {
745- _service.EnableThrottlingLimits(isEnabled);
746- }
747- }
748-
749- [Test]
750- public void IsEnabledThrottlingLimitsCorrectMessageTest()
751- {
752- _message.Type = ConfigurationMessage.MessageType.ENABLETHROTTLING;
753- _mocks.BackToRecord(_message);
754- using (_mocks.Record())
755- {
756- Expect.Call(_messageFactory.QueryThrottling())
757- .Return(_message)
758- .Repeat.Once();
759- Expect.Call(_communicator.SendReceiveMessage<bool>(_message, Convert.ToIsEnabledThrottling))
760- .Return(true)
761- .Repeat.Once();
762- }
763- using (_mocks.Playback())
764- {
765- _service.IsEnabledThrottlingLimits();
766- }
767- }
768-
769- [TestCase(true)]
770- [TestCase(false)]
771- public void EnableUdfAutosubscribeCorrectMessageTest(bool isEnabled)
772- {
773- using (_mocks.Record())
774- {
775- Expect.Call(_messageFactory.EnablesAutosubscribe(isEnabled))
776- .Return(_message);
777- Expect.Call(() => _communicator.SendMessage(_message))
778- .Repeat.Once();
779- }
780- using (_mocks.Playback())
781- {
782- _service.EnableUdfAutosubscribe(isEnabled);
783- }
784- }
785-
786- [Test]
787- public void IsEnabledUdfAutosubscribeCorrectMessageTest()
788- {
789- _message.Type = ConfigurationMessage.MessageType.ENABLEAUTOSUBSCRIBE;
790- _mocks.BackToRecord(_message);
791- using (_mocks.Record())
792- {
793- Expect.Call(_messageFactory.QueryThrottling())
794- .Return(_message)
795- .Repeat.Once();
796- Expect.Call(_communicator.SendReceiveMessage<bool>(_message, Convert.ToIsAutosubscribe))
797- .Return(false)
798- .Repeat.Once();
799- }
800- using (_mocks.Playback())
801- {
802- _service.IsEnabledUdfAutosubscribe();
803- }
804- }
805-
806- #endregion
807+
808+ // TODO: Implemente the tests when ever a new solution is found.
809 }
810 }
811
812=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncDaemonServiceFixture.cs'
813--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncDaemonServiceFixture.cs 2010-08-11 10:23:31 +0000
814+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncDaemonServiceFixture.cs 2010-08-24 15:21:43 +0000
815@@ -17,552 +17,13 @@
816 *
817 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
818 */
819-using System.Collections.Generic;
820-using Canonical.UbuntuOne.Common;
821-using Canonical.UbuntuOne.ProcessDispatcher.Net;
822-using log4net;
823 using NUnit.Framework;
824-using Rhino.Mocks;
825
826 namespace Canonical.UbuntuOne.ProcessDispatcher.Tests
827 {
828 [TestFixture]
829 public class SyncDaemonServiceFixture
830 {
831- #region Variables
832-
833- private ISyncDaemonMessageFactory _messageFactory;
834- private SyncDaemonMessage _message;
835- private MockRepository _mocks;
836- private SyncDaemonService _service;
837- private IAuthentication _authentication;
838- private ILog _logger;
839- private IProcessManagerFactory _processManagerFactory;
840- private IProcessManager _processManager;
841- private ITcpClientCommunicator<SyncDaemonMessage> _communicator;
842-
843- #endregion
844-
845- #region Setup
846-
847- [SetUp]
848- public void Setup()
849- {
850- _mocks = new MockRepository();
851- _messageFactory = _mocks.StrictMock<ISyncDaemonMessageFactory>();
852- _message = _mocks.StrictMock<SyncDaemonMessage>();
853- _logger = _mocks.DynamicMock<ILog>();
854- _authentication = _mocks.StrictMock<IAuthentication>();
855- _processManagerFactory = _mocks.StrictMock<IProcessManagerFactory>();
856- _processManager = _mocks.StrictMock<IProcessManager>();
857- _communicator = _mocks.StrictMock<ITcpClientCommunicator<SyncDaemonMessage>>();
858- _service = new SyncDaemonService
859- {
860- SyncDaemonMessageFactory = _messageFactory,
861- Authentication = _authentication,
862- Logger = _logger,
863- ProcessManagerFactory = _processManagerFactory,
864- TcpClientCommunicator = _communicator
865- };
866- }
867-
868-
869- #endregion
870-
871- #region Tests
872-
873- /// <summary>
874- /// This test ensures that the different componets used by the service are called
875- /// correctly in order when we are following the default path where everything went ok.
876- /// </summary>
877- [Test]
878- public void StartTest()
879- {
880- using (_mocks.Record())
881- {
882- // expect to call the authentication class as well as
883- // the factory and the manager.
884- SetupResult.For(_authentication.IsAuthenticated)
885- .Return(true)
886- .Repeat.Once();
887-
888- SetupResult.For(_authentication.Username)
889- .Return("mandel")
890- .Repeat.Once();
891-
892- Expect.Call(_processManagerFactory.GetManager())
893- .Return(_processManager)
894- .Repeat.Once();
895-
896- Expect.Call(() => _processManager.Start())
897- .Repeat.Once();
898-
899- }
900- using (_mocks.Playback())
901- {
902- _service.Start();
903- }
904- }
905-
906- /// <summary>
907- /// This tests makes sure that the TryStart method works correctly when the
908- /// start method works correctly.
909- /// </summary>
910- [Test]
911- public void TryStartSuccessTest()
912- {
913- using (_mocks.Record())
914- {
915- // expect to call the authentication class as well as
916- // the factory and the manager.
917- SetupResult.For(_authentication.IsAuthenticated)
918- .Return(true)
919- .Repeat.Once();
920-
921- SetupResult.For(_authentication.Username)
922- .Return("mandel")
923- .Repeat.Once();
924-
925- Expect.Call(_processManagerFactory.GetManager())
926- .Return(_processManager)
927- .Repeat.Once();
928-
929- Expect.Call(() => _processManager.Start())
930- .Repeat.Once();
931-
932- }
933- using (_mocks.Playback())
934- {
935- Assert.IsTrue(_service.TryStart());
936- }
937- }
938-
939- /// <summary>
940- /// This test ensures that we cover the path in which we did not managed to start the process due
941- /// to an issue with the process manager.
942- /// </summary>
943- [Test]
944- [ExpectedException(typeof(SyncDaemonException))]
945- public void StartExceptionTest()
946- {
947- using (_mocks.Record())
948- {
949- // we try to run the process but we will throw an exception when
950- // trying to start the process
951- SetupResult.For(_authentication.IsAuthenticated)
952- .Return(true)
953- .Repeat.Once();
954-
955- SetupResult.For(_authentication.Username)
956- .Return("mandel")
957- .Repeat.Once();
958-
959- Expect.Call(_processManagerFactory.GetManager())
960- .Return(_processManager)
961- .Repeat.Once();
962-
963- Expect.Call(() => _processManager.Start())
964- .Throw(new ProcessManagementException());
965- }
966-
967- using (_mocks.Playback())
968- {
969- _service.Start();
970- }
971- }
972-
973- /// <summary>
974- /// This test makes sure that the path that is used when we could not start the test works
975- /// as expected and returns a false.
976- /// </summary>
977- [Test]
978- public void TryStartFailTest()
979- {
980- using (_mocks.Record())
981- {
982- // we try to run the process but we will throw an exception when
983- // trying to start the process
984- SetupResult.For(_authentication.IsAuthenticated)
985- .Return(true)
986- .Repeat.Once();
987-
988- SetupResult.For(_authentication.Username)
989- .Return("mandel")
990- .Repeat.Once();
991-
992- Expect.Call(_processManagerFactory.GetManager())
993- .Return(_processManager)
994- .Repeat.Once();
995-
996- Expect.Call(() => _processManager.Start())
997- .Throw(new ProcessManagementException());
998- }
999-
1000- using (_mocks.Playback())
1001- {
1002- Assert.False(_service.TryStart());
1003- }
1004- }
1005-
1006- /// <summary>
1007- /// This method tests that we do not start the process when the user is not the correct one.
1008- /// </summary>
1009- [Test]
1010- public void StartNotAuthenticatedTest()
1011- {
1012- using (_mocks.Record())
1013- {
1014- SetupResult.For(_authentication.IsAuthenticated)
1015- .Return(false)
1016- .Repeat.Once();
1017-
1018- Expect.Call(_processManagerFactory.GetManager())
1019- .Repeat.Never();
1020-
1021- Expect.Call(() => _processManager.Start())
1022- .Repeat.Never();
1023- }
1024- using (_mocks.Playback())
1025- {
1026- _service.Start();
1027- }
1028- }
1029-
1030- /// <summary>
1031- /// This method tests the path that will go through the normal behaviour of the stop method.
1032- /// </summary>
1033- [Test]
1034- public void StopTest()
1035- {
1036- using (_mocks.Record())
1037- {
1038- // set basic set up to be able to start and stop
1039- SetupResult.For(_authentication.IsAuthenticated)
1040- .Return(true)
1041- .Repeat.Once();
1042-
1043- SetupResult.For(_authentication.Username)
1044- .Return("mandel")
1045- .Repeat.Once();
1046-
1047- Expect.Call(_processManagerFactory.GetManager())
1048- .Return(_processManager)
1049- .Repeat.Once();
1050-
1051- Expect.Call(() => _processManager.Start())
1052- .Repeat.Once();
1053- Expect.Call(() => _processManager.Stop())
1054- .Repeat.Once();
1055- }
1056-
1057- using (_mocks.Playback())
1058- {
1059- _service.Start();
1060- _service.Stop();
1061- }
1062- }
1063-
1064- /// <summary>
1065- /// This test ensures that the path used when we can stop does work as expected and returns a true.
1066- /// </summary>
1067- [Test]
1068- public void TryStopSuccessTest()
1069- {
1070- using (_mocks.Record())
1071- {
1072- // set basic set up to be able to start and stop
1073- SetupResult.For(_authentication.IsAuthenticated)
1074- .Return(true)
1075- .Repeat.Once();
1076-
1077- SetupResult.For(_authentication.Username)
1078- .Return("mandel")
1079- .Repeat.Once();
1080-
1081- Expect.Call(_processManagerFactory.GetManager())
1082- .Return(_processManager)
1083- .Repeat.Once();
1084-
1085- Expect.Call(() => _processManager.Start())
1086- .Repeat.Once();
1087-
1088- Expect.Call(() => _processManager.Stop())
1089- .Repeat.Once();
1090- }
1091-
1092- using (_mocks.Playback())
1093- {
1094- _service.Start();
1095- Assert.IsTrue(_service.TryStop());
1096- }
1097- }
1098-
1099- /// <summary>
1100- /// This method tests the path in which we are going to try and stop a process that has
1101- /// not been started.
1102- /// </summary>
1103- [Test]
1104- public void StopNotStartedTest()
1105- {
1106- using (_mocks.Record())
1107- {
1108- SetupResult.For(_authentication.IsAuthenticated)
1109- .Return(true)
1110- .Repeat.Once();
1111-
1112- SetupResult.For(_authentication.Username)
1113- .Return("mandel")
1114- .Repeat.Once();
1115- }
1116-
1117- using (_mocks.Playback())
1118- {
1119- _service.Stop();
1120- }
1121- }
1122-
1123- /// <summary>
1124- /// This method tests that the path used when there is an issue with the process work as expected.
1125- /// </summary>
1126- [Test]
1127- [ExpectedException(typeof(SyncDaemonException))]
1128- public void StopProcessExceptionTest()
1129- {
1130- using (_mocks.Record())
1131- {
1132- SetupResult.For(_authentication.IsAuthenticated)
1133- .Return(true)
1134- .Repeat.Once();
1135-
1136- SetupResult.For(_authentication.Username)
1137- .Return("mandel")
1138- .Repeat.Once();
1139-
1140- Expect.Call(_processManagerFactory.GetManager())
1141- .Return(_processManager)
1142- .Repeat.Once();
1143-
1144- Expect.Call(() => _processManager.Start())
1145- .Repeat.Once();
1146-
1147- Expect.Call(() => _processManager.Stop())
1148- .Throw(new ProcessManagementException());
1149- }
1150-
1151- using (_mocks.Playback())
1152- {
1153- _service.Start();
1154- _service.Stop();
1155- }
1156- }
1157-
1158- /// <summary>
1159- /// This method test tha tpath that is used when there is n issue with the process and we cannot stop it.
1160- /// </summary>
1161- [Test]
1162- public void TryStopFailTEst()
1163- {
1164-
1165- using (_mocks.Record())
1166- {
1167- SetupResult.For(_authentication.IsAuthenticated)
1168- .Return(true)
1169- .Repeat.Once();
1170-
1171- SetupResult.For(_authentication.Username)
1172- .Return("mandel")
1173- .Repeat.Once();
1174-
1175- Expect.Call(_processManagerFactory.GetManager())
1176- .Return(_processManager)
1177- .Repeat.Once();
1178-
1179- Expect.Call(() => _processManager.Start())
1180- .Repeat.Once();
1181-
1182- Expect.Call(() => _processManager.Stop())
1183- .Throw(new ProcessManagementException());
1184- }
1185-
1186- using (_mocks.Playback())
1187- {
1188- _service.Start();
1189- Assert.IsFalse(_service.TryStop());
1190- }
1191- }
1192-
1193- [Test]
1194- public void GetListeningSocketTest()
1195- {
1196- Assert.Ignore("To be implemented.");
1197- }
1198-
1199- [Test]
1200- public void GetCurrentStatusCorrectMessageTest()
1201- {
1202- _message.Type = SyncDaemonMessage.MessageType.STATUS;
1203- _message.State = new SyncDaemonMessage.StateMessage();
1204- _mocks.BackToRecord(_message);
1205- using(_mocks.Record())
1206- {
1207- Expect.Call(_messageFactory.QueryState())
1208- .Return(_message)
1209- .Repeat.Once();
1210- Expect.Call(_communicator.SendReceiveMessage<StateData>(_message, Convert.ToStateData))
1211- .Repeat.Once();
1212- }
1213- using(_mocks.Playback())
1214- {
1215- _service.GetCurrentStatus();
1216- }
1217- }
1218-
1219- [Test]
1220- public void GetCurrentDownloadsCorrectMessageTest()
1221- {
1222- _message.Type = SyncDaemonMessage.MessageType.DOWNLOADS;
1223- _mocks.BackToRecord(_message);
1224- using (_mocks.Record())
1225- {
1226- Expect.Call(_messageFactory.QueryDownloads())
1227- .Return(_message)
1228- .Repeat.Once();
1229- Expect.Call(_communicator.SendReceiveMessage<IList<DownloadData>>(_message, Convert.ToCurrentDownloads))
1230- .Repeat.Once();
1231- }
1232- using (_mocks.Playback())
1233- {
1234- _service.GetCurrentDownloads();
1235- }
1236- }
1237-
1238- [Test]
1239- public void GetWaitingContentCorrectMessageTest()
1240- {
1241- _message.Type = SyncDaemonMessage.MessageType.WAITING;
1242- _mocks.BackToRecord(_message);
1243- using (_mocks.Record())
1244- {
1245- Expect.Call(_messageFactory.QueryWaiting())
1246- .Return(_message)
1247- .Repeat.Once();
1248- Expect.Call(_communicator.SendReceiveMessage<IList<QueueItemData>>(_message, Convert.ToCurrentWaiting))
1249- .Repeat.Once();
1250- }
1251- using (_mocks.Playback())
1252- {
1253- _service.GetWaitingContent();
1254- }
1255- }
1256-
1257- [TestCase("ShareId", "NodeId")]
1258- [TestCase("Share", "Node")]
1259- public void ScheduleAsNextTest(string shareId, string nodeId)
1260- {
1261- using (_mocks.Record())
1262- {
1263- Expect.Call(_messageFactory.ScheduleAsNext(shareId, nodeId))
1264- .Return(_message)
1265- .Repeat.Once();
1266- Expect.Call(() => _communicator.SendMessage(_message))
1267- .Repeat.Once();
1268- }
1269- using (_mocks.Playback())
1270- {
1271- _service.ScheduleAsNext(shareId, nodeId);
1272- }
1273- }
1274-
1275- [Test]
1276- public void GetCurrentUploadsCorrectMessageTest()
1277- {
1278- _message.Type = SyncDaemonMessage.MessageType.UPLOADS;
1279- _mocks.BackToRecord(_message);
1280- using (_mocks.Record())
1281- {
1282- Expect.Call(_messageFactory.QueryUploads())
1283- .Return(_message)
1284- .Repeat.Once();
1285- Expect.Call(_communicator.SendReceiveMessage<IList<UploadData>>(_message, Convert.ToCurrentUploads))
1286- .Repeat.Once();
1287- }
1288- using (_mocks.Playback())
1289- {
1290- _service.GetCurrentUploads();
1291- }
1292- }
1293-
1294- [Test]
1295- public void ConnectTest()
1296- {
1297- using (_mocks.Record())
1298- {
1299- Expect.Call(_messageFactory.Connect())
1300- .Return(_message)
1301- .Repeat.Once();
1302- Expect.Call(() => _communicator.SendMessage(_message))
1303- .Repeat.Once();
1304- }
1305- using (_mocks.Playback())
1306- {
1307- _service.Connect();
1308- }
1309- }
1310-
1311- [Test]
1312- public void DisconnectTest()
1313- {
1314- using (_mocks.Record())
1315- {
1316- Expect.Call(_messageFactory.Disconnect())
1317- .Return(_message)
1318- .Repeat.Once();
1319- Expect.Call(() => _communicator.SendMessage(_message))
1320- .Repeat.Once();
1321- }
1322- using (_mocks.Playback())
1323- {
1324- _service.Disconnect();
1325- }
1326- }
1327-
1328- [Test]
1329- public void GetRootDirectoryTest()
1330- {
1331- _message.Type = SyncDaemonMessage.MessageType.ROOT;
1332- _mocks.BackToRecord(_message);
1333- using (_mocks.Record())
1334- {
1335- Expect.Call(_messageFactory.QueryRoot())
1336- .Return(_message)
1337- .Repeat.Once();
1338- Expect.Call(_communicator.SendReceiveMessage<string>(_message, Convert.ToRootDirectory))
1339- .Return("test")
1340- .Repeat.Once();
1341- }
1342- using (_mocks.Playback())
1343- {
1344- _service.GetRootDirectory();
1345- }
1346- }
1347-
1348- [Test]
1349- public void QuitTest()
1350- {
1351- using (_mocks.Record())
1352- {
1353- Expect.Call(_messageFactory.Quit())
1354- .Return(_message)
1355- .Repeat.Once();
1356- Expect.Call(() => _communicator.SendMessage(_message))
1357- .Repeat.Once();
1358- }
1359- using (_mocks.Playback())
1360- {
1361- _service.Quit();
1362- }
1363- }
1364-
1365- #endregion
1366+ // TODO: Implemente when ever a new solution is found.
1367 }
1368 }
1369
1370=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncFoldersServiceFixture.cs'
1371--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncFoldersServiceFixture.cs 2010-08-11 10:23:31 +0000
1372+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncFoldersServiceFixture.cs 2010-08-24 15:21:43 +0000
1373@@ -17,184 +17,13 @@
1374 *
1375 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1376 */
1377-using System.Collections.Generic;
1378-using Canonical.UbuntuOne.Common;
1379-using Canonical.UbuntuOne.ProcessDispatcher.Net;
1380 using NUnit.Framework;
1381-using Rhino.Mocks;
1382
1383 namespace Canonical.UbuntuOne.ProcessDispatcher.Tests
1384 {
1385 [TestFixture]
1386 public class SyncFoldersServiceFixture
1387 {
1388- #region Variables
1389-
1390- private ISyncFolderMessageFactory _messageFactory;
1391- private FolderMessage _message;
1392- private MockRepository _mocks;
1393- private SyncFoldersService _service;
1394- private ITcpClientCommunicator<FolderMessage> _communicator;
1395-
1396- #endregion
1397-
1398- #region Setup & Tear downs
1399-
1400- [SetUp]
1401- public void Setup()
1402- {
1403- _mocks = new MockRepository();
1404- _messageFactory = _mocks.StrictMock<ISyncFolderMessageFactory>();
1405- _message = _mocks.StrictMock<FolderMessage>();
1406- _communicator = _mocks.StrictMock<ITcpClientCommunicator<FolderMessage>>();
1407- _service = new SyncFoldersService
1408- {
1409- SyncFolderMessageFactory = _messageFactory,
1410- TcpClientCommunicator = _communicator
1411- };
1412- }
1413-
1414- #endregion
1415-
1416- #region Tests
1417-
1418- [TestCase("path1")]
1419- [TestCase("path to new location")]
1420- public void CreateFolderUdfTest(string path)
1421- {
1422- using (_mocks.Record())
1423- {
1424- Expect.Call(_messageFactory.CreateFolder(path))
1425- .Return(_message);
1426- Expect.Call(() => _communicator.SendMessage(_message))
1427- .Repeat.Once();
1428- }
1429- using (_mocks.Playback())
1430- {
1431- _service.CreateFolderUdf(path);
1432- }
1433- }
1434-
1435- [TestCase("path1")]
1436- [TestCase("path to old location")]
1437- public void DeleteFolderUdfTest(string path)
1438- {
1439- using (_mocks.Record())
1440- {
1441- Expect.Call(_messageFactory.DeleteFolder(path))
1442- .Return(_message);
1443- Expect.Call(() => _communicator.SendMessage(_message))
1444- .Repeat.Once();
1445- }
1446- using (_mocks.Playback())
1447- {
1448- _service.DeleteFolderUdf(path);
1449- }
1450- }
1451-
1452- [Test]
1453- public void GetFoldersCorrectMessageTest()
1454- {
1455- var data = new FolderMessage.UdfDataMessage
1456- {
1457- Node = new FolderMessage.NodeMessage()
1458- };
1459- _message = new FolderMessage(new List<FolderMessage.UdfDataMessage>())
1460- {
1461- Type = FolderMessage.MessageType.FOLDERS
1462- };
1463- _message.Udfs.Add(data);
1464- using (_mocks.Record())
1465- {
1466- Expect.Call(_messageFactory.QueryFolders())
1467- .Return(_message)
1468- .Repeat.Once();
1469- Expect.Call(_communicator.SendReceiveMessage<IList<UdfData>>(_message, Convert.ToAllFolders))
1470- .Repeat.Once();
1471- }
1472- using (_mocks.Playback())
1473- {
1474- _service.GetFolders();
1475- }
1476- }
1477-
1478- [TestCase("firstId")]
1479- [TestCase("secondId")]
1480- public void SubscribeTest(string folderId)
1481- {
1482- using (_mocks.Record())
1483- {
1484- Expect.Call(_messageFactory.Subscribe(folderId))
1485- .Return(_message);
1486- Expect.Call(() => _communicator.SendMessage(_message))
1487- .Repeat.Once();
1488- }
1489- using (_mocks.Playback())
1490- {
1491- _service.Subscribe(folderId);
1492- }
1493- }
1494-
1495- [TestCase("firstId")]
1496- [TestCase("secondId")]
1497- public void UnsubscribeTest(string folderId)
1498- {
1499- using (_mocks.Record())
1500- {
1501- Expect.Call(_messageFactory.Unsubscribe(folderId))
1502- .Return(_message);
1503- Expect.Call(() => _communicator.SendMessage((_message)))
1504- .Repeat.Once();
1505- }
1506- using (_mocks.Playback())
1507- {
1508- _service.Unsubscribe(folderId);
1509- }
1510- }
1511-
1512- [TestCase("FirstPath")]
1513- [TestCase("secondPath")]
1514- public void GetInfoCorrectMessageTest(string path)
1515- {
1516- var data = new FolderMessage.UdfDataMessage
1517- {
1518- Node = new FolderMessage.NodeMessage()
1519- };
1520- _message = new FolderMessage(new List<FolderMessage.UdfDataMessage>())
1521- {
1522- Type = FolderMessage.MessageType.INFO
1523- };
1524- _message.Udfs.Add(data);
1525- using (_mocks.Record())
1526- {
1527- Expect.Call(_messageFactory.QueryInfo(path))
1528- .Return(_message)
1529- .Repeat.Once();
1530- Expect.Call(_communicator.SendReceiveMessage<UdfData>(_message, Convert.ToUdfData))
1531- .Repeat.Once();
1532- }
1533- using (_mocks.Playback())
1534- {
1535- _service.GetInfo(path);
1536- }
1537- }
1538-
1539- [Test]
1540- public void RefreshVolumes()
1541- {
1542- using (_mocks.Record())
1543- {
1544- Expect.Call(_messageFactory.RefreshVolumes())
1545- .Return(_message);
1546- Expect.Call(() => _communicator.SendMessage(_message))
1547- .Repeat.Once();
1548- }
1549- using (_mocks.Playback())
1550- {
1551- _service.RefreshVolumes();
1552- }
1553- }
1554-
1555- #endregion
1556+ // TODO: Implement whenever a new solution is found.
1557 }
1558 }
1559
1560=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncSharesServiceFixture.cs'
1561--- src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncSharesServiceFixture.cs 2010-08-11 10:23:31 +0000
1562+++ src/Canonical.UbuntuOne.ProcessDispatcher.Tests/SyncSharesServiceFixture.cs 2010-08-24 15:21:43 +0000
1563@@ -17,151 +17,13 @@
1564 *
1565 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1566 */
1567-using System.Collections.Generic;
1568-using Canonical.UbuntuOne.Common;
1569-using Canonical.UbuntuOne.ProcessDispatcher.Net;
1570 using NUnit.Framework;
1571-using Rhino.Mocks;
1572
1573 namespace Canonical.UbuntuOne.ProcessDispatcher.Tests
1574 {
1575 [TestFixture]
1576 public class SyncSharesServiceFixture
1577 {
1578- #region Variables
1579-
1580- private ISyncShareMessageFactory _messageFactory;
1581- private ShareMessage _message;
1582- private MockRepository _mocks;
1583- private SyncSharesService _service;
1584- private ITcpClientCommunicator<ShareMessage> _communicator;
1585-
1586- #endregion
1587-
1588- #region Setup & Tear down
1589-
1590- [SetUp]
1591- public void Setup()
1592- {
1593- _mocks = new MockRepository();
1594- _messageFactory = _mocks.StrictMock<ISyncShareMessageFactory>();
1595- _message = _mocks.StrictMock<ShareMessage>();
1596- _communicator = _mocks.StrictMock<ITcpClientCommunicator<ShareMessage>>();
1597- _service = new SyncSharesService
1598- {
1599- SyncShareMessageFactory = _messageFactory,
1600- TcpClientCommunicator = _communicator
1601- };
1602- }
1603-
1604- #endregion
1605-
1606- #region Tests
1607-
1608- [Test]
1609- public void GetSharesTest()
1610- {
1611- using(_mocks.Record())
1612- {
1613- Expect.Call(_messageFactory.QueryShares())
1614- .Return(_message)
1615- .Repeat.Once();
1616- Expect.Call(_communicator.SendReceiveMessage<IList<ShareData>>(_message, Convert.ToGetShares))
1617- .Return(new List<ShareData>())
1618- .Repeat.Once();
1619- }
1620- using(_mocks.Playback())
1621- {
1622- _service.GetShares();
1623- }
1624- }
1625-
1626- [TestCase("ShareId")]
1627- public void AcceptShare(string shareId)
1628- {
1629- using (_mocks.Record())
1630- {
1631- Expect.Call(_messageFactory.AcceptShare(shareId))
1632- .Return(_message)
1633- .Repeat.Once();
1634- Expect.Call(() => _communicator.SendMessage(_message))
1635- .Repeat.Once();
1636- }
1637- using (_mocks.Playback())
1638- {
1639- _service.AcceptShare(shareId);
1640- }
1641- }
1642-
1643- [TestCase("ShareID")]
1644- public void RejectShare(string shareId)
1645- {
1646- using (_mocks.Record())
1647- {
1648- Expect.Call(_messageFactory.RejectShare(shareId))
1649- .Return(_message)
1650- .Repeat.Once();
1651- Expect.Call(() => _communicator.SendMessage(_message))
1652- .Repeat.Once();
1653- }
1654- using (_mocks.Playback())
1655- {
1656- _service.RejectShare(shareId);
1657- }
1658- }
1659-
1660- [TestCase("Path", "Username", "Name", AccessLevel.MODIFY)]
1661- public void CreateShare(string path, string username, string name, AccessLevel accessLevel)
1662- {
1663- using (_mocks.Record())
1664- {
1665- Expect.Call(_messageFactory.CreateShare(path, username, name, accessLevel))
1666- .Return(_message)
1667- .Repeat.Once();
1668- Expect.Call(() => _communicator.SendMessage(_message))
1669- .Repeat.Once();
1670- }
1671- using (_mocks.Playback())
1672- {
1673- _service.CreateShare(path, username, name, accessLevel);
1674- }
1675- }
1676-
1677- [Test]
1678- public void UpdateShares()
1679- {
1680- using (_mocks.Record())
1681- {
1682- Expect.Call(_messageFactory.UpdateShares())
1683- .Return(_message)
1684- .Repeat.Once();
1685- Expect.Call(() => _communicator.SendMessage(_message))
1686- .Repeat.Once();
1687- }
1688- using (_mocks.Playback())
1689- {
1690- _service.UpdateShares();
1691- }
1692- }
1693-
1694- [Test]
1695- public void GetShared()
1696- {
1697- using (_mocks.Record())
1698- {
1699- Expect.Call(_messageFactory.GetShared())
1700- .Return(_message)
1701- .Repeat.Once();
1702- Expect.Call(_communicator.SendReceiveMessage<IList<ShareData>>(_message, Convert.ToGetShared))
1703- .Return(new List<ShareData>())
1704- .Repeat.Once();
1705- }
1706- using (_mocks.Playback())
1707- {
1708- _service.GetShared();
1709- }
1710- }
1711-
1712- #endregion
1713+ // TODO: Implement when ever new solution is found
1714 }
1715 }
1716
1717=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj'
1718--- src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj 2010-08-18 12:44:45 +0000
1719+++ src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj 2010-08-24 15:21:43 +0000
1720@@ -75,16 +75,6 @@
1721 <Compile Include="EventNotifier.cs" />
1722 <Compile Include="ICallerContext.cs" />
1723 <Compile Include="IEventDispatcher.cs" />
1724- <Compile Include="Net\IPortFinder.cs" />
1725- <Compile Include="Net\IPortManager.cs" />
1726- <Compile Include="Net\ITcpClient.cs" />
1727- <Compile Include="Net\ITcpClientCommunicator.cs" />
1728- <Compile Include="Net\ITcpClientFactory.cs" />
1729- <Compile Include="Net\PortFinder.cs" />
1730- <Compile Include="Net\PortManager.cs" />
1731- <Compile Include="Net\TcpClientCommunicator.cs" />
1732- <Compile Include="Net\TcpClientFactory.cs" />
1733- <Compile Include="Net\TcpClientWrapper.cs" />
1734 <Compile Include="Program.cs" />
1735 <Compile Include="ProjectInstaller.cs">
1736 <SubType>Component</SubType>
1737
1738=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/EventNotifier.cs'
1739--- src/Canonical.UbuntuOne.ProcessDispatcher/EventNotifier.cs 2010-08-18 09:38:08 +0000
1740+++ src/Canonical.UbuntuOne.ProcessDispatcher/EventNotifier.cs 2010-08-24 15:21:43 +0000
1741@@ -20,14 +20,10 @@
1742 using System;
1743 using System.Collections.Generic;
1744 using System.IO;
1745-using System.Net;
1746 using System.Net.Sockets;
1747-using System.Threading;
1748 using Canonical.UbuntuOne.Common;
1749 using Canonical.UbuntuOne.Common.OperationContracts;
1750-using Canonical.UbuntuOne.ProcessDispatcher.Net;
1751 using log4net;
1752-using PortManagerImpl = Canonical.UbuntuOne.ProcessDispatcher.Net.PortManager;
1753
1754 namespace Canonical.UbuntuOne.ProcessDispatcher
1755 {
1756@@ -71,17 +67,13 @@
1757
1758 #region Vars
1759
1760- private IPortManager _portManager;
1761 private ILog _logger;
1762 private readonly object _loggerLock = new object();
1763 private readonly object _clientsLock = new object();
1764 private readonly object _portManagerLock = new object();
1765 private readonly object _isListeningLock = new object();
1766- private static readonly ManualResetEvent _allDone = new ManualResetEvent(false);
1767 private static readonly HashSet<ISyncDaemonClient> _registeredClients = new HashSet<ISyncDaemonClient>();
1768- private bool _hasToListen;
1769 private bool _isListening;
1770- private Thread _listeningThread;
1771
1772 #endregion
1773
1774@@ -122,155 +114,9 @@
1775 }
1776 set { _logger = value; }
1777 }
1778- /// <summary>
1779- /// Gets and sets the port manager that is used to ensure that the ports are correctly used
1780- /// for the application per user.
1781- /// </summary>
1782- internal IPortManager PortManager
1783- {
1784- get
1785- {
1786- if(_portManager == null)
1787- {
1788- lock (_portManagerLock)
1789- {
1790- _portManager = PortManagerImpl.Instance;
1791- }
1792- }
1793- return _portManager;
1794- }
1795- set { _portManager = value; }
1796- }
1797-
1798- #endregion
1799-
1800- #region HelperMethods
1801-
1802- /// <summary>
1803- /// This method listens to the port that has been set for this service to be listening for
1804- /// </summary>
1805- private void Listen()
1806- {
1807-
1808- var localEndPoint = new IPEndPoint(IPAddress.Any, PortManager.GetDotNetClientPort());
1809- var listener = new Socket(localEndPoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
1810- try
1811- {
1812- listener.Bind(localEndPoint);
1813- listener.Listen(1000);
1814- lock (_isListeningLock)
1815- {
1816- _isListening = true;
1817- }
1818- while (_hasToListen)
1819- {
1820- _allDone.Reset();
1821-
1822- Logger.Info("Waiting for a connection...");
1823- listener.BeginAccept(
1824- new AsyncCallback(AcceptCallback),
1825- listener);
1826-
1827- _allDone.WaitOne();
1828- }
1829- }
1830- catch (Exception e)
1831- {
1832- var message = string.Format("An exception was thrown when listening to port {0}",
1833- PortManager.GetDotNetClientPort());
1834- Logger.Error(message, e);
1835- }
1836- }
1837-
1838- /// <summary>
1839- /// Callback that will be used to accept connections in an async manner. The method
1840- /// will be ran in a separate thread and will take care of dispathinch the work to other threads.
1841- /// </summary>
1842- /// <param name="asyncResult">The async result that will be passed to the call back with the
1843- /// connect information.</param>
1844- private void AcceptCallback(IAsyncResult asyncResult)
1845- {
1846- var listener = (Socket)asyncResult.AsyncState;
1847- var handler = listener.EndAccept(asyncResult);
1848- // Signal the main thread to continue.
1849- _allDone.Set();
1850-
1851- // Create the state object.
1852- var state = new StateObject
1853- {
1854- WorkSocket = handler
1855- };
1856- handler.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0,
1857- new AsyncCallback(ReadCallback), state);
1858- }
1859-
1860- /// <summary>
1861- /// Callback that will be used after a read operation has been performed once the data from
1862- /// the python client has arrived.
1863- /// </summary>
1864- /// <param name="ar">The async result that will be passed to the callback with the read information
1865- /// that has been collected so far.</param>
1866- private void ReadCallback(IAsyncResult ar)
1867- {
1868- var state = (StateObject)ar.AsyncState;
1869- var handler = state.WorkSocket;
1870-
1871- // Read data from the client socket.
1872- var read = handler.EndReceive(ar);
1873-
1874- // Data was read from the client socket.
1875- if (read > 0)
1876- {
1877- // create a binary writer that will be used to append the data to the stream.
1878- var writer = new BinaryWriter(state.ResultBuilder);
1879- writer.Write(state.Buffer, 0, read);
1880- writer.Flush();
1881- // start another callback to see if we have more info to read.
1882- handler.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0,
1883- new AsyncCallback(ReadCallback), state);
1884- }
1885- else
1886- {
1887- if (state.ResultBuilder.Length > 1)
1888- {
1889- // All the data has been read from the client;
1890- // display it on the console.
1891- var workThread = new Thread(ProcessMessage);
1892- workThread.Start(state.ResultBuilder);
1893-
1894- }
1895- handler.Close();
1896- }
1897- }
1898-
1899- /// <summary>
1900- /// Method that will be executed in a thread that will process the message comming from python and
1901- /// will notify the different clients.
1902- /// </summary>
1903- /// <param name="o">An object that should be castable to a MemoryStream that contains the data of the
1904- /// protobuf message.</param>
1905- private void ProcessMessage(object o)
1906- {
1907- // cast the object to the data that we actually have,
1908- var data = (MemoryStream) o;
1909- var protobufMessage = ProtobufSerializer.Deserialize<SyncDaemonClientMessage>(data);
1910- EventDispatcher.Dispatch(protobufMessage, _registeredClients);
1911- }
1912-
1913- #endregion
1914-
1915- /// <summary>
1916- /// Helper method that can be used internally to kill the listening thread to allow the event listener to stop. This
1917- /// method is very useful when running tests to be sure that not too many threads are kept alive.
1918- /// </summary>
1919- internal void KillListeningThread()
1920- {
1921- if (_listeningThread != null)
1922- {
1923- _hasToListen = false;
1924- _listeningThread.Abort();
1925- }
1926- }
1927+
1928+
1929+ #endregion
1930
1931 #region Implementation of IEventNotifier
1932
1933@@ -311,17 +157,8 @@
1934 /// </summary>
1935 public void StartListening()
1936 {
1937- if (!_hasToListen)
1938- {
1939- _hasToListen = true;
1940- // Once created, start listening to the port used by python to talk with us
1941- _listeningThread = new Thread(Listen) {Name = "EventNotifierSocketServer"};
1942- _listeningThread.Start();
1943- }
1944- else
1945- {
1946- throw new InvalidOperationException("EventNotifier cannot start listning because it already is.");
1947- }
1948+ // TODO: Implement when ever a new techinque is used
1949+ throw new NotImplementedException();
1950 }
1951
1952 /// <summary>
1953@@ -329,19 +166,7 @@
1954 /// </summary>
1955 public void StopListening()
1956 {
1957- if (_hasToListen)
1958- {
1959- _hasToListen = false;
1960- lock (_isListeningLock)
1961- {
1962- _isListening = false;
1963- }
1964- _listeningThread.Join();
1965- }
1966- else
1967- {
1968- throw new InvalidOperationException("Cannot stop listening because EventNotifier never started to listen.");
1969- }
1970+ // TODO: Implement whenever a new techique is used.
1971 }
1972
1973 /// <summary>
1974
1975=== removed directory 'src/Canonical.UbuntuOne.ProcessDispatcher/Net'
1976=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/IPortFinder.cs'
1977--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/IPortFinder.cs 2010-08-12 07:59:15 +0000
1978+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/IPortFinder.cs 1970-01-01 00:00:00 +0000
1979@@ -1,37 +0,0 @@
1980-/*
1981- * Copyright 2010 Canonical Ltd.
1982- *
1983- * This file is part of UbuntuOne on Windows.
1984- *
1985- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
1986- * it under the terms of the GNU Lesser General Public License version
1987- * as published by the Free Software Foundation.
1988- *
1989- * Ubuntu One on Windows is distributed in the hope that it will be useful,
1990- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1991- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1992- * GNU Lesser General Public License for more details.
1993- *
1994- * You should have received a copy of the GNU Lesser General Public License
1995- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
1996- *
1997- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
1998- */
1999-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2000-{
2001- /// <summary>
2002- /// Interface to be implemented by a class that is able to find ports that are free to
2003- /// be used for IPC.
2004- /// </summary>
2005- internal interface IPortFinder
2006- {
2007- /// <summary>
2008- /// Returns a free port that can be used to perform IPC throw sockets.
2009- /// </summary>
2010- /// <returns></returns>
2011- /// <remarks>The implementation has to be thread safe to ensure that a port
2012- /// is not returned more than once ensuring otherwhise more than one process will
2013- /// try to use the same port.</remarks>
2014- int GetFreePort();
2015- }
2016-}
2017
2018=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/IPortManager.cs'
2019--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/IPortManager.cs 2010-08-12 07:59:15 +0000
2020+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/IPortManager.cs 1970-01-01 00:00:00 +0000
2021@@ -1,41 +0,0 @@
2022-/*
2023- * Copyright 2010 Canonical Ltd.
2024- *
2025- * This file is part of UbuntuOne on Windows.
2026- *
2027- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2028- * it under the terms of the GNU Lesser General Public License version
2029- * as published by the Free Software Foundation.
2030- *
2031- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2032- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2033- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2034- * GNU Lesser General Public License for more details.
2035- *
2036- * You should have received a copy of the GNU Lesser General Public License
2037- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2038- *
2039- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2040- */
2041-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2042-{
2043- /// <summary>
2044- /// Interface to be implemented by a manager that will allow classes to query about the
2045- /// ports that are used to communicate with pyton according to the user.
2046- /// </summary>
2047- public interface IPortManager
2048- {
2049- /// <summary>
2050- /// Gets the port that the in the current user space can be used to communicate
2051- /// with the python code.
2052- /// </summary>
2053- /// <returns>The port number that is used to communicate with the python code.</returns>
2054- int GetPythonServerPort();
2055-
2056- /// <summary>
2057- /// Gets the port that the DotNet client uses to receive messages from the client port.
2058- /// </summary>
2059- /// <returns>The port used by the .Net client to get events from the python code.</returns>
2060- int GetDotNetClientPort();
2061- }
2062-}
2063
2064=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClient.cs'
2065--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClient.cs 2010-08-10 08:48:19 +0000
2066+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClient.cs 1970-01-01 00:00:00 +0000
2067@@ -1,42 +0,0 @@
2068-/*
2069- * Copyright 2010 Canonical Ltd.
2070- *
2071- * This file is part of UbuntuOne on Windows.
2072- *
2073- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2074- * it under the terms of the GNU Lesser General Public License version
2075- * as published by the Free Software Foundation.
2076- *
2077- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2078- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2079- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2080- * GNU Lesser General Public License for more details.
2081- *
2082- * You should have received a copy of the GNU Lesser General Public License
2083- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2084- *
2085- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2086- */
2087-using System.Net.Sockets;
2088-
2089-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2090-{
2091- /// <summary>
2092- /// Interface to be implemented by a TcpClient that allows to communicate with the
2093- /// python code.
2094- /// </summary>
2095- internal interface ITcpClient
2096- {
2097- /// <summary>
2098- /// Returns the stream that is used by the tcp client to communicate with
2099- /// the python code.
2100- /// </summary>
2101- /// <returns>A stream that can send data to the python process.</returns>
2102- NetworkStream GetStream();
2103-
2104- /// <summary>
2105- /// Closes the TcpClient release the different used resources.
2106- /// </summary>
2107- void Close();
2108- }
2109-}
2110
2111=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientCommunicator.cs'
2112--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientCommunicator.cs 2010-08-11 10:23:31 +0000
2113+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientCommunicator.cs 1970-01-01 00:00:00 +0000
2114@@ -1,48 +0,0 @@
2115-/*
2116- * Copyright 2010 Canonical Ltd.
2117- *
2118- * This file is part of UbuntuOne on Windows.
2119- *
2120- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2121- * it under the terms of the GNU Lesser General Public License version
2122- * as published by the Free Software Foundation.
2123- *
2124- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2125- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2126- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2127- * GNU Lesser General Public License for more details.
2128- *
2129- * You should have received a copy of the GNU Lesser General Public License
2130- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2131- *
2132- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2133- */
2134-using System;
2135-
2136-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2137-{
2138- /// <summary>
2139- /// Interface to be implemented by a class that allows to send an receive
2140- /// protobuf messages using sockets and a tcp client.
2141- /// </summary>
2142- internal interface ITcpClientCommunicator<TMessage>
2143- {
2144- /// <summary>
2145- /// Sends a message to the python code but does not expecte and answer
2146- /// back.
2147- /// </summary>
2148- /// <param name="message">The message to be sent to the python code.</param>
2149- void SendMessage(TMessage message);
2150-
2151- /// <summary>
2152- /// Sends a message to the python code and expects and answer back.
2153- /// </summary>
2154- /// <typeparam name="TResult">The type of object that is expected to be in the return from the
2155- /// python code.</typeparam>
2156- /// <param name="message">The message to be sent to the python code.</param>
2157- /// <param name="conversion">A function that can convert the message type from the python code to
2158- /// the expected result type.</param>
2159- /// <returns>The resposne that the python returned once the message has been processed.</returns>
2160- TResult SendReceiveMessage<TResult>(TMessage message, Func<TMessage, TResult> conversion);
2161- }
2162-}
2163
2164=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientFactory.cs'
2165--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientFactory.cs 2010-08-10 08:48:19 +0000
2166+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/ITcpClientFactory.cs 1970-01-01 00:00:00 +0000
2167@@ -1,36 +0,0 @@
2168-/*
2169- * Copyright 2010 Canonical Ltd.
2170- *
2171- * This file is part of UbuntuOne on Windows.
2172- *
2173- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2174- * it under the terms of the GNU Lesser General Public License version
2175- * as published by the Free Software Foundation.
2176- *
2177- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2178- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2179- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2180- * GNU Lesser General Public License for more details.
2181- *
2182- * You should have received a copy of the GNU Lesser General Public License
2183- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2184- *
2185- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2186- */
2187-using System.Net.Sockets;
2188-
2189-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2190-{
2191- /// <summary>
2192- /// Interface to be implemented by a factory that will return TcpClients that are configured ready
2193- /// to communicate with the python code.
2194- /// </summary>
2195- internal interface ITcpClientFactory
2196- {
2197- /// <summary>
2198- /// Returns a client that allows to communicate with the python code.
2199- /// </summary>
2200- /// <returns>A TcpClient configured to talk with the python code through sockets.</returns>
2201- ITcpClient GetClient();
2202- }
2203-}
2204
2205=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/PortFinder.cs'
2206--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/PortFinder.cs 2010-08-12 07:59:15 +0000
2207+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/PortFinder.cs 1970-01-01 00:00:00 +0000
2208@@ -1,107 +0,0 @@
2209-/*
2210- * Copyright 2010 Canonical Ltd.
2211- *
2212- * This file is part of UbuntuOne on Windows.
2213- *
2214- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2215- * it under the terms of the GNU Lesser General Public License version
2216- * as published by the Free Software Foundation.
2217- *
2218- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2219- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2220- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2221- * GNU Lesser General Public License for more details.
2222- *
2223- * You should have received a copy of the GNU Lesser General Public License
2224- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2225- *
2226- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2227- */
2228-using System;
2229-using System.Collections.Generic;
2230-using System.Linq;
2231-using System.Net;
2232-using System.Net.NetworkInformation;
2233-
2234-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2235-{
2236- /// <summary>
2237- /// Thread safe implementation of the IPortFinder that provides free socket ports to be used to communicate. This
2238- /// implementation does not ensure that the port will not be used by another application in the system
2239- /// if the client does not use the free port fast enough.
2240- /// </summary>
2241- internal class PortFinder : IPortFinder
2242- {
2243- #region Variables
2244-
2245- public const int NumberOfTries = 1000;
2246- private readonly Random _random;
2247- private List<int> _ports;
2248-
2249- #endregion
2250-
2251- #region Helpers
2252-
2253- /// <summary>
2254- /// Helper methods that gets a port number and interacts with the os to ensure that such a port is free.
2255- /// </summary>
2256- /// <param name="port">The number of the port we want to use.</param>
2257- /// <returns>A flag that indicates if the port is free or not.</returns>
2258- private static bool IsFree(int port)
2259- {
2260- // Evaluate current system tcp connections. This is the same information provided
2261- // by the netstat command line application, just in .Net strongly-typed object
2262- // form. We will look through the list, and if our port we would like to use
2263- // in our TcpClient is occupied, we will set isAvailable to false.
2264- var ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
2265- var tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
2266-
2267- return tcpConnInfoArray.All(tcpi => tcpi.LocalEndPoint.Port != port);
2268- }
2269-
2270- #endregion
2271-
2272- #region Constructors
2273-
2274- /// <summary>
2275- /// Creates a new instance of the port finder that can be used to find free ports in the system.
2276- /// </summary>
2277- public PortFinder()
2278- {
2279- _random = new Random();
2280- _ports = new List<int>();
2281- }
2282-
2283- #endregion
2284-
2285- #region Implementation of IPortFinder
2286-
2287- /// <summary>
2288- /// Returns a free port that can be used to perform IPC throw sockets.
2289- /// </summary>
2290- /// <returns></returns>
2291- /// <remarks>The implementation has to be thread safe to ensure that a port
2292- /// is not returned more than once ensuring otherwhise more than one process will
2293- /// try to use the same port.</remarks>
2294- public int GetFreePort()
2295- {
2296- var port = _random.Next(IPEndPoint.MaxPort);
2297- var triedPorts = new List<int>(100) {port};
2298- for (var atempt = 0; atempt < NumberOfTries; atempt++)
2299- {
2300- if (!_ports.Contains(port) && IsFree(port))
2301- {
2302- _ports.Add(port);
2303- return port;
2304- }
2305- while (triedPorts.Contains(port) || _ports.Contains(port))
2306- {
2307- port = _random.Next(IPEndPoint.MaxPort);
2308- }
2309- }
2310- throw new InvalidOperationException("No free ports found.");
2311- }
2312-
2313- #endregion
2314- }
2315-}
2316
2317=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/PortManager.cs'
2318--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/PortManager.cs 2010-08-18 09:49:09 +0000
2319+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/PortManager.cs 1970-01-01 00:00:00 +0000
2320@@ -1,331 +0,0 @@
2321-/*
2322- * Copyright 2010 Canonical Ltd.
2323- *
2324- * This file is part of UbuntuOne on Windows.
2325- *
2326- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2327- * it under the terms of the GNU Lesser General Public License version
2328- * as published by the Free Software Foundation.
2329- *
2330- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2331- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2332- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2333- * GNU Lesser General Public License for more details.
2334- *
2335- * You should have received a copy of the GNU Lesser General Public License
2336- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2337- *
2338- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2339- */
2340-using System;
2341-using System.Collections.Generic;
2342-using System.Data;
2343-using Canonical.UbuntuOne.Common;
2344-using Spring.Data.Common;
2345-using Spring.Data.Core;
2346-
2347-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2348-{
2349- /// <summary>
2350- /// Implementation of the IPortManager that keeps track of the ports assigned to the different users and ensures that
2351- /// there are correctly managed. The port manager create a sqlite db that will be used to ensure that a user
2352- /// allw
2353- /// </summary>
2354- internal class PortManager : IPortManager
2355- {
2356- #region Helper class
2357-
2358- /// <summary>
2359- /// Internal structure used to remember the ports that have been assigned to a user.
2360- /// </summary>
2361- private struct UserPorts
2362- {
2363- #region Vars
2364-
2365- private readonly int _python;
2366- private readonly int _dotNet;
2367-
2368- #endregion
2369-
2370- /// <summary>
2371- /// Gets and sets the port used for python.
2372- /// </summary>
2373- public int PythonPort { get { return _python; } }
2374-
2375- /// <summary>
2376- /// Gets and sets the port used for DotNet.
2377- /// </summary>
2378- public int DotNetPort { get { return _dotNet; } }
2379-
2380- public UserPorts(int pythonPort, int dotNet)
2381- {
2382- _python = pythonPort;
2383- _dotNet = dotNet;
2384- }
2385- }
2386-
2387- #endregion
2388-
2389- private static readonly PortManager _instance;
2390-
2391- #region Variables
2392-
2393- private readonly object _dictionaryLock = new object();
2394- private readonly Dictionary<string, UserPorts> _ports;
2395- internal const string UserPortsTableName = "UserPorts";
2396- private bool _usetTableExists;
2397-
2398- #endregion
2399-
2400- #region DI properties
2401-
2402- /// <summary>
2403- /// Gets and sets the object that is used to perform the different auth operations.
2404- /// </summary>
2405- internal IAuthentication Authentication { get; set; }
2406-
2407- /// <summary>
2408- /// Gets and sets the object used to find the unused ports in the system.
2409- /// </summary>
2410- internal IPortFinder PortFinder { get; set; }
2411-
2412- /// <summary>
2413- /// Gets and sets the provider that the port manager uses to store the relation between a user and the
2414- /// ports he use in the application.
2415- /// </summary>
2416- internal IDbProvider DbProvider { get; set; }
2417-
2418- #endregion
2419-
2420- #region Helpers
2421-
2422- /// <summary>
2423- /// Helper method that finds the ports of a user when they are not present.
2424- /// </summary>
2425- private void FindUserPorts()
2426- {
2427- lock (_dictionaryLock)
2428- {
2429- // we check if the table exists, this can happe either the first time we start in the system
2430- // and the table does not exists or when we reboot and we lost the info of the flag. Ofcourse the
2431- // the table could have been drop at some point
2432- if(!_usetTableExists)
2433- {
2434- var reallyExists = UserPortsTableExists();
2435- if(!reallyExists)
2436- {
2437- CreateUserPortsTable();
2438- }
2439- _usetTableExists = true;
2440- }
2441- int dotNetPort;
2442- int pythonPort;
2443- // we try to get the data from the db
2444- if(!TryGetUserPortFromDb(Authentication.Username, out pythonPort, out dotNetPort))
2445- {
2446- // we cannot get the ports, therefore we generate them.
2447- pythonPort = PortFinder.GetFreePort();
2448- dotNetPort = PortFinder.GetFreePort();
2449- // store the user ports in the db for the next time
2450- InserUserPortsInDb(Authentication.Username, pythonPort, dotNetPort);
2451- }
2452- var userPorts = new UserPorts(pythonPort, dotNetPort);
2453- _ports.Add(Authentication.Username, userPorts);
2454- }
2455- }
2456-
2457-
2458- /// <summary>
2459- /// Helper method that returns if the table that stores the user name and ports relation is
2460- /// present in the db.
2461- /// </summary>
2462- /// <returns>A boolean value stating if the UserPorts table is present in the db.</returns>
2463- private bool UserPortsTableExists()
2464- {
2465- // query the sqlite schema using and ado template
2466- var template = new AdoTemplate(DbProvider);
2467- var result = template.Execute(
2468- command =>
2469- {
2470- command.CommandText = "SELECT count(*) FROM sqlite_master WHERE type='table' AND name=:tableName;";
2471- var parameter = command.CreateParameter();
2472- parameter.ParameterName = ":tableName";
2473- parameter.Value = UserPortsTableName;
2474- command.Parameters.Add(parameter);
2475- var count = command.ExecuteScalar();
2476- return (long)count != 0;
2477- }
2478- );
2479-
2480- return (bool)result;
2481- }
2482-
2483- /// <summary>
2484- /// Helper method that will create the user porst table in the db when needed.
2485- /// </summary>
2486- private void CreateUserPortsTable()
2487- {
2488- // create the table using an ado template.
2489- var template = new AdoTemplate(DbProvider);
2490- template.ExecuteNonQuery( CommandType.Text,
2491- String.Format("CREATE TABLE IF NOT EXISTS {0}('Username' TEXT PRIMARY KEY, 'PythonPort' INT, 'DotNetPort' INT);",
2492- UserPortsTableName));
2493- }
2494-
2495- /// <summary>
2496- /// Helper method that adds a new pair of ports for a user in the db.
2497- /// </summary>
2498- /// <param name="username">The name of the user whose ports we are going to insert.</param>
2499- /// <param name="pythonPort">The port to be used to talk to python.</param>
2500- /// <param name="dotNetPort">The port to be used to talk to dotNet.</param>
2501- private void InserUserPortsInDb(string username, int pythonPort, int dotNetPort)
2502- {
2503- var template = new AdoTemplate(DbProvider);
2504- template.Execute(
2505- command =>
2506- {
2507- command.CommandText = String.Format(
2508- "INSERT INTO {0}(Username, PythonPort, DotNetPort) VALUES (:username, :pythonPort, :dotNetPort)",
2509- UserPortsTableName);
2510- var usernameParam = command.CreateParameter();
2511- usernameParam.ParameterName = ":username";
2512- usernameParam.Value = username;
2513- command.Parameters.Add(usernameParam);
2514-
2515- var pythonParam = command.CreateParameter();
2516- pythonParam.ParameterName = ":pythonPort";
2517- pythonParam.Value = pythonPort;
2518- command.Parameters.Add(pythonParam);
2519-
2520- var dotNetParam = command.CreateParameter();
2521- dotNetParam.ParameterName = ":dotNetPort";
2522- dotNetParam.Value = dotNetPort;
2523- command.Parameters.Add(dotNetParam);
2524-
2525- return command.ExecuteScalar();
2526- }
2527- );
2528- }
2529-
2530- /// <summary>
2531- /// Helper method that allows to retrieve the ports of a user from the db. If the data cannot be retrieved from
2532- /// the db.
2533- /// </summary>
2534- /// <param name="username">The username whose ports we want to retrieve.</param>
2535- /// <param name="pythonPort">Out parameter used to return the port used to talk with python.</param>
2536- /// <param name="dotNetPort">Out parameter used to return the port used to talk with dot net.</param>
2537- /// <returns>A boolean flag that indicates if the data could have been retrieved from the db.</returns>
2538- private bool TryGetUserPortFromDb(string username, out int pythonPort, out int dotNetPort)
2539- {
2540- // try to get the ports from the db, if it is not possible we return false
2541- var template = new AdoTemplate(DbProvider);
2542- try
2543- {
2544- var userPorts = (UserPorts)template.Execute(
2545- command =>
2546- {
2547- command.CommandText =
2548- String.Format("SELECT PythonPort, DotNetPort FROM {0} WHERE Username=:username;",
2549- UserPortsTableName);
2550- var parameter = command.CreateParameter();
2551- parameter.ParameterName = ":username";
2552- parameter.Value = username;
2553- command.Parameters.Add(parameter);
2554- var reader = command.ExecuteReader();
2555- while (reader.Read())
2556- {
2557- return new UserPorts(System.Convert.ToInt32((long) reader["PythonPort"]),
2558- System.Convert.ToInt32((long) reader["DotNetPort"]));
2559- }
2560- return new UserPorts(-1, -1);
2561- }
2562- );
2563- pythonPort = userPorts.PythonPort;
2564- dotNetPort = userPorts.DotNetPort;
2565- return false;
2566- }
2567- catch(Exception)
2568- {
2569- // an exception will be thrown if we cannot get the data from the db, therefore we return false
2570- pythonPort = -1;
2571- dotNetPort = -1;
2572- return false;
2573- }
2574- }
2575-
2576- #endregion
2577-
2578- #region Constructors
2579-
2580- /// <summary>
2581- /// Static constructor that ensures that only on port manager will exist in the application.
2582- /// </summary>
2583- static PortManager()
2584- {
2585- _instance = new PortManager();
2586- }
2587-
2588- /// <summary>
2589- /// Private constructor used by the static constructor to create the singleton
2590- /// instance to be used.
2591- /// </summary>
2592- private PortManager()
2593- {
2594- _ports = new Dictionary<string, UserPorts>();
2595- }
2596-
2597- #endregion
2598-
2599- /// <summary>
2600- /// Removes the storage data regarding of the ports that have been given so far.
2601- /// </summary>
2602- internal void Clear()
2603- {
2604- _ports.Clear();
2605- }
2606-
2607- #region Implementation of IPortManager
2608-
2609- /// <summary>
2610- /// Gets the port that the in the current user space can be used to communicate
2611- /// with the python code.
2612- /// </summary>
2613- /// <returns>The port number that is used to communicate with the python code.</returns>
2614- public int GetPythonServerPort()
2615- {
2616- if (!_ports.ContainsKey(Authentication.Username))
2617- {
2618- FindUserPorts();
2619- }
2620- return _ports[Authentication.Username].PythonPort;
2621- }
2622-
2623- /// <summary>
2624- /// Gets the port that the DotNet client uses to receive messages from the client port.
2625- /// </summary>
2626- /// <returns>The port used by the .Net client to get events from the python code.</returns>
2627- public int GetDotNetClientPort()
2628- {
2629- if (!_ports.ContainsKey(Authentication.Username))
2630- {
2631- FindUserPorts();
2632- }
2633- return _ports[Authentication.Username].DotNetPort;
2634- }
2635-
2636- #endregion
2637-
2638- #region Static methods
2639-
2640- /// <summary>
2641- /// Gets the singleton instance.
2642- /// </summary>
2643- public static PortManager Instance
2644- {
2645- get { return _instance; }
2646- }
2647-
2648- #endregion
2649-
2650- }
2651-}
2652
2653=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientCommunicator.cs'
2654--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientCommunicator.cs 2010-08-11 10:23:31 +0000
2655+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientCommunicator.cs 1970-01-01 00:00:00 +0000
2656@@ -1,88 +0,0 @@
2657-/*
2658- * Copyright 2010 Canonical Ltd.
2659- *
2660- * This file is part of UbuntuOne on Windows.
2661- *
2662- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2663- * it under the terms of the GNU Lesser General Public License version
2664- * as published by the Free Software Foundation.
2665- *
2666- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2667- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2668- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2669- * GNU Lesser General Public License for more details.
2670- *
2671- * You should have received a copy of the GNU Lesser General Public License
2672- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2673- *
2674- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2675- */
2676-using System;
2677-
2678-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2679-{
2680- /// <summary>
2681- /// Implementation of ITcpClientCommunicator that allows to send and receive
2682- /// messages from the python code.
2683- /// </summary>
2684- internal class TcpClientCommunicator<TMessage> : ITcpClientCommunicator<TMessage>
2685- {
2686- #region DI properties
2687-
2688- /// <summary>
2689- /// Gets and sets the factory that is used to crete a tcp client that will communicate with
2690- /// the python code.
2691- /// </summary>
2692- internal ITcpClientFactory TcpClientFactory { get; set; }
2693-
2694- /// <summary>
2695- /// Gets and sets the serializer that is used to serialize the protobuf messages that
2696- /// are used to communicate with the python code.
2697- /// </summary>
2698- internal IProtobufSerializer ProtobufSerializer { get; set; }
2699-
2700- #endregion
2701-
2702- #region Implementation of ITcpClientCommunicator<TMessage>
2703-
2704- /// <summary>
2705- /// Sends a message to the python code but does not expecte and answer
2706- /// back.
2707- /// </summary>
2708- /// <param name="message">The message to be sent to the python code.</param>
2709- public void SendMessage(TMessage message)
2710- {
2711- // get the tcp client that will be used to communicate with python
2712- var client = TcpClientFactory.GetClient();
2713- var stream = client.GetStream();
2714- ProtobufSerializer.Serialize(stream, message);
2715- stream.Close();
2716- client.Close();
2717- }
2718-
2719- /// <summary>
2720- /// Sends a message to the python code and expects and answer back.
2721- /// </summary>
2722- /// <typeparam name="TResult">The type of object that is expected to be in the return from the
2723- /// python code.</typeparam>
2724- /// <param name="message">The message to be sent to the python code.</param>
2725- /// <param name="conversion">A function that can convert the message type from the python code to
2726- /// the expected result type.</param>
2727- /// <returns>The resposne that the python returned once the message has been processed.</returns>
2728- public TResult SendReceiveMessage<TResult>(TMessage message, Func<TMessage, TResult> conversion)
2729- {
2730- // get the tcp client that will be used to communicate with python
2731- var client = TcpClientFactory.GetClient();
2732- var stream = client.GetStream();
2733- ProtobufSerializer.Serialize(stream, message);
2734- var response = ProtobufSerializer.Deserialize<TMessage>(stream);
2735- var result = conversion(response);
2736- // close resources
2737- stream.Close();
2738- client.Close();
2739- return result;
2740- }
2741-
2742- #endregion
2743- }
2744-}
2745
2746=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientFactory.cs'
2747--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientFactory.cs 2010-08-12 07:59:15 +0000
2748+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientFactory.cs 1970-01-01 00:00:00 +0000
2749@@ -1,74 +0,0 @@
2750-/*
2751- * Copyright 2010 Canonical Ltd.
2752- *
2753- * This file is part of UbuntuOne on Windows.
2754- *
2755- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2756- * it under the terms of the GNU Lesser General Public License version
2757- * as published by the Free Software Foundation.
2758- *
2759- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2760- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2761- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2762- * GNU Lesser General Public License for more details.
2763- *
2764- * You should have received a copy of the GNU Lesser General Public License
2765- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2766- *
2767- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2768- */
2769-using PortManagerImpl = Canonical.UbuntuOne.ProcessDispatcher.Net.PortManager;
2770-
2771-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2772-{
2773-
2774- /// <summary>
2775- /// Implementation of the ITcpClientFactory that uses the port factory to create the tcp clients used
2776- /// to communicate with the python code.
2777- /// </summary>
2778- internal class TcpClientFactory : ITcpClientFactory
2779- {
2780- #region Vars
2781-
2782- private IPortManager _portManager;
2783- private readonly object _portManagerLock = new object();
2784- private const string Localhost = "localhost";
2785- #endregion
2786-
2787- #region DI properties
2788-
2789- /// <summary>
2790- /// Gets and sets the port manager used to get the ports used in the tcpclients.
2791- /// </summary>
2792- internal IPortManager PortManager
2793- {
2794- get
2795- {
2796- if(_portManager == null)
2797- {
2798- lock (_portManagerLock)
2799- {
2800- _portManager = PortManagerImpl.Instance;
2801- }
2802- }
2803- return _portManager;
2804- }
2805- set { _portManager = value; }
2806- }
2807-
2808- #endregion
2809-
2810- #region Implementation of ITcpClientFactory
2811-
2812- /// <summary>
2813- /// Returns a client that allows to communicate with the python code.
2814- /// </summary>
2815- /// <returns>A TcpClient configured to talk with the python code through sockets.</returns>
2816- public ITcpClient GetClient()
2817- {
2818- return new TcpClientWrapper(Localhost, PortManager.GetPythonServerPort());
2819- }
2820-
2821- #endregion
2822- }
2823-}
2824
2825=== removed file 'src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientWrapper.cs'
2826--- src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientWrapper.cs 2010-08-12 07:59:15 +0000
2827+++ src/Canonical.UbuntuOne.ProcessDispatcher/Net/TcpClientWrapper.cs 1970-01-01 00:00:00 +0000
2828@@ -1,63 +0,0 @@
2829-/*
2830- * Copyright 2010 Canonical Ltd.
2831- *
2832- * This file is part of UbuntuOne on Windows.
2833- *
2834- * UbuntuOne on Windows is free software: you can redistribute it and/or modify
2835- * it under the terms of the GNU Lesser General Public License version
2836- * as published by the Free Software Foundation.
2837- *
2838- * Ubuntu One on Windows is distributed in the hope that it will be useful,
2839- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2840- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2841- * GNU Lesser General Public License for more details.
2842- *
2843- * You should have received a copy of the GNU Lesser General Public License
2844- * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
2845- *
2846- * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2847- */
2848-using System.Net.Sockets;
2849-
2850-namespace Canonical.UbuntuOne.ProcessDispatcher.Net
2851-{
2852- internal class TcpClientWrapper : ITcpClient
2853- {
2854- #region Variables
2855-
2856- private readonly TcpClient _client;
2857-
2858- #endregion
2859-
2860- #region Constructors
2861-
2862- public TcpClientWrapper(string server, int port)
2863- {
2864- _client = new TcpClient(server, port);
2865- }
2866-
2867- #endregion
2868-
2869- #region Implementation of ITcpClient
2870-
2871- /// <summary>
2872- /// Returns the stream that is used by the tcp client to communicate with
2873- /// the python code.
2874- /// </summary>
2875- /// <returns>A stream that can send data to the python process.</returns>
2876- public NetworkStream GetStream()
2877- {
2878- return _client.GetStream();
2879- }
2880-
2881- /// <summary>
2882- /// Closes the TcpClient release the different used resources.
2883- /// </summary>
2884- public void Close()
2885- {
2886- _client.Close();
2887- }
2888-
2889- #endregion
2890- }
2891-}
2892
2893=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncConfigurationService.cs'
2894--- src/Canonical.UbuntuOne.ProcessDispatcher/SyncConfigurationService.cs 2010-08-11 10:23:31 +0000
2895+++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncConfigurationService.cs 2010-08-24 15:21:43 +0000
2896@@ -17,9 +17,9 @@
2897 *
2898 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
2899 */
2900+using System;
2901 using Canonical.UbuntuOne.Common;
2902 using Canonical.UbuntuOne.Common.Aop;
2903-using Canonical.UbuntuOne.ProcessDispatcher.Net;
2904
2905 namespace Canonical.UbuntuOne.ProcessDispatcher
2906 {
2907@@ -29,20 +29,6 @@
2908 /// </summary>
2909 internal class SyncConfigurationService : ISyncConfiguration
2910 {
2911- #region DI properties
2912-
2913- /// <summary>
2914- /// Gets and sets the message factory that can be used to generate the appropiate messages to
2915- /// communicate with the python process that manages the configuration.
2916- /// </summary>
2917- internal ISyncConfigurationMessageFactory SyncConfigurationMessageFactory { get; set; }
2918-
2919- /// <summary>
2920- /// Gets and sets the communicator that is used to send and receive messages to the socket.
2921- /// </summary>
2922- internal ITcpClientCommunicator<ConfigurationMessage> TcpClientCommunicator { get; set; }
2923-
2924- #endregion
2925
2926 /// <summary>
2927 /// Returns the throttling limits that have been set up for the daemon.
2928@@ -51,9 +37,7 @@
2929 [DebugLogged]
2930 public ThrottlingData GetThrottlingLimits()
2931 {
2932- // create a message that will be used to query the thorttling limits to the python process
2933- var message = SyncConfigurationMessageFactory.QueryThrottling();
2934- return TcpClientCommunicator.SendReceiveMessage<ThrottlingData>(message, Convert.ToThrottlingData);
2935+ throw new NotImplementedException();
2936 }
2937
2938 /// <summary>
2939@@ -63,8 +47,8 @@
2940 [DebugLogged]
2941 public void SetThrottlingLimits(ThrottlingData limits)
2942 {
2943- var message = SyncConfigurationMessageFactory.SetThrottlingLimits(limits);
2944- TcpClientCommunicator.SendMessage(message);
2945+ throw new NotImplementedException();
2946+
2947 }
2948
2949 /// <summary>
2950@@ -74,8 +58,8 @@
2951 [DebugLogged]
2952 public void EnableThrottlingLimits(bool isEnabled)
2953 {
2954- var message = SyncConfigurationMessageFactory.EnableThrottling(isEnabled);
2955- TcpClientCommunicator.SendMessage(message);
2956+ throw new NotImplementedException();
2957+
2958 }
2959
2960 /// <summary>
2961@@ -85,8 +69,8 @@
2962 [DebugLogged]
2963 public bool IsEnabledThrottlingLimits()
2964 {
2965- var message = SyncConfigurationMessageFactory.QueryThrottling();
2966- return TcpClientCommunicator.SendReceiveMessage<bool>(message, Convert.ToIsEnabledThrottling);
2967+ throw new NotImplementedException();
2968+
2969 }
2970
2971 /// <summary>
2972@@ -96,8 +80,8 @@
2973 [DebugLogged]
2974 public void EnableUdfAutosubscribe(bool isEnable)
2975 {
2976- var message = SyncConfigurationMessageFactory.EnablesAutosubscribe(isEnable);
2977- TcpClientCommunicator.SendMessage(message);
2978+ throw new NotImplementedException();
2979+
2980 }
2981
2982 /// <summary>
2983@@ -107,8 +91,8 @@
2984 [DebugLogged]
2985 public bool IsEnabledUdfAutosubscribe()
2986 {
2987- var message = SyncConfigurationMessageFactory.QueryThrottling();
2988- return TcpClientCommunicator.SendReceiveMessage<bool>(message, Convert.ToIsAutosubscribe);
2989+ throw new NotImplementedException();
2990+
2991 }
2992 }
2993 }
2994
2995=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs'
2996--- src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-08-11 10:23:31 +0000
2997+++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-08-24 15:21:43 +0000
2998@@ -22,7 +22,6 @@
2999 using Canonical.UbuntuOne.Common;
3000 using Canonical.UbuntuOne.Common.Aop;
3001 using Canonical.UbuntuOne.Common.Validation;
3002-using Canonical.UbuntuOne.ProcessDispatcher.Net;
3003 using log4net;
3004
3005 namespace Canonical.UbuntuOne.ProcessDispatcher
3006@@ -76,17 +75,6 @@
3007 /// </summary>
3008 internal IAuthentication Authentication { get; set; }
3009
3010- /// <summary>
3011- /// Allows to get and set the factory that is used to generate the different messages that are sent
3012- /// to the python code.
3013- /// </summary>
3014- internal ISyncDaemonMessageFactory SyncDaemonMessageFactory { get; set; }
3015-
3016- /// <summary>
3017- /// Gets and sets the communicator that is used to send and receive messages to the socket.
3018- /// </summary>
3019- internal ITcpClientCommunicator<SyncDaemonMessage> TcpClientCommunicator { get; set; }
3020-
3021 #endregion
3022
3023 public SyncDaemonService()
3024@@ -222,8 +210,7 @@
3025 [DebugLogged]
3026 public StateData GetCurrentStatus()
3027 {
3028- var message = SyncDaemonMessageFactory.QueryState();
3029- return TcpClientCommunicator.SendReceiveMessage<StateData>(message, Convert.ToStateData);
3030+ throw new NotImplementedException();
3031 }
3032
3033 /// <summary>
3034@@ -233,8 +220,7 @@
3035 [DebugLogged]
3036 public IList<DownloadData> GetCurrentDownloads()
3037 {
3038- var message = SyncDaemonMessageFactory.QueryDownloads();
3039- return TcpClientCommunicator.SendReceiveMessage<IList<DownloadData>>(message, Convert.ToCurrentDownloads);
3040+ throw new NotImplementedException();
3041 }
3042
3043 /// <summary>
3044@@ -244,8 +230,7 @@
3045 [DebugLogged]
3046 public IList<QueueItemData> GetWaitingContent()
3047 {
3048- var message = SyncDaemonMessageFactory.QueryWaiting();
3049- return TcpClientCommunicator.SendReceiveMessage<IList<QueueItemData>>(message, Convert.ToCurrentWaiting);
3050+ throw new NotImplementedException();
3051 }
3052
3053 /// <summary>
3054@@ -257,8 +242,7 @@
3055 [DebugLogged]
3056 public void ScheduleAsNext(string shareId, string nodeId)
3057 {
3058- var message = SyncDaemonMessageFactory.ScheduleAsNext(shareId, nodeId);
3059- TcpClientCommunicator.SendMessage(message);
3060+ throw new NotImplementedException();
3061 }
3062
3063 /// <summary>
3064@@ -268,8 +252,7 @@
3065 [DebugLogged]
3066 public IList<UploadData> GetCurrentUploads()
3067 {
3068- var message = SyncDaemonMessageFactory.QueryUploads();
3069- return TcpClientCommunicator.SendReceiveMessage<IList<UploadData>>(message, Convert.ToCurrentUploads);
3070+ throw new NotImplementedException();
3071 }
3072
3073 /// <summary>
3074@@ -279,8 +262,7 @@
3075 [DebugLogged]
3076 public void Connect()
3077 {
3078- var message = SyncDaemonMessageFactory.Connect();
3079- TcpClientCommunicator.SendMessage(message);
3080+ throw new NotImplementedException();
3081 }
3082
3083 /// <summary>
3084@@ -289,8 +271,7 @@
3085 [DebugLogged]
3086 public void Disconnect()
3087 {
3088- var message = SyncDaemonMessageFactory.Disconnect();
3089- TcpClientCommunicator.SendMessage(message);
3090+ throw new NotImplementedException();
3091 }
3092
3093 /// <summary>
3094@@ -300,8 +281,7 @@
3095 [DebugLogged]
3096 public string GetRootDirectory()
3097 {
3098- var message = SyncDaemonMessageFactory.QueryRoot();
3099- return TcpClientCommunicator.SendReceiveMessage<string>(message, Convert.ToRootDirectory);
3100+ throw new NotImplementedException();
3101 }
3102
3103 /// <summary>
3104@@ -311,8 +291,7 @@
3105 [DebugLogged]
3106 public void Quit()
3107 {
3108- var message = SyncDaemonMessageFactory.Quit();
3109- TcpClientCommunicator.SendMessage(message);
3110+ throw new NotImplementedException();
3111 }
3112 }
3113 }
3114
3115=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncFoldersService.cs'
3116--- src/Canonical.UbuntuOne.ProcessDispatcher/SyncFoldersService.cs 2010-08-11 10:23:31 +0000
3117+++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncFoldersService.cs 2010-08-24 15:21:43 +0000
3118@@ -17,9 +17,9 @@
3119 *
3120 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
3121 */
3122+using System;
3123 using System.Collections.Generic;
3124 using Canonical.UbuntuOne.Common;
3125-using Canonical.UbuntuOne.ProcessDispatcher.Net;
3126
3127 namespace Canonical.UbuntuOne.ProcessDispatcher
3128 {
3129@@ -28,20 +28,6 @@
3130 /// </summary>
3131 internal class SyncFoldersService : ISyncFolders
3132 {
3133- #region DI properties
3134-
3135- /// <summary>
3136- /// Gets and sets the factory that is used to generate the messages used to communicate with the
3137- /// python process.
3138- /// </summary>
3139- internal ISyncFolderMessageFactory SyncFolderMessageFactory { get; set; }
3140-
3141- /// <summary>
3142- /// Gets and sets the communicator that is used to send and receive messages to the socket.
3143- /// </summary>
3144- internal ITcpClientCommunicator<FolderMessage> TcpClientCommunicator { get; set; }
3145-
3146- #endregion
3147
3148 /// <summary>
3149 /// Creates a new udf for the given path.
3150@@ -49,8 +35,7 @@
3151 /// <param name="path">The path to which the Udf will be created.</param>
3152 public void CreateFolderUdf(string path)
3153 {
3154- var message = SyncFolderMessageFactory.CreateFolder(path);
3155- TcpClientCommunicator.SendMessage(message);
3156+ throw new NotImplementedException();
3157 }
3158
3159 /// <summary>
3160@@ -59,8 +44,7 @@
3161 /// <param name="path">The path whose Udf we will remove.</param>
3162 public void DeleteFolderUdf(string path)
3163 {
3164- var message = SyncFolderMessageFactory.DeleteFolder(path);
3165- TcpClientCommunicator.SendMessage(message);
3166+ throw new NotImplementedException();
3167 }
3168
3169 /// <summary>
3170@@ -69,8 +53,7 @@
3171 /// <returns>A list with all the udfs.</returns>
3172 public IList<UdfData> GetFolders()
3173 {
3174- var message = SyncFolderMessageFactory.QueryFolders();
3175- return TcpClientCommunicator.SendReceiveMessage<IList<UdfData>>(message, Convert.ToAllFolders);
3176+ throw new NotImplementedException();
3177 }
3178
3179 /// <summary>
3180@@ -79,8 +62,7 @@
3181 /// <param name="folderId">The id of the folder to subscribe to.</param>
3182 public void Subscribe(string folderId)
3183 {
3184- var message = SyncFolderMessageFactory.Subscribe(folderId);
3185- TcpClientCommunicator.SendMessage(message);
3186+ throw new NotImplementedException();
3187 }
3188
3189 /// <summary>
3190@@ -89,8 +71,7 @@
3191 /// <param name="folderId">The id of the folder to unsubscribe from.</param>
3192 public void Unsubscribe(string folderId)
3193 {
3194- var message = SyncFolderMessageFactory.Unsubscribe(folderId);
3195- TcpClientCommunicator.SendMessage(message);
3196+ throw new NotImplementedException();
3197 }
3198
3199 /// <summary>
3200@@ -100,8 +81,7 @@
3201 /// <returns>The udf data of the given path.</returns>
3202 public UdfData GetInfo(string path)
3203 {
3204- var message = SyncFolderMessageFactory.QueryInfo(path);
3205- return TcpClientCommunicator.SendReceiveMessage<UdfData>(message, Convert.ToUdfData);
3206+ throw new NotImplementedException();
3207 }
3208
3209 /// <summary>
3210@@ -109,8 +89,7 @@
3211 /// </summary>
3212 public void RefreshVolumes()
3213 {
3214- var message = SyncFolderMessageFactory.RefreshVolumes();
3215- TcpClientCommunicator.SendMessage(message);
3216+ throw new NotImplementedException();
3217 }
3218 }
3219 }
3220
3221=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncSharesService.cs'
3222--- src/Canonical.UbuntuOne.ProcessDispatcher/SyncSharesService.cs 2010-08-11 10:23:31 +0000
3223+++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncSharesService.cs 2010-08-24 15:21:43 +0000
3224@@ -17,10 +17,10 @@
3225 *
3226 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
3227 */
3228+using System;
3229 using System.Collections.Generic;
3230 using Canonical.UbuntuOne.Common;
3231 using Canonical.UbuntuOne.Common.Aop;
3232-using Canonical.UbuntuOne.ProcessDispatcher.Net;
3233
3234 namespace Canonical.UbuntuOne.ProcessDispatcher
3235 {
3236@@ -30,20 +30,6 @@
3237 /// </summary>
3238 internal class SyncSharesService : ISyncShares
3239 {
3240- #region DI properties
3241-
3242- /// <summary>
3243- /// Gets and sets the factory that is used to create the protobuf messages used
3244- /// to communicate with the python code.
3245- /// </summary>
3246- internal ISyncShareMessageFactory SyncShareMessageFactory { get; set; }
3247-
3248- /// <summary>
3249- /// Gets and sets the communicator that is used to send and receive messages to the socket.
3250- /// </summary>
3251- internal ITcpClientCommunicator<ShareMessage> TcpClientCommunicator { get; set; }
3252-
3253- #endregion
3254
3255 /// <summary>
3256 /// Allows the client to query and get all the different shares that the user has.
3257@@ -52,8 +38,7 @@
3258 [DebugLogged]
3259 public IList<ShareData> GetShares()
3260 {
3261- var message = SyncShareMessageFactory.QueryShares();
3262- return TcpClientCommunicator.SendReceiveMessage<IList<ShareData>>(message, Convert.ToGetShares);
3263+ throw new NotImplementedException();
3264
3265 }
3266
3267@@ -65,8 +50,7 @@
3268 [DebugLogged]
3269 public void AcceptShare(string shareId)
3270 {
3271- var message = SyncShareMessageFactory.AcceptShare(shareId);
3272- TcpClientCommunicator.SendMessage(message);
3273+ throw new NotImplementedException();
3274 }
3275
3276 /// <summary>
3277@@ -77,8 +61,7 @@
3278 [DebugLogged]
3279 public void RejectShare(string shareId)
3280 {
3281- var message = SyncShareMessageFactory.RejectShare(shareId);
3282- TcpClientCommunicator.SendMessage(message);
3283+ throw new NotImplementedException();
3284 }
3285
3286 /// <summary>
3287@@ -92,8 +75,7 @@
3288 [DebugLogged]
3289 public void CreateShare(string path, string username, string name, AccessLevel accessLevel)
3290 {
3291- var message = SyncShareMessageFactory.CreateShare(path, username, name, accessLevel);
3292- TcpClientCommunicator.SendMessage(message);
3293+ throw new NotImplementedException();
3294 }
3295
3296 /// <summary>
3297@@ -102,8 +84,7 @@
3298 [DebugLogged]
3299 public void UpdateShares()
3300 {
3301- var message = SyncShareMessageFactory.UpdateShares();
3302- TcpClientCommunicator.SendMessage(message);
3303+ throw new NotImplementedException();
3304 }
3305
3306 /// <summary>
3307@@ -113,8 +94,7 @@
3308 [DebugLogged]
3309 public IList<ShareData> GetShared()
3310 {
3311- var message = SyncShareMessageFactory.GetShared();
3312- return TcpClientCommunicator.SendReceiveMessage<IList<ShareData>>(message, Convert.ToGetShared);
3313+ throw new NotImplementedException();
3314 }
3315 }
3316 }

Subscribers

People subscribed via source and target branches

to all changes: