So…The docs are wrong. Sorry.
I’m referring to the docs we shipped with the "Unified Communications Enhanced Presence Schemas for Microsoft Office Communications Server 2007" (UCMA) package, found here.This package contains good stuff as far as Presence goes. If you want to work with OCS presence, you'll need to know how to form your xml. These Xsds give you that info.
There’s a cool section in the docs that talk about creating C# code from the XSDs using xsd.exe, a tool shipped with visual studio.
Problem is...that section is borked. Seriously.
Now, I don't know if the writer of these docs was working from old information, or the devs changed something just before ship, or maybe this was written the day after one of those famous doc writer parties that I always wish I'd get invited to.
In any case, if you've tried to do this on your own, I apologize.
Anyway - the steps in the chm file are completely wrong. Not only do they no give you correct information, they also don't mention that there's more code to be written after code generation to actually do anything.
I'll try to rectify that with this and my next post. I've attached a zip file here that contains scripts that will automatically generate the source from the xsds. Mind you - the schemas can change at any moment, so my code might be out of date. That's why I've attached the scripts.
If you're impatient - you can just download the file attached and poke around. Otherwise - keep reading to get a handle on what I actually did.
Before getting into the how, let me explain the why. The theory is, once C# code is generated I no longer need to work with XML. I can just examine the classes, set the things I need and then tell the .NET serializer to create my xml for me.
It does work...after some tinkering.
After installing the xsds from the link above, copy the scripts into the schemas directory, or - if you trust me, then just use the generated c# files I provide.
On my machine, the schemas were installed to:
C:\Program Files (x86)\Microsoft Office Communications Server 2007\Enhanced Presence Schemas\Schemas
XsdProc.cmd
set XMLSERIALIZER_GENERATOR=xmlserializerwrapper.cmd
echo Generating Presence "CalendarData" Category
set XSD_FILES=CalendarData.xsd CommonTypes.xsd CalendarDataTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryCalendarData….
This is a very simple script. It’s composed of multiple sections of the code above. It calls XMLSERIALIZER_GENERATOR which is the other script below. We call set XSD_FILES here because xmlserializerwrapper.cmd depends on this environment variable to decide what files to process. The majority of the work for each section is then done in xmlserializerwrapper.
XmlSerializerWrapper.cmd
"%_XSDDIR%\xsd" /nologo /c /o:%_OUTDIR% /n:%NAMESPACE_PREFIX% %XSD_FILES%
That’s the important line in this script. _XSDDIR should be set to your xsd.exe path. On my machine the path is
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin
You may need to modify this. Xsd.exe is an application shipped with Visual Studio that takes Xml and generates C# code to suit. We will pass in custom namespaces for each of the files we generate because xsd.exe doesn’t support a ‘shared’ cs reference file. This becomes a problem because all the categories rely on a commontypes.xsd to define, well, common types. If we don’t specify a custom namespace, we get collisions and bad things happen.
Assuming you copy this file to the right place and run it, you should get a ‘generated’ directory at the end of the day that contains a bunch of c# code. This is the code you want to use.
I won't go into the C# code here...but they will be used in a future post to actually publish some presence. Stay tuned!
@ECHO OFF setlocal rem Look at xsdproc.cmd to see how this script is used... set _XSDDIR=C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin set _MCUINFTOOLDIR=%_LCSROOT%\Tools set _OUTDIR=Generated set _LOGFILE=xmlserializer.log Set NAMESPACE_PREFIX=%1 if {%NAMESPACE_PREFIX%} EQU {} ( echo The xsd files used will be taken from the XSD_FILES environment variable. echo To set this, enter set XSD_FILES=file1.xsd file2.xsd at the command line. echo Generated cs files will have the namespace NAMESPACE_PREFIX, and will be placed in the .\generated directory. echo This file must be called from the directory where the xsds currently reside. echo Usage: echo xmlserializerwrapper NAMESPACE_PREFIX goto :EOF ) if not exist %_OUTDIR% ( md %_OUTDIR% ) "%_XSDDIR%\xsd" /nologo /c /o:%_OUTDIR% /n:%NAMESPACE_PREFIX% %XSD_FILES%
Rem End xmlserializerwrapper.cmd
XsdProc:
@echo off
rem This script should be run from the directory your xsds were installed. by default, this will look like
rem C:\Program Files (x86)\Microsoft Office Communications Server 2007\Enhanced Presence Schemas\Schemas
call %XMLSERIALIZER_GENERATOR% PresenceCategoryCalendarData
echo Generating Presence "ContactCard" Category
set XSD_FILES=ContactCard.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryContactCard
echo Generating Presence "Device" Category
set XSD_FILES=Device.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryDevice
rem echo Generating Presence "Routing" Category
rem set XSD_FILES=Routing.xsd
rem call %XMLSERIALIZER_GENERATOR% PresenceCategoryRouting
echo Generating Presence "Note" Category
set XSD_FILES=Note.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryNote
echo Generating Presence "Service" Category
set XSD_FILES=Service.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryService
echo Generating Presence "State" Category
set XSD_FILES=State.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryState
echo Generating Presence "Alerts" Category
set XSD_FILES=options-Alerts.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryAlerts
echo Generating Presence "RccOptions" Category
set XSD_FILES=options-RccOptions.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryRcc
echo Generating Presence "UserInformation" Category
set XSD_FILES=options-UserInformation.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryUserInformation
echo Generating Presence "UserProperties" Category
set XSD_FILES=userProperties.xsd CommonTypes.xsd
call %XMLSERIALIZER_GENERATOR% PresenceCategoryUserProperties
rem End XsdProc