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

Commit e60edf1

Browse files
committed
Did some cleaning. Disabled PushNotificationServices for now...
1 parent 6e8985a commit e60edf1

18 files changed

Lines changed: 262 additions & 283 deletions

CodeHub.Core/App.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Cirrious.MvvmCross.ViewModels;
22
using CodeHub.Core.ViewModels.App;
3+
using CodeFramework.Core.Services;
4+
using Cirrious.CrossCore;
35

46
namespace CodeHub.Core
57
{
@@ -16,6 +18,9 @@ public override void Initialize()
1618
//Ensure this is loaded
1719
Cirrious.MvvmCross.Plugins.Messenger.PluginLoader.Instance.EnsureLoaded();
1820

21+
var httpService = Mvx.Resolve<IHttpClientService>();
22+
GitHubSharp.Client.ClientConstructor = httpService.Create;
23+
1924
// Start the app with the First View Model.
2025
this.RegisterAppStart<StartupViewModel>();
2126
}

CodeHub.Core/CodeHub.Core.iOS.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,13 @@
136136
<Reference Include="Cirrious.MvvmCross">
137137
<HintPath>..\lib\CodeFramework\lib\iOS\Cirrious.MvvmCross.dll</HintPath>
138138
</Reference>
139-
<Reference Include="RestSharp.MonoTouch">
140-
<HintPath>..\lib\GitHubSharp\lib\RestSharp\RestSharp.MonoTouch.dll</HintPath>
141-
</Reference>
142139
<Reference Include="Cirrious.MvvmCross.Plugins.Messenger">
143140
<HintPath>..\lib\CodeFramework\lib\iOS\Cirrious.MvvmCross.Plugins.Messenger.dll</HintPath>
144141
</Reference>
142+
<Reference Include="System.Net.Http" />
143+
<Reference Include="Newtonsoft.Json">
144+
<HintPath>..\lib\GitHubSharp\lib\Newtonsoft.Json.dll</HintPath>
145+
</Reference>
145146
</ItemGroup>
146147
<ItemGroup>
147148
<ProjectReference Include="..\lib\CodeFramework\CodeFramework.Core\CodeFramework.Core.iOS.csproj">

CodeHub.Core/Services/JsonSerializationService.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
using CodeFramework.Core.Services;
2+
using System.Text.RegularExpressions;
23

34
namespace CodeHub.Core.Services
45
{
56
public class JsonSerializationService : IJsonSerializationService
67
{
7-
public string Serialize(object o)
8+
private static readonly Newtonsoft.Json.JsonSerializerSettings Settings = new Newtonsoft.Json.JsonSerializerSettings { ContractResolver = new JsonLowerCaseUnderscoreContractResolver() };
9+
public T Deserialize<T>(string data)
810
{
9-
return new RestSharp.Serializers.JsonSerializer().Serialize(o);
11+
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(data, Settings);
1012
}
1113

12-
public TData Deserialize<TData>(string data)
14+
public string Serialize(object data)
1315
{
14-
return new RestSharp.Deserializers.JsonDeserializer().Deserialize<TData>(new RestSharp.RestResponse { Content = data });
16+
return Newtonsoft.Json.JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.None, Settings);
17+
}
18+
19+
public class JsonLowerCaseUnderscoreContractResolver : Newtonsoft.Json.Serialization.DefaultContractResolver
20+
{
21+
private readonly Regex regex = new Regex("(?!(^[A-Z]))([A-Z])");
22+
23+
protected override string ResolvePropertyName(string propertyName)
24+
{
25+
return regex.Replace(propertyName, "_$2").ToLower();
26+
}
1527
}
1628
}
1729
}

CodeHub.Core/ViewModels/Accounts/AddAccountViewModel.cs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ public class AddAccountViewModel : BaseViewModel
1818
private string _domain;
1919
private bool _isLoggingIn;
2020

21-
public event EventHandler<Exception> LoginException;
22-
23-
protected virtual void OnLoginException(Exception e)
24-
{
25-
var handler = LoginException;
26-
if (handler != null) handler(this, e);
27-
}
28-
2921
public bool IsEnterprise { get; private set; }
3022

3123
public bool IsLoggingIn
@@ -56,7 +48,7 @@ public string Domain
5648

5749
public ICommand LoginCommand
5850
{
59-
get { return new MvxCommand(Login, CanLogin);}
51+
get { return new MvxCommand(() => Login(), CanLogin);}
6052
}
6153

6254
public AddAccountViewModel(IApplicationService application, ILoginService loginService)
@@ -90,7 +82,7 @@ private bool CanLogin()
9082
return true;
9183
}
9284

93-
private async void Login()
85+
private async Task Login()
9486
{
9587
var apiUrl = IsEnterprise ? Domain : null;
9688
if (apiUrl != null)
@@ -103,9 +95,6 @@ private async void Login()
10395
apiUrl += "api/v3/";
10496
}
10597

106-
// Get the accounts service so we can do some special things
107-
Exception exception = null;
108-
10998
try
11099
{
111100
IsLoggingIn = true;
@@ -122,18 +111,13 @@ private async void Login()
122111
if (!(e is LoginService.TwoFactorRequiredException))
123112
{
124113
Password = null;
125-
ReportError(e);
114+
DisplayException(e);
126115
}
127-
128-
exception = e;
129116
}
130117
finally
131118
{
132119
IsLoggingIn = false;
133120
}
134-
135-
if (exception != null)
136-
OnLoginException(exception);
137121
}
138122

139123
public class NavObject

CodeHub.Core/ViewModels/Accounts/LoginViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using CodeHub.Core.Services;
55
using System.Windows.Input;
66
using Cirrious.MvvmCross.ViewModels;
7+
using System.Threading.Tasks;
78

