fixes GCM id sending to server

This commit is contained in:
Paul Schneider 2016-07-21 22:02:53 +02:00
commit fcbf3ffeb7
13 changed files with 366 additions and 53 deletions

View file

@ -8,11 +8,12 @@ using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Yavsc.Helpers;
/*
Glyphish icons from
http://www.glyphish.com/
http://www.glyphish.com/
under
http://creativecommons.org/licenses/by/3.0/us/
http://creativecommons.org/licenses/by/3.0/us/
support them by buying the full set / Retina versions
*/
@ -82,35 +83,12 @@ namespace BookAStar
else deviceInfoPage.Focus();
}
public async void RegisterThisDevice()
public async Task PostDeviceInfo()
{
HttpClient client = new HttpClient();
// var request = new HttpRequestMessage(HttpMethod.Post, MainSettings.MobileRegistrationUrl);
// request.Headers.Authorization
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", MainSettings.CurrentUser.YavscTokens.AccessToken);
/* client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")
);*/
var info =PlateformSpecificInstance.GetDeviceInfo();
/* var serSettings = new JsonSerializerSettings(); serSettings.Formatting = Formatting.None; serSettings.StringEscapeHandling = StringEscapeHandling.EscapeNonAscii;*/
client.MaxResponseContentBufferSize = 256000;
using ( client)
{
var json = Newtonsoft.Json.JsonConvert.SerializeObject(info);
/*
var dataString = JsonConvert.SerializeObject(info,serSettings); */
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(MainSettings.MobileRegistrationUrl, content);
if (response.IsSuccessStatusCode)
Debug.WriteLine(@"Device info successfully saved.");
}
var res = PlateformSpecificInstance.InvokeApi(
"gcm/register", PlateformSpecificInstance.GetDeviceInfo());
}
}
}

View file

@ -126,16 +126,14 @@
<Folder Include="Model\Workflow\" />
</ItemGroup>
<ItemGroup>
<Reference Include="Json.NET.Web, Version=1.0.49.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Json.NET.Web">
<HintPath>..\..\packages\Json.NET.Web.1.0.49\lib\portable45-net45+win8+wpa81\Json.NET.Web.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Android">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\Mono.Android.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Plugin.Settings, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugins.Settings.2.1.0\lib\portable-net45+wp8+wpa81+win8+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10\Plugin.Settings.dll</HintPath>
@ -162,6 +160,12 @@
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Yavsc.Client\Yavsc.Client.csproj">
<Project>{67F9D3A8-F71E-4428-913F-C37AE82CDB24}</Project>
<Name>Yavsc.Client</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\..\packages\Xamarin.Forms.2.3.0.107\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.0.107\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View file

@ -5,12 +5,13 @@ using System.Linq;
using System.Text;
using Xamarin.Forms;
using Yavsc.Models.Identity;
namespace BookAStar
{
public class DeviceInfoPage : ContentPage
{
public DeviceInfoPage(GoogleCloudMobileDeclaration infos)
public DeviceInfoPage(IGCMDeclaration infos)
{
Content = new StackLayout
{

View file

@ -6,7 +6,7 @@ using Plugin.Settings.Abstractions;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace BookAStar
@ -69,14 +69,19 @@ namespace BookAStar
}
}
public static string GoogleRegId
public static string GoogleRegId
{
set {
set {
var oldregid = GoogleRegId;
AppSettings.AddOrUpdateValue<string>(GoogleRegIdKey, value);
// TODO If it changed, and there's an identified user,
// Inform the server of it.
if (oldregid != value) App.CurrentApp.RegisterThisDevice();
if (oldregid != value)
{
Task.Run( async () => {
await App.CurrentApp.PostDeviceInfo();
});
}
}
get { return AppSettings.GetValueOrDefault<string>(GoogleRegIdKey); }
}
@ -126,7 +131,9 @@ namespace BookAStar
{
if (olduserid != value.Id)
{
App.CurrentApp.RegisterThisDevice();
Task.Run(async () => {
await App.CurrentApp.PostDeviceInfo();
});
}
}
}

View file

@ -1,4 +1,5 @@
using BookAStar.Model.Auth.Account;
using Yavsc.Models.Identity;
namespace BookAStar
{
@ -16,10 +17,11 @@ namespace BookAStar
void RevokeAccount(string userName);
GoogleCloudMobileDeclaration GetDeviceInfo();
IGCMDeclaration GetDeviceInfo();
void PostDeviceInfo();
TAnswer InvokeApi<TAnswer>(string method, object arg);
object InvokeApi(string method, object arg);
}
}

View file

@ -1,12 +1,36 @@
using System;
using Yavsc.Models;
using Yavsc.Models.Identity;
namespace BookAStar.Model.Auth.Account
{
public class GoogleCloudMobileDeclaration
public class GoogleCloudMobileDeclaration : IGoogleCloudMobileDeclaration
{
public string GCMRegistrationId { get; set; }
public string DeviceId { get; set; }
public string Model { get; set; }
public string Platform { get; set; }
public string Version { get; set; }
public IApplicationUser DeviceOwner
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
public string DeviceOwnerId
{
get;
set;
}
}
}