Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit 87201aa

Browse files
committed
Fixed bugs?
1 parent a6272d1 commit 87201aa

File tree

10 files changed

+131
-80
lines changed

10 files changed

+131
-80
lines changed

CodeHub.Core/ViewModels/Accounts/AccountsViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using CodeHub.Core.Services;
66
using System;
77
using CodeHub.Core.Factories;
8+
using System.Threading.Tasks;
9+
using System.Net;
810

911
namespace CodeHub.Core.ViewModels.Accounts
1012
{
@@ -60,6 +62,14 @@ protected async override void SelectAccount(IAccount account)
6062
else
6163
ShowViewModel<LoginViewModel>(LoginViewModel.NavObject.CreateDontRemember(githubAccount));
6264
}
65+
catch (TaskCanceledException)
66+
{
67+
DisplayAlert("Timeout waiting for a response from GitHub! Please try again.");
68+
}
69+
catch (WebException)
70+
{
71+
DisplayAlert("Unable to communicate with GitHub. Please check your connection and try again.");
72+
}
6373
catch (Exception e)
6474
{
6575
ReportException(e);

CodeHub.Core/ViewModels/App/StartupViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using CodeHub.Core.Services;
55
using System.Linq;
66
using CodeHub.Core.Factories;
7+
using System.Threading.Tasks;
78

89
namespace CodeHub.Core.ViewModels.App
910
{
@@ -71,7 +72,8 @@ protected async override void Startup()
7172
}
7273
catch (Exception e)
7374
{
74-
ReportException(e);
75+
if (!(e is TaskCanceledException))
76+
ReportException(e);
7577
ShowViewModel<Accounts.AccountsViewModel>();
7678
}
7779
finally

CodeHub.Core/ViewModels/Issues/IssueViewModel.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,19 @@ public void Init(NavObject navObject)
164164
});
165165
}
166166

167-
public async Task AddComment(string text)
168-
{
169-
var comment = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].CreateComment(text));
170-
Comments.Items.Add(comment.Data);
167+
public async Task<bool> AddComment(string text)
168+
{
169+
try
170+
{
171+
var comment = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].CreateComment(text));
172+
Comments.Items.Add(comment.Data);
173+
return true;
174+
}
175+
catch (Exception e)
176+
{
177+
DisplayAlert(e.Message);
178+
return false;
179+
}
171180
}
172181

173182
private async Task ToggleState(bool closed)

CodeHub.Core/ViewModels/PullRequests/PullRequestViewModel.cs

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@
1010
using CodeFramework.Core.ViewModels;
1111
using CodeHub.Core.Messages;
1212

13-
namespace CodeHub.Core.ViewModels.PullRequests
13+
namespace CodeHub.Core.ViewModels.PullRequests
1414
{
15-
public class PullRequestViewModel : LoadableViewModel
15+
public class PullRequestViewModel : LoadableViewModel
1616
{
1717
private MvxSubscriptionToken _issueEditSubscription;
1818
private MvxSubscriptionToken _pullRequestEditSubscription;
1919

20-
public long Id
20+
public long Id
2121
{
2222
get;
2323
private set;
2424
}
2525

26-
public string Username
26+
public string Username
2727
{
2828
get;
2929
private set;
3030
}
3131

32-
public string Repository
32+
public string Repository
3333
{
3434
get;
3535
private set;
@@ -41,37 +41,58 @@ public string MarkdownDescription
4141
}
4242

4343
private bool _merged;
44+
4445
public bool Merged
4546
{
4647
get { return _merged; }
47-
set { _merged = value; RaisePropertyChanged(() => Merged); }
48+
set
49+
{
50+
_merged = value;
51+
RaisePropertyChanged(() => Merged);
52+
}
4853
}
4954

5055
private IssueModel _issueModel;
56+
5157
public IssueModel Issue
5258
{
5359
get { return _issueModel; }
54-
set { _issueModel = value; RaisePropertyChanged(() => Issue); }
60+
set
61+
{
62+
_issueModel = value;
63+
RaisePropertyChanged(() => Issue);
64+
}
5565
}
5666

5767
private PullRequestModel _model;
58-
public PullRequestModel PullRequest
68+
69+
public PullRequestModel PullRequest
5970
{
6071
get { return _model; }
61-
set { _model = value; RaisePropertyChanged(() => PullRequest); }
72+
set
73+
{
74+
_model = value;
75+
RaisePropertyChanged(() => PullRequest);
76+
}
6277
}
6378

6479
private bool _isModifying;
80+
6581
public bool IsModifying
6682
{
6783
get { return _isModifying; }
68-
set { _isModifying = value; RaisePropertyChanged(() => IsModifying); }
84+
set
85+
{
86+
_isModifying = value;
87+
RaisePropertyChanged(() => IsModifying);
88+
}
6989
}
7090

7191
private ICommand _goToAssigneeCommand;
92+
7293
public ICommand GoToAssigneeCommand
7394
{
74-
get
95+
get
7596
{
7697
if (_goToAssigneeCommand == null)
7798
{
@@ -90,9 +111,10 @@ public ICommand GoToAssigneeCommand
90111
}
91112

92113
private ICommand _goToMilestoneCommand;
114+
93115
public ICommand GoToMilestoneCommand
94116
{
95-
get
117+
get
96118
{
97119
if (_goToMilestoneCommand == null)
98120
{
@@ -111,9 +133,10 @@ public ICommand GoToMilestoneCommand
111133
}
112134

113135
private ICommand _goToLabelsCommand;
136+
114137
public ICommand GoToLabelsCommand
115138
{
116-
get
139+
get
117140
{
118141
if (_goToLabelsCommand == null)
119142
{
@@ -133,16 +156,18 @@ public ICommand GoToLabelsCommand
133156

134157
public ICommand GoToEditCommand
135158
{
136-
get
159+
get
137160
{
138-
return new MvxCommand(() => {
161+
return new MvxCommand(() =>
162+
{
139163
GetService<IViewModelTxService>().Add(Issue);
140164
ShowViewModel<IssueEditViewModel>(new IssueEditViewModel.NavObject { Username = Username, Repository = Repository, Id = Id });
141165
}, () => Issue != null);
142166
}
143167
}
144168

145169
private ICommand _shareCommmand;
170+
146171
public new ICommand ShareCommand
147172
{
148173
get
@@ -162,7 +187,7 @@ public ICommand ToggleStateCommand
162187
{
163188
get { return new MvxCommand(() => ToggleState(PullRequest.State == "open")); }
164189
}
165-
190+
166191
public ICommand GoToCommitsCommand
167192
{
168193
get { return new MvxCommand(() => ShowViewModel<PullRequestCommitsViewModel>(new PullRequestCommitsViewModel.NavObject { Username = Username, Repository = Repository, PullRequestId = Id })); }
@@ -174,17 +199,19 @@ public ICommand GoToFilesCommand
174199
}
175200

176201
private readonly CollectionViewModel<IssueCommentModel> _comments = new CollectionViewModel<IssueCommentModel>();
202+
177203
public CollectionViewModel<IssueCommentModel> Comments
178204
{
179205
get { return _comments; }
180206
}
181207

182208
private readonly CollectionViewModel<IssueEventModel> _events = new CollectionViewModel<IssueEventModel>();
209+
183210
public CollectionViewModel<IssueEventModel> Events
184211
{
185212
get { return _events; }
186213
}
187-
214+
188215
public string ConvertToMarkdown(string str)
189216
{
190217
return (GetService<IMarkdownService>().Convert(str));
@@ -211,10 +238,19 @@ public void Init(NavObject navObject)
211238
});
212239
}
213240

214-
public async Task AddComment(string text)
241+
public async Task<bool> AddComment(string text)
215242
{
216-
var comment = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].CreateComment(text));
217-
Comments.Items.Add(comment.Data);
243+
try
244+
{
245+
var comment = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].CreateComment(text));
246+
Comments.Items.Add(comment.Data);
247+
return true;
248+
}
249+
catch (Exception e)
250+
{
251+
DisplayAlert(e.Message);
252+
return false;
253+
}
218254
}
219255

220256
private async Task ToggleState(bool closed)
@@ -235,20 +271,20 @@ private async Task ToggleState(bool closed)
235271
}
236272
}
237273

238-
protected override Task Load(bool forceCacheInvalidation)
274+
protected override Task Load(bool forceCacheInvalidation)
239275
{
240276
var pullRequest = this.GetApplication().Client.Users[Username].Repositories[Repository].PullRequests[Id].Get();
241-
var t1 = this.RequestModel(pullRequest, forceCacheInvalidation, response => PullRequest = response.Data);
277+
var t1 = this.RequestModel(pullRequest, forceCacheInvalidation, response => PullRequest = response.Data);
242278
Events.SimpleCollectionLoad(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].GetEvents(), forceCacheInvalidation).FireAndForget();
243279
Comments.SimpleCollectionLoad(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].GetComments(), forceCacheInvalidation).FireAndForget();
244280
this.RequestModel(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].Get(), forceCacheInvalidation, response => Issue = response.Data).FireAndForget();
245281
return t1;
246282
}
247283

248-
public async Task Merge()
284+
public async Task Merge()
249285
{
250286
var response = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[Repository].PullRequests[Id].Merge());
251-
if (!response.Data.Merged)
287+
if (!response.Data.Merged)
252288
throw new Exception(response.Data.Message);
253289

254290
var pullRequest = this.GetApplication().Client.Users[Username].Repositories[Repository].PullRequests[Id].Get();
@@ -270,7 +306,9 @@ private bool CanMerge()
270306
public class NavObject
271307
{
272308
public string Username { get; set; }
309+
273310
public string Repository { get; set; }
311+
274312
public long Id { get; set; }
275313
}
276314
}

