Thursday, May 15, 2008

Creating a CWA client with Silverlight 2 beta 1 (part 5)

In Part 4 we have seen how to get events from the cwa-server. But we still have to schedule this. The pollWaitTime tells us when we can get our next events.

You could use the System.Windows.Threading.DispatcherTimer  but this ticks with a regular interval and as our interval is dynamic I went for a stroryboard in Silverlight.

Creating the timer
Just add a story board to XAML in your application/usercontrol.

image

In the code file add the code that handles the TimerCompleted Event. In this Method we set the timer duration stop the timer, get our events and start the timer again.

image

 

 

 

We still have to start our timer manually the first time. We can only do this only after we have signed in. So from our userAgent we raise our event that we have successfully signed in. Then start our timer. As you can see in that eventhandler I also hide our login part.

image

Creating the User controls

So now let’s finally start and do something in the UI. We have our Page.xaml. Just add a StackPanel and name it Contacts . In this StackPanel we want to show our groups and contacts belonging to these groups. A way of doing this is creating 2 usercontrol. A GroupControl and a ContactControl.

In Part 4 in our userAgent class we created events we raise when we get  groupEvents and contactEvents. In the first event we get from our server we first get back the groups and then our contacts belonging to that groups. In the presenceEvent, which probably will be addressed in one of the next parts of this series, we get detailed information of these contacts and status information. For now we only get the sip uris and to which groups the contact belongs.

Let’s create our contactControl.

image

As you can see this is simple control. For the status indication I use an Ellipse with brush. I added a name attribute to the gradient stop color. This makes it easier to change the status color later on.

image

This control will be extended later with a private method, which changes the color depending on the availability of the user. If we do not have a display name yet we just show the sip address of the contact.
Create the GroupControl. Again with some sample xaml and the code belonging to that user control.

image

image

Adding event handlers.
Let’s get back to our main page. In one of the first parts we created the login boxes and a button to signin. After clicking that button we create an instance of our UserAgent, sign in and handle our events. As you see below the GroupEvent and ContactEvent.

image

GroupEvent
Let’s Handle our group events. For now I only handle the added action.

image

ContactEvent
Let’s Handle our contact events. For now I only handle the added action. As you can see I use an extra function to find the correct control.

image

image

Please note that this is a series how you can create a cwa silverlight application, not a complete sample yet. Next part of this series will show you how to handle presence events.

Any questions/ comments please free to contact us.
Sip:Marc.Wetters@e-office.com or email:Marc.Wetters@e-office.com or Sip:joachim.farla@e-office.com or email:Joachim.Farla@e-office.com.

No comments: