Browse Source

Merge branch 'feature/track-user-location-mongodb' of https://github.com/dotnet-architecture/eShopOnContainers into feature/track-user-location-mongodb

pull/223/head
Ramón Tomás 7 years ago
parent
commit
f0cb13b96e
9 changed files with 312 additions and 24 deletions
  1. +3
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/GlobalSettings.cs
  2. +39
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs
  3. +8
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Models/Location/LocationRequest.cs
  4. +10
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Location/ILocationService.cs
  5. +28
    -0
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Location/LocationService.cs
  6. +6
    -4
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs
  7. +140
    -16
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs
  8. +74
    -3
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml
  9. +4
    -1
      src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj

+ 3
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/GlobalSettings.cs View File

@ -43,6 +43,8 @@
public string IdentityEndpoint { get; set; }
public string LocationEndpoint { get; set; }
public string UserInfoEndpoint { get; set; }
public string LogoutEndpoint { get; set; }
@ -62,6 +64,7 @@
LogoutEndpoint = string.Format("{0}:5105/connect/endsession", baseEndpoint);
IdentityCallback = string.Format("{0}:5105/xamarincallback", baseEndpoint);
LogoutCallback = string.Format("{0}:5105/Account/Redirecting", baseEndpoint);
LocationEndpoint = string.Format("{0}:5109", baseEndpoint);
}
}
}

+ 39
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Helpers/Settings.cs View File

@ -24,9 +24,13 @@ namespace eShopOnContainers.Core.Helpers
private const string IdToken = "id_token";
private const string IdUseMocks = "use_mocks";
private const string IdUrlBase = "url_base";
private const string IdUseFakeLocation = "use_fake_location";
private const string IdFakeLatitude = "fake_latitude";
private const string IdFakeLongitude = "fake_longitude";
private static readonly string AccessTokenDefault = string.Empty;
private static readonly string IdTokenDefault = string.Empty;
private static readonly bool UseMocksDefault = true;
private static readonly bool UseFakeLocationDefault = false;
private static readonly string UrlBaseDefault = GlobalSetting.Instance.BaseEndpoint;
#endregion
@ -78,5 +82,40 @@ namespace eShopOnContainers.Core.Helpers
AppSettings.AddOrUpdateValue<string>(IdUrlBase, value);
}
}
public static bool UseFakeLocation
{
get
{
return AppSettings.GetValueOrDefault<bool>(IdUseFakeLocation, UseFakeLocationDefault);
}
set
{
AppSettings.AddOrUpdateValue<bool>(IdUseFakeLocation, value);
}
}
public static double FakeLatitude
{
get
{
return AppSettings.GetValueOrDefault<double>(IdFakeLatitude);
}
set
{
AppSettings.AddOrUpdateValue<double>(IdFakeLatitude, value);
}
}
public static double FakeLongitude
{
get
{
return AppSettings.GetValueOrDefault<double>(IdFakeLongitude);
}
set
{
AppSettings.AddOrUpdateValue<double>(IdFakeLongitude, value);
}
}
}
}

+ 8
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Models/Location/LocationRequest.cs View File

@ -0,0 +1,8 @@
namespace eShopOnContainers.Core.Models.Location
{
public class LocationRequest
{
public double Longitude { get; set; }
public double Latitude { get; set; }
}
}

+ 10
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Location/ILocationService.cs View File

@ -0,0 +1,10 @@
namespace eShopOnContainers.Core.Services.Location
{
using System.Threading.Tasks;
using eShopOnContainers.Core.Models.Location;
public interface ILocationService
{
Task UpdateUserLocation(LocationRequest newLocReq);
}
}

+ 28
- 0
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Services/Location/LocationService.cs View File

@ -0,0 +1,28 @@
namespace eShopOnContainers.Core.Services.Location
{
using eShopOnContainers.Core.Models.Location;
using eShopOnContainers.Core.Services.RequestProvider;
using System;
using System.Threading.Tasks;
public class LocationService : ILocationService
{
private readonly IRequestProvider _requestProvider;
public LocationService(IRequestProvider requestProvider)
{
_requestProvider = requestProvider;
}
public async Task UpdateUserLocation(LocationRequest newLocReq)
{
UriBuilder builder = new UriBuilder(GlobalSetting.Instance.LocationEndpoint);
builder.Path = "api/v1/locations";
string uri = builder.ToString();
var result = await _requestProvider.PostAsync(uri, newLocReq);
}
}
}

