Cookie CSS

Saturday, December 13, 2014

Building the Ultimate Lync Presentation Tool Helper - Part 4

Last week we went over the design of our screen, and the layout of the items we are going to want to control during a Lync presentation.  This week we'll take a peek at the code behind the window, and examine how to do some of the Lync specific functions.


In case you forgot here is what our screen layout looks like.  So to begin we need to do some general housekeeping and get an instance of our local Lync desktop client.


Microsoft.Lync.Model.LyncClient _LyncClient;
_LyncClient = LyncClient.GetClient();

if (_LyncClient.InSuppressedMode == true)
                {
                    MessageBox.Show(
                        "Lync Client is in UI Suppressed mode. Sharing is not supported.",
                        "Application Error");
                    this.Close();
                }

Any time or window changes sizes, when you expand or collapse something, we'll make sure to keep it docked in the lower right hand part of the screen.

try
            {
                var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
                this.Left = desktopWorkingArea.Right - this.Width;
                this.Top = desktopWorkingArea.Bottom - this.Height;
            }

            catch { }


We are also going to want a conversation place holder to store the default conversation we are working with.  We are going to make the assumption that you will only have 1 conference going at a time in this regard.

Conversation _conversation = null;

In our timer we are going to scan the active conversations and select the one that matters, that way you can have the program running and loaded before you join.

bool hasConf = false;

                foreach (Conversation c in _LyncClient.ConversationManager.Conversations)
                {
                    try
                    {
                        if (ContainsAVConf(c))
                        {
                            hasConf = true;

                            _ConvChanged = false;

                            try
                            {
                                if (_conversation != c)
                                {
                                    _ConvChanged = true;
                                }
                                else
                                {
                                    _ConvChanged = false;
                                }
                            }
                            catch 
                            {
                                Console.WriteLine("Could not compare conv");
                                //old conv was null so true
                                _ConvChanged = true;

                                if (_ConvChanged)
                                {
                                    Console.WriteLine("Updating Shared Resources List");
                                    UpdateSharedResources();
                                }
                            }

                            _conversation = c;

                            

                        }
                    }
                    catch { }

                    if (!hasConf)
                    {
                        _conversation = null;
                        
                        if (cbSharedResources.Items.Count > 0)
                        {
                            cbSharedResources.Items.Clear();
                        }
                    }
                }

The function ContainsAVConf(Conversation c) is a simple function that returns whether or not the particular conversation have audio/video as one of it's modalities.

 private bool ContainsAVConf(Conversation c)
        {
            bool hasit = false;
            try
            {
                
                if (c.Modalities.ContainsKey(ModalityTypes.AudioVideo) && c.Modalities[ModalityTypes.AudioVideo].State != ModalityState.Disconnected)
                {
                    if (!string.IsNullOrEmpty((string)c.Properties[ConversationProperty.ConferencingUri]))
                    {
                        hasit = true;
                    }
                }
            }
            catch
            {
                return false;
            }
            return hasit;
        }

The other part of our timer, is going to do some GUI updates of the meeting bin, shared resources, etc.  It will also change the color indicator to display when you are in a valid conference.

 try
            {
                this.Dispatcher.BeginInvoke((Action)delegate()
                {
                    try
                    {
                        setControls();

                        if (DateTime.Now.Second % 60 == 0)
                        {
                            loadMeetingBin();

                            UpdateSharedResources();
                        }
                    }
                    catch { }
                }, DispatcherPriority.ApplicationIdle);
            }
            catch { }


Next week we'll begin our discussion about how to share resources in Lync, and we'll examine the sharing resources toolbar in our app.

Doug Routledge, C# Lync, SQL, Exchange, UC Developer

No comments:

Post a Comment

Any spam comments will be deleted and your user account will be disabled.