Skip to content

Instantly share code, notes, and snippets.

View tomorgan's full-sized avatar

Tom Morgan tomorgan

View GitHub Profile
@tomorgan
tomorgan / pchatEndpointConstructor
Created June 17, 2014 14:01
Persistent Chat Endpoint Constructor
public PersistentChatEndpoint(
Uri groupChatServerAddress,
LocalEndpoint ocs
)
@tomorgan
tomorgan / begin..endExample
Last active August 29, 2015 14:04
Async Begin..End example
private void MyMethod() {
//do some stuff
var flow = GetFlowFromSomewhere();
var message = GetMessageFromSomewhere();
flow.BeginSendInstantMessage(message, EndBeginSendInstanceMessage, flow);
//do some other things....
}
@tomorgan
tomorgan / Async lambda
Created July 29, 2014 12:40
Asynchronous Lambda Expression Example
private void MyMethod() {
//do some stuff
var flow = GetFlowFromSomewhere();
var message = GetMessageFromSomewhere();
flow.BeginSendInstantMessage(message, result =>
{
try
{
private void MyMethod()
{
await CallLongRunningTaskAsync();
//this code runs AFTER the task has completed;
}
@tomorgan
tomorgan / asynctask
Last active August 29, 2015 14:04
Example: Async Task extension method
public static Task SendMessageAsync(this InstantMessagingFlow flow, IMessage message)
{
return Task.Factory.FromAsync(flow.BeginSendMessage,
flow.EndSendMessage, message, null);
}
@tomorgan
tomorgan / async.chaining
Created July 29, 2014 13:00
Example: chaining asynchronous methods
public void MyMethod()
{
flow.EndSendMessage(flow.BeginSendMessage,null,null);
}
@tomorgan
tomorgan / LyncDesktopDev-FirstSteps
Created August 6, 2014 04:20
Lync Desktop Development - First Steps
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Lync.Model;
namespace DesktopDevDemo
{
class Program
{
Function Populate-UserObject($UserArg)
{
$thisUser = new-Object($t + ".User")
$thisUser.Name = $UserArg.Name
$thisUser.Email = $UserArg.EmailAddress
$thisUser.ID = $UserArg.Guid
$innerObject = $UserArg.GetUnderlyingObject()
$thisUser.SIP = $innerObject."msRTCSIP-PrimaryUserAddress"
return $thisUser
}
@tomorgan
tomorgan / PS_LDAP_Request
Created March 1, 2013 14:18
Powershell LDAP Request to get AD objects including Lync SIP Address and Home Server. Good if you can't use Import-Module ActiveDirectory
$Request = New-Object System.DirectoryServices.Protocols.SearchRequest
$Request.DistinguishedName = $RootContainer
$Request.Filter = $SearchFilter
$Request.Scope = "Subtree"
$Request.Attributes.Add("distinguishedName") | Out-Null
$Request.Attributes.Add("objectclass") | Out-Null
$Request.Attributes.Add("mail") | Out-Null
$Request.Attributes.Add("objectguid") | Out-Null
$Request.Attributes.Add("msrtcsip-primaryhomeserver") | Out-Null
Function Get-UserPrincipal($userName)
{
$dsam = "System.DirectoryServices.AccountManagement"
$rtn = [reflection.assembly]::LoadWithPartialName($dsam)
$cType = "domain" #context type
$iType = "DistinguishedName"
$dsamUserPrincipal = "$dsam.userPrincipal" -as [type]
$principalContext = new-object "$dsam.PrincipalContext"($cType,$RootDomain)
Write-Host Looking for DN $UserName in Container $principalContext.Name