+ 6
- 4
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/Base/ViewModelLocator.cs View File

@ -11,6 +11,7 @@ using eShopOnContainers.Core.Services.Identity;
using eShopOnContainers.Core.Services.Order;
using eShopOnContainers.Core.Services.User;
using Xamarin.Forms;
using eShopOnContainers.Core.Services.Location;
namespace eShopOnContainers.Core.ViewModels.Base
{
@ -53,24 +54,25 @@ namespace eShopOnContainers.Core.ViewModels.Base
builder.RegisterType<OpenUrlService>().As<IOpenUrlService>();
builder.RegisterType<IdentityService>().As<IIdentityService>();
builder.RegisterType<RequestProvider>().As<IRequestProvider>();
builder.RegisterType<LocationService>().As<ILocationService>().SingleInstance();
if (useMockServices)
if (useMockServices)
{
builder.RegisterInstance(new CatalogMockService()).As<ICatalogService>();
builder.RegisterInstance(new BasketMockService()).As<IBasketService>();
builder.RegisterInstance(new OrderMockService()).As<IOrderService>();
builder.RegisterInstance(new UserMockService()).As<IUserService>();
UseMockService = true;
UseMockService = true;
}
else
{
builder.RegisterType<CatalogService>().As<ICatalogService>().SingleInstance();
builder.RegisterType<BasketService>().As<IBasketService>().SingleInstance();
builder.RegisterType<OrderService>().As<IOrderService>().SingleInstance();
builder.RegisterType<UserService>().As<IUserService>().SingleInstance();
builder.RegisterType<UserService>().As<IUserService>().SingleInstance();
UseMockService = false;
UseMockService = false;
}
if (_container != null)


+ 140
- 16
src/Mobile/eShopOnContainers/eShopOnContainers.Core/ViewModels/SettingsViewModel.cs View File

@ -4,38 +4,51 @@ using Xamarin.Forms;
using System.Threading.Tasks;
using eShopOnContainers.Core.Helpers;
using eShopOnContainers.Core.Models.User;
using System;
using eShopOnContainers.Core.Models.Location;
using eShopOnContainers.Core.Services.Location;
namespace eShopOnContainers.Core.ViewModels
{
public class SettingsViewModel : ViewModelBase
{
private string _title;
private string _description;
private string _titleUseAzureServices;
private string _descriptionUseAzureServices;
private bool _useAzureServices;
private string _titleUseFakeLocation;
private string _descriptionUseFakeLocation;
private bool _useFakeLocation;
private string _endpoint;
private double _latitude;
private double _longitude;
private ILocationService _locationService;
public SettingsViewModel()
public SettingsViewModel(ILocationService locationService)
{
UseAzureServices = !Settings.UseMocks;
_useFakeLocation = Settings.UseFakeLocation;
_latitude = Settings.FakeLatitude;
_longitude = Settings.FakeLongitude;
_locationService = locationService;
}
public string Title
public string TitleUseAzureServices
{
get { return _title; }
get { return _titleUseAzureServices; }
set
{
_title = value;
RaisePropertyChanged(() => Title);
_titleUseAzureServices = value;
RaisePropertyChanged(() => TitleUseAzureServices);
}
}
public string Description
public string DescriptionUseAzureServices
{
get { return _description; }
get { return _descriptionUseAzureServices; }
set
{
_description = value;
RaisePropertyChanged(() => Description);
_descriptionUseAzureServices = value;
RaisePropertyChanged(() => DescriptionUseAzureServices);
}
}
@ -52,6 +65,39 @@ namespace eShopOnContainers.Core.ViewModels
}
}
public string TitleUseFakeLocation
{
get { return _titleUseFakeLocation; }
set
{
_titleUseFakeLocation = value;
RaisePropertyChanged(() => TitleUseFakeLocation);
}
}
public string DescriptionUseFakeLocation
{
get { return _descriptionUseFakeLocation; }
set
{
_descriptionUseFakeLocation = value;
RaisePropertyChanged(() => DescriptionUseFakeLocation);
}
}
public bool UseFakeLocation
{
get { return _useFakeLocation; }
set
{
_useFakeLocation = value;
// Save use fake location services to local storage
Settings.UseFakeLocation = _useFakeLocation;
RaisePropertyChanged(() => UseFakeLocation);
}
}
public string Endpoint
{
get { return _endpoint; }
@ -68,12 +114,47 @@ namespace eShopOnContainers.Core.ViewModels
}
}
public double Latitude
{
get { return _latitude; }
set
{
_latitude = value;
UpdateLatitude(_latitude);
RaisePropertyChanged(() => Latitude);
}
}
public double Longitude
{
get { return _longitude; }
set
{
_longitude = value;
UpdateLongitude(_longitude);
RaisePropertyChanged(() => Longitude);
}
}
public ICommand ToggleMockServicesCommand => new Command(async () => await ToggleMockServicesAsync());
public ICommand ToggleFakeLocationCommand => new Command(() => ToggleFakeLocationAsync());
public ICommand ToggleSendLocationCommand => new Command(async () => await ToggleSendLocationAsync());
public override Task InitializeAsync(object navigationData)
{
UpdateInfo();
UpdateInfoFakeLocation();
Endpoint = Settings.UrlBase;
_latitude = Settings.FakeLatitude;
_longitude = Settings.FakeLongitude;
_useFakeLocation = Settings.UseFakeLocation;
return base.InitializeAsync(navigationData);
}
@ -100,17 +181,48 @@ namespace eShopOnContainers.Core.ViewModels
}
}
private void UpdateInfo()
private void ToggleFakeLocationAsync()
{
ViewModelLocator.RegisterDependencies(!UseAzureServices);
UpdateInfoFakeLocation();
}
private async Task ToggleSendLocationAsync()
{
LocationRequest locationRequest = new LocationRequest
{
Latitude = _latitude,
Longitude = _longitude
};
await _locationService.UpdateUserLocation(locationRequest);
}
private void UpdateInfo()
{
if (!UseAzureServices)
{
Title = "Use Mock Services";
Description = "Mock Services are simulated objects that mimic the behavior of real services using a controlled approach.";
TitleUseAzureServices = "Use Mock Services";
DescriptionUseAzureServices = "Mock Services are simulated objects that mimic the behavior of real services using a controlled approach.";
}
else
{
Title = "Use Microservices/Containers from eShopOnContainers";
Description = "When enabling the use of microservices/containers, the app will attempt to use real services deployed as Docker containers at the specified base endpoint, which will must be reachable through the network.";
TitleUseAzureServices = "Use Microservices/Containers from eShopOnContainers";
DescriptionUseAzureServices = "When enabling the use of microservices/containers, the app will attempt to use real services deployed as Docker containers at the specified base endpoint, which will must be reachable through the network.";
}
}
private void UpdateInfoFakeLocation()
{
if (!UseFakeLocation)
{
TitleUseFakeLocation = "Use Fake Location";
DescriptionUseFakeLocation = "Fake Location are added for marketing campaign testing.";
}
else
{
TitleUseFakeLocation = "Use Real Location";
DescriptionUseFakeLocation = "When enabling the use of real location, the app will attempt to use real location from the device.";
}
}
@ -119,5 +231,17 @@ namespace eShopOnContainers.Core.ViewModels
// Update remote endpoint (save to local storage)
Settings.UrlBase = endpoint;
}
private void UpdateLatitude(double latitude)
{
// Update fake latitude (save to local storage)
Settings.FakeLatitude = latitude;
}
private void UpdateLongitude(double longitude)
{
// Update fake longitude (save to local storage)
Settings.FakeLongitude = longitude;
}
}
}

+ 74
- 3
src/Mobile/eShopOnContainers/eShopOnContainers.Core/Views/SettingsView.xaml View File

@ -108,11 +108,11 @@
Grid.Column="0"
Grid.Row="1">
<Label
Text="{Binding Title}"
Text="{Binding TitleUseAzureServices}"
TextColor="{StaticResource GreenColor}"
Style="{StaticResource SettingsTitleStyle}"/>
<Label
Text="{Binding Description}"
Text="{Binding DescriptionUseAzureServices}"
Style="{StaticResource SettingsDescriptionStyle}"/>
</StackLayout>
<!-- ON / OFF -->
@ -160,8 +160,79 @@
<Grid
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"/>
<StackLayout
Grid.Column="0"
Grid.Row="4">
<Label
Text="{Binding TitleUseFakeLocation}"
TextColor="{StaticResource GreenColor}"
Style="{StaticResource SettingsTitleStyle}"/>
<Label
Text="{Binding DescriptionUseFakeLocation}"
Style="{StaticResource SettingsDescriptionStyle}"/>
</StackLayout>
<!-- ON / OFF -->
<controls:ToggleButton
Grid.Column="1"
Grid.Row="4"
Animate="True"
Checked="{Binding UseFakeLocation, Mode=TwoWay}"
Command="{Binding ToggleFakeLocationCommand}"
Style="{StaticResource SettingsToggleButtonStyle}">
<controls:ToggleButton.CheckedImage>
<OnPlatform x:TypeArguments="ImageSource"
Android="switch_on.png"
iOS="switchOn.png"
WinPhone="Assets/switchOn.png"/>
</controls:ToggleButton.CheckedImage>
<controls:ToggleButton.UnCheckedImage>
<OnPlatform x:TypeArguments="ImageSource"
Android="switch_off.png"
iOS="switchOff.png"
WinPhone="Assets/switchOff.png"/>
</controls:ToggleButton.UnCheckedImage>
</controls:ToggleButton>
<!-- ENDPOINT -->
<StackLayout
Grid.Row="5"
Grid.Column="0"
Grid.ColumnSpan="2"
BackgroundColor="Gray"/>
Margin="12, 0, 12, 12"
IsVisible="{Binding UseFakeLocation}">
<Label
Text="Latitude"
Style="{StaticResource HeaderLabelStyle}"/>
<Entry
Text="{Binding Latitude, Mode=TwoWay}"
Keyboard="Numeric">
<Entry.Style>
<OnPlatform
x:TypeArguments="Style"
iOS="{StaticResource EntryStyle}"
Android="{StaticResource EntryStyle}"
WinPhone="{StaticResource UwpEntryStyle}"/>
</Entry.Style>
</Entry>
<Label
Text="Longitude"
Style="{StaticResource HeaderLabelStyle}"/>
<Entry
Text="{Binding Longitude, Mode=TwoWay}"
Keyboard="Numeric">
<Entry.Style>
<OnPlatform
x:TypeArguments="Style"
iOS="{StaticResource EntryStyle}"
Android="{StaticResource EntryStyle}"
WinPhone="{StaticResource UwpEntryStyle}"/>
</Entry.Style>
</Entry>
<Button
Command="{Binding ToggleSendLocationCommand}"
Text="Send Location"/>
</StackLayout>
</Grid>
</StackLayout>
</ScrollView>


+ 4
- 1
src/Mobile/eShopOnContainers/eShopOnContainers.Core/eShopOnContainers.Core.csproj View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
@ -70,6 +70,7 @@
<Compile Include="Models\Catalog\CatalogItem.cs" />
<Compile Include="Models\Catalog\CatalogRoot.cs" />
<Compile Include="Models\Catalog\CatalogType.cs" />
<Compile Include="Models\Location\LocationRequest.cs" />
<Compile Include="Models\Navigation\TabParameter.cs" />
<Compile Include="Models\Orders\CardType.CS" />
<Compile Include="Models\Orders\Order.cs" />
@ -91,6 +92,8 @@
<Compile Include="Services\Dialog\IDialogService.cs" />
<Compile Include="Services\Identity\IdentityService.cs" />
<Compile Include="Services\Identity\IIdentityService.cs" />
<Compile Include="Services\Location\ILocationService.cs" />
<Compile Include="Services\Location\LocationService.cs" />
<Compile Include="Services\Navigation\INavigationService.cs" />
<Compile Include="Services\Navigation\NavigationService.cs" />
<Compile Include="Services\OpenUrl\IOpenUrlService.cs" />


Loading…
Cancel
Save