@@ -61,7 +61,15 @@ private async Task LogoutInternal(UriString host)
61
61
public async Task CreateRepository ( NewRepository newRepository , Action < Octokit . Repository , Exception > callback , string organization = null )
62
62
{
63
63
Guard . ArgumentNotNull ( callback , "callback" ) ;
64
- await CreateRepositoryInternal ( newRepository , callback , organization ) ;
64
+ try
65
+ {
66
+ var repository = await CreateRepositoryInternal ( newRepository , organization ) ;
67
+ callback ( repository , null ) ;
68
+ }
69
+ catch ( Exception e )
70
+ {
71
+ callback ( null , e ) ;
72
+ }
65
73
}
66
74
67
75
public async Task GetOrganizations ( Action < IList < Organization > > callback )
@@ -71,6 +79,13 @@ public async Task GetOrganizations(Action<IList<Organization>> callback)
71
79
callback ( organizations ) ;
72
80
}
73
81
82
+ public async Task LoadKeychain ( Action < bool > callback )
83
+ {
84
+ Guard . ArgumentNotNull ( callback , "callback" ) ;
85
+ var hasLoadedKeys = await LoadKeychainInternal ( ) ;
86
+ callback ( hasLoadedKeys ) ;
87
+ }
88
+
74
89
public async Task GetCurrentUser ( Action < Octokit . User > callback )
75
90
{
76
91
Guard . ArgumentNotNull ( callback , "callback" ) ;
@@ -174,16 +189,15 @@ public async Task<bool> ContinueLoginAsync(LoginResult loginResult, Func<LoginRe
174
189
return result . Code == LoginResultCodes . Success ;
175
190
}
176
191
177
- private async Task CreateRepositoryInternal ( NewRepository newRepository , Action < Octokit . Repository , Exception > callback , string organization )
192
+ private async Task < Octokit . Repository > CreateRepositoryInternal ( NewRepository newRepository , string organization )
178
193
{
179
194
try
180
195
{
181
196
logger . Trace ( "Creating repository" ) ;
182
197
183
- if ( ! await EnsureKeychainLoaded ( ) )
198
+ if ( ! await LoadKeychainInternal ( ) )
184
199
{
185
- callback ( null , new Exception ( "Keychain Not Loaded" ) ) ;
186
- return ;
200
+ throw new InvalidOperationException ( "The keychain did not load" ) ;
187
201
}
188
202
189
203
Octokit . Repository repository ;
@@ -201,13 +215,12 @@ private async Task CreateRepositoryInternal(NewRepository newRepository, Action<
201
215
}
202
216
203
217
logger . Trace ( "Created Repository" ) ;
204
-
205
- callback ( repository , null ) ;
218
+ return repository ;
206
219
}
207
220
catch ( Exception ex )
208
221
{
209
222
logger . Error ( ex , "Error Creating Repository" ) ;
210
- callback ( null , ex ) ;
223
+ throw ;
211
224
}
212
225
}
213
226
@@ -217,9 +230,9 @@ private async Task<IList<Organization>> GetOrganizationInternal()
217
230
{
218
231
logger . Trace ( "Getting Organizations" ) ;
219
232
220
- if ( ! await EnsureKeychainLoaded ( ) )
233
+ if ( ! await LoadKeychainInternal ( ) )
221
234
{
222
- return null ;
235
+ return new List < Organization > ( ) ;
223
236
}
224
237
225
238
var organizations = await githubClient . Organization . GetAllForCurrent ( ) ;
@@ -246,7 +259,7 @@ private async Task<IList<Organization>> GetOrganizationInternal()
246
259
{
247
260
logger . Trace ( "Getting Organizations" ) ;
248
261
249
- if ( ! await EnsureKeychainLoaded ( ) )
262
+ if ( ! await LoadKeychainInternal ( ) )
250
263
{
251
264
return null ;
252
265
}
@@ -262,27 +275,28 @@ private async Task<IList<Organization>> GetOrganizationInternal()
262
275
return userCache ;
263
276
}
264
277
265
- private async Task < bool > EnsureKeychainLoaded ( )
278
+ private async Task < bool > LoadKeychainInternal ( )
266
279
{
267
- logger . Trace ( "EnsureKeychainLoaded " ) ;
280
+ logger . Trace ( "LoadKeychainInternal " ) ;
268
281
269
282
if ( keychain . HasKeys )
270
283
{
271
284
if ( ! keychain . NeedsLoad )
272
285
{
273
- logger . Trace ( "EnsureKeychainLoaded : Has keys does not need load" ) ;
286
+ logger . Trace ( "LoadKeychainInternal : Has keys does not need load" ) ;
274
287
return true ;
275
288
}
276
289
277
- logger . Trace ( "EnsureKeychainLoaded : Loading" ) ;
290
+ logger . Trace ( "LoadKeychainInternal : Loading" ) ;
278
291
292
+ //TODO: ONE_USER_LOGIN This assumes only ever one user can login
279
293
var uriString = keychain . Connections . First ( ) . Host ;
280
294
var keychainAdapter = await keychain . Load ( uriString ) ;
281
295
282
296
return keychainAdapter . OctokitCredentials != Credentials . Anonymous ;
283
297
}
284
298
285
- logger . Trace ( "EnsureKeychainLoaded : No keys to load" ) ;
299
+ logger . Trace ( "LoadKeychainInternal : No keys to load" ) ;
286
300
287
301
return false ;
288
302
}
0 commit comments