protected virtual void OnTabUpdated(TabArgs e)
 {
     var handler = TabUpdated;
     if (handler != null)
         handler(this, e);
 }
        /// <summary>
        /// Handles the callback TabActivated event, activates the tab
        /// </summary>
        void OnTabActivated(object sender, TabArgs e)
        {
            System.Diagnostics.Trace.TraceInformation ("Activating public tab {0}.", e.Tab.Title);
            Tab tab = PublicSession.FindByGuid(e.Tab.Id);
            if (tab == null) return;

            App.Current.Dispatcher.BeginInvoke (new Action(
                () =>
                    {
                        /* this updates the renderer also */
                        MainWindow main = App.Current.MainWindow as MainWindow;
                        if (main != null && main.ClientStatus.IsWatching)
                            main.dockingManager.ActiveDocument = tab;
                    }));
        }
        /// <summary>
        /// Handles the callback TabClosed event, removes the closed tab from the 
        /// public session
        /// </summary>
        void OnTabClosed(object sender, TabArgs e)
        {
            System.Windows.Threading.DispatcherOperation op = App.Current.Dispatcher.BeginInvoke
                (
                new Action (() =>
                    {
                        MainWindow main = App.Current.MainWindow as MainWindow;

                        if (main.ClientStatus.IsWatching)
                        {
                            int index = main.dockingManager.Documents.IndexOf(main.dockingManager.ActiveDocument as PublicTab);
                            if (index == 0)
                                if (main.dockingManager.Documents.Count > 1)
                                    TabNext = main.dockingManager.Documents[1] as PublicTab;
                                else
                                    TabNext = null;
                            else if (index != -1)
                                TabNext = main.dockingManager.Documents[index - 1] as PublicTab;
                        }
                        else TabNext = null;

                        PublicSession.Remove((PublicSession.FindByGuid(e.Tab.Id)));
                    })
                );

            op.Completed +=new EventHandler(op_Completed);
        }
        /// <summary>
        /// Handles the callback TabUpdated event, updates the tab's data
        /// </summary>
        void OnTabUpdated(object sender, TabArgs e)
        {
            Tab tab = PublicSession.FindByGuid(e.Tab.Id);
            if (tab == null) return;

            tab.TabData.Title = e.Tab.Title;
            tab.TabData.Url = e.Tab.Url;
            tab.NavigateFirst = true;

            App.Current.Dispatcher.BeginInvoke(new Action(
                () =>
                    {
                        tab.Title = tab.TabData.Title;

                        /* this updates the renderer also */
                        MainWindow main = App.Current.MainWindow as MainWindow;
                        if (main != null && main.ClientStatus.IsWatching)
                            if (tab.renderer.IsHandleCreated)
                                tab.renderer.Navigate(tab.TabData.Url);
                    }
                    ));
        }
        /// <summary>
        /// Handles the callback TabAdded event, adds the received tab to the
        /// public session.
        /// </summary>
        void OnTabAdded(object sender, TabArgs e)
        {
            System.Windows.Threading.DispatcherOperation op = App.Current.Dispatcher.BeginInvoke
                (
                new Action(() =>
                    {
                        TabNext = new PublicTab(e.Tab);
                        PublicSession.Add(TabNext);
                    })
                );

            op.Completed += new EventHandler(op_Completed);
        }