Merge lp:~mandel/ubuntuone-windows-installer/add_chatty_u1sync into lp:ubuntuone-windows-installer/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
Reviewer Review Type Date Requested Status
Ubuntu One hackers Pending
Review via email: mp+38200@code.launchpad.net

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
=== modified file 'build.number'
--- build.number 2010-10-12 10:18:45 +0000
+++ build.number 2010-10-12 10:18:45 +0000
@@ -1,1 +1,1 @@
11.0.606.5623
2\ No newline at end of file1\ No newline at end of file
21.0.611.8185
3\ No newline at end of file3\ No newline at end of file
44
=== modified file 'main.build'
--- main.build 2010-10-06 13:13:50 +0000
+++ main.build 2010-10-12 10:18:45 +0000
@@ -213,7 +213,7 @@
213 managed="true"213 managed="true"
214 workingdir="src"214 workingdir="src"
215 program="python.exe"215 program="python.exe"
216 commandline="setup.py py2exe" />216 commandline="setup.py py2exe --packages=ubuntuone.storageprotocol" />
217 217
218 </target>218 </target>
219 219
220220
=== modified file 'src/Canonical.Ubuntu.SSO.Tests/Canonical.Ubuntu.SSO.Tests.csproj'
--- src/Canonical.Ubuntu.SSO.Tests/Canonical.Ubuntu.SSO.Tests.csproj 2010-10-05 09:49:29 +0000
+++ src/Canonical.Ubuntu.SSO.Tests/Canonical.Ubuntu.SSO.Tests.csproj 2010-10-12 10:18:45 +0000
@@ -31,6 +31,10 @@
31 <WarningLevel>4</WarningLevel>31 <WarningLevel>4</WarningLevel>
32 </PropertyGroup>32 </PropertyGroup>
33 <ItemGroup>33 <ItemGroup>
34 <Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
35 <SpecificVersion>False</SpecificVersion>
36 <HintPath>..\..\lib\JsonNet\Newtonsoft.Json.dll</HintPath>
37 </Reference>
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 <SpecificVersion>False</SpecificVersion>39 <SpecificVersion>False</SpecificVersion>
36 <HintPath>..\..\lib\Nunit\nunit.framework.dll</HintPath>40 <HintPath>..\..\lib\Nunit\nunit.framework.dll</HintPath>
@@ -49,8 +53,13 @@
49 </ItemGroup>53 </ItemGroup>
50 <ItemGroup>54 <ItemGroup>
51 <Compile Include="ColonSeparatedSSOCredentialsEncoderFixture.cs" />55 <Compile Include="ColonSeparatedSSOCredentialsEncoderFixture.cs" />
56 <Compile Include="CredentialsDeniedEventArgsFixture.cs" />
57 <Compile Include="CredentialsErrorEventArgsFixture.cs" />
58 <Compile Include="CredentialsFoundEventArgsFixture.cs" />
59 <Compile Include="JsonCredentialsEncoderFixture.cs" />
52 <Compile Include="JsonSSOCredentialsEncoderFixture.cs" />60 <Compile Include="JsonSSOCredentialsEncoderFixture.cs" />
53 <Compile Include="KeyringFixture.cs" />61 <Compile Include="KeyringFixture.cs" />
62 <Compile Include="LoginCredentialsEventArgsFixture.cs" />
54 <Compile Include="Properties\AssemblyInfo.cs" />63 <Compile Include="Properties\AssemblyInfo.cs" />
55 <Compile Include="SSOLoginProcessorFixture.cs" />64 <Compile Include="SSOLoginProcessorFixture.cs" />
56 </ItemGroup>65 </ItemGroup>
5766
=== added file 'src/Canonical.Ubuntu.SSO.Tests/CredentialsDeniedEventArgsFixture.cs'
--- src/Canonical.Ubuntu.SSO.Tests/CredentialsDeniedEventArgsFixture.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.Ubuntu.SSO.Tests/CredentialsDeniedEventArgsFixture.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,55 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of Ubuntu One on Windows.
5 *
6 * Ubuntu One on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with Ubuntu One for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20using NUnit.Framework;
21
22namespace Canonical.Ubuntu.SSO.Tests
23{
24 [TestFixture]
25 public class CredentialsDeniedEventArgsFixture
26 {
27 #region Variables
28
29 private CredentialsDeniedEventArgs _args;
30
31 #endregion
32
33 #region Tests
34
35 [Test]
36 public void EmptyConstructorTest()
37 {
38 _args = new CredentialsDeniedEventArgs();
39 Assert.AreEqual(string.Empty, _args.ApplicationName);
40 }
41
42 [TestCase("UbuntuOne")]
43 [TestCase("OtherApp")]
44 [TestCase("Tomboy")]
45 public void StringConstructorTest(string appName)
46 {
47 // create the credentials and make sure the correct data is used.
48 _args = new CredentialsDeniedEventArgs(appName);
49 Assert.AreEqual(appName, _args.ApplicationName);
50 }
51
52 #endregion
53
54 }
55}
056
=== added file 'src/Canonical.Ubuntu.SSO.Tests/CredentialsErrorEventArgsFixture.cs'
--- src/Canonical.Ubuntu.SSO.Tests/CredentialsErrorEventArgsFixture.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.Ubuntu.SSO.Tests/CredentialsErrorEventArgsFixture.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,70 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of Ubuntu One on Windows.
5 *
6 * Ubuntu One on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with Ubuntu One for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20using NUnit.Framework;
21
22namespace Canonical.Ubuntu.SSO.Tests
23{
24
25 [TestFixture]
26 public class CredentialsErrorEventArgsFixture
27 {
28
29 #region Variables
30
31 private CredentialsErrorEventArgs _args;
32 #endregion
33
34 #region Tests
35
36 [Test]
37 public void EmptyConstructorTest()
38 {
39 _args = new CredentialsErrorEventArgs();
40 Assert.AreEqual(string.Empty, _args.ApplicationName);
41 Assert.AreEqual(string.Empty, _args.DetailedErrorMessage);
42 Assert.AreEqual(string.Empty, _args.ErrorMessage);
43 }
44
45 [TestCase("UbuntuOne", "Error 08")]
46 [TestCase("Tomboy", "NullReferenceException")]
47 [TestCase("OtherApp", "StupidError")]
48 public void ApplicationErrorConstructorTest(string appName, string error)
49 {
50 _args = new CredentialsErrorEventArgs(appName, error);
51 Assert.AreEqual(appName, _args.ApplicationName);
52 Assert.AreEqual(error, _args.ErrorMessage);
53 Assert.AreEqual(string.Empty, _args.DetailedErrorMessage);
54 }
55
56 [TestCase("UbuntuOne", "Error 08", "You do not have the keyring rigths.")]
57 [TestCase("Tomboy", "NullReferenceException", "Stupid extension")]
58 [TestCase("OtherApp", "StupidError", "Learn to code")]
59 public void ApplicationErrorDetailConstructorTest(string appName, string error, string detail)
60 {
61 _args = new CredentialsErrorEventArgs(appName, error, detail);
62 Assert.AreEqual(appName, _args.ApplicationName);
63 Assert.AreEqual(error, _args.ErrorMessage);
64 Assert.AreEqual(detail, _args.DetailedErrorMessage);
65 }
66
67 #endregion
68
69 }
70}
071
=== added file 'src/Canonical.Ubuntu.SSO.Tests/CredentialsFoundEventArgsFixture.cs'
--- src/Canonical.Ubuntu.SSO.Tests/CredentialsFoundEventArgsFixture.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.Ubuntu.SSO.Tests/CredentialsFoundEventArgsFixture.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of Ubuntu One on Windows.
5 *
6 * Ubuntu One on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with Ubuntu One for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20using System.Collections;
21using System.Collections.Generic;
22using NUnit.Framework;
23
24namespace Canonical.Ubuntu.SSO.Tests
25{
26 [TestFixture]
27 public class CredentialsFoundEventArgsFixture
28 {
29 #region Variables
30
31 private CredentialsFoundEventArgs _args;
32
33 #endregion
34
35 #region Tests
36
37 [Test]
38 public void EmptyConstructorTest()
39 {
40 _args = new CredentialsFoundEventArgs();
41 Assert.AreEqual(string.Empty, _args.ApplicationName);
42 Assert.IsEmpty((ICollection)_args.Credentials.Values);
43 }
44
45 [TestCase("UbuntuOne", "token", "tokenSecret", "consumerKey", "consumerSecret")]
46 [TestCase("Tomboy", "tomboyToken", "tomboyToeknSecret", "tomboyConsumerKey", "tomboyConsumerSecret")]
47 public void AppNameCredentialsConstructor(string appName, string token, string tokenSecret,
48 string consumerKey, string consumerSecret )
49 {
50 // create the dict with the data
51 var credentials = new Dictionary<string, string>
52 {
53 {"Token", token},
54 {"TokenSecret", tokenSecret},
55 {"ConsumerKey", consumerKey},
56 {"ConsumerSecret", consumerSecret}
57 };
58 _args = new CredentialsFoundEventArgs(appName, credentials);
59 Assert.AreEqual(appName, _args.ApplicationName);
60 Assert.AreSame(credentials, _args.Credentials);
61 }
62
63 #endregion
64 }
65}
066
=== added file 'src/Canonical.Ubuntu.SSO.Tests/JsonCredentialsEncoderFixture.cs'
--- src/Canonical.Ubuntu.SSO.Tests/JsonCredentialsEncoderFixture.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.Ubuntu.SSO.Tests/JsonCredentialsEncoderFixture.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,100 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19using Newtonsoft.Json.Linq;
20using NUnit.Framework;
21
22namespace Canonical.Ubuntu.SSO.Tests
23{
24 [TestFixture]
25 public class JsonCredentialsEncoderFixture
26 {
27 #region Variables
28
29 private JsonSSOCredentialsEncoder _encoder;
30
31 #endregion
32
33 #region Setup & TearDown
34
35 [SetUp]
36 public void Setup()
37 {
38 _encoder = new JsonSSOCredentialsEncoder();
39 }
40
41 #endregion
42
43 #region Tests
44
45 [TestCase("token", "tokenSecret", "consumerKey", "consumerSecret")]
46 [TestCase("asasferer", "ykvchdclsc", "sdahdlfa", "zcknvculdsnv")]
47 public void EncodeTest(string token, string tokenSecret, string consumerKey, string consumerSecret)
48 {
49 // pass the data to encode, later test that the required data is present
50 // and that the data is the same.
51 var encodedData = _encoder.Encode(token, tokenSecret, consumerKey, consumerSecret);
52 // use the Json.Net to read the result string and ensure we do have the data
53 var credentials = JObject.Parse(encodedData);
54 Assert.AreEqual(token, (string)credentials["token"]);
55 Assert.AreEqual(tokenSecret, (string)credentials["token_secret"]);
56 Assert.AreEqual(consumerKey, (string)credentials["consumer_key"]);
57 Assert.AreEqual(consumerSecret, (string)credentials["consumer_secret"]);
58 }
59
60 [TestCase("token", "tokenSecret", "consumerKey", "consumerSecret")]
61 [TestCase("asasferer", "ykvchdclsc", "sdahdlfa", "zcknvculdsnv")]
62 public void DecodeTest(string token, string tokenSecret, string consumerKey, string consumerSecret)
63 {
64 // create the encoded data, decode it an ensure is the same
65 string returnedToken;
66 string returnedTokenSecret;
67 string returnedConsumerKey;
68 string returnedConsumerSecret;
69
70 var encodedData = _encoder.Encode(token, tokenSecret, consumerKey, consumerSecret);
71 _encoder.Decode(encodedData, out returnedToken, out returnedTokenSecret,
72 out returnedConsumerKey, out returnedConsumerSecret);
73 Assert.AreEqual(token, returnedToken);
74 Assert.AreEqual(tokenSecret, returnedTokenSecret);
75 Assert.AreEqual(consumerKey, returnedConsumerKey);
76 Assert.AreEqual(consumerSecret, returnedConsumerSecret);
77 }
78
79 [TestCase(null, "tokenSecret", "consumerKey", "consumerSecret")]
80 [TestCase("token", null, "consumerKey", "consumerSecret")]
81 [TestCase("token", "tokenSecret", null, "consumerSecret")]
82 [TestCase("token", "tokenSecret", "consumerKey", null)]
83 [ExpectedException(typeof(SSOException))]
84 public void DecodeEmptyDataTest(string token, string tokenSecret, string consumerKey, string consumerSecret)
85 {
86 // encode the data, then try to decode an expect the exception
87 string returnedToken;
88 string returnedTokenSecret;
89 string returnedConsumerKey;
90 string returnedConsumerSecret;
91
92 var encodedData = _encoder.Encode(token, tokenSecret, consumerKey, consumerSecret);
93 _encoder.Decode(encodedData, out returnedToken, out returnedTokenSecret,
94 out returnedConsumerKey, out returnedConsumerSecret);
95 }
96
97 #endregion
98
99 }
100}
0101
=== added file 'src/Canonical.Ubuntu.SSO.Tests/LoginCredentialsEventArgsFixture.cs'
--- src/Canonical.Ubuntu.SSO.Tests/LoginCredentialsEventArgsFixture.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.Ubuntu.SSO.Tests/LoginCredentialsEventArgsFixture.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,52 @@
1/* Copyright 2010 Canonical Ltd.
2 *
3 * This file is part of UbuntuOne on Windows.
4 *
5 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version
7 * as published by the Free Software Foundation.
8 *
9 * Ubuntu One on Windows is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
18 */
19using NUnit.Framework;
20
21namespace Canonical.Ubuntu.SSO.Tests
22{
23 [TestFixture]
24 public class LoginCredentialsEventArgsFixture
25 {
26 #region Variables
27
28 private LoginCredentialsEventArgs _args;
29
30 #endregion
31
32 #region Tests
33
34 [Test]
35 public void EmptyConstructorTest()
36 {
37 _args = new LoginCredentialsEventArgs();
38 Assert.AreEqual(string.Empty, _args.Username);
39 Assert.AreEqual(string.Empty, _args.Password);
40 }
41
42 [TestCase("username", "password")]
43 [TestCase("otherUsername", "otherPassword")]
44 public void UsernamePasswordConstructor(string username, string password)
45 {
46 _args = new LoginCredentialsEventArgs(username, password);
47 Assert.AreEqual(username, _args.Username);
48 Assert.AreEqual(password, _args.Password);
49 }
50 #endregion
51 }
52}
053
=== modified file 'src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs'
--- src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-05 15:20:36 +0000
+++ src/Canonical.Ubuntu.SSO/SSOCredentialsProvider.cs 2010-10-12 10:18:45 +0000
@@ -20,7 +20,6 @@
20using System;20using System;
21using System.Collections.Generic;21using System.Collections.Generic;
22using System.Windows;22using System.Windows;
23using Canonical.UbuntuOne.Common;
24using Canonical.UbuntuOne.Common.Aop;23using Canonical.UbuntuOne.Common.Aop;
2524
26namespace Canonical.Ubuntu.SSO25namespace Canonical.Ubuntu.SSO
@@ -150,6 +149,7 @@
150 [DebugLogged]149 [DebugLogged]
151 public void LoginOrRegisterToGetCredentials()150 public void LoginOrRegisterToGetCredentials()
152 {151 {
152 throw new NotImplementedException();
153 }153 }
154154
155 #endregion155 #endregion
156156
=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj'
--- src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj 2010-10-12 10:18:45 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/Canonical.UbuntuOne.ProcessDispatcher.csproj 2010-10-12 10:18:45 +0000
@@ -91,6 +91,15 @@
91 <Compile Include="..\Version.cs">91 <Compile Include="..\Version.cs">
92 <Link>Properties\Version.cs</Link>92 <Link>Properties\Version.cs</Link>
93 </Compile>93 </Compile>
94 <Compile Include="IMessageProcessor.cs" />
95 <Compile Include="IPipeListener.cs" />
96 <Compile Include="IPipeStreamer.cs" />
97 <Compile Include="IPipeStreamerFactory.cs" />
98 <Compile Include="JsonMessageProcessor.cs" />
99 <Compile Include="JsonPipeStreamer.cs" />
100 <Compile Include="JsonPipeStreamerFactory.cs" />
101 <Compile Include="PipeListener.cs" />
102 <Compile Include="PipeListenerException.cs" />
94 <Compile Include="SyncDaemonWindowsService.cs">103 <Compile Include="SyncDaemonWindowsService.cs">
95 </Compile>104 </Compile>
96 <Compile Include="CallerContext.cs" />105 <Compile Include="CallerContext.cs" />
@@ -113,6 +122,10 @@
113 <SpecificVersion>False</SpecificVersion>122 <SpecificVersion>False</SpecificVersion>
114 <HintPath>..\..\lib\log4net\log4net.dll</HintPath>123 <HintPath>..\..\lib\log4net\log4net.dll</HintPath>
115 </Reference>124 </Reference>
125 <Reference Include="Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
126 <SpecificVersion>False</SpecificVersion>
127 <HintPath>..\..\lib\JsonNet\Newtonsoft.Json.dll</HintPath>
128 </Reference>
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">
117 <SpecificVersion>False</SpecificVersion>130 <SpecificVersion>False</SpecificVersion>
118 <HintPath>..\..\lib\Spring.Net\Spring.Core.dll</HintPath>131 <HintPath>..\..\lib\Spring.Net\Spring.Core.dll</HintPath>
119132
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/IMessageProcessor.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/IMessageProcessor.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/IMessageProcessor.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,33 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of UbuntuOne on Windows.
5 *
6 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20namespace Canonical.UbuntuOne.ProcessDispatcher
21{
22 /// <summary>
23 /// Interface to be implemented by those objects that now how to process the messages comming from python.
24 /// </summary>
25 public interface IMessageProcessor
26 {
27 /// <summary>
28 /// Will process the message sent by the python code and will perform all the possibly required operations.
29 /// </summary>
30 /// <param name="message"></param>
31 void ProcessMessage(object message);
32 }
33}
0\ No newline at end of file34\ No newline at end of file
135
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/IPipeListener.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/IPipeListener.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/IPipeListener.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,43 @@
1using System;
2
3namespace Canonical.UbuntuOne.ProcessDispatcher
4{
5 internal interface IPipeListener
6 {
7 /// <summary>
8 /// Gets if the pipe listener is indeed listening to the pipe.
9 /// </summary>
10 bool IsListening { get; }
11
12 /// <summary>
13 /// Gets and sets the number of threads that will be used to listen to the
14 /// pipe. Each thread will listeng to connections and will dispatch the
15 /// messages when ever they are done.
16 /// </summary>
17 int NumberOfThreads { get; set; }
18
19 /// <summary>
20 /// Gets and sets the pipe stream factory that know how to generate the streamers used for the communication.
21 /// </summary>
22 IPipeStreamerFactory PipeStreamerFactory { get; set; }
23
24 /// <summary>
25 /// Gets and sets the action that will be performed with the message of that
26 /// is received by the pipe listener.
27 /// </summary>
28 IMessageProcessor MessageProcessor { get; set; }
29
30 /// <summary>
31 /// Starts listening to the different pipe messages and will perform the appropiate
32 /// action when a message is received.
33 /// </summary>
34 /// <param name="namedPipe">The name fof the pipe to listen.</param>
35 void StartListening(string namedPipe);
36
37 /// <summary>
38 /// Stops listening to the different pipe messages. All the thread that are listening already will
39 /// be forced to stop.
40 /// </summary>
41 void StopListening();
42 }
43}
0\ No newline at end of file44\ No newline at end of file
145
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamer.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamer.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamer.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,52 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of UbuntuOne on Windows.
5 *
6 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20using System.IO;
21using System.Text;
22
23namespace Canonical.UbuntuOne.ProcessDispatcher
24{
25 /// <summary>
26 /// Interface that should be implemented by those objects that
27 /// know the protocol that is used to communicate with the python code.
28 /// </summary>
29 public interface IPipeStreamer
30 {
31 /// <summary>
32 /// Gets and sets the encoding used by the streamer.
33 /// </summary>
34 Encoding Encoding { get; set; }
35
36 /// <summary>
37 /// Reads the current contents that are present in the stream and returns an object that
38 /// represents them.
39 /// </summary>
40 /// <param name="stream">The stream from which the data is read.</param>
41 /// <returns>An object that represents the data in the stream.</returns>
42 object Read(Stream stream);
43
44 /// <summary>
45 /// Writes the given object to the stream so that the python code can read it.
46 /// </summary>
47 /// <param name="outData">The object to be serialized in the stream.</param>
48 /// <param name="stream">The stream to which the serialization will be written.</param>
49 /// <returns>The position in the stream after the write operation.</returns>
50 int Write(object outData, Stream stream);
51 }
52}
053
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamerFactory.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamerFactory.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/IPipeStreamerFactory.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,33 @@
1/*
2 * This file is part of UbuntuOne on Windows.
3 *
4 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version
6 * as published by the Free Software Foundation.
7 *
8 * Ubuntu One on Windows is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
17 */
18namespace Canonical.UbuntuOne.ProcessDispatcher
19{
20 /// <summary>
21 /// Factory that will generate the IPipeStream objects that understand the protocol used to communicate
22 /// between the different processes.
23 /// </summary>
24 public interface IPipeStreamerFactory
25 {
26 /// <summary>
27 /// Creates a new PipeStreamer that know the streamer to create that will
28 /// know the protocol used to communicate between processes.
29 /// </summary>
30 /// <returns>A pipe streamer that knoww how to the protocol works.</returns>
31 IPipeStreamer Create();
32 }
33}
034
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/JsonMessageProcessor.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/JsonMessageProcessor.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/JsonMessageProcessor.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,38 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of UbuntuOne on Windows.
5 *
6 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20using System;
21
22namespace Canonical.UbuntuOne.ProcessDispatcher
23{
24 /// <summary>
25 /// Message processor that works with json messages from python.
26 /// </summary>
27 internal class JsonMessageProcessor : IMessageProcessor
28 {
29 /// <summary>
30 /// Will process the message sent by the python code and will perform all the possibly required operations.
31 /// </summary>
32 /// <param name="message"></param>
33 public void ProcessMessage(object message)
34 {
35 throw new NotImplementedException();
36 }
37 }
38}
039
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamer.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamer.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamer.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,91 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of UbuntuOne on Windows.
5 *
6 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20using System;
21using System.IO;
22using System.Text;
23using Newtonsoft.Json;
24using Newtonsoft.Json.Linq;
25
26namespace Canonical.UbuntuOne.ProcessDispatcher
27{
28 /// <summary>
29 /// Pipe streamer that uses json to talk with the python code.
30 /// </summary>
31 internal class JsonPipeStreamer : IPipeStreamer
32 {
33 #region Implementation of IPipeStreamer
34
35 /// <summary>
36 /// Gets and sets the encoding used by the streamer.
37 /// </summary>
38 public Encoding Encoding
39 {
40 get { return new UTF8Encoding(); }
41 set { throw new NotImplementedException(); }
42 }
43
44 /// <summary>
45 /// Reads the current contents that are present in the stream and returns an object that
46 /// represents them.
47 /// </summary>
48 /// <param name="stream">The stream from which the data is read.</param>
49 /// <returns>An object that represents the data in the stream.</returns>
50 public object Read(Stream stream)
51 {
52 int len = 0;
53
54 len = stream.ReadByte() * 256;
55 len += stream.ReadByte();
56 byte[] inBuffer = new byte[len];
57 stream.Read(inBuffer, 0, len);
58 var json = Encoding.GetString(inBuffer);
59
60 // we just need to read the string from the python code and parse it as a json string :D
61 var message = JObject.Parse(json);
62 return message;
63 }
64
65 /// <summary>
66 /// Writes the given object to the stream so that the python code can read it.
67 /// </summary>
68 /// <param name="outData">The object to be serialized in the stream.</param>
69 /// <param name="stream">The stream to which the serialization will be written.</param>
70 /// <returns>The position in the stream after the write operation.</returns>
71 public int Write(object outData, Stream stream)
72 {
73 // generate the json from the outData and write it ot the stream
74 var json = JsonConvert.SerializeObject(outData, Formatting.None);
75 byte[] outBuffer = Encoding.GetBytes(json);
76 int len = outBuffer.Length;
77 if (len > UInt16.MaxValue)
78 {
79 len = (int)UInt16.MaxValue;
80 }
81 stream.WriteByte((byte)(len / 256));
82 stream.WriteByte((byte)(len & 255));
83 stream.Write(outBuffer, 0, len);
84 stream.Flush();
85
86 return outBuffer.Length + 2;
87 }
88
89 #endregion
90 }
91}
092
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamerFactory.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamerFactory.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/JsonPipeStreamerFactory.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of UbuntuOne on Windows.
5 *
6 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20namespace Canonical.UbuntuOne.ProcessDispatcher
21{
22 /// <summary>
23 /// PipeStreamerFactory that creates streamers that use json for communication.
24 /// </summary>
25 internal class JsonPipeStreamerFactory : IPipeStreamerFactory
26 {
27 #region Implementation of IPipeStreamerFactory
28
29 /// <summary>
30 /// Creates a new PipeStreamer that know the streamer to create that will
31 /// know the protocol used to communicate between processes.
32 /// </summary>
33 /// <returns>A pipe streamer that knoww how to the protocol works.</returns>
34 public IPipeStreamer Create()
35 {
36 return new JsonPipeStreamer();
37 }
38
39 #endregion
40 }
41}
042
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/PipeListener.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/PipeListener.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/PipeListener.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,244 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of UbuntuOne on Windows.
5 *
6 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20using System;
21using System.IO;
22using System.IO.Pipes;
23using System.Threading;
24using log4net;
25
26namespace Canonical.UbuntuOne.ProcessDispatcher
27{
28 /// <summary>
29 /// This oject represents a listener that will be waiting for messages
30 /// from the python code and will perform an operation for each messages
31 /// that has been recived.
32 /// </summary>
33 internal class PipeListener : IPipeListener
34 {
35 #region Helper strcut
36
37 /// <summary>
38 /// Private structure used to pass the start of the listener to the
39 /// different listening threads.
40 /// </summary>
41 private struct PipeListenerState
42 {
43 #region Variables
44
45 private readonly string _namedPipe;
46 private readonly Action<object> _callback;
47
48 #endregion
49
50 #region Properties
51
52 /// <summary>
53 /// Gets the named pipe to which the thread should listen.
54 /// </summary>
55 public string NamedPipe { get { return _namedPipe; } }
56
57 /// <summary>
58 /// Gets the callback that the listening pipe should execute.
59 /// </summary>
60 public Action<object> Callback { get { return _callback; } }
61
62 #endregion
63
64 public PipeListenerState(string namedPipe, Action<object> callback)
65 {
66 _namedPipe = namedPipe;
67 _callback = callback;
68 }
69 }
70
71 #endregion
72
73 #region Variables
74
75 private readonly object _loggerLock = new object();
76 private ILog _logger;
77 private bool _isListening;
78 private readonly object _isListeningLock = new object();
79
80 #endregion
81
82 #region Properties
83
84 /// <summary>
85 /// Gets the logger to used with the object.
86 /// </summary>
87 internal ILog Logger
88 {
89 get
90 {
91 if (_logger == null)
92 {
93 lock (_loggerLock)
94 {
95 _logger = LogManager.GetLogger(typeof(PipeListener));
96 }
97 }
98 return _logger;
99 }
100 set
101 {
102 _logger = value;
103 }
104 }
105
106 /// <summary>
107 /// Gets if the pipe listener is indeed listening to the pipe.
108 /// </summary>
109 public bool IsListening
110 {
111 get { return _isListening; }
112 private set
113 {
114 // we have to lock to ensure that the threads do not screw each
115 // other up, this makes a small step of the processing to be sync :(
116 lock (_isListeningLock)
117 {
118 _isListening = value;
119 }
120 }
121 }
122
123 /// <summary>
124 /// Gets and sets the number of threads that will be used to listen to the
125 /// pipe. Each thread will listeng to connections and will dispatch the
126 /// messages when ever they are done.
127 /// </summary>
128 public int NumberOfThreads { get; set; }
129
130 /// <summary>
131 /// Gets and sets the pipe stream factory that know how to generate the streamers used for the communication.
132 /// </summary>
133 public IPipeStreamerFactory PipeStreamerFactory { get; set; }
134
135 /// <summary>
136 /// Gets and sets the action that will be performed with the message of that
137 /// is received by the pipe listener.
138 /// </summary>
139 public IMessageProcessor MessageProcessor { get; set; }
140
141 #endregion
142
143 #region Helpers
144
145 /// <summary>
146 /// Helper method that is used in another thread that will be listening to the possible events from
147 /// the pipe.
148 /// </summary>
149 private void Listen(object state)
150 {
151 var namedPipeState = (PipeListenerState)state;
152
153 try
154 {
155 var threadNumber = Thread.CurrentThread.ManagedThreadId;
156 // starts the named pipe since in theory it should not be present, if there is
157 // a pipe already present we have an issue.
158 using (var pipeServer = new NamedPipeServerStream(namedPipeState.NamedPipe, PipeDirection.InOut, NumberOfThreads,PipeTransmissionMode.Message,PipeOptions.Asynchronous))
159 {
160 Logger.DebugFormat("Thread {0} listenitng to pipe {1}", threadNumber, namedPipeState.NamedPipe);
161 // we wait until the python code connects to the pipe, we do not block the
162 // rest of the app because we are in another thread.
163 pipeServer.WaitForConnection();
164
165 Logger.DebugFormat("Got clien connection in tread {0}", threadNumber);
166 try
167 {
168 // create a streamer that know the protocol
169 var streamer = PipeStreamerFactory.Create();
170 // Read the request from the client.
171 var message = streamer.Read(pipeServer);
172 Logger.DebugFormat("Message received to thread {0} is {1}", threadNumber, message);
173
174 // execute the action that has to occur with the message
175 namedPipeState.Callback(message);
176 }
177 // Catch the IOException that is raised if the pipe is broken
178 // or disconnected.
179 catch (IOException e)
180 {
181 Logger.DebugFormat("Error in thread {0} when reading pipe {1}",threadNumber, e.Message);
182 throw new PipeListenerException(
183 string.Format("Error in thread {0} when reading pipe {1}", threadNumber, e.Message), e);
184 }
185
186 }
187 // if we are still listening, we will create a new thread to be used for listening,
188 // otherwhise we will not and not lnger threads will be added. Ofcourse if the rest of the
189 // threads do no add more than one work, we will have no issues with the pipe server since it
190 // has been disposed
191 if (IsListening)
192 {
193 ThreadPool.QueueUserWorkItem(Listen, namedPipeState.NamedPipe);
194 }
195 }
196 catch (PlatformNotSupportedException e)
197 {
198 // are we running on an OS that does not have pipes (Mono on some os)
199 throw new PipeListenerException(string.Format("Cannot listen to pipe {0}", namedPipeState.NamedPipe), e);
200 }
201 catch (IOException e)
202 {
203 // there are too many servers listening to this pipe.
204 throw new PipeListenerException(
205 string.Format("There are too many servers listening to {0}", namedPipeState.NamedPipe), e);
206 }
207 }
208
209 #endregion
210
211 /// <summary>
212 /// Starts listening to the different pipe messages and will perform the appropiate
213 /// action when a message is received.
214 /// </summary>
215 /// <param name="namedPipe">The name fof the pipe to listen.</param>
216 public void StartListening(string namedPipe)
217 {
218 if (NumberOfThreads < 0)
219 {
220 throw new PipeListenerException(
221 "The number of threads to use to listen to the pipe must be at least one.");
222 }
223 // we will be using a thread pool that will allow to have the different threads listening to
224 // the messages of the pipes. There could be issues if the devel provided far to many threads
225 // to listen to the pipe since the number of pipe servers is limited.
226 for (var currentThreaCount = 0; currentThreaCount < NumberOfThreads; currentThreaCount++)
227 {
228 // we add an new thread to listen
229 ThreadPool.QueueUserWorkItem(Listen, new PipeListenerState(namedPipe, MessageProcessor.ProcessMessage));
230 }
231
232 }
233
234 /// <summary>
235 /// Stops listening to the different pipe messages. All the thread that are listening already will
236 /// be forced to stop.
237 /// </summary>
238 public void StopListening()
239 {
240 IsListening = false;
241 }
242
243 }
244}
0245
=== added file 'src/Canonical.UbuntuOne.ProcessDispatcher/PipeListenerException.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/PipeListenerException.cs 1970-01-01 00:00:00 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/PipeListenerException.cs 2010-10-12 10:18:45 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright 2010 Canonical Ltd.
3 *
4 * This file is part of UbuntuOne on Windows.
5 *
6 * UbuntuOne on Windows is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version
8 * as published by the Free Software Foundation.
9 *
10 * Ubuntu One on Windows is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with UbuntuOne for Windows. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */
20using System;
21
22namespace Canonical.UbuntuOne.ProcessDispatcher
23{
24 /// <summary>
25 /// Base class exception thrown where there is an issue while listening to the pipe used
26 /// by python to send messages.
27 /// </summary>
28 public class PipeListenerException : Exception
29 {
30
31 /// <summary>
32 /// Creates a new instance of the exception.
33 /// </summary>
34 public PipeListenerException()
35 {
36
37 }
38
39 /// <summary>
40 /// Creates a new instance of the exception that will carry the given
41 /// message.
42 /// </summary>
43 /// <param name="message">The message to be carrie by the exception.</param>
44 public PipeListenerException(string message)
45 : base(message)
46 {
47
48 }
49
50 /// <summary>
51 /// Creates a new instance of the exception that will carry the given message and
52 /// inner exception.
53 /// </summary>
54 /// <param name="message">The message to be carried by the exception.</param>
55 /// <param name="inner">The inner exception that originated this exception.</param>
56 public PipeListenerException(string message, Exception inner)
57 : base(message, inner)
58 {
59
60 }
61 }
62}
063
=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/Program.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/Program.cs 2010-10-12 10:18:45 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/Program.cs 2010-10-12 10:18:45 +0000
@@ -18,6 +18,7 @@
18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>18 * Authors: Manuel de la Peña <manuel.delapena@canonical.com>
19 */19 */
20using System;20using System;
21using System.Security.Principal;
21using Canonical.UbuntuOne.Common.Container;22using Canonical.UbuntuOne.Common.Container;
22using Canonical.UbuntuOne.Common.Utils;23using Canonical.UbuntuOne.Common.Utils;
23using log4net;24using log4net;
@@ -29,6 +30,8 @@
29 {30 {
30 private static readonly ILog _logger = LogManager.GetLogger(typeof(Program));31 private static readonly ILog _logger = LogManager.GetLogger(typeof(Program));
31 private static readonly ConfigurationLocator _configLocator = new ConfigurationLocator();32 private static readonly ConfigurationLocator _configLocator = new ConfigurationLocator();
33 private static readonly string _listegingPipe =
34 "PythonMessages";
3235
33 /// <summary>36 /// <summary>
34 /// This method starts the service.37 /// This method starts the service.
@@ -71,6 +74,12 @@
71 var syncDaemonWindowsService = ObjectsContainer.GetImplementationOf<SyncDaemonWindowsService>();74 var syncDaemonWindowsService = ObjectsContainer.GetImplementationOf<SyncDaemonWindowsService>();
72 // To run more than one service you have to add them here75 // To run more than one service you have to add them here
73 syncDaemonWindowsService.Start();76 syncDaemonWindowsService.Start();
77 // we need to start listening to the possible messages sent by the python code, we
78 // ensure that it is done to a ipe just for the user
79 var pipeListener = ObjectsContainer.GetImplementationOf<IPipeListener>();
80 var userPipe = _listegingPipe + WindowsIdentity.GetCurrent().Name;
81 _logger.InfoFormat("Listening on {0}", userPipe);
82 pipeListener.StartListening(userPipe);
74 while (true) ;83 while (true) ;
75 });84 });
7685
7786
=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs'
--- src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-10-12 10:18:45 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-10-12 10:18:45 +0000
@@ -283,11 +283,17 @@
283 UseShellExecute = false,283 UseShellExecute = false,
284 RedirectStandardOutput = true,284 RedirectStandardOutput = true,
285 RedirectStandardError = true,285 RedirectStandardError = true,
286 CreateNoWindow = true,286 CreateNoWindow = false,
287 WindowStyle = ProcessWindowStyle.Hidden287 WindowStyle = ProcessWindowStyle.Hidden
288 }288 }
289 };289 };
290 proc.Start();290 proc.Start();
291 // we wait, we are in a diff thread in a diff process this will not block the user UI
292 proc.WaitForExit();
293 var error = proc.StandardError.ReadToEnd();
294 Logger.InfoFormat("StandarOutput from u1sync is: {0}", proc.StandardOutput.ReadToEnd());
295 Logger.ErrorFormat("StandardError from u1sync is: {0}", proc.StandardError.ReadToEnd());
296 proc.Close();
291 }297 }
292298
293 /// <summary>299 /// <summary>
294300
=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/objects.xml'
--- src/Canonical.UbuntuOne.ProcessDispatcher/objects.xml 2010-10-12 10:18:45 +0000
+++ src/Canonical.UbuntuOne.ProcessDispatcher/objects.xml 2010-10-12 10:18:45 +0000
@@ -116,5 +116,24 @@
116 <property name="SyncShares"116 <property name="SyncShares"
117 ref="SyncSharesServiceHost" />117 ref="SyncSharesServiceHost" />
118 </object>118 </object>
119
120 <!-- ###################################################################################################### -->
121 <!-- The pipe listener that will be used to know what the python code wants to tell us -->
122 <!-- ###################################################################################################### -->
123
124 <object id="PipeStreamerFactory"
125 type="Canonical.UbuntuOne.ProcessDispatcher.JsonPipeStreamerFactory, Canonical.UbuntuOne.ProcessDispatcher"
126 autowire="autodetect"/>
127
128 <object id="MessageProcessor"
129 type="Canonical.UbuntuOne.ProcessDispatcher.JsonMessageProcessor, Canonical.UbuntuOne.ProcessDispatcher"
130 autowire="autodetect" />
119 131
132 <object id="PipeListener"
133 type="Canonical.UbuntuOne.ProcessDispatcher.PipeListener, Canonical.UbuntuOne.ProcessDispatcher"
134 autowire="autodetect">
135 <property name="NumberOfThreads"
136 value="5"/>
137 </object>
138
120</objects>139</objects>
121\ No newline at end of file140\ No newline at end of file
122141
=== modified file 'src/Version.cs'
--- src/Version.cs 2010-10-12 10:18:45 +0000
+++ src/Version.cs 2010-10-12 10:18:45 +0000
@@ -10,6 +10,6 @@
10// </auto-generated>10// </auto-generated>
11//------------------------------------------------------------------------------11//------------------------------------------------------------------------------
1212
13[assembly: AssemblyVersionAttribute("1.0.606.5623")]13[assembly: AssemblyVersionAttribute("1.0.611.8185")]
14[assembly: AssemblyFileVersionAttribute("1.0.606.5623")]14[assembly: AssemblyFileVersionAttribute("1.0.611.8185")]
1515
1616
=== modified file 'src/u1sync/main.py'
--- src/u1sync/main.py 2010-09-27 17:33:52 +0000
+++ src/u1sync/main.py 2010-10-12 10:18:45 +0000
@@ -43,7 +43,7 @@
43from u1sync.merge import (43from u1sync.merge import (
44 SyncMerge, ClobberServerMerge, ClobberLocalMerge, merge_trees)44 SyncMerge, ClobberServerMerge, ClobberLocalMerge, merge_trees)
45from u1sync.sync import download_tree, upload_tree45from u1sync.sync import download_tree, upload_tree
46from u1sync.utils import safe_mkdir46from u1sync.utils import safe_mkdir, send_bus_error
47from u1sync import metadata47from u1sync import metadata
48from u1sync.constants import METADATA_DIR_NAME48from u1sync.constants import METADATA_DIR_NAME
49from u1sync.ubuntuone_optparse import UbuntuOneOptionsParser49from u1sync.ubuntuone_optparse import UbuntuOneOptionsParser
@@ -332,21 +332,29 @@
332 try:332 try:
333 do_main(argv, UbuntuOneOptionsParser())333 do_main(argv, UbuntuOneOptionsParser())
334 except AuthenticationError, e:334 except AuthenticationError, e:
335 sed_bus_error("Authentication failed: %s" % e, e)
335 print "Authentication failed: %s" % e336 print "Authentication failed: %s" % e
336 except ConnectionError, e:337 except ConnectionError, e:
338 sed_bus_error("Connection failed: %s" % e, e)
337 print "Connection failed: %s" % e339 print "Connection failed: %s" % e
338 except DirectoryNotInitializedError:340 except DirectoryNotInitializedError, e:
341 sed_bus_error("Directory not initialized", e)
339 print "Directory not initialized; " \342 print "Directory not initialized; " \
340 "use --init [DIRECTORY] to initialize it."343 "use --init [DIRECTORY] to initialize it."
341 except DirectoryAlreadyInitializedError:344 except DirectoryAlreadyInitializedError, e:
345 sed_bus_error("Directory not initialized", e)
342 print "Directory already initialized."346 print "Directory already initialized."
343 except NoSuchShareError:347 except NoSuchShareError, e:
348 sed_bus_error("No matching share found.", e)
344 print "No matching share found."349 print "No matching share found."
345 except ReadOnlyShareError:350 except ReadOnlyShareError, e:
351 sed_bus_error("The selected action isn't possible on a read-only share.", e)
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."
347 except (ForcedShutdown, KeyboardInterrupt):353 except (ForcedShutdown, KeyboardInterrupt), e:
354 sed_bus_error("Interrupted!", e)
348 print "Interrupted!"355 print "Interrupted!"
349 except TreesDiffer, e:356 except TreesDiffer, e:
357 sed_bus_error("Trees differ.", e)
350 if not e.quiet:358 if not e.quiet:
351 print "Trees differ."359 print "Trees differ."
352 else:360 else:
353361
=== modified file 'src/u1sync/utils.py'
--- src/u1sync/utils.py 2010-08-27 14:43:32 +0000
+++ src/u1sync/utils.py 2010-10-12 10:18:45 +0000
@@ -19,7 +19,11 @@
19# with this program. If not, see <http://www.gnu.org/licenses/>.19# with this program. If not, see <http://www.gnu.org/licenses/>.
20"""Miscellaneous utility functions."""20"""Miscellaneous utility functions."""
2121
22import json
22import os23import os
24import getpass
25
26import win32pipe
23from errno import EEXIST, ENOENT27from errno import EEXIST, ENOENT
24from u1sync.constants import (28from u1sync.constants import (
25 METADATA_DIR_NAME, SPECIAL_FILE_RE)29 METADATA_DIR_NAME, SPECIAL_FILE_RE)
@@ -48,3 +52,36 @@
48 except OSError, e:52 except OSError, e:
49 if e.errno != ENOENT:53 if e.errno != ENOENT:
50 raise54 raise
55
56def get_user():
57 """Return the name of the current user."""
58 return r'{0}\{1}'.format(os.getenv('COMPUTERNAME'), getpass.getuser())
59
60def create_error_message(error_message, exception):
61 """Create a new error message"""
62 # hack, I really dislike this, later using protobuf we
63 # can state the type of error, right now, this should do the work.
64 message = {'type':'error',
65 'message':error_message,
66 'expcetion':type(exception.__class__.__name__)}
67 return message
68
69def send_bus_message(message):
70 """Sends a message to a pipe listen by an other lang."""
71 pipe_name = r'\\.\pipe\PythonMessages{0}'.format(get_user())
72 # calulate json representation of the message
73 data_json = json.dumps(message)
74 length = str(len(data_json)/256)
75 length += str(len(data_json)&256)
76 data_json = length + data_json
77 # call the pipe with the message
78 try:
79 data = win32pipe.CallNamedPipe(pipe_name,
80 data_json, len(data_json), 0 )
81 except Exception:
82 print "Error: C# client is not listening!!"
83
84def send_bus_error(error_message, exception):
85 message = create_error_message(error_message, exception)
86 send_bus_message(message)
87
51\ No newline at end of file88\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: