How to publish presence in UCMA without using XML

Michael Green published a great article about how to publish presence using UCMA, but it involves using XML. If you hate XML as much as I do, this article is for you.

Note that the code presented here is a snippet and therefore won’t compile/work by itself.

Publishing states

The process for publishing your state is the same for any of the four states (user state, machine state, phone state, calendar state). Let’s look at how to publish the user state:

var userState = new UserState(availability, activity);

_endpoint.LocalOwnerPresence.BeginPublishPresence(
    new PresenceCategory[] { userState },
    PublishPresenceCompleted,
    null);

Wow, that was tough! The other three states have similar classes you can use: MachineState, PhoneState, and CalendarState, all of which are located in the Microsoft.Rtc.Internal.Collaboration namespace. PublishPresenceCompleted is as about as dumb as you might expect:

_endpoint.LocalOwnerPresence.EndPublishPresence(result);

What if you don’t have activity (anything you want it to be)? Don’t pass anything in, and Communicator will show the default activity for your availability.

Publishing device capabilities

Publishing the device capabilities is slightly more involved:

var capability = new DeviceCapability(true, true, true);

var capabilities = new DeviceCapabilities(_endpoint.InnerEndpoint.Uri);

// Set capabilities; i.e., capabilities.Text = capability

var device = new Device(
    _endpoint.InnerEndpoint.Id, _
    new DeviceCapabilities[] { capabilities });

Like the *State classes, Device derives from PresenceCategory. You can view the XML that will be generated by calling PresenceCategory.GetCategoryDataXml() method.

Get all running processes on a remote machine

You know that you can get all the running processes on the local machine with:

Process.GetProcesses();</code

With very little modification, you can also get all the running processes on a remote machine (that you have access to, of course):

Processes.GetProcesses("machine name or IP address here"); 

SqlDataReader.GetSqlType() of column

I ran into an interesting problem today that required me to identify the SqlType of any given column, so that I could do special processing where appropriate. It normally wouldn't be such a big deal, because you can call GetType(i) to learn whether it's a string, boolean, DateTime, etc. However, there are some types that need to be differentiated further: for example, money and numbers in SQL might both map to the same .NET type.

Continue reading "SqlDataReader.GetSqlType() of column"

Lambda Expressions

Lambda expressions are a new construct in C# 3.0 that provide a more concise way of writing anonymous methods (which were introduced in C# 2.0). Lambda expressions are especially useful in LINQ statements but can be used any place anonymous methods are.

Continue reading "Lambda Expressions"

How to get all users and computers in a domain via C#

I was playing around with Active Directory and C# today. I don't pretend to understand anything yet, but you don't need to know anything about Active Directory or LDAP to do stuff against it with C#.

To start with, the classes we're interested in are found in the following namespaces:

System.DirectoryServices;
System.DirectoryServices.ActiveDirectory;

Continue reading "How to get all users and computers in a domain via C#"

TextInfo: ToTitleCase, ToLower, ToUpper

ToTitleCase(), ToLower(), ToUpper() results

I was poking around the .NET framework yesterday and came across these three methods in the TextInfo class:

string text = "this is a test string";

System.Globalization.TextInfo info = new System.Globalization.CultureInfo("en-US", false).TextInfo;

// First letter of every word is capitalized. System.Console.WriteLine(info.ToTitleCase(text));

// Lowercase all letters // System.Console.WriteLine(info.ToLower(text));

// Uppercase all letters // System.Console.WriteLine(info.ToUpper(text));

info = new System.Globalization.CultureInfo("de-DE", false).TextInfo;

System.Console.ReadLine();

Nice. :-)

Blockwriter 1.0 Beta

Yes! The last of the modifications I wanted to make for 1.0 are done. The squashing of known bugs also went well (the undead screen now minimizes along with the text editor. The text editor's scroll position stays put. And the user is prompted to save the file when there are unsaved changes).

So: download Blockwriter and let me know what you think!

Translate colors

Go from html (hex) colors to argb and vice versa.

Continue reading "Translate colors"

2 of 7 pages  <  1 2 3 4 >  Last »

On the Side