Skip to content

Instantly share code, notes, and snippets.

@tswann
tswann / gist:892163
Created March 29, 2011 10:57
WPF FocusBehaviour
using System;
using System.Windows;
namespace MyProject.WPF.Helpers
{
/// <summary>
/// Allows an arbitrary UI element to bind keyboard focus to an attached property.
/// </summary>
public static class FocusBehaviour
{
@tswann
tswann / makecert.txt
Created May 16, 2011 11:56
Self-Certified SSL Certificates using makecert
# Create a trusted authority
makecert -sv SignRoot.pvk -cy authority -r signroot.cer -a sha1 -n "CN=Dev Cert Authority" -ss my -sr localmachine
# First install root auth certificate above (See comment), then...
# Create authorised certificate for actual use
makecert -iv SignRoot.pvk -ic signroot.cer -cy end -pe -n "CN=localhost" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localmachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12
@tswann
tswann / TagStory.cs
Created May 23, 2011 19:41
StoryQ test sample
using NUnit.Framework;
using Should.Fluent;
using StoryQ;
namespace CodeSlice.UnitTesting.StoryQ
{
[TestFixture]
public class Tag
{
Model.Tag _tag;
@tswann
tswann / gherkin.txt
Created May 23, 2011 21:33
Gherkin example
# language: en
Feature: Division
In order to avoid silly mistakes
Cashiers must be able to calculate a fraction
Scenario: Regular numbers
Given I have entered 3 into the calculator
And I have entered 2 into the calculator
When I press divide
Then the result should be 1.5 on the screen
@tswann
tswann / CrmSvcUtil.exe.config
Created September 20, 2011 16:29
Sample config file for the CrmSvcUtil.exe tool in the Dynamics 2011 SDK
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="di" value="<< your device id here >>" />
<add key="dp" value="<< your device password here>>" />
<add key="username" value="<< Live Id here >>" />
<add key="password" value="<< Live Id password here>>" />
<add key="serviceContextName" value="MyServiceContext" />
<add key="l" value="CS" />
<add key="codewriterfilter" value="SvcUtilFilter.CodeWriterFilter,SvcUtilFilter" />
@tswann
tswann / CreateContext.cs
Created September 21, 2011 12:05
Some code for creating an instance of generated Organisation Service context class
private OrganizationServiceProxy _serviceProxy;
private IOrganizationService _service;
// Instance of your generated ServiceContext class
private MyServiceContext _context;
private ServerConnection _serverConnection; = new ServerConnection();
// This class can be found in the crmservicehelpers file under the samplecode\{language}\helpercode directory
@tswann
tswann / CreateContact.cs
Created September 21, 2011 12:23
Create a new dynamics crm 2011 contact entity
Contact contact = new Contact()
{
FirstName = "Testing",
LastName = "McTesterson"
};
_context.AddObject(contact);
_context.SaveChanges();
@tswann
tswann / FetchAndUpdate.cs
Created September 21, 2011 12:38
Retrieve a CRM Contact using LINQ, update and save it back to Dynamics.
IList<Contact> testers = _context.ContactSet.Where(x => x.LastName == "McTesterson").ToList();
Contact tester = testers[0];
tester.FirstName = "Pete";
_context.UpdateObject(tester);
_context.SaveChanges();
// FAIL
_context.ContactSet.Where(x => !string.IsNullOrEmpty(x.LastName));
// WIN
_context.ContactSet.Where(x => x.LastName != null && x.LastName != string.Empty);
@tswann
tswann / Assign.cs
Created September 21, 2011 13:02
Assign contact to a new Owner.
contact.FirstName = "Tom";
// Assign record to new owner
AssignRequest assign = new AssignRequest
{
Assignee = new EntityReference(SystemUser.EntityLogicalName, newOwnerId),
Target = new EntityReference(Contact.EntityLogicalName, contact.Id)
};
_context.UpdateObject(contact);