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