Skip to content

Instantly share code, notes, and snippets.

View zoint's full-sized avatar

jmshapland zoint

View GitHub Profile
@zoint
zoint / gist:7867765
Created December 9, 2013 05:37
Start position tracking Windows Phone 8
public void StartTracking()
{
_geolocator.ReportInterval = (uint)TimeSpan.FromSeconds(30).TotalMilliseconds;
_geolocator.MovementThreshold = 100;
// this implicitly starts the tracking operation
_geolocator.PositionChanged += PositionChangedHandler;
}
@zoint
zoint / PositionChanged.cs
Last active December 30, 2015 18:29
Basic position changed event handler
private async void PositionChangedHandler(Geolocator sender, PositionChangedEventArgs args)
{
if (args.Position == null || args.Position.Coordinate == null) return;
//save updated coordinates to a property on the class
//can do whatever we want with position, all I need are the coordinates
Position = args.Position.Coordinate;
//stop the tracking once we have our desired accuracy in meters
if (args.Position.Coordinate.Accuracy < 500)
@zoint
zoint / SettingsService.cs
Last active January 1, 2016 16:59
Localization of App Settings for Windows Phone 8.
using System;
using System.Globalization;
using MadWorldApps.Phone.Helpers.Interfaces;
namespace Places.BLL.Services
{
public enum DistanceType { Miles, Kilometers };
public class SettingsService : ISettingsService
public static class EnumExtensions
{
/// <summary>
/// Converts the enum member names into an enumberable of strings.
/// </summary>
/// <typeparam name="TEnum">A valid enum type.</typeparam>
/// <returns>An enumerable of strings based on the enum members.</returns>
public static IEnumerable<string> GetNames<TEnum>() where TEnum : struct
{
var typeInfo = ValidateEnum<TEnum>();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace MadWorldApps.PCL.Helpers.Extensions
{
public static class EnumExtensions
{
/// <summary>
using System;
namespace MadWorldApps.PCL.Helpers.Extensions
{
public static class StringExtensions
{
/// <summary>
/// Adds spaces to words based on capital characters.
/// </summary>
/// <param name="s">The CamelCase string you want spaces added to.</param>
public async Task<IEnumerable<StorageFile>> GetFilesInCameraRoll()
{
var cameraRoll = await KnownFolders.PicturesLibrary.GetFolderAsync("Camera Roll");
return await cameraRoll.GetFilesAsync();
}
public async Task<bool> LoginAsync()
{
var authenticator = new Windows.Security.Authentication.OnlineId.OnlineIdAuthenticator();
var mobileServicesTicket = new Windows.Security.Authentication.OnlineId.OnlineIdServiceTicketRequest("https://yourendpoint.azure-mobile.net/", "JWT");
var ticketRequests = new List<OnlineIdServiceTicketRequest>() { mobileServicesTicket };
var authResult = await authenticator.AuthenticateUserAsync(ticketRequests, CredentialPromptType.PromptIfNeeded);
if ((authResult.Tickets.Count == 1) && (authResult.Tickets[0].ErrorCode == 0))
private async Task SaveChangesAsync()
{
try
{
await _dbContext.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException ex)
{
//adapted from: https://docs.microsoft.com/en-us/ef/core/saving/concurrency
foreach (var entry in ex.Entries)