Skip to content

Instantly share code, notes, and snippets.

View dotMorten's full-sized avatar
:octocat:

Morten Nielsen dotMorten

:octocat:
View GitHub Profile
@dotMorten
dotMorten / XamlMarkerSymbol.cs
Created November 1, 2013 21:16
A XAML based PictureMarkerSymbol for the ArcGIS Runtime .NET SDK
using Esri.ArcGISRuntime.Symbology;
using System;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
#if NETFX_CORE
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.Foundation;
@dotMorten
dotMorten / NamingGuidelinesTest.cs
Last active December 21, 2015 02:19
Unit test that checks that Task-returning methods are postfixed 'Async"
[TestMethod]
[TestCategory("Naming guidelines")]
public void TasksReturningMethodsArePostfixedAsync()
{
var asm = typeof(SomeTypeInMyAssembly).Assembly;
StringBuilder sb = new StringBuilder();
foreach (var type in asm.GetExportedTypes())
{
foreach (var mi in type.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static |
@dotMorten
dotMorten / PointAnimator.cs
Created March 24, 2013 07:12
Code for animating a MapPoint to a new location
using ESRI.ArcGIS.Runtime;
using System;
using Windows.UI.Xaml.Media;
namespace GeometryUtils
{
public class PointAnimator
{
public PointAnimator(MapPoint point, MapPoint to, TimeSpan duration)
{
@dotMorten
dotMorten / TestMessageHandler.cs
Created March 24, 2013 02:45
Custom Http message handler used for mocking web responses in UnitTests relying on HttpClient. Add a resource file named "TestResponses.resw" and add your responses in this, and you can simply use TestMessageHandler.FromResourceResponse(key) and use this handler in you HttpClient.
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;
namespace TestHarness
{
/// <summary>
/// A message handler for simulating web requests
@dotMorten
dotMorten / SharpGIS.Bing.ElevationServiceClient.cs
Created January 16, 2013 05:16
Bing Maps Elevation Service for Windows 8/RT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
@dotMorten
dotMorten / ObservableCollection2.cs
Created November 26, 2015 20:36
Observable Collection supporting range adds efficiently without causing a lot of UI updates
public class ObservableCollection2<T> : ObservableCollection<T>
{
public void AddRange(IEnumerable<T> items)
{
InsertRange(Count, items);
}
public void InsertRange(int index, IEnumerable<T> items)
{
int count = 0;
foreach(var item in items)
@dotMorten
dotMorten / Haversine.cs
Last active October 23, 2015 06:37
Calculate the distance between two points on the globe using Haversine and Vincenty formulas.
#region Haversine
/// <summary>
/// Gets the distance between two points in meters using the Haversine Formula.
/// </summary>
/// <param name="startLong">The start longitude.</param>
/// <param name="startLat">The start latitude.</param>
/// <param name="endLat">The end latitude.</param>
/// <param name="endLong">The end longitude.</param>
/// <returns>Distance between the two points in meters</returns>
public static double GetDistanceHaversine(double startLong, double startLat, double endLat, double endLong)
@dotMorten
dotMorten / RenderCode
Last active October 23, 2015 06:36
XamlRenderingBackgroundTask snippets
internal class GraphTile
{
public static Task CreateTileGraphAsync(Data data, int width, int height, string filename)
{
return RenderAndSaveToFileAsync(GetVisual(data, width, height), (uint)width, (uint)height, filename);
}
public static Task CreateTileGraphAsync(Data data, int width, int height, IRandomAccessStream stream)
{
return RenderAndSaveToStreamAsync(GetVisual(data, width, height), (uint)width, (uint)height, stream);
}
@dotMorten
dotMorten / AsyncTaskExtensions.cs
Created December 12, 2012 01:35
Silverlight/WPF/WP7 Async tasks - for ESRI.ArcGIS.Client
using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using ESRI.ArcGIS.Client.Tasks;
namespace ESRI.Samples.Async.Tasks
{
public static partial class Extensions
{
/**
* Smartenit ZHBT-2
*
* Copyright 2015 Morten Nielsen
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*