CodeHub.Core/ViewModels/Repositories/UserRepositoriesViewModel.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,23 @@
77

88
namespace CodeHub.Core.ViewModels.User
99
{
10-
class UserRepositoriesViewModel : RepositoriesViewModel
10+
public class UserRepositoriesViewModel : RepositoriesViewModel
1111
{
12-
public string Username
13-
{
14-
get;
15-
private set;
16-
}
12+
public string Username { get; private set; }
1713

1814
public void Init(NavObject navObject)
1915
{
2016
Username = navObject.Username;
2117
}
2218

23-
protected override Task Load(bool forceDataRefresh)
19+
protected override Task Load(bool forceCacheInvalidation)
2420
{
2521
GitHubRequest<List<RepositoryModel>> request;
26-
if (string.Equals(this.GetApplication().Account.Username, Username, StringComparison.OrdinalIgnoreCase))
27-
request = this.GetApplication().Client.AuthenticatedUser.Repositories.GetAll();
22+
if (string.Equals(this.GetApplication().Account.Username, Username, StringComparison.OrdinalIgnoreCase))
23+
request = this.GetApplication().Client.AuthenticatedUser.Repositories.GetAll();
2824
else
29-
request = this.GetApplication().Client.Users[Username].Repositories.GetAll();
30-
return Repositories.SimpleCollectionLoad(request, forceDataRefresh);
25+
request = this.GetApplication().Client.Users[Username].Repositories.GetAll();
26+
return Repositories.SimpleCollectionLoad(request, forceCacheInvalidation);
3127
}
3228

3329
public class NavObject

CodeHub.iOS/InAppPurchases.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ private void RestoreTransaction (SKPaymentTransaction transaction)
9191
private void FailedTransaction (SKPaymentTransaction transaction)
9292
{
9393
SKPaymentQueue.DefaultQueue.FinishTransaction(transaction);
94-
OnPurchaseError(new Exception(transaction.Error.LocalizedDescription));
94+
var errorString = transaction.Error != null ? transaction.Error.LocalizedDescription : "Unable to process transaction!";
95+
OnPurchaseError(new Exception(errorString));
9596
}
9697

9798
private class TransactionObserver : SKPaymentTransactionObserver
@@ -105,22 +106,29 @@ public TransactionObserver(InAppPurchases inAppPurchases)
105106

106107
public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
107108
{
108-
Console.WriteLine ("UpdatedTransactions");
109109
foreach (SKPaymentTransaction transaction in transactions)
110110
{
111-
switch (transaction.TransactionState)
111+
try
112112
{
113-
case SKPaymentTransactionState.Purchased:
114-
_inAppPurchases.CompleteTransaction(transaction);
115-
break;
116-
case SKPaymentTransactionState.Failed:
117-
_inAppPurchases.FailedTransaction(transaction);
118-
break;
119-
case SKPaymentTransactionState.Restored:
120-
_inAppPurchases.RestoreTransaction(transaction);
121-
break;
122-
default:
123-
break;
113+
switch (transaction.TransactionState)
114+
{
115+
case SKPaymentTransactionState.Purchased:
116+
_inAppPurchases.CompleteTransaction(transaction);
117+
break;
118+
case SKPaymentTransactionState.Failed:
119+
_inAppPurchases.FailedTransaction(transaction);
120+
break;
121+
case SKPaymentTransactionState.Restored:
122+
_inAppPurchases.RestoreTransaction(transaction);
123+
break;
124+
default:
125+
break;
126+
}
127+
}
128+
catch (Exception e)
129+
{
130+
MonoTouch.Utilities.ShowAlert("Error", "Unable to process transaction: " + e.Message);
131+
e.Report();
124132
}
125133
}
126134
}

0 commit comments

Comments
 (0)