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

Proposed by Manuel de la Peña
Status: Merged
Approved by: Manuel de la Peña
Approved revision: 129
Merged at revision: 111
Proposed branch: lp:~mandel/ubuntuone-windows-installer/fix_659848_and_659876
Merge into: lp:ubuntuone-windows-installer/beta
Prerequisite: lp:~mandel/ubuntuone-windows-installer/add_preferences_dialog
Diff against target: 313 lines (+101/-56)
6 files modified
src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs (+5/-0)
src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs (+7/-0)
src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs (+65/-55)
src/UbuntuOneClient.Tests/ProgramFixture.cs (+14/-1)
src/UbuntuOneClient/Program.cs (+8/-0)
src/UbuntuOneClient/objects.xml (+2/-0)
To merge this branch: bzr merge lp:~mandel/ubuntuone-windows-installer/fix_659848_and_659876
Reviewer Review Type Date Requested Status
Ubuntu One hackers Pending
Review via email: mp+38320@code.launchpad.net

Description of the change

Fix lp:659848 by calling the presenter and loading the settings. Fix lp:659876 by ensureing that just one process can be executed.

To post a comment you must log in.
129. By Manuel de la Peña

Updated program test to work with the new design.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs'
2--- src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs 2010-10-13 18:35:59 +0000
3+++ src/Canonical.UbuntuOne.Client/Preferences/IPreferencesDialogPresenter.cs 2010-10-13 18:36:00 +0000
4@@ -31,5 +31,10 @@
5 /// Updates the preferences that the user will use in the application.
6 /// </summary>
7 void UpdatePreferences();
8+
9+ /// <summary>
10+ /// Allows to load the preferences in the application so that they are used.
11+ /// </summary>
12+ void LoadPreferences();
13 }
14 }
15
16=== modified file 'src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs'
17--- src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-10-13 18:35:59 +0000
18+++ src/Canonical.UbuntuOne.Client/Preferences/PreferencesDialogPresenter.cs 2010-10-13 18:36:00 +0000
19@@ -178,5 +178,12 @@
20 }
21 PreferencesManager.Save();
22 }
23+
24+ public void LoadPreferences()
25+ {
26+ if(PreferencesManager.IsAutoSyncEnable)
27+ // we get the credentials, because we have register an action to the credetials aquired, we do nothing besides this
28+ SSOCredentialsProvider.LoginToGetCredentials();
29+ }
30 }
31 }
32
33=== modified file 'src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs'
34--- src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-10-13 18:35:59 +0000
35+++ src/Canonical.UbuntuOne.ProcessDispatcher/SyncDaemonService.cs 2010-10-13 18:36:00 +0000
36@@ -122,6 +122,8 @@
37 private Thread _autoManualSyncThread;
38 private bool _isAutoManualSync;
39 private readonly object _isAutoManualSyncLock = new object();
40+ private Process _u1syncProcess;
41+ private readonly object _u1syncProcessLock = new object();
42
43 #endregion
44
45@@ -207,10 +209,10 @@
46
47 #region Helpers
48
49-
50+
51 private void AutoManualSync(object o)
52 {
53- var state = (AutoSyncState) o;
54+ var state = (AutoSyncState)o;
55 // TODO: Doing this might be an issue later in the project. In this case the aouth info is kept in the thread and
56 // if there are changes, we will not know it. Is better to use the SSO lib to get the data and then perform the sync.
57
58@@ -223,7 +225,7 @@
59 (sender, args) => ManualSync(state.Path, state.Token, state.TokenSecret, state.ConsumerKey, state.ConsumerSecret);
60
61 // we got the number of seconds, therefor multiple by 1000 the value
62- manualSyncTimer.Interval = state.Seconds*1000;
63+ manualSyncTimer.Interval = state.Seconds * 1000;
64 manualSyncTimer.Enabled = true;
65 //stay here forever until we are killed
66 while (IsAutoManualSync)
67@@ -373,59 +375,67 @@
68 {
69 Directory.CreateDirectory(path);
70 }
71- if (!Directory.Exists(Path.Combine(path, ".ubuntuone-sync")))
72+ if (!Directory.Exists(Path.Combine(path, ".ubuntuone-sync")) && _u1syncProcess == null)
73 {
74- var initCommand = String.Format("{0} --init \"{1}\" --oauth {2}",
75- Path.Combine(u1SyncPath, "main.exe"),
76- path, tokens);
77- Logger.DebugFormat("Executing {0} as user.", initCommand);
78-
79- //init the directory
80- var init = new Process
81- {
82- StartInfo =
83+ lock (_u1syncProcessLock)
84+ {
85+ var initCommand = String.Format("{0} --init \"{1}\" --oauth {2}",
86+ Path.Combine(u1SyncPath, "main.exe"),
87+ path, tokens);
88+ Logger.DebugFormat("Executing {0} as user.", initCommand);
89+
90+ //init the directory
91+ _u1syncProcess = new Process
92+ {
93+ StartInfo =
94+ {
95+ WorkingDirectory = u1SyncPath,
96+ FileName = Path.Combine(u1SyncPath, "main.exe"),
97+ Arguments = String.Format(" --init \"{0}\" --oauth {1}", path, tokens),
98+ UseShellExecute = false,
99+ RedirectStandardOutput = true,
100+ RedirectStandardError = true,
101+ CreateNoWindow = true,
102+ WindowStyle = ProcessWindowStyle.Hidden
103+
104+ }
105+ };
106+ Logger.InfoFormat("Executing u1sync with args: {0}", _u1syncProcess.StartInfo.Arguments);
107+ _u1syncProcess.Start();
108+ _u1syncProcess.WaitForExit();
109+ Logger.InfoFormat("StandarOutput from u1sync is: {0}", _u1syncProcess.StandardOutput.ReadToEnd());
110+ Logger.ErrorFormat("StandardError from u1sync is: {0}", _u1syncProcess.StandardError.ReadToEnd());
111+ _u1syncProcess.Close();
112+ _u1syncProcess = null;
113+ }
114+
115+ }
116+ if (_u1syncProcess == null)
117+ lock (_u1syncProcessLock)
118+ {
119+ var syncCommand = String.Format("{0} --oauth {1}", Path.Combine(u1SyncPath, "main.exe"), tokens);
120+ _u1syncProcess = new Process
121 {
122- WorkingDirectory = u1SyncPath,
123- FileName = Path.Combine(u1SyncPath, "main.exe"),
124- Arguments = String.Format(" --init \"{0}\" --oauth {1}", path, tokens),
125- UseShellExecute = false,
126- RedirectStandardOutput = true,
127- RedirectStandardError = true,
128- CreateNoWindow = true,
129- WindowStyle = ProcessWindowStyle.Hidden
130-
131- }
132- };
133- Logger.InfoFormat("Executing u1sync with args: {0}", init.StartInfo.Arguments);
134- init.Start();
135- init.WaitForExit();
136- Logger.InfoFormat("StandarOutput from u1sync is: {0}", init.StandardOutput.ReadToEnd());
137- Logger.ErrorFormat("StandardError from u1sync is: {0}", init.StandardError.ReadToEnd());
138- init.Close();
139-
140- }
141- var syncCommand = String.Format("{0} --oauth {1}", Path.Combine(u1SyncPath, "main.exe"), tokens);
142- var proc = new Process
143- {
144- StartInfo =
145- {
146- WorkingDirectory = u1SyncPath,
147- FileName = Path.Combine(u1SyncPath, "main.exe"),
148- Arguments = String.Format("\"{0}\" --oauth {1}", path, tokens),
149- UseShellExecute = false,
150- RedirectStandardOutput = true,
151- RedirectStandardError = true,
152- CreateNoWindow = true,
153- WindowStyle = ProcessWindowStyle.Hidden
154+ StartInfo =
155+ {
156+ WorkingDirectory = u1SyncPath,
157+ FileName = Path.Combine(u1SyncPath, "main.exe"),
158+ Arguments = String.Format("\"{0}\" --oauth {1}", path, tokens),
159+ UseShellExecute = false,
160+ RedirectStandardOutput = true,
161+ RedirectStandardError = true,
162+ CreateNoWindow = true,
163+ WindowStyle = ProcessWindowStyle.Hidden
164+ }
165+ };
166+ _u1syncProcess.Start();
167+ // we wait, we are in a diff thread in a diff process this will not block the user UI
168+ _u1syncProcess.WaitForExit();
169+ var error = _u1syncProcess.StandardError.ReadToEnd();
170+ Logger.InfoFormat("StandarOutput from u1sync is: {0}", _u1syncProcess.StandardOutput.ReadToEnd());
171+ Logger.ErrorFormat("StandardError from u1sync is: {0}", _u1syncProcess.StandardError.ReadToEnd());
172+ _u1syncProcess.Close();
173 }
174- };
175- proc.Start();
176- // we wait, we are in a diff thread in a diff process this will not block the user UI
177- proc.WaitForExit();
178- var error = proc.StandardError.ReadToEnd();
179- Logger.InfoFormat("StandarOutput from u1sync is: {0}", proc.StandardOutput.ReadToEnd());
180- Logger.ErrorFormat("StandardError from u1sync is: {0}", proc.StandardError.ReadToEnd());
181- proc.Close();
182 }
183
184 /// <summary>
185@@ -439,7 +449,7 @@
186 /// <param name="numberOfSeconds">The number of seconds that the timer will wiat everytime it executes the sync.</param>
187 public void EnableManualSyncAutoExecution(string path, string token, string tokenSecret, string consumerKey, string consumerSecret, int numberOfSeconds)
188 {
189- if(AutoManualSyncThread != null)
190+ if (AutoManualSyncThread != null)
191 // we are already doing it, ignore
192 return;
193 Logger.InfoFormat("Enabling auto sync every {0} seconds", numberOfSeconds);
194@@ -447,7 +457,7 @@
195 // we set var to tell that we are going to perform the auto execution
196 IsAutoManualSync = true;
197 // we create the tread
198- AutoManualSyncThread = new Thread(AutoManualSync) {Name = "AutoManualSyncThread"};
199+ AutoManualSyncThread = new Thread(AutoManualSync) { Name = "AutoManualSyncThread" };
200 AutoManualSyncThread.Start(state);
201 }
202
203
204=== modified file 'src/UbuntuOneClient.Tests/ProgramFixture.cs'
205--- src/UbuntuOneClient.Tests/ProgramFixture.cs 2010-09-29 11:41:10 +0000
206+++ src/UbuntuOneClient.Tests/ProgramFixture.cs 2010-10-13 18:36:00 +0000
207@@ -20,6 +20,7 @@
208 using System;
209 using System.Windows;
210 using Canonical.UbuntuOne.Client.Notification;
211+using Canonical.UbuntuOne.Client.Preferences;
212 using Canonical.UbuntuOne.Common.Update;
213 using Canonical.UbuntuOne.Common.Utils;
214 using NUnit.Framework;
215@@ -40,6 +41,7 @@
216 private IApplication _app;
217 private MockRepository _mocks;
218 private Program _program;
219+ private IPreferencesDialogPresenter _preferencesDialogPresenter;
220
221 #endregion
222
223@@ -52,11 +54,13 @@
224 _updater = _mocks.StrictMock<IUpdater>();
225 _notifyIcon = _mocks.StrictMock<INotificationIconView>();
226 _app = _mocks.StrictMock<IApplication>();
227+ _preferencesDialogPresenter = _mocks.StrictMock<IPreferencesDialogPresenter>();
228 _program = new Program
229 {
230 NotifyIcon = _notifyIcon,
231 Updater = _updater,
232- Application = _app
233+ Application = _app,
234+ PreferencesDialogPresenter = _preferencesDialogPresenter
235 };
236 }
237
238@@ -88,6 +92,9 @@
239 // fail if we perform the update.
240 Expect.Call(_updater.UpdatesArePresent())
241 .Return(false);
242+
243+ Expect.Call(() => _preferencesDialogPresenter.LoadPreferences())
244+ .Repeat.Once();
245 }
246 using (_mocks.Playback())
247 {
248@@ -113,6 +120,9 @@
249 Expect.Call(_updater.UpdatesArePresent())
250 .Return(true);
251
252+ Expect.Call(() => _preferencesDialogPresenter.LoadPreferences())
253+ .Repeat.Once();
254+
255 Expect.Call(() => _updater.PerformUpdate())
256 .Repeat.Any();
257 }
258@@ -139,6 +149,9 @@
259 Expect.Call(_updater.UpdatesArePresent())
260 .Throw(new SelfUpdateException());
261
262+ Expect.Call(() => _preferencesDialogPresenter.LoadPreferences())
263+ .Repeat.Once();
264+
265 }
266 using (_mocks.Playback())
267 {
268
269=== modified file 'src/UbuntuOneClient/Program.cs'
270--- src/UbuntuOneClient/Program.cs 2010-10-13 18:35:59 +0000
271+++ src/UbuntuOneClient/Program.cs 2010-10-13 18:36:00 +0000
272@@ -21,6 +21,7 @@
273 using System.Threading;
274 using System.Windows;
275 using Canonical.UbuntuOne.Client.Notification;
276+using Canonical.UbuntuOne.Client.Preferences;
277 using Canonical.UbuntuOne.Common.Container;
278 using Canonical.UbuntuOne.Common.Update;
279 using Canonical.UbuntuOne.Common.Utils;
280@@ -91,6 +92,10 @@
281 /// </summary>
282 internal IApplication Application { get; set; }
283
284+ /// <summary>
285+ /// Allows to get and set the presenter that knows how to deal with the settings.
286+ /// </summary>
287+ internal IPreferencesDialogPresenter PreferencesDialogPresenter { get; set; }
288 #endregion
289
290 #region Helper methods
291@@ -126,6 +131,9 @@
292 // that way we will not stop the execution of the application while we chec the rss feed.
293 _updatesThread = new Thread(CheckForUpdates);
294 _updatesThread.Start();
295+ // we are goign to load the current settings
296+ // TODO: using the presenter here is very ugly.
297+ PreferencesDialogPresenter.LoadPreferences();
298 // we do not worry about looping to allow the other thread to finish, we no that app should take longer
299 Application.Run(NotifyIcon as Window);
300 }
301
302=== modified file 'src/UbuntuOneClient/objects.xml'
303--- src/UbuntuOneClient/objects.xml 2010-10-13 18:35:59 +0000
304+++ src/UbuntuOneClient/objects.xml 2010-10-13 18:36:00 +0000
305@@ -55,6 +55,8 @@
306 autowire="autodetect" >
307 <property name="Application"
308 ref="Application" />
309+ <property name="PreferencesDialogPresenter"
310+ ref="PreferencesDialogPresenter" />
311 </object>
312
313 <!-- ############################################################### -->

Subscribers

People subscribed via source and target branches

to all changes: