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

Commit

Permalink
Better cache loading support
Browse files Browse the repository at this point in the history
  • Loading branch information
thedillonb committed Apr 16, 2014
1 parent 32f5490 commit 394b6c1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
33 changes: 10 additions & 23 deletions CodeHub.Core/ViewModels/ViewModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace CodeHub.Core.ViewModels
{
public static class ViewModelExtensions
{
public static Task RequestModel<TRequest>(this MvxViewModel viewModel, GitHubRequest<TRequest> request, bool forceDataRefresh, Action<GitHubResponse<TRequest>> update) where TRequest : new()
public static async Task RequestModel<TRequest>(this MvxViewModel viewModel, GitHubRequest<TRequest> request, bool forceDataRefresh, Action<GitHubResponse<TRequest>> update) where TRequest : new()
{
if (forceDataRefresh)
{
Expand All @@ -23,29 +23,16 @@ public static class ViewModelExtensions
var application = Mvx.Resolve<IApplicationService>();
var uiThrad = Mvx.Resolve<IUIThreadService>();

return Task.Run(async () =>
{
var result = await application.Client.ExecuteAsync(request).ConfigureAwait(false);
uiThrad.MarshalOnUIThread(() => update(result));

if (result.WasCached)
{
request.RequestFromCache = false;
var result = await application.Client.ExecuteAsync(request).ConfigureAwait(false);
uiThrad.MarshalOnUIThread(() => update(result));

Task.Run(async () =>
{
try
{
var r = await application.Client.ExecuteAsync(request).ConfigureAwait(false);
uiThrad.MarshalOnUIThread(() => update(r));
}
catch (NotModifiedException)
{
System.Diagnostics.Debug.WriteLine("Not modified: " + request.Url);
}
}).FireAndForget();
}
});
if (result.WasCached)
{
request.RequestFromCache = false;
var uncachedTask = application.Client.ExecuteAsync(request);
uncachedTask.FireAndForget();
uncachedTask.ContinueWith(t => uiThrad.MarshalOnUIThread(() => update(t.Result)), TaskContinuationOptions.OnlyOnRanToCompletion);
}
}

public static void CreateMore<T>(this MvxViewModel viewModel, GitHubResponse<T> response,
Expand Down
5 changes: 2 additions & 3 deletions CodeHub.iOS/CodeHub.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchUseThumb>true</MtouchUseThumb>
<MtouchI18n>
</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<IpaPackageName>
</IpaPackageName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">
<DebugType>none</DebugType>
Expand All @@ -96,7 +97,6 @@
<CodesignProvision>Automatic:AdHoc</CodesignProvision>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<DefineConstants>DEBUG</DefineConstants>
<MtouchExtraArgs>--linkskip=CodeFramework.Core.iOS --linkskip=CodeFramework.iOS --linkskip=CodeHub.Core.iOS --linkskip=CodeHub.iOS</MtouchExtraArgs>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' ">
<DebugType>none</DebugType>
Expand All @@ -107,7 +107,6 @@
<ConsolePause>False</ConsolePause>
<CodesignKey>iPhone Distribution</CodesignKey>
<CodesignProvision>Automatic:AppStore</CodesignProvision>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchUseThumb>true</MtouchUseThumb>
<IpaPackageName>
</IpaPackageName>
Expand Down

0 comments on commit 394b6c1

Please sign in to comment.