89
namespace CodeHub.Core.ViewModels.Accounts
910
{
@@ -85,7 +86,7 @@ public void Init(NavObject navObject)
8586
}
8687
}
8788

88-
public async void Login(string code)
89+
public async Task Login(string code)
8990
{
9091
string apiUrl;
9192
if (IsEnterprise)

CodeHub.Core/ViewModels/Gists/GistViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public ICommand ToggleStarCommand
8282
{
8383
get
8484
{
85-
return new MvxCommand(ToggleStarred, () => Gist != null);
85+
return new MvxCommand(() => ToggleStarred(), () => Gist != null);
8686
}
8787
}
8888

@@ -91,17 +91,17 @@ public void Init(NavObject navObject)
9191
Id = navObject.Id;
9292
}
9393

94-
private async void ToggleStarred()
94+
private async Task ToggleStarred()
9595
{
9696
try
9797
{
9898
var request = IsStarred ? this.GetApplication().Client.Gists[Id].Unstar() : this.GetApplication().Client.Gists[Id].Star();
9999
await this.GetApplication().Client.ExecuteAsync(request);
100100
IsStarred = !IsStarred;
101101
}
102-
catch (Exception)
102+
catch (Exception e)
103103
{
104-
// Do nothing
104+
ReportError(e);
105105
}
106106
}
107107

CodeHub.Core/ViewModels/NotificationsViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public bool IsMarking
5050

5151
public ICommand ReadCommand
5252
{
53-
get { return _readCommand ?? (_readCommand = new MvxCommand<NotificationModel>(Read));}
53+
get { return _readCommand ?? (_readCommand = new MvxCommand<NotificationModel>(x => Read(x)));}
5454
}
5555

5656
public ICommand ReadRepositoriesCommand
@@ -121,11 +121,12 @@ protected override Task Load(bool forceCacheInvalidation)
121121
});
122122
}
123123

124-
private async void Read(NotificationModel model)
124+
private async Task Read(NotificationModel model)
125125
{
126126
// If its already read, ignore it
127127
if (!model.Unread)
128128
return;
129+
129130
try
130131
{
131132
var response = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Notifications[model.Id].MarkAsRead());

CodeHub.Core/ViewModels/Repositories/RepositoryViewModel.cs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,42 +190,55 @@ protected override Task Load(bool forceCacheInvalidation)
190190

191191
public ICommand ToggleWatchCommand
192192
{
193-
get { return new MvxCommand(ToggleWatch, () => IsWatched != null); }
193+
get { return new MvxCommand(() => ToggleWatch(), () => IsWatched != null); }
194194
}
195195

196-
private async void ToggleWatch()
196+
private async Task ToggleWatch()
197197
{
198198
if (IsWatched == null)
199199
return;
200200

201-
if (IsWatched.Value)
202-
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[RepositoryName].StopWatching());
203-
else
204-
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[RepositoryName].Watch());
205-
206-
IsWatched = !IsWatched;
201+
try
202+
{
203+
if (IsWatched.Value)
204+
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[RepositoryName].StopWatching());
205+
else
206+
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[RepositoryName].Watch());
207+
IsWatched = !IsWatched;
208+
}
209+
catch (Exception e)
210+
{
211+
ReportError(e);
212+
}
207213
}
208214

209215
public ICommand ToggleStarCommand
210216
{
211-
get { return new MvxCommand(ToggleStar, () => IsStarred != null); }
217+
get { return new MvxCommand(() => ToggleStar(), () => IsStarred != null); }
212218
}
213219

214220
public bool IsPinned
215221
{
216222
get { return this.GetApplication().Account.PinnnedRepositories.GetPinnedRepository(Username, RepositoryName) != null; }
217223
}
218224

219-
private async void ToggleStar()
225+
private async Task ToggleStar()
220226
{
221227
if (IsStarred == null)
222228
return;
223229

224-
if (IsStarred.Value)
225-
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[RepositoryName].Unstar());
226-
else
227-
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[RepositoryName].Star());
228-
IsStarred = !IsStarred;
230+
try
231+
{
232+
if (IsStarred.Value)
233+
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[RepositoryName].Unstar());
234+
else
235+
await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[RepositoryName].Star());
236+
IsStarred = !IsStarred;
237+
}
238+
catch (Exception e)
239+
{
240+
ReportError(e);
241+
}
229242
}
230243

231244
public class NavObject

CodeHub.Core/ViewModels/Source/SourceViewModel.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ public class SourceViewModel : FileSourceViewModel
1717
protected override async Task Load(bool forceCacheInvalidation)
1818
{
1919
var filepath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetFileName(_name));
20+
string mime = string.Empty;
2021

21-
var mime = await Task.Run<string>(() =>
22+
using (var stream = new System.IO.FileStream(filepath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
2223
{
23-
using (var stream = new System.IO.FileStream(filepath, System.IO.FileMode.Create, System.IO.FileAccess.Write))
24-
{
25-
return this.GetApplication().Client.DownloadRawResource2(_gitUrl, stream) ?? string.Empty;
26-
}
27-
});
24+
mime = await this.GetApplication().Client.DownloadRawResource2(_gitUrl, stream) ?? string.Empty;
25+
}
2826

2927
FilePath = filepath;
3028

CodeHub.Core/ViewModels/User/ProfileViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public ICommand GoToGistsCommand
7676

7777
public ICommand ToggleFollowingCommand
7878
{
79-
get { return new MvxCommand(ToggleFollowing); }
79+
get { return new MvxCommand(() => ToggleFollowing()); }
8080
}
8181

82-
private async void ToggleFollowing()
82+
private async Task ToggleFollowing()
8383
{
8484
try
8585
{

0 commit comments

Comments
 (0)