Silverlight 4 plus Dynamics CRM 4

Today at PDC Scott Guthrie announced not only loads of cool new features for Silverlight 4, but also the release today of the Beta. So, what in the world does that have to do with CRM? Glad that you asked. We’ve got a quick demo of Dynamics CRM 4 with a Silverlight 4 tool. First a little about new Silverlight functions that allow access to web camera and microphone, then using that in CRM.  Be sure to check out Silverlight Jumpstart for extensive (over 50 pages of new content) for Silverlight 4 updates, available only from the publisher. (in case anyone is wondering, no I didn’t write the code samples, my hubby did)

Web Camera / Microphone Support

Silverlight 4 now allows developers to access to the raw audio and video streams on the local machine from applications running both in and out of the browser. Using these capabilities developers can write applications including capture and collaboration using audio and video. This is built-in to the core runtime and no other special downloads are required on each machine. When the audio or video is accessed for the first time by the application the user will be prompted to approve the request. This ensures that audio and video is never accessed without the user’s knowledge preventing applications that capture silently in the background. The following is an example of the prompt the user sees when the application requests access to the devices.

1

You will notice in the above image the site name is displayed. This is another safeguard to ensure the user knows which site is requesting access to the devices. Access is granted to just this application and only for this session of the application. Currently there is no option to persist the user’s approval to avoid re-prompting each time the application is run. Additionally, it’s all or nothing; you don’t get to choose video or microphone. It’s a combined approval.

Users with multiple devices can select the devices they want to be the default devices using the properties on the Silverlight plug-in. This can be selected by right-clicking on a Silverlight application and going to the Webcam/Mic tab.

The following is an example of what you will see on that tab.

2

Developers can get access to the chosen devices using the CaptureDeviceConfiguration class. Using this class you can call the GetDefaultAudioCaptureDevice or GetDefaultVideoCaptureDevice methods to retrieve the users selected defaults. The class also has GetAvailableAudioCaptureDevices and GetAvailableVideoCaptureDevices methods that allow you to enumerate the available devices if you want more control of choosing a device besides the default.

Prior to using the devices you must request access to the device by calling the RequestDeviceAccess() method from the CaptureDeviceConfiguration class. When this method is called it is responsible for showing the user approval dialog we saw earlier. This method must be called from a user initiated event handler like the event handler for a button click event. If you call it at other times it will either not do anything or produce an error. Using the AllowedDeviceAccess property you can query if access has already been granted to the device.

The quickest way to get started using the video is to attach the capture from the device to a VideoBrush and then use the brush to paint the background of a border. The following XAML sets up the button to trigger the capture and a border that we will paint with a video brush.

<StackPanel>

<Button x:Name="btnStartvideo" Click="btnStartvideo_Click"

Content="Start Video"></Button>

<Border x:Name="borderVideo" Height="200" Width="200"></Border>

</StackPanel>

Next, the following private method TurnOnVideo method is called from the handler for the click event on the button. This satisfies the requirement to be user initiated.

private void TurnOnVideo()

{

VideoCaptureDevice videoCap =

CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

AudioCaptureDevice audioCap =

CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();

CaptureSource capsource = new CaptureSource();

capsource.AudioCaptureDevice = audioCap;

capsource.VideoCaptureDevice = videoCap;

if (CaptureDeviceConfiguration.AllowedDeviceAccess

|| CaptureDeviceConfiguration.RequestDeviceAccess())

{

capsource.Start();

VideoBrush vidBrush = new VideoBrush();

vidBrush.SetSource(capsource);

borderVideo.Background = vidBrush;

}

}

As you can see in the code above, default audio and video devices are retrieved and assigned to a CaptureSource. Access to the devices is then checked and requested if not already approved.

If access is granted the Start() method on the CaptureSource is invoked to begin capturing audio and video. Finally, the VideoBrush source is set to the CaptureSource instance and the background on the border is set to the VideoBrush.

Overtime we will probably see some very interesting applications of the audio and video support. One example that we put together was using it with Microsoft Dynamics CRM. In this example application a membership application was simulated that associated members with pictures and stored the pictures in a database. Think of a place similar to Costco, Sam’s Club or your local gym that snaps your photo for their records.

In the following image you can see how a tab has been added to the Contact form using the CRM customization capabilities.

3

A Silverlight 4 application is then hosted inside that tab that will provide the user experience for capturing the images. When the Start Camera button is clicked the user will be prompted to approve the access and the video feed will begin as you can see below.

4

The video feed will keep showing the live image updated from the web cam until stopped. The Capture button on the above application allows the user to capture one of the image frames from the capture source. The AsyncCaptureImage(..) method on the CaptureSource class allows you to request that a frame be captured and your callback invoked. The callback is then invoked and passed a WriteableBitmap representing the captured frame.

5

This image can then be saved back to the Dynamics CRM server and associated with the record being viewed.

Silverlight Jumpstart

Previous Post

Open-source CRM and ERP: New kids on the cloud

Nov 15
Make sure to read the full article below, this is my biased feedback. I can happily admit my bias toward Microsoft Dynamics CRM, Azure and for profit software programming. However, ComputerWorld tries to pull off being a news provider, which...
Next Post

If this were true a few years ago I would be dead

Nov 20
Not even exaggerating, I wish I were. If I had to wait three years between cancer screenings my children would be without their mother. And even though I sometimes fantasize about the day after they leave for college turning their...

Comments

click here

Upon completion of the project the chapter will have covered over 45 sites. The QR codes are displayed on the kiosk just outside the Shelby County Historical Society’s welcome center.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name is required. Email address will not be displayed with the comment.)