Skip to content

Instantly share code, notes, and snippets.

View clausjoergensen's full-sized avatar

Claus Jørgensen clausjoergensen

View GitHub Profile
Example XAML:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<ProgressBar x:Name="PART_ProgressBar" />
<Image>
<Image.Source>
<BitmapImage behaviors:ImageDownloadProgress.ProgressBar="{Binding ElementName=PART_ProgressBar}" UriSource="{Binding Image}" />
</Image.Source>
<ItemGroup>
<!-- Specify the folder, or files we want to include -->
<AdditionalPublishFiles Include="ListAndLabel\*.*">
<Visible>False</Visible>
</AdditionalPublishFiles>
<!-- Alternative syntax, for individual files -->
<!--
<AdditionalPublishFiles Include="ListAndLabel\cmbr15.dll;ListAndLabel\Cmct15.dll">
<Visible>False</Visible>
public static class StringExtensions
{
public static bool TryParseInt16(this string source, Func<short, bool> condition)
{
short result = 0;
if (short.TryParse(source, out result))
return condition(result);
else
return false;
}
@clausjoergensen
clausjoergensen / MarshallExtensions.cs
Created January 7, 2012 14:20
Marshall Extensions for System.IO.Stream
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
namespace System.Runtime.InteropServices
{
/// <summary>
int startTickCount = Environment.TickCount;
int timeout = 10000;
var dataSent = false;
var socket = tcpClient.Client;
while (dataSent == false)
{
if (Environment.TickCount > startTickCount + timeout)
{
throw new Exception("Timeout.");
int offset = 0;
var socket = tcpClient.Client;
while (offset != data.Length)
{
if (socket.Poll(30, SelectMode.SelectWrite))
{
offset += tcpClient.Client.Send(data, offset, data.Length - offset, SocketFlags.None);
}
}
@clausjoergensen
clausjoergensen / GeoLocationHelper.cs
Created January 11, 2012 09:01
Geodetic location helper, for translating RT90 coordinates from/To WGS84 coordinates.
public static class GeoLocationHelper
{
public static GeoCoordinate ToWGS84(double x, double y)
{
var axis = 6378137.0;
var flattening = 1.0 / 298.257222101;
var centralMeridian = 15.0 + 48.0 / 60.0 + 22.624306 / 3600.0;
var scale = 1.00000561024;
var falseNorthing = -667.711;
var falseEasting = 1500064.274;
#pragma warning disable 0809
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Base
{
public class MeterTestDataContext : DbContext, IMeterTestDataContext
{
public MeterTestDataContext(string fileOrServerOrConnection)
: base(fileOrServerOrConnection)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
class Test<PageType> : DbContext
where PageType : class
{
private Dictionary<Type, PageType> callbacks = new Dictionary<Type, PageType>();
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
foreach (var type in callbacks.Keys)