public Conference[] GetConferences() { // Get the full list of conferences, and remove those that do not have proper end times Conference[] fullList = DBHelper.GetConferences(); ArrayList confsWithEndTimes = new ArrayList(fullList.Length); foreach (Conference conf in fullList) { if (conf.End != DateTime.MinValue) { confsWithEndTimes.Add(conf); } } // Return an array of those conferences Conference[] confsWithEndTimesArray = (Conference[])confsWithEndTimes.ToArray(typeof(Conference)); return(confsWithEndTimesArray); }
public void CleanUpDatabase() { // Find: // - conferences w/o participants // - participants w/o streams // - streams w/o bytes ArrayList confs = new ArrayList(), parts = new ArrayList(), streams = new ArrayList(); #region Depth-first-search of tree // By collecting a full list of the conferences, participants, and streams to be deleted // we can more effeciently delete the objects by doing quick bulk deletes from the database, // rather than transacting for each individual delete. foreach (TreeNode yearNode in Nodes) { foreach (TreeNode monthNode in yearNode.Nodes) { foreach (TreeNode dateNode in monthNode.Nodes) { foreach (TreeNode confNode in dateNode.Nodes) { if (!confNode.Nodes.GetEnumerator().MoveNext()) // check for emptiness { confs.Add(confNode); } else { foreach (TreeNode partNode in confNode.Nodes) { if (!partNode.Nodes.GetEnumerator().MoveNext()) { parts.Add(partNode); } else { foreach (TreeNode streamNode in partNode.Nodes) { if ((streamNode.Tag as Stream).Bytes <= 1) { streams.Add(streamNode); } } } } } } } } } #endregion #region Transact on DB for Delete: // - conferences int[] confIDs = new int[confs.Count]; for (int cnt = 0; cnt < confIDs.Length; ++cnt) { confIDs[cnt] = ((confs[cnt] as TreeNode).Tag as Conference).ConferenceID; } DBHelper.DeleteConferences(confIDs); // - participants int[] partIDs = new int[parts.Count]; for (int cnt = 0; cnt < partIDs.Length; ++cnt) { partIDs[cnt] = ((parts[cnt] as TreeNode).Tag as Participant).ParticipantID; } DBHelper.DeleteParticipants(partIDs); // - streams int[] streamIDs = new int[streams.Count]; for (int cnt = 0; cnt < streamIDs.Length; ++cnt) { streamIDs[cnt] = ((streams[cnt] as TreeNode).Tag as Stream).StreamID; } DBHelper.DeleteStreams(streamIDs); #endregion // Delete from UI RemoveNodes(confs); RemoveNodes(parts); RemoveNodes(streams); // Find Conferences w/o end times // (for simplicity, just get them from the DB again) Conference[] allConfs = DBHelper.GetConferences(); foreach (Conference conf in allConfs) { if (conf.End == DateTime.MinValue) { DBHelper.CreateConferenceEndTime(conf.ConferenceID); } } }
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; } }