Merge lp:~mandel/ubuntuone-windows-installer/add_chatty_u1sync into lp:ubuntuone-windows-installer/beta
- add_chatty_u1sync
- Merge into beta
Proposed by
Manuel de la Peña
Status: | Merged |
---|---|
Approved by: | Manuel de la Peña |
Approved revision: | 111 |
Merged at revision: | 102 |
Proposed branch: | lp:~mandel/ubuntuone-windows-installer/add_chatty_u1sync |
Merge into: | lp:ubuntuone-windows-installer/beta |
Prerequisite: | lp:~mandel/ubuntuone-windows-installer/move_sync_to_service |
Diff against target: |
1354 lines (+1092/-12) 25 files modified
build.number (+1/-1) main.build (+1/-1) src/Canonical.Ubuntu.SSO.Tests/Canonical.Ubuntu.SSO.Tests.csproj (+9/-0) src/Canonical.Ubuntu.SSO.Tests/CredentialsDeniedEventArgsFixture.cs (+55/-0) src/Canonical.Ubuntu.SSO.Tests/CredentialsErrorEventArgsFixture.cs (+70/-0) src/Canonical.Ubuntu.SSO.Tests/CredentialsFoundEventArgsFixture.cs (+65/-0) src/Canonical.Ubuntu.SSO.Tests/JsonCredentialsEncoderFixture.cs (+100/-0) src/Canonical.Ubuntu.SSO.Tests/LoginCredentialsEventArgsFixture.cs (+52/-0) src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs (+1/-1) src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj (+13/-0) src/Canonical.UbuntuOne.ProcessDispatcher/IMessageProcessor.cs (+33/-0) src/Canonical.UbuntuOne.ProcessDispatcher/IPipeListener.cs (+43/-0) src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamer.cs (+52/-0) src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamerFactory.cs (+33/-0) src/Canonical.UbuntuOne.ProcessDispatcher/JsonMessageProcessor.cs (+38/-0) src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamer.cs (+91/-0) src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamerFactory.cs (+41/-0) src/Canonical.UbuntuOne.ProcessDispatcher/PipeListener.cs (+244/-0) src/Canonical.UbuntuOne.ProcessDispatcher/PipeListenerException.cs (+62/-0) src/Canonical.UbuntuOne.ProcessDispatcher/Program.cs (+9/-0) src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs (+7/-1) src/Canonical.UbuntuOne.ProcessDispatcher/objects.xml (+19/-0) src/Version.cs (+2/-2) src/u1sync/main.py (+14/-6) src/u1sync/utils.py (+37/-0) |
To merge this branch: | bzr merge lp:~mandel/ubuntuone-windows-installer/add_chatty_u1sync |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu One hackers | Pending | ||
Review via email:
|
Commit message
Description of the change
Provides the required code to allow the python code to send messages to the c# processes using the CallNamedPipe method from win32pipe
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'build.number' |
2 | --- build.number 2010-10-12 10:18:45 +0000 |
3 | +++ build.number 2010-10-12 10:18:45 +0000 |
4 | @@ -1,1 +1,1 @@ |
5 | -1.0.606.5623 |
6 | \ No newline at end of file |
7 | +1.0.611.8185 |
8 | \ No newline at end of file |
9 | |
10 | === modified file 'main.build' |
11 | --- main.build 2010-10-06 13:13:50 +0000 |
12 | +++ main.build 2010-10-12 10:18:45 +0000 |
13 | @@ -213,7 +213,7 @@ |
14 | managed="true" |
15 | workingdir="src" |
16 | program="python.exe" |
17 | - commandline="setup.py py2exe" /> |
18 | + commandline="setup.py py2exe --packages=ubuntuone.storageprotocol" /> |
19 | |
20 | </target> |
21 | |
22 | |
23 | === modified file 'src/Canonical.Ubuntu.SSO.Tests/Canonical.Ubuntu.SSO.Tests.csproj' |
24 | --- src/Canonical.Ubuntu.SSO.Tests/Canonical.Ubuntu.SSO.Tests.csproj 2010-10-05 09:49:29 +0000 |
25 | +++ src/Canonical.Ubuntu.SSO.Tests/Canonical.Ubuntu.SSO.Tests.csproj 2010-10-12 10:18:45 +0000 |
26 | @@ -31,6 +31,10 @@ |
27 | <WarningLevel>4</WarningLevel> |
28 | </PropertyGroup> |
29 | <ItemGroup> |
30 | + <Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> |
31 | + <SpecificVersion>False</SpecificVersion> |
32 | + <HintPath>..\..\lib\JsonNet\Newtonsoft.Json.dll</HintPath> |
33 | + </Reference> |
34 | <Reference Include="nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> |
35 | <SpecificVersion>False</SpecificVersion> |
36 | <HintPath>..\..\lib\Nunit\nunit.framework.dll</HintPath> |
37 | @@ -49,8 +53,13 @@ |
38 | </ItemGroup> |
39 | <ItemGroup> |
40 | <Compile Include="ColonSeparatedSSOCredentialsEncoderFixture.cs" /> |
41 | + <Compile Include="CredentialsDeniedEventArgsFixture.cs" /> |
42 | + <Compile Include="CredentialsErrorEventArgsFixture.cs" /> |
43 | + <Compile Include="CredentialsFoundEventArgsFixture.cs" /> |
44 | + <Compile Include="JsonCredentialsEncoderFixture.cs" /> |
45 | <Compile Include="JsonSSOCredentialsEncoderFixture.cs" /> |
46 | <Compile Include="KeyringFixture.cs" /> |
47 | + <Compile Include="LoginCredentialsEventArgsFixture.cs" /> |
48 | <Compile Include="Properties\AssemblyInfo.cs" /> |
49 | <Compile Include="SSOLoginProcessorFixture.cs" /> |
50 | </ItemGroup> |
51 | |
52 | === added file 'src/Canonical.Ubuntu.SSO.Tests/CredentialsDeniedEventArgsFixture.cs' |
53 | --- src/Canonical.Ubuntu.SSO.Tests/CredentialsDeniedEventArgsFixture.cs 1970-01-01 00:00:00 +0000 |
54 | +++ src/Canonical.Ubuntu.SSO.Tests/CredentialsDeniedEventArgsFixture.cs 2010-10-12 10:18:45 +0000 |
55 | @@ -0,0 +1,55 @@ |
56 | +/* |
57 | + * Copyright 2010 Canonical Ltd. |
58 | + * |
59 | + * This file is part of Ubuntu One on Windows. |
60 | + * |
61 | + * Ubuntu One on Windows is free software: you can redistribute it and/or modify |
62 | + * it under the terms of the GNU Lesser General Public License version |
63 | + * as published by the Free Software Foundation. |
64 | + * |
65 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
66 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
67 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
68 | + * GNU Lesser General Public License for more details. |
69 | + * |
70 | + * You should have received a copy of the GNU Lesser General Public License |
71 | + * along with Ubuntu One for Windows. If not, see <http://www.gnu.org/licenses/>. |
72 | + * |
73 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
74 | + */ |
75 | +using NUnit.Framework; |
76 | + |
77 | +namespace Canonical.Ubuntu.SSO.Tests |
78 | +{ |
79 | + [TestFixture] |
80 | + public class CredentialsDeniedEventArgsFixture |
81 | + { |
82 | + #region Variables |
83 | + |
84 | + private CredentialsDeniedEventArgs _args; |
85 | + |
86 | + #endregion |
87 | + |
88 | + #region Tests |
89 | + |
90 | + [Test] |
91 | + public void EmptyConstructorTest() |
92 | + { |
93 | + _args = new CredentialsDeniedEventArgs(); |
94 | + Assert.AreEqual(string.Empty, _args.ApplicationName); |
95 | + } |
96 | + |
97 | + [TestCase("UbuntuOne")] |
98 | + [TestCase("OtherApp")] |
99 | + [TestCase("Tomboy")] |
100 | + public void StringConstructorTest(string appName) |
101 | + { |
102 | + // create the credentials and make sure the correct data is used. |
103 | + _args = new CredentialsDeniedEventArgs(appName); |
104 | + Assert.AreEqual(appName, _args.ApplicationName); |
105 | + } |
106 | + |
107 | + #endregion |
108 | + |
109 | + } |
110 | +} |
111 | |
112 | === added file 'src/Canonical.Ubuntu.SSO.Tests/CredentialsErrorEventArgsFixture.cs' |
113 | --- src/Canonical.Ubuntu.SSO.Tests/CredentialsErrorEventArgsFixture.cs 1970-01-01 00:00:00 +0000 |
114 | +++ src/Canonical.Ubuntu.SSO.Tests/CredentialsErrorEventArgsFixture.cs 2010-10-12 10:18:45 +0000 |
115 | @@ -0,0 +1,70 @@ |
116 | +/* |
117 | + * Copyright 2010 Canonical Ltd. |
118 | + * |
119 | + * This file is part of Ubuntu One on Windows. |
120 | + * |
121 | + * Ubuntu One on Windows is free software: you can redistribute it and/or modify |
122 | + * it under the terms of the GNU Lesser General Public License version |
123 | + * as published by the Free Software Foundation. |
124 | + * |
125 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
126 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
127 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
128 | + * GNU Lesser General Public License for more details. |
129 | + * |
130 | + * You should have received a copy of the GNU Lesser General Public License |
131 | + * along with Ubuntu One for Windows. If not, see <http://www.gnu.org/licenses/>. |
132 | + * |
133 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
134 | + */ |
135 | +using NUnit.Framework; |
136 | + |
137 | +namespace Canonical.Ubuntu.SSO.Tests |
138 | +{ |
139 | + |
140 | + [TestFixture] |
141 | + public class CredentialsErrorEventArgsFixture |
142 | + { |
143 | + |
144 | + #region Variables |
145 | + |
146 | + private CredentialsErrorEventArgs _args; |
147 | + #endregion |
148 | + |
149 | + #region Tests |
150 | + |
151 | + [Test] |
152 | + public void EmptyConstructorTest() |
153 | + { |
154 | + _args = new CredentialsErrorEventArgs(); |
155 | + Assert.AreEqual(string.Empty, _args.ApplicationName); |
156 | + Assert.AreEqual(string.Empty, _args.DetailedErrorMessage); |
157 | + Assert.AreEqual(string.Empty, _args.ErrorMessage); |
158 | + } |
159 | + |
160 | + [TestCase("UbuntuOne", "Error 08")] |
161 | + [TestCase("Tomboy", "NullReferenceException")] |
162 | + [TestCase("OtherApp", "StupidError")] |
163 | + public void ApplicationErrorConstructorTest(string appName, string error) |
164 | + { |
165 | + _args = new CredentialsErrorEventArgs(appName, error); |
166 | + Assert.AreEqual(appName, _args.ApplicationName); |
167 | + Assert.AreEqual(error, _args.ErrorMessage); |
168 | + Assert.AreEqual(string.Empty, _args.DetailedErrorMessage); |
169 | + } |
170 | + |
171 | + [TestCase("UbuntuOne", "Error 08", "You do not have the keyring rigths.")] |
172 | + [TestCase("Tomboy", "NullReferenceException", "Stupid extension")] |
173 | + [TestCase("OtherApp", "StupidError", "Learn to code")] |
174 | + public void ApplicationErrorDetailConstructorTest(string appName, string error, string detail) |
175 | + { |
176 | + _args = new CredentialsErrorEventArgs(appName, error, detail); |
177 | + Assert.AreEqual(appName, _args.ApplicationName); |
178 | + Assert.AreEqual(error, _args.ErrorMessage); |
179 | + Assert.AreEqual(detail, _args.DetailedErrorMessage); |
180 | + } |
181 | + |
182 | + #endregion |
183 | + |
184 | + } |
185 | +} |
186 | |
187 | === added file 'src/Canonical.Ubuntu.SSO.Tests/CredentialsFoundEventArgsFixture.cs' |
188 | --- src/Canonical.Ubuntu.SSO.Tests/CredentialsFoundEventArgsFixture.cs 1970-01-01 00:00:00 +0000 |
189 | +++ src/Canonical.Ubuntu.SSO.Tests/CredentialsFoundEventArgsFixture.cs 2010-10-12 10:18:45 +0000 |
190 | @@ -0,0 +1,65 @@ |
191 | +/* |
192 | + * Copyright 2010 Canonical Ltd. |
193 | + * |
194 | + * This file is part of Ubuntu One on Windows. |
195 | + * |
196 | + * Ubuntu One on Windows is free software: you can redistribute it and/or modify |
197 | + * it under the terms of the GNU Lesser General Public License version |
198 | + * as published by the Free Software Foundation. |
199 | + * |
200 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
201 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
202 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
203 | + * GNU Lesser General Public License for more details. |
204 | + * |
205 | + * You should have received a copy of the GNU Lesser General Public License |
206 | + * along with Ubuntu One for Windows. If not, see <http://www.gnu.org/licenses/>. |
207 | + * |
208 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
209 | + */ |
210 | +using System.Collections; |
211 | +using System.Collections.Generic; |
212 | +using NUnit.Framework; |
213 | + |
214 | +namespace Canonical.Ubuntu.SSO.Tests |
215 | +{ |
216 | + [TestFixture] |
217 | + public class CredentialsFoundEventArgsFixture |
218 | + { |
219 | + #region Variables |
220 | + |
221 | + private CredentialsFoundEventArgs _args; |
222 | + |
223 | + #endregion |
224 | + |
225 | + #region Tests |
226 | + |
227 | + [Test] |
228 | + public void EmptyConstructorTest() |
229 | + { |
230 | + _args = new CredentialsFoundEventArgs(); |
231 | + Assert.AreEqual(string.Empty, _args.ApplicationName); |
232 | + Assert.IsEmpty((ICollection)_args.Credentials.Values); |
233 | + } |
234 | + |
235 | + [TestCase("UbuntuOne", "token", "tokenSecret", "consumerKey", "consumerSecret")] |
236 | + [TestCase("Tomboy", "tomboyToken", "tomboyToeknSecret", "tomboyConsumerKey", "tomboyConsumerSecret")] |
237 | + public void AppNameCredentialsConstructor(string appName, string token, string tokenSecret, |
238 | + string consumerKey, string consumerSecret ) |
239 | + { |
240 | + // create the dict with the data |
241 | + var credentials = new Dictionary<string, string> |
242 | + { |
243 | + {"Token", token}, |
244 | + {"TokenSecret", tokenSecret}, |
245 | + {"ConsumerKey", consumerKey}, |
246 | + {"ConsumerSecret", consumerSecret} |
247 | + }; |
248 | + _args = new CredentialsFoundEventArgs(appName, credentials); |
249 | + Assert.AreEqual(appName, _args.ApplicationName); |
250 | + Assert.AreSame(credentials, _args.Credentials); |
251 | + } |
252 | + |
253 | + #endregion |
254 | + } |
255 | +} |
256 | |
257 | === added file 'src/Canonical.Ubuntu.SSO.Tests/JsonCredentialsEncoderFixture.cs' |
258 | --- src/Canonical.Ubuntu.SSO.Tests/JsonCredentialsEncoderFixture.cs 1970-01-01 00:00:00 +0000 |
259 | +++ src/Canonical.Ubuntu.SSO.Tests/JsonCredentialsEncoderFixture.cs 2010-10-12 10:18:45 +0000 |
260 | @@ -0,0 +1,100 @@ |
261 | +/* Copyright 2010 Canonical Ltd. |
262 | + * |
263 | + * This file is part of UbuntuOne on Windows. |
264 | + * |
265 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
266 | + * it under the terms of the GNU Lesser General Public License version |
267 | + * as published by the Free Software Foundation. |
268 | + * |
269 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
270 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
271 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
272 | + * GNU Lesser General Public License for more details. |
273 | + * |
274 | + * You should have received a copy of the GNU Lesser General Public License |
275 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
276 | + * |
277 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
278 | + */ |
279 | +using Newtonsoft.Json.Linq; |
280 | +using NUnit.Framework; |
281 | + |
282 | +namespace Canonical.Ubuntu.SSO.Tests |
283 | +{ |
284 | + [TestFixture] |
285 | + public class JsonCredentialsEncoderFixture |
286 | + { |
287 | + #region Variables |
288 | + |
289 | + private JsonSSOCredentialsEncoder _encoder; |
290 | + |
291 | + #endregion |
292 | + |
293 | + #region Setup & TearDown |
294 | + |
295 | + [SetUp] |
296 | + public void Setup() |
297 | + { |
298 | + _encoder = new JsonSSOCredentialsEncoder(); |
299 | + } |
300 | + |
301 | + #endregion |
302 | + |
303 | + #region Tests |
304 | + |
305 | + [TestCase("token", "tokenSecret", "consumerKey", "consumerSecret")] |
306 | + [TestCase("asasferer", "ykvchdclsc", "sdahdlfa", "zcknvculdsnv")] |
307 | + public void EncodeTest(string token, string tokenSecret, string consumerKey, string consumerSecret) |
308 | + { |
309 | + // pass the data to encode, later test that the required data is present |
310 | + // and that the data is the same. |
311 | + var encodedData = _encoder.Encode(token, tokenSecret, consumerKey, consumerSecret); |
312 | + // use the Json.Net to read the result string and ensure we do have the data |
313 | + var credentials = JObject.Parse(encodedData); |
314 | + Assert.AreEqual(token, (string)credentials["token"]); |
315 | + Assert.AreEqual(tokenSecret, (string)credentials["token_secret"]); |
316 | + Assert.AreEqual(consumerKey, (string)credentials["consumer_key"]); |
317 | + Assert.AreEqual(consumerSecret, (string)credentials["consumer_secret"]); |
318 | + } |
319 | + |
320 | + [TestCase("token", "tokenSecret", "consumerKey", "consumerSecret")] |
321 | + [TestCase("asasferer", "ykvchdclsc", "sdahdlfa", "zcknvculdsnv")] |
322 | + public void DecodeTest(string token, string tokenSecret, string consumerKey, string consumerSecret) |
323 | + { |
324 | + // create the encoded data, decode it an ensure is the same |
325 | + string returnedToken; |
326 | + string returnedTokenSecret; |
327 | + string returnedConsumerKey; |
328 | + string returnedConsumerSecret; |
329 | + |
330 | + var encodedData = _encoder.Encode(token, tokenSecret, consumerKey, consumerSecret); |
331 | + _encoder.Decode(encodedData, out returnedToken, out returnedTokenSecret, |
332 | + out returnedConsumerKey, out returnedConsumerSecret); |
333 | + Assert.AreEqual(token, returnedToken); |
334 | + Assert.AreEqual(tokenSecret, returnedTokenSecret); |
335 | + Assert.AreEqual(consumerKey, returnedConsumerKey); |
336 | + Assert.AreEqual(consumerSecret, returnedConsumerSecret); |
337 | + } |
338 | + |
339 | + [TestCase(null, "tokenSecret", "consumerKey", "consumerSecret")] |
340 | + [TestCase("token", null, "consumerKey", "consumerSecret")] |
341 | + [TestCase("token", "tokenSecret", null, "consumerSecret")] |
342 | + [TestCase("token", "tokenSecret", "consumerKey", null)] |
343 | + [ExpectedException(typeof(SSOException))] |
344 | + public void DecodeEmptyDataTest(string token, string tokenSecret, string consumerKey, string consumerSecret) |
345 | + { |
346 | + // encode the data, then try to decode an expect the exception |
347 | + string returnedToken; |
348 | + string returnedTokenSecret; |
349 | + string returnedConsumerKey; |
350 | + string returnedConsumerSecret; |
351 | + |
352 | + var encodedData = _encoder.Encode(token, tokenSecret, consumerKey, consumerSecret); |
353 | + _encoder.Decode(encodedData, out returnedToken, out returnedTokenSecret, |
354 | + out returnedConsumerKey, out returnedConsumerSecret); |
355 | + } |
356 | + |
357 | + #endregion |
358 | + |
359 | + } |
360 | +} |
361 | |
362 | === added file 'src/Canonical.Ubuntu.SSO.Tests/LoginCredentialsEventArgsFixture.cs' |
363 | --- src/Canonical.Ubuntu.SSO.Tests/LoginCredentialsEventArgsFixture.cs 1970-01-01 00:00:00 +0000 |
364 | +++ src/Canonical.Ubuntu.SSO.Tests/LoginCredentialsEventArgsFixture.cs 2010-10-12 10:18:45 +0000 |
365 | @@ -0,0 +1,52 @@ |
366 | +/* Copyright 2010 Canonical Ltd. |
367 | + * |
368 | + * This file is part of UbuntuOne on Windows. |
369 | + * |
370 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
371 | + * it under the terms of the GNU Lesser General Public License version |
372 | + * as published by the Free Software Foundation. |
373 | + * |
374 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
375 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
376 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
377 | + * GNU Lesser General Public License for more details. |
378 | + * |
379 | + * You should have received a copy of the GNU Lesser General Public License |
380 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
381 | + * |
382 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
383 | + */ |
384 | +using NUnit.Framework; |
385 | + |
386 | +namespace Canonical.Ubuntu.SSO.Tests |
387 | +{ |
388 | + [TestFixture] |
389 | + public class LoginCredentialsEventArgsFixture |
390 | + { |
391 | + #region Variables |
392 | + |
393 | + private LoginCredentialsEventArgs _args; |
394 | + |
395 | + #endregion |
396 | + |
397 | + #region Tests |
398 | + |
399 | + [Test] |
400 | + public void EmptyConstructorTest() |
401 | + { |
402 | + _args = new LoginCredentialsEventArgs(); |
403 | + Assert.AreEqual(string.Empty, _args.Username); |
404 | + Assert.AreEqual(string.Empty, _args.Password); |
405 | + } |
406 | + |
407 | + [TestCase("username", "password")] |
408 | + [TestCase("otherUsername", "otherPassword")] |
409 | + public void UsernamePasswordConstructor(string username, string password) |
410 | + { |
411 | + _args = new LoginCredentialsEventArgs(username, password); |
412 | + Assert.AreEqual(username, _args.Username); |
413 | + Assert.AreEqual(password, _args.Password); |
414 | + } |
415 | + #endregion |
416 | + } |
417 | +} |
418 | |
419 | === modified file 'src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs' |
420 | --- src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-05 15:20:36 +0000 |
421 | +++ src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-12 10:18:45 +0000 |
422 | @@ -20,7 +20,6 @@ |
423 | using System; |
424 | using System.Collections.Generic; |
425 | using System.Windows; |
426 | -using Canonical.UbuntuOne.Common; |
427 | using Canonical.UbuntuOne.Common.Aop; |
428 | |
429 | namespace Canonical.Ubuntu.SSO |
430 | @@ -150,6 +149,7 @@ |
431 | [DebugLogged] |
432 | public void LoginOrRegisterToGetCredentials() |
433 | { |
434 | + throw new NotImplementedException(); |
435 | } |
436 | |
437 | #endregion |
438 | |
439 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj' |
440 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj 2010-10-12 10:18:45 +0000 |
441 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj 2010-10-12 10:18:45 +0000 |
442 | @@ -91,6 +91,15 @@ |
443 | <Compile Include="..\Version.cs"> |
444 | <Link>Properties\Version.cs</Link> |
445 | </Compile> |
446 | + <Compile Include="IMessageProcessor.cs" /> |
447 | + <Compile Include="IPipeListener.cs" /> |
448 | + <Compile Include="IPipeStreamer.cs" /> |
449 | + <Compile Include="IPipeStreamerFactory.cs" /> |
450 | + <Compile Include="JsonMessageProcessor.cs" /> |
451 | + <Compile Include="JsonPipeStreamer.cs" /> |
452 | + <Compile Include="JsonPipeStreamerFactory.cs" /> |
453 | + <Compile Include="PipeListener.cs" /> |
454 | + <Compile Include="PipeListenerException.cs" /> |
455 | <Compile Include="SyncDaemonWindowsService.cs"> |
456 | </Compile> |
457 | <Compile Include="CallerContext.cs" /> |
458 | @@ -113,6 +122,10 @@ |
459 | <SpecificVersion>False</SpecificVersion> |
460 | <HintPath>..\..\lib\log4net\log4net.dll</HintPath> |
461 | </Reference> |
462 | + <Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> |
463 | + <SpecificVersion>False</SpecificVersion> |
464 | + <HintPath>..\..\lib\JsonNet\Newtonsoft.Json.dll</HintPath> |
465 | + </Reference> |
466 | <Reference Include="Spring.Core, Version=1.3.0.20349, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL"> |
467 | <SpecificVersion>False</SpecificVersion> |
468 | <HintPath>..\..\lib\Spring.Net\Spring.Core.dll</HintPath> |
469 | |
470 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/IMessageProcessor.cs' |
471 | --- src/Canonical.UbuntuOne.ProcessDispatcher/IMessageProcessor.cs 1970-01-01 00:00:00 +0000 |
472 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/IMessageProcessor.cs 2010-10-12 10:18:45 +0000 |
473 | @@ -0,0 +1,33 @@ |
474 | +/* |
475 | + * Copyright 2010 Canonical Ltd. |
476 | + * |
477 | + * This file is part of UbuntuOne on Windows. |
478 | + * |
479 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
480 | + * it under the terms of the GNU Lesser General Public License version |
481 | + * as published by the Free Software Foundation. |
482 | + * |
483 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
484 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
485 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486 | + * GNU Lesser General Public License for more details. |
487 | + * |
488 | + * You should have received a copy of the GNU Lesser General Public License |
489 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
490 | + * |
491 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
492 | + */ |
493 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
494 | +{ |
495 | + /// <summary> |
496 | + /// Interface to be implemented by those objects that now how to process the messages comming from python. |
497 | + /// </summary> |
498 | + public interface IMessageProcessor |
499 | + { |
500 | + /// <summary> |
501 | + /// Will process the message sent by the python code and will perform all the possibly required operations. |
502 | + /// </summary> |
503 | + /// <param name="message"></param> |
504 | + void ProcessMessage(object message); |
505 | + } |
506 | +} |
507 | \ No newline at end of file |
508 | |
509 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/IPipeListener.cs' |
510 | --- src/Canonical.UbuntuOne.ProcessDispatcher/IPipeListener.cs 1970-01-01 00:00:00 +0000 |
511 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/IPipeListener.cs 2010-10-12 10:18:45 +0000 |
512 | @@ -0,0 +1,43 @@ |
513 | +using System; |
514 | + |
515 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
516 | +{ |
517 | + internal interface IPipeListener |
518 | + { |
519 | + /// <summary> |
520 | + /// Gets if the pipe listener is indeed listening to the pipe. |
521 | + /// </summary> |
522 | + bool IsListening { get; } |
523 | + |
524 | + /// <summary> |
525 | + /// Gets and sets the number of threads that will be used to listen to the |
526 | + /// pipe. Each thread will listeng to connections and will dispatch the |
527 | + /// messages when ever they are done. |
528 | + /// </summary> |
529 | + int NumberOfThreads { get; set; } |
530 | + |
531 | + /// <summary> |
532 | + /// Gets and sets the pipe stream factory that know how to generate the streamers used for the communication. |
533 | + /// </summary> |
534 | + IPipeStreamerFactory PipeStreamerFactory { get; set; } |
535 | + |
536 | + /// <summary> |
537 | + /// Gets and sets the action that will be performed with the message of that |
538 | + /// is received by the pipe listener. |
539 | + /// </summary> |
540 | + IMessageProcessor MessageProcessor { get; set; } |
541 | + |
542 | + /// <summary> |
543 | + /// Starts listening to the different pipe messages and will perform the appropiate |
544 | + /// action when a message is received. |
545 | + /// </summary> |
546 | + /// <param name="namedPipe">The name fof the pipe to listen.</param> |
547 | + void StartListening(string namedPipe); |
548 | + |
549 | + /// <summary> |
550 | + /// Stops listening to the different pipe messages. All the thread that are listening already will |
551 | + /// be forced to stop. |
552 | + /// </summary> |
553 | + void StopListening(); |
554 | + } |
555 | +} |
556 | \ No newline at end of file |
557 | |
558 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamer.cs' |
559 | --- src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamer.cs 1970-01-01 00:00:00 +0000 |
560 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamer.cs 2010-10-12 10:18:45 +0000 |
561 | @@ -0,0 +1,52 @@ |
562 | +/* |
563 | + * Copyright 2010 Canonical Ltd. |
564 | + * |
565 | + * This file is part of UbuntuOne on Windows. |
566 | + * |
567 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
568 | + * it under the terms of the GNU Lesser General Public License version |
569 | + * as published by the Free Software Foundation. |
570 | + * |
571 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
572 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
573 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
574 | + * GNU Lesser General Public License for more details. |
575 | + * |
576 | + * You should have received a copy of the GNU Lesser General Public License |
577 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
578 | + * |
579 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
580 | + */ |
581 | +using System.IO; |
582 | +using System.Text; |
583 | + |
584 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
585 | +{ |
586 | + /// <summary> |
587 | + /// Interface that should be implemented by those objects that |
588 | + /// know the protocol that is used to communicate with the python code. |
589 | + /// </summary> |
590 | + public interface IPipeStreamer |
591 | + { |
592 | + /// <summary> |
593 | + /// Gets and sets the encoding used by the streamer. |
594 | + /// </summary> |
595 | + Encoding Encoding { get; set; } |
596 | + |
597 | + /// <summary> |
598 | + /// Reads the current contents that are present in the stream and returns an object that |
599 | + /// represents them. |
600 | + /// </summary> |
601 | + /// <param name="stream">The stream from which the data is read.</param> |
602 | + /// <returns>An object that represents the data in the stream.</returns> |
603 | + object Read(Stream stream); |
604 | + |
605 | + /// <summary> |
606 | + /// Writes the given object to the stream so that the python code can read it. |
607 | + /// </summary> |
608 | + /// <param name="outData">The object to be serialized in the stream.</param> |
609 | + /// <param name="stream">The stream to which the serialization will be written.</param> |
610 | + /// <returns>The position in the stream after the write operation.</returns> |
611 | + int Write(object outData, Stream stream); |
612 | + } |
613 | +} |
614 | |
615 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamerFactory.cs' |
616 | --- src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamerFactory.cs 1970-01-01 00:00:00 +0000 |
617 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamerFactory.cs 2010-10-12 10:18:45 +0000 |
618 | @@ -0,0 +1,33 @@ |
619 | +/* |
620 | + * This file is part of UbuntuOne on Windows. |
621 | + * |
622 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
623 | + * it under the terms of the GNU Lesser General Public License version |
624 | + * as published by the Free Software Foundation. |
625 | + * |
626 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
627 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
628 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
629 | + * GNU Lesser General Public License for more details. |
630 | + * |
631 | + * You should have received a copy of the GNU Lesser General Public License |
632 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
633 | + * |
634 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
635 | + */ |
636 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
637 | +{ |
638 | + /// <summary> |
639 | + /// Factory that will generate the IPipeStream objects that understand the protocol used to communicate |
640 | + /// between the different processes. |
641 | + /// </summary> |
642 | + public interface IPipeStreamerFactory |
643 | + { |
644 | + /// <summary> |
645 | + /// Creates a new PipeStreamer that know the streamer to create that will |
646 | + /// know the protocol used to communicate between processes. |
647 | + /// </summary> |
648 | + /// <returns>A pipe streamer that knoww how to the protocol works.</returns> |
649 | + IPipeStreamer Create(); |
650 | + } |
651 | +} |
652 | |
653 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/JsonMessageProcessor.cs' |
654 | --- src/Canonical.UbuntuOne.ProcessDispatcher/JsonMessageProcessor.cs 1970-01-01 00:00:00 +0000 |
655 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/JsonMessageProcessor.cs 2010-10-12 10:18:45 +0000 |
656 | @@ -0,0 +1,38 @@ |
657 | +/* |
658 | + * Copyright 2010 Canonical Ltd. |
659 | + * |
660 | + * This file is part of UbuntuOne on Windows. |
661 | + * |
662 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
663 | + * it under the terms of the GNU Lesser General Public License version |
664 | + * as published by the Free Software Foundation. |
665 | + * |
666 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
667 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
668 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
669 | + * GNU Lesser General Public License for more details. |
670 | + * |
671 | + * You should have received a copy of the GNU Lesser General Public License |
672 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
673 | + * |
674 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
675 | + */ |
676 | +using System; |
677 | + |
678 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
679 | +{ |
680 | + /// <summary> |
681 | + /// Message processor that works with json messages from python. |
682 | + /// </summary> |
683 | + internal class JsonMessageProcessor : IMessageProcessor |
684 | + { |
685 | + /// <summary> |
686 | + /// Will process the message sent by the python code and will perform all the possibly required operations. |
687 | + /// </summary> |
688 | + /// <param name="message"></param> |
689 | + public void ProcessMessage(object message) |
690 | + { |
691 | + throw new NotImplementedException(); |
692 | + } |
693 | + } |
694 | +} |
695 | |
696 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamer.cs' |
697 | --- src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamer.cs 1970-01-01 00:00:00 +0000 |
698 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamer.cs 2010-10-12 10:18:45 +0000 |
699 | @@ -0,0 +1,91 @@ |
700 | +/* |
701 | + * Copyright 2010 Canonical Ltd. |
702 | + * |
703 | + * This file is part of UbuntuOne on Windows. |
704 | + * |
705 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
706 | + * it under the terms of the GNU Lesser General Public License version |
707 | + * as published by the Free Software Foundation. |
708 | + * |
709 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
710 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
711 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
712 | + * GNU Lesser General Public License for more details. |
713 | + * |
714 | + * You should have received a copy of the GNU Lesser General Public License |
715 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
716 | + * |
717 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
718 | + */ |
719 | +using System; |
720 | +using System.IO; |
721 | +using System.Text; |
722 | +using Newtonsoft.Json; |
723 | +using Newtonsoft.Json.Linq; |
724 | + |
725 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
726 | +{ |
727 | + /// <summary> |
728 | + /// Pipe streamer that uses json to talk with the python code. |
729 | + /// </summary> |
730 | + internal class JsonPipeStreamer : IPipeStreamer |
731 | + { |
732 | + #region Implementation of IPipeStreamer |
733 | + |
734 | + /// <summary> |
735 | + /// Gets and sets the encoding used by the streamer. |
736 | + /// </summary> |
737 | + public Encoding Encoding |
738 | + { |
739 | + get { return new UTF8Encoding(); } |
740 | + set { throw new NotImplementedException(); } |
741 | + } |
742 | + |
743 | + /// <summary> |
744 | + /// Reads the current contents that are present in the stream and returns an object that |
745 | + /// represents them. |
746 | + /// </summary> |
747 | + /// <param name="stream">The stream from which the data is read.</param> |
748 | + /// <returns>An object that represents the data in the stream.</returns> |
749 | + public object Read(Stream stream) |
750 | + { |
751 | + int len = 0; |
752 | + |
753 | + len = stream.ReadByte() * 256; |
754 | + len += stream.ReadByte(); |
755 | + byte[] inBuffer = new byte[len]; |
756 | + stream.Read(inBuffer, 0, len); |
757 | + var json = Encoding.GetString(inBuffer); |
758 | + |
759 | + // we just need to read the string from the python code and parse it as a json string :D |
760 | + var message = JObject.Parse(json); |
761 | + return message; |
762 | + } |
763 | + |
764 | + /// <summary> |
765 | + /// Writes the given object to the stream so that the python code can read it. |
766 | + /// </summary> |
767 | + /// <param name="outData">The object to be serialized in the stream.</param> |
768 | + /// <param name="stream">The stream to which the serialization will be written.</param> |
769 | + /// <returns>The position in the stream after the write operation.</returns> |
770 | + public int Write(object outData, Stream stream) |
771 | + { |
772 | + // generate the json from the outData and write it ot the stream |
773 | + var json = JsonConvert.SerializeObject(outData, Formatting.None); |
774 | + byte[] outBuffer = Encoding.GetBytes(json); |
775 | + int len = outBuffer.Length; |
776 | + if (len > UInt16.MaxValue) |
777 | + { |
778 | + len = (int)UInt16.MaxValue; |
779 | + } |
780 | + stream.WriteByte((byte)(len / 256)); |
781 | + stream.WriteByte((byte)(len & 255)); |
782 | + stream.Write(outBuffer, 0, len); |
783 | + stream.Flush(); |
784 | + |
785 | + return outBuffer.Length + 2; |
786 | + } |
787 | + |
788 | + #endregion |
789 | + } |
790 | +} |
791 | |
792 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamerFactory.cs' |
793 | --- src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamerFactory.cs 1970-01-01 00:00:00 +0000 |
794 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamerFactory.cs 2010-10-12 10:18:45 +0000 |
795 | @@ -0,0 +1,41 @@ |
796 | +/* |
797 | + * Copyright 2010 Canonical Ltd. |
798 | + * |
799 | + * This file is part of UbuntuOne on Windows. |
800 | + * |
801 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
802 | + * it under the terms of the GNU Lesser General Public License version |
803 | + * as published by the Free Software Foundation. |
804 | + * |
805 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
806 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
807 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
808 | + * GNU Lesser General Public License for more details. |
809 | + * |
810 | + * You should have received a copy of the GNU Lesser General Public License |
811 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
812 | + * |
813 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
814 | + */ |
815 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
816 | +{ |
817 | + /// <summary> |
818 | + /// PipeStreamerFactory that creates streamers that use json for communication. |
819 | + /// </summary> |
820 | + internal class JsonPipeStreamerFactory : IPipeStreamerFactory |
821 | + { |
822 | + #region Implementation of IPipeStreamerFactory |
823 | + |
824 | + /// <summary> |
825 | + /// Creates a new PipeStreamer that know the streamer to create that will |
826 | + /// know the protocol used to communicate between processes. |
827 | + /// </summary> |
828 | + /// <returns>A pipe streamer that knoww how to the protocol works.</returns> |
829 | + public IPipeStreamer Create() |
830 | + { |
831 | + return new JsonPipeStreamer(); |
832 | + } |
833 | + |
834 | + #endregion |
835 | + } |
836 | +} |
837 | |
838 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/PipeListener.cs' |
839 | --- src/Canonical.UbuntuOne.ProcessDispatcher/PipeListener.cs 1970-01-01 00:00:00 +0000 |
840 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/PipeListener.cs 2010-10-12 10:18:45 +0000 |
841 | @@ -0,0 +1,244 @@ |
842 | +/* |
843 | + * Copyright 2010 Canonical Ltd. |
844 | + * |
845 | + * This file is part of UbuntuOne on Windows. |
846 | + * |
847 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
848 | + * it under the terms of the GNU Lesser General Public License version |
849 | + * as published by the Free Software Foundation. |
850 | + * |
851 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
852 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
853 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
854 | + * GNU Lesser General Public License for more details. |
855 | + * |
856 | + * You should have received a copy of the GNU Lesser General Public License |
857 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
858 | + * |
859 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
860 | + */ |
861 | +using System; |
862 | +using System.IO; |
863 | +using System.IO.Pipes; |
864 | +using System.Threading; |
865 | +using log4net; |
866 | + |
867 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
868 | +{ |
869 | + /// <summary> |
870 | + /// This oject represents a listener that will be waiting for messages |
871 | + /// from the python code and will perform an operation for each messages |
872 | + /// that has been recived. |
873 | + /// </summary> |
874 | + internal class PipeListener : IPipeListener |
875 | + { |
876 | + #region Helper strcut |
877 | + |
878 | + /// <summary> |
879 | + /// Private structure used to pass the start of the listener to the |
880 | + /// different listening threads. |
881 | + /// </summary> |
882 | + private struct PipeListenerState |
883 | + { |
884 | + #region Variables |
885 | + |
886 | + private readonly string _namedPipe; |
887 | + private readonly Action<object> _callback; |
888 | + |
889 | + #endregion |
890 | + |
891 | + #region Properties |
892 | + |
893 | + /// <summary> |
894 | + /// Gets the named pipe to which the thread should listen. |
895 | + /// </summary> |
896 | + public string NamedPipe { get { return _namedPipe; } } |
897 | + |
898 | + /// <summary> |
899 | + /// Gets the callback that the listening pipe should execute. |
900 | + /// </summary> |
901 | + public Action<object> Callback { get { return _callback; } } |
902 | + |
903 | + #endregion |
904 | + |
905 | + public PipeListenerState(string namedPipe, Action<object> callback) |
906 | + { |
907 | + _namedPipe = namedPipe; |
908 | + _callback = callback; |
909 | + } |
910 | + } |
911 | + |
912 | + #endregion |
913 | + |
914 | + #region Variables |
915 | + |
916 | + private readonly object _loggerLock = new object(); |
917 | + private ILog _logger; |
918 | + private bool _isListening; |
919 | + private readonly object _isListeningLock = new object(); |
920 | + |
921 | + #endregion |
922 | + |
923 | + #region Properties |
924 | + |
925 | + /// <summary> |
926 | + /// Gets the logger to used with the object. |
927 | + /// </summary> |
928 | + internal ILog Logger |
929 | + { |
930 | + get |
931 | + { |
932 | + if (_logger == null) |
933 | + { |
934 | + lock (_loggerLock) |
935 | + { |
936 | + _logger = LogManager.GetLogger(typeof(PipeListener)); |
937 | + } |
938 | + } |
939 | + return _logger; |
940 | + } |
941 | + set |
942 | + { |
943 | + _logger = value; |
944 | + } |
945 | + } |
946 | + |
947 | + /// <summary> |
948 | + /// Gets if the pipe listener is indeed listening to the pipe. |
949 | + /// </summary> |
950 | + public bool IsListening |
951 | + { |
952 | + get { return _isListening; } |
953 | + private set |
954 | + { |
955 | + // we have to lock to ensure that the threads do not screw each |
956 | + // other up, this makes a small step of the processing to be sync :( |
957 | + lock (_isListeningLock) |
958 | + { |
959 | + _isListening = value; |
960 | + } |
961 | + } |
962 | + } |
963 | + |
964 | + /// <summary> |
965 | + /// Gets and sets the number of threads that will be used to listen to the |
966 | + /// pipe. Each thread will listeng to connections and will dispatch the |
967 | + /// messages when ever they are done. |
968 | + /// </summary> |
969 | + public int NumberOfThreads { get; set; } |
970 | + |
971 | + /// <summary> |
972 | + /// Gets and sets the pipe stream factory that know how to generate the streamers used for the communication. |
973 | + /// </summary> |
974 | + public IPipeStreamerFactory PipeStreamerFactory { get; set; } |
975 | + |
976 | + /// <summary> |
977 | + /// Gets and sets the action that will be performed with the message of that |
978 | + /// is received by the pipe listener. |
979 | + /// </summary> |
980 | + public IMessageProcessor MessageProcessor { get; set; } |
981 | + |
982 | + #endregion |
983 | + |
984 | + #region Helpers |
985 | + |
986 | + /// <summary> |
987 | + /// Helper method that is used in another thread that will be listening to the possible events from |
988 | + /// the pipe. |
989 | + /// </summary> |
990 | + private void Listen(object state) |
991 | + { |
992 | + var namedPipeState = (PipeListenerState)state; |
993 | + |
994 | + try |
995 | + { |
996 | + var threadNumber = Thread.CurrentThread.ManagedThreadId; |
997 | + // starts the named pipe since in theory it should not be present, if there is |
998 | + // a pipe already present we have an issue. |
999 | + using (var pipeServer = new NamedPipeServerStream(namedPipeState.NamedPipe, PipeDirection.InOut, NumberOfThreads,PipeTransmissionMode.Message,PipeOptions.Asynchronous)) |
1000 | + { |
1001 | + Logger.DebugFormat("Thread {0} listenitng to pipe {1}", threadNumber, namedPipeState.NamedPipe); |
1002 | + // we wait until the python code connects to the pipe, we do not block the |
1003 | + // rest of the app because we are in another thread. |
1004 | + pipeServer.WaitForConnection(); |
1005 | + |
1006 | + Logger.DebugFormat("Got clien connection in tread {0}", threadNumber); |
1007 | + try |
1008 | + { |
1009 | + // create a streamer that know the protocol |
1010 | + var streamer = PipeStreamerFactory.Create(); |
1011 | + // Read the request from the client. |
1012 | + var message = streamer.Read(pipeServer); |
1013 | + Logger.DebugFormat("Message received to thread {0} is {1}", threadNumber, message); |
1014 | + |
1015 | + // execute the action that has to occur with the message |
1016 | + namedPipeState.Callback(message); |
1017 | + } |
1018 | + // Catch the IOException that is raised if the pipe is broken |
1019 | + // or disconnected. |
1020 | + catch (IOException e) |
1021 | + { |
1022 | + Logger.DebugFormat("Error in thread {0} when reading pipe {1}",threadNumber, e.Message); |
1023 | + throw new PipeListenerException( |
1024 | + string.Format("Error in thread {0} when reading pipe {1}", threadNumber, e.Message), e); |
1025 | + } |
1026 | + |
1027 | + } |
1028 | + // if we are still listening, we will create a new thread to be used for listening, |
1029 | + // otherwhise we will not and not lnger threads will be added. Ofcourse if the rest of the |
1030 | + // threads do no add more than one work, we will have no issues with the pipe server since it |
1031 | + // has been disposed |
1032 | + if (IsListening) |
1033 | + { |
1034 | + ThreadPool.QueueUserWorkItem(Listen, namedPipeState.NamedPipe); |
1035 | + } |
1036 | + } |
1037 | + catch (PlatformNotSupportedException e) |
1038 | + { |
1039 | + // are we running on an OS that does not have pipes (Mono on some os) |
1040 | + throw new PipeListenerException(string.Format("Cannot listen to pipe {0}", namedPipeState.NamedPipe), e); |
1041 | + } |
1042 | + catch (IOException e) |
1043 | + { |
1044 | + // there are too many servers listening to this pipe. |
1045 | + throw new PipeListenerException( |
1046 | + string.Format("There are too many servers listening to {0}", namedPipeState.NamedPipe), e); |
1047 | + } |
1048 | + } |
1049 | + |
1050 | + #endregion |
1051 | + |
1052 | + /// <summary> |
1053 | + /// Starts listening to the different pipe messages and will perform the appropiate |
1054 | + /// action when a message is received. |
1055 | + /// </summary> |
1056 | + /// <param name="namedPipe">The name fof the pipe to listen.</param> |
1057 | + public void StartListening(string namedPipe) |
1058 | + { |
1059 | + if (NumberOfThreads < 0) |
1060 | + { |
1061 | + throw new PipeListenerException( |
1062 | + "The number of threads to use to listen to the pipe must be at least one."); |
1063 | + } |
1064 | + // we will be using a thread pool that will allow to have the different threads listening to |
1065 | + // the messages of the pipes. There could be issues if the devel provided far to many threads |
1066 | + // to listen to the pipe since the number of pipe servers is limited. |
1067 | + for (var currentThreaCount = 0; currentThreaCount < NumberOfThreads; currentThreaCount++) |
1068 | + { |
1069 | + // we add an new thread to listen |
1070 | + ThreadPool.QueueUserWorkItem(Listen, new PipeListenerState(namedPipe, MessageProcessor.ProcessMessage)); |
1071 | + } |
1072 | + |
1073 | + } |
1074 | + |
1075 | + /// <summary> |
1076 | + /// Stops listening to the different pipe messages. All the thread that are listening already will |
1077 | + /// be forced to stop. |
1078 | + /// </summary> |
1079 | + public void StopListening() |
1080 | + { |
1081 | + IsListening = false; |
1082 | + } |
1083 | + |
1084 | + } |
1085 | +} |
1086 | |
1087 | === added file 'src/Canonical.UbuntuOne.ProcessDispatcher/PipeListenerException.cs' |
1088 | --- src/Canonical.UbuntuOne.ProcessDispatcher/PipeListenerException.cs 1970-01-01 00:00:00 +0000 |
1089 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/PipeListenerException.cs 2010-10-12 10:18:45 +0000 |
1090 | @@ -0,0 +1,62 @@ |
1091 | +/* |
1092 | + * Copyright 2010 Canonical Ltd. |
1093 | + * |
1094 | + * This file is part of UbuntuOne on Windows. |
1095 | + * |
1096 | + * UbuntuOne on Windows is free software: you can redistribute it and/or modify |
1097 | + * it under the terms of the GNU Lesser General Public License version |
1098 | + * as published by the Free Software Foundation. |
1099 | + * |
1100 | + * Ubuntu One on Windows is distributed in the hope that it will be useful, |
1101 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1102 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1103 | + * GNU Lesser General Public License for more details. |
1104 | + * |
1105 | + * You should have received a copy of the GNU Lesser General Public License |
1106 | + * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>. |
1107 | + * |
1108 | + * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1109 | + */ |
1110 | +using System; |
1111 | + |
1112 | +namespace Canonical.UbuntuOne.ProcessDispatcher |
1113 | +{ |
1114 | + /// <summary> |
1115 | + /// Base class exception thrown where there is an issue while listening to the pipe used |
1116 | + /// by python to send messages. |
1117 | + /// </summary> |
1118 | + public class PipeListenerException : Exception |
1119 | + { |
1120 | + |
1121 | + /// <summary> |
1122 | + /// Creates a new instance of the exception. |
1123 | + /// </summary> |
1124 | + public PipeListenerException() |
1125 | + { |
1126 | + |
1127 | + } |
1128 | + |
1129 | + /// <summary> |
1130 | + /// Creates a new instance of the exception that will carry the given |
1131 | + /// message. |
1132 | + /// </summary> |
1133 | + /// <param name="message">The message to be carrie by the exception.</param> |
1134 | + public PipeListenerException(string message) |
1135 | + : base(message) |
1136 | + { |
1137 | + |
1138 | + } |
1139 | + |
1140 | + /// <summary> |
1141 | + /// Creates a new instance of the exception that will carry the given message and |
1142 | + /// inner exception. |
1143 | + /// </summary> |
1144 | + /// <param name="message">The message to be carried by the exception.</param> |
1145 | + /// <param name="inner">The inner exception that originated this exception.</param> |
1146 | + public PipeListenerException(string message, Exception inner) |
1147 | + : base(message, inner) |
1148 | + { |
1149 | + |
1150 | + } |
1151 | + } |
1152 | +} |
1153 | |
1154 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Program.cs' |
1155 | --- src/Canonical.UbuntuOne.ProcessDispatcher/Program.cs 2010-10-12 10:18:45 +0000 |
1156 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/Program.cs 2010-10-12 10:18:45 +0000 |
1157 | @@ -18,6 +18,7 @@ |
1158 | * Authors: Manuel de la Peña <manuel.delapena@canonical.com> |
1159 | */ |
1160 | using System; |
1161 | +using System.Security.Principal; |
1162 | using Canonical.UbuntuOne.Common.Container; |
1163 | using Canonical.UbuntuOne.Common.Utils; |
1164 | using log4net; |
1165 | @@ -29,6 +30,8 @@ |
1166 | { |
1167 | private static readonly ILog _logger = LogManager.GetLogger(typeof(Program)); |
1168 | private static readonly ConfigurationLocator _configLocator = new ConfigurationLocator(); |
1169 | + private static readonly string _listegingPipe = |
1170 | + "PythonMessages"; |
1171 | |
1172 | /// <summary> |
1173 | /// This method starts the service. |
1174 | @@ -71,6 +74,12 @@ |
1175 | var syncDaemonWindowsService = ObjectsContainer.GetImplementationOf<SyncDaemonWindowsService>(); |
1176 | // To run more than one service you have to add them here |
1177 | syncDaemonWindowsService.Start(); |
1178 | + // we need to start listening to the possible messages sent by the python code, we |
1179 | + // ensure that it is done to a ipe just for the user |
1180 | + var pipeListener = ObjectsContainer.GetImplementationOf<IPipeListener>(); |
1181 | + var userPipe = _listegingPipe + WindowsIdentity.GetCurrent().Name; |
1182 | + _logger.InfoFormat("Listening on {0}", userPipe); |
1183 | + pipeListener.StartListening(userPipe); |
1184 | while (true) ; |
1185 | }); |
1186 | |
1187 | |
1188 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs' |
1189 | --- src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-10-12 10:18:45 +0000 |
1190 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-10-12 10:18:45 +0000 |
1191 | @@ -283,11 +283,17 @@ |
1192 | UseShellExecute = false, |
1193 | RedirectStandardOutput = true, |
1194 | RedirectStandardError = true, |
1195 | - CreateNoWindow = true, |
1196 | + CreateNoWindow = false, |
1197 | WindowStyle = ProcessWindowStyle.Hidden |
1198 | } |
1199 | }; |
1200 | proc.Start(); |
1201 | + // we wait, we are in a diff thread in a diff process this will not block the user UI |
1202 | + proc.WaitForExit(); |
1203 | + var error = proc.StandardError.ReadToEnd(); |
1204 | + Logger.InfoFormat("StandarOutput from u1sync is: {0}", proc.StandardOutput.ReadToEnd()); |
1205 | + Logger.ErrorFormat("StandardError from u1sync is: {0}", proc.StandardError.ReadToEnd()); |
1206 | + proc.Close(); |
1207 | } |
1208 | |
1209 | /// <summary> |
1210 | |
1211 | === modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/objects.xml' |
1212 | --- src/Canonical.UbuntuOne.ProcessDispatcher/objects.xml 2010-10-12 10:18:45 +0000 |
1213 | +++ src/Canonical.UbuntuOne.ProcessDispatcher/objects.xml 2010-10-12 10:18:45 +0000 |
1214 | @@ -116,5 +116,24 @@ |
1215 | <property name="SyncShares" |
1216 | ref="SyncSharesServiceHost" /> |
1217 | </object> |
1218 | + |
1219 | + <!-- ###################################################################################################### --> |
1220 | + <!-- The pipe listener that will be used to know what the python code wants to tell us --> |
1221 | + <!-- ###################################################################################################### --> |
1222 | + |
1223 | + <object id="PipeStreamerFactory" |
1224 | + type="Canonical.UbuntuOne.ProcessDispatcher.JsonPipeStreamerFactory, Canonical.UbuntuOne.ProcessDispatcher" |
1225 | + autowire="autodetect"/> |
1226 | + |
1227 | + <object id="MessageProcessor" |
1228 | + type="Canonical.UbuntuOne.ProcessDispatcher.JsonMessageProcessor, Canonical.UbuntuOne.ProcessDispatcher" |
1229 | + autowire="autodetect" /> |
1230 | |
1231 | + <object id="PipeListener" |
1232 | + type="Canonical.UbuntuOne.ProcessDispatcher.PipeListener, Canonical.UbuntuOne.ProcessDispatcher" |
1233 | + autowire="autodetect"> |
1234 | + <property name="NumberOfThreads" |
1235 | + value="5"/> |
1236 | + </object> |
1237 | + |
1238 | </objects> |
1239 | \ No newline at end of file |
1240 | |
1241 | === modified file 'src/Version.cs' |
1242 | --- src/Version.cs 2010-10-12 10:18:45 +0000 |
1243 | +++ src/Version.cs 2010-10-12 10:18:45 +0000 |
1244 | @@ -10,6 +10,6 @@ |
1245 | // </auto-generated> |
1246 | //------------------------------------------------------------------------------ |
1247 | |
1248 | -[assembly: AssemblyVersionAttribute("1.0.606.5623")] |
1249 | -[assembly: AssemblyFileVersionAttribute("1.0.606.5623")] |
1250 | +[assembly: AssemblyVersionAttribute("1.0.611.8185")] |
1251 | +[assembly: AssemblyFileVersionAttribute("1.0.611.8185")] |
1252 | |
1253 | |
1254 | === modified file 'src/u1sync/main.py' |
1255 | --- src/u1sync/main.py 2010-09-27 17:33:52 +0000 |
1256 | +++ src/u1sync/main.py 2010-10-12 10:18:45 +0000 |
1257 | @@ -43,7 +43,7 @@ |
1258 | from u1sync.merge import ( |
1259 | SyncMerge, ClobberServerMerge, ClobberLocalMerge, merge_trees) |
1260 | from u1sync.sync import download_tree, upload_tree |
1261 | -from u1sync.utils import safe_mkdir |
1262 | +from u1sync.utils import safe_mkdir, send_bus_error |
1263 | from u1sync import metadata |
1264 | from u1sync.constants import METADATA_DIR_NAME |
1265 | from u1sync.ubuntuone_optparse import UbuntuOneOptionsParser |
1266 | @@ -332,21 +332,29 @@ |
1267 | try: |
1268 | do_main(argv, UbuntuOneOptionsParser()) |
1269 | except AuthenticationError, e: |
1270 | + sed_bus_error("Authentication failed: %s" % e, e) |
1271 | print "Authentication failed: %s" % e |
1272 | except ConnectionError, e: |
1273 | + sed_bus_error("Connection failed: %s" % e, e) |
1274 | print "Connection failed: %s" % e |
1275 | - except DirectoryNotInitializedError: |
1276 | + except DirectoryNotInitializedError, e: |
1277 | + sed_bus_error("Directory not initialized", e) |
1278 | print "Directory not initialized; " \ |
1279 | "use --init [DIRECTORY] to initialize it." |
1280 | - except DirectoryAlreadyInitializedError: |
1281 | + except DirectoryAlreadyInitializedError, e: |
1282 | + sed_bus_error("Directory not initialized", e) |
1283 | print "Directory already initialized." |
1284 | - except NoSuchShareError: |
1285 | + except NoSuchShareError, e: |
1286 | + sed_bus_error("No matching share found.", e) |
1287 | print "No matching share found." |
1288 | - except ReadOnlyShareError: |
1289 | + except ReadOnlyShareError, e: |
1290 | + sed_bus_error("The selected action isn't possible on a read-only share.", e) |
1291 | print "The selected action isn't possible on a read-only share." |
1292 | - except (ForcedShutdown, KeyboardInterrupt): |
1293 | + except (ForcedShutdown, KeyboardInterrupt), e: |
1294 | + sed_bus_error("Interrupted!", e) |
1295 | print "Interrupted!" |
1296 | except TreesDiffer, e: |
1297 | + sed_bus_error("Trees differ.", e) |
1298 | if not e.quiet: |
1299 | print "Trees differ." |
1300 | else: |
1301 | |
1302 | === modified file 'src/u1sync/utils.py' |
1303 | --- src/u1sync/utils.py 2010-08-27 14:43:32 +0000 |
1304 | +++ src/u1sync/utils.py 2010-10-12 10:18:45 +0000 |
1305 | @@ -19,7 +19,11 @@ |
1306 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
1307 | """Miscellaneous utility functions.""" |
1308 | |
1309 | +import json |
1310 | import os |
1311 | +import getpass |
1312 | + |
1313 | +import win32pipe |
1314 | from errno import EEXIST, ENOENT |
1315 | from u1sync.constants import ( |
1316 | METADATA_DIR_NAME, SPECIAL_FILE_RE) |
1317 | @@ -48,3 +52,36 @@ |
1318 | except OSError, e: |
1319 | if e.errno != ENOENT: |
1320 | raise |
1321 | + |
1322 | +def get_user(): |
1323 | + """Return the name of the current user.""" |
1324 | + return r'{0}\{1}'.format(os.getenv('COMPUTERNAME'), getpass.getuser()) |
1325 | + |
1326 | +def create_error_message(error_message, exception): |
1327 | + """Create a new error message""" |
1328 | + # hack, I really dislike this, later using protobuf we |
1329 | + # can state the type of error, right now, this should do the work. |
1330 | + message = {'type':'error', |
1331 | + 'message':error_message, |
1332 | + 'expcetion':type(exception.__class__.__name__)} |
1333 | + return message |
1334 | + |
1335 | +def send_bus_message(message): |
1336 | + """Sends a message to a pipe listen by an other lang.""" |
1337 | + pipe_name = r'\\.\pipe\PythonMessages{0}'.format(get_user()) |
1338 | + # calulate json representation of the message |
1339 | + data_json = json.dumps(message) |
1340 | + length = str(len(data_json)/256) |
1341 | + length += str(len(data_json)&256) |
1342 | + data_json = length + data_json |
1343 | + # call the pipe with the message |
1344 | + try: |
1345 | + data = win32pipe.CallNamedPipe(pipe_name, |
1346 | + data_json, len(data_json), 0 ) |
1347 | + except Exception: |
1348 | + print "Error: C# client is not listening!!" |
1349 | + |
1350 | +def send_bus_error(error_message, exception): |
1351 | + message = create_error_message(error_message, exception) |
1352 | + send_bus_message(message) |
1353 | + |
1354 | \ No newline at end of file |