Buenas,
today close series where I discuss how using C# can check the status of the lights of a USB Email Notifier little more than U$ S 8.00.
- [#GADGETS] How to control USB Email Notifier with C# (I)
- [#GADGETS] How to control USB Email Notifier with C# (II)
- [#GADGETS] HowTo: Integrate the USB Email Notifier to display the States of Lync 2013 Beta (III)
First real example which was to build an application showing the alerts for a Server Builds with Team Foundation Server 2012. As once long ago already built something similar with the Lance missiles USB and Team Foundation Server 2008, because today I will do something different.
Some time ago I caught my attention this post by Scott Hanselman , which says it has been aBusyLight on the door of his Office so your family will know if you are in a call, Conference, etc. In addition to feel quite identified with your situation, it struck me that nobody has created a “cheap” solution for this. Well, here is some u $S 20 and with the satisfaction of having done self.
The only thing we need is a notifier light and a couple of USB extensions, for example
- USB Universal E-mail/Webmail Notifier + 4-Port Hub (Gmail/Outlook/Outlook Express/POP3)
- USB 2.0 High Speed Cable Extension with Signal Power Amplifier Chip (5 – Meter)
The following is to create a WPF application where use of Lync presence controls. In this case I’m using LYNC 2013 BETA, so I had to also download the SDK in Beta mode from here. The good thing about this SDK, is that in addition to the classical object model, we also have a set of WPF controls that allow us to create an application like that we can see the next image in a few minutes:
The WPF code
1: <Window x:Class="ElBruno.LyncLightNotifier.MainWindow"
2: xmlns:controls="clr-namespace:Microsoft.Lync.Controls;assembly=Microsoft.Lync.Controls"
3: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5: Title="El Bruno - LYNC 2013 Light Alert"
6: Height="264"
7: Width="405">
8: <Grid>
9: <Grid.RowDefinitions>
10: <RowDefinition />
11: <RowDefinition />
12: </Grid.RowDefinitions>
13: <Grid.ColumnDefinitions>
14: <ColumnDefinition Width="187*" />
15: <ColumnDefinition Width="384*" />
16: </Grid.ColumnDefinitions>
17: <Grid.Background>
18: <ImageBrush ImageSource="Lync.png" />
19: </Grid.Background>
20: <StackPanel Orientation="Vertical"
21: Margin="10,0,0,10"
22: HorizontalAlignment="Stretch"
23: VerticalAlignment="Center"
24: Height="106"
25: Grid.Column="1"
26: Grid.Row="1">
27: <controls:MyPresenceChooser x:Name="myPresence"
28: HorizontalAlignment="Stretch" />
29: <controls:MyStatusArea x:Name="myStatus" />
30: </StackPanel>
31: </Grid>
32: </Window>
Now as I have not invested much time in seeing how the SDK, in the first 10 minutes I found an event that indicate me the state change. Therefore, the following code is almost just as damaging to the world of programming such as killing the last Unicorn or making a couple of miles in my car (the last is harmful for Ecology).
1: using System;
2: using System.Timers;
3: using System.Windows;
4: using System.Windows.Threading;
5: using ElBruno.LightNotifier;
6: using Microsoft.Lync.Controls;
7:
8: namespace ElBruno.LyncLightNotifier
9: {
10: public partial class MainWindow
11: {
12: private readonly Timer _timer = new Timer(1000);
13: public MainWindow()
14: {
15: InitializeComponent();
16: Loaded += MainWindowLoaded;
17: Unloaded += MainWindowUnloaded;
18: }
19:
20: void MainWindowUnloaded(object sender, RoutedEventArgs e)
21: {
22: _timer.Elapsed -= TimerElapsed;
23: _timer.Stop();
24: }
25:
26: void MainWindowLoaded(object sender, RoutedEventArgs e)
27: {
28: _timer.Elapsed += TimerElapsed;
29: _timer.Enabled = true;
30: }
31:
32: void TimerElapsed(object sender, ElapsedEventArgs e)
33: {
34: Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(CheckLyncState));
35: }
36: void CheckLyncState()
37: {
38: var state = myPresence.AvailabilityState;
39: var lightController = new LightController();
40: lightController.TurnLight(state == ContactAvailability.DoNotDisturb);
41: }
42: }
43: }
Well, the solution is quite simple: a timer every second verifying the LYNC 2013 State and if it is Do Not Disturb, as the notifier light turned on. Lines 32 to 41 will make you happy.
If a picture is worth a thousand words, the next value should be worth 2 or 3 monosyllables
Video: http://youtu.be/Tah42D8Vozw
The full application code can be downloaded from http://sdrv.ms/PkgQ4L .
References:
- Microsoft Lync 2013 SDK (Preview)
http://www.microsoft.com/en-gb/download/details.aspx?id=30350 - Lync 2013 Preview SDK Documentation
http://msdn.microsoft.com/en-us/library/lync/jj265569(v=office.15).aspx - Is Daddy on a call? A BusyLight Presence indicator for Lync for my Home Office
http://www.hanselman.com/blog/IsDaddyOnACallABusyLightPresenceIndicatorForLyncForM
Saludos @ La Finca
El Bruno

Leave a reply to elbruno Cancel reply