예제 #1
0
        public void Connect()
        {
            try
            {
                // - Display wait message
                Cursor.Current = Cursors.WaitCursor;

                // - Get conferences ordered by start time
                Conference[] confs = DBHelper.GetConferences();

                // - Add items with parents: year, month, date
                TreeNode   lastNode = null;
                Conference lastConf = null;

                if (confs != null && confs.Length > 0)
                {
                    this.Nodes.Clear();
                }
                foreach (Conference conf in confs)
                {
                    TreeNode newNode = new TreeNode(string.Format(CultureInfo.CurrentCulture, Strings.Conference,
                                                                  conf.Start.ToShortTimeString(), conf.Description));
                    newNode.Tag                = conf;
                    newNode.ImageIndex         = conferenceImageIndex;
                    newNode.SelectedImageIndex = conferenceImageIndex;

                    TreeNode parent     = null;
                    bool     tripSwitch = (lastNode == null);

                    #region Add parents for this node
                    // Optimize creation of parents by tracking the last node & using the knowledge
                    //  that confs is organized by startTime (thank you, Mr. SQL, for the "order by" command.)

                    // My apologies for the lack of readability of this code.  It _was_ worse...
                    if (tripSwitch || conf.Start.Year != lastConf.Start.Year)
                    {
                        parent                    = this.Nodes.Add(conf.Start.Year.ToString(CultureInfo.InvariantCulture));
                        parent.Tag                = ParentNode.Year;
                        parent.ImageIndex         = folderImageIndex;
                        parent.SelectedImageIndex = parent.ImageIndex;

                        if (tripSwitch != true)
                        {
                            tripSwitch = true;
                        }
                    }
                    if (tripSwitch || conf.Start.Month != lastConf.Start.Month)
                    {
                        if (!tripSwitch)
                        {
                            parent = lastNode.Parent.Parent.Parent;
                        }

                        parent                    = parent.Nodes.Add(conf.Start.ToString("MMMM", CultureInfo.InvariantCulture));
                        parent.Tag                = ParentNode.Month;
                        parent.ImageIndex         = folderImageIndex;
                        parent.SelectedImageIndex = parent.ImageIndex;

                        if (tripSwitch != true)
                        {
                            tripSwitch = true;
                        }
                    }
                    if (tripSwitch || conf.Start.Day != lastConf.Start.Day)
                    {
                        if (!tripSwitch)
                        {
                            parent = lastNode.Parent.Parent;
                        }

                        parent                    = parent.Nodes.Add(conf.Start.ToLongDateString());
                        parent.Tag                = ParentNode.Date;
                        parent.ImageIndex         = folderImageIndex;
                        parent.SelectedImageIndex = parent.ImageIndex;
                    }
                    else
                    {
                        parent = lastNode.Parent;
                    }
                    #endregion

                    // Pri3: Optimize getting of participants/streams.  Try to find a way to do it only after
                    //  each conference is expanded (note that a conference can't be "expanded" if it doesn't
                    //  have any children yet.  consider using a placeholder)
                    #region Get participants / streams
                    Participant[] participants = DBHelper.GetParticipants(conf.ConferenceID);
                    foreach (Participant part in participants)
                    {
                        // Create Participant node
                        TreeNode partNode = new TreeNode(string.Format(CultureInfo.CurrentCulture,
                                                                       Strings.Participant, part.CName));
                        partNode.Tag                = part;
                        partNode.ImageIndex         = participantImageIndex;
                        partNode.SelectedImageIndex = partNode.ImageIndex;

                        // Add all of the streams for this participant
                        Stream[] streams = DBHelper.GetStreamsFaster(part.ParticipantID);
                        foreach (Stream str in streams)
                        {
                            TreeNode streamNode = partNode.Nodes.Add(string.Format(CultureInfo.CurrentCulture,
                                                                                   Strings.Stream, str.Name));
                            streamNode.Tag = str;

                            // Set the payload type icon
                            MSR.LST.Net.Rtp.PayloadType payload = (MSR.LST.Net.Rtp.PayloadType)Enum.Parse(typeof(MSR.LST.Net.Rtp.PayloadType), str.Payload);
                            if (payload == MSR.LST.Net.Rtp.PayloadType.dynamicVideo)
                            {
                                streamNode.ImageIndex = videoImageIndex;
                            }
                            else if (payload == MSR.LST.Net.Rtp.PayloadType.dynamicAudio)
                            {
                                streamNode.ImageIndex = soundImageIndex;
                            }
                            else //if( payload == MSR.LST.Net.Rtp.PayloadType.dynamicPresentation )
                            {
                                streamNode.ImageIndex = presentationImageIndex;
                            }

                            streamNode.SelectedImageIndex = streamNode.ImageIndex;
                        }

                        newNode.Nodes.Add(partNode);
                    }
                    #endregion

                    parent.Nodes.Add(newNode);
                    lastNode = newNode;
                    lastConf = conf;
                }

                foreach (TreeNode rootNode in base.Nodes)
                {
                    rootNode.Expand();
                }

                this.canConnect = true;

                // - Remove wait message
                Cursor.Current = Cursors.Default;
            }
            catch
            {
                this.canConnect = false;
            }
        }