While I don't find time to do a proper introduction over
Unified Service Desk, Microsoft's platform for the development of call center systems, I'll keep bringing some nice-to-know-facts about it.
Custom Hosted Controls
A custom hosted control is basically a WPF UserControl specialized to wire-up against USD's internal engines. To develop it, you can download and install the UII SDK and the Visual Studio Extension that contains the templates for it. Or you can do it the hardcode way, which I prefer, and simply install a USD nuget:
PM > Install-Package Microsoft.CrmSdk.USD.CoreAssemblies
Once that's done, simply create a new WPF UserControl and change it's base class to DynamicsBaseHostedControl:
< dynamics:dynamicsbasehostedcontrol x:class="MyLib.Controls.Views.FooView"
xmlns:dynamics="clr-namespace:Microsoft.Crm.UnifiedServiceDesk.Dynamics;assembly=Microsoft.Crm.UnifiedServiceDesk.Dynamics"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" >
Nice! Now you can start developing you own USD control.
Actions and Action Calls
There are only two reasons to actually create DynamicsBaseHostedControl controls. One is to access the USD Context, the other is to wire up Actions and Events.
Microsoft's documentation over Action and Events is surprisingly good, so it's worth to check out. But it fails to talk about how to
develop using action and events. I'll probably address this more comprehensively in the coming posts, but, for now, let's just focus on how to create custom actions that you can call from other controls.
In your DynamicsBaseHostedControl, override the method DoAction:
protected override void DoAction(RequestActionEventArgs args)
{
switch (args.Action)
{
case "ActionName":
DoSomething();
break;
case "AnotherAction":
DoSomethingElse();
break;
// (...)
}
base.DoAction(args);
}
The args contain everything you should need to implement that call:
- Its property Action contains the name of the action that was called. You should switch on it.
- Its property Data contains the parameters that were sent with the action call.
[as you can see from above, USD unfortunately suffers from String Obsession (a common kind of
Primitive Obsession), since it's heavily based on parametrization]
Now, the call to base.DoAction is
very important: every DynamicsBaseHostedControl implements a few standard actions. Microsoft documentation on this is very thin (as is on everything USD), but at least these actions are implemented:
- new
- new_crm_page
- open
- open_crm_page
- popup
- close
- fireevent
- movetopanel
- setsize
If you don't call the base, you are effectively disabling all these standard behaviors. But
here's the grand finale and the reason for this post: USD won't warn against unknown actions, so if you send the action "foobar" against it, it will not reject, only log it. You can imagine what this means in practice: a typo can cause all sorts of pain. So,
be wary when dealing with actions.