Skip to content

Instantly share code, notes, and snippets.

@Injac
Injac / sample scratch
Created October 7, 2014 16:50
Sample IDataService
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// Interface that specifies
/// the CRUD operations to
@Injac
Injac / SimpleNSF.cs
Last active August 29, 2015 14:03
Simple named string formatting for WinRT
/// <summary>
/// Formats the log entry.
/// /// Taken from:
/// http://stackoverflow.com/questions/561125/can-i-pass-parameters-to-string-format-without-specifying-numbers
/// and adapted to WINRT
/// </summary>
/// <param name="format">The format.</param>
/// <param name="args">The arguments.</param>
/// <returns></returns>
/// <exception cref="System.FormatException">The string format is not valid</exception>
@Injac
Injac / XDocExtension
Last active August 29, 2015 14:02
Useful XDocument extension to check if an element exists
public static class XDocExtensions
{
public static bool CheckIfElementExists(this XDocument doc, string elementName)
{
return doc.Descendants().FirstOrDefault(e => e.Name.LocalName.Equals(elementName)) != null;
}
}
@Injac
Injac / DynamicMethodInvocation
Last active August 29, 2015 14:01
Dynamic method invocation WinRT
private void Button_Click(object sender, RoutedEventArgs e)
{
Type objType = Type.GetType("TestReflection.CallMyMethods, TestReflection.WindowsPhone, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
TypeInfo mm = objType.GetTypeInfo();
var methods = mm.DeclaredMethods;
@Injac
Injac / Mobile Services 8.1 Snippet
Created May 17, 2014 03:45
Windows Phone 8.1 (WinRT, Universal Apps) Mobile Services - Important Snippet to avoid Exceptions if the user cancels the login
protected override void OnActivated(IActivatedEventArgs args)
{
base.OnActivated(args);
#if WINDOWS_PHONE_APP
if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
{
App.<mobileservice>.LoginComplete(args as WebAuthenticationBrokerContinuationEventArgs);
}
#endif
@Injac
Injac / Sample Request Structure
Created May 13, 2014 09:26
JSON Request Class
public class Location
{
public string __type { get; set; }
public double latitude { get; set; }
public double longitude { get; set; }
}
public class LocationRequest
{
public Location location { get; set; }
@Injac
Injac / SettingsBehavior
Created May 12, 2014 19:33
SettingsBehavior to save Roamed Settings (attach to TextBox) in WinRT
[Microsoft.Xaml.Interactivity.TypeConstraint(typeof(Windows.UI.Xaml.Controls.TextBox))]
class SettingsBehavior : DependencyObject, IBehavior
{
#region IBehavior Members
public Windows.UI.Xaml.DependencyObject AssociatedObject { get; set; }
public string SettingsIndex
{
@Injac
Injac / Exception
Created April 17, 2014 14:03
Invalid cast exception, Azure Emulator using Azure SDK 2.2
System.InvalidCastException was unhandled
Message: An unhandled exception of type 'System.InvalidCastException' occurred in WaWorkerHost.exe
Additional information: Unable to cast transparent proxy to type 'Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge'.
Solution: Upgrade your Worker Role to SDK 2.3 if you use VS2013 Update 2 RC
@Injac
Injac / Twitter.sql
Created March 17, 2014 20:24
Twitter Entitiy Model for SQL Server - to be used with Linq2Twitter (unofficial)
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 03/17/2014 21:20:43
SET QUOTED_IDENTIFIER OFF;
GO
USE [AdvancedTweeps];
@Injac
Injac / GetClientIP
Created March 11, 2014 15:28
WebApiThrottleChange
protected IPAddress GetClientIp(HttpRequestMessage request)
{
if (request.Properties.ContainsKey("MS_HttpContext"))
{
IPAddress ipAddress;
var ok = IPAddress.TryParse(((HttpContextBase)request.Properties["MS_HttpContext"]).Request.UserHostAddress,out ipAddress);
if(ok)
{