public static bool SortLists(RecurringRecordingList[] lists, int length, RecNameSort sortByName, RecSizeSort sortBySize) { if (lists == null || lists.Length == 0 || length < 1) { return(false); } if (length > lists.Length) { length = lists.Length; } if (length == 1) { return(true); } if (sortByName == RecNameSort.None && sortBySize == RecSizeSort.None) { return(true); } KeyValuePair <int, RecurringRecordingList>[] sortedTable = new KeyValuePair <int, RecurringRecordingList> [length]; for (int i = 0; i < length; i++) { sortedTable[i] = new KeyValuePair <int, RecurringRecordingList>(lists[i].ChannelOID, lists[i]); } sRecListComparer.SortByName = sortByName; sRecListComparer.SortBySize = sortBySize; Array.Sort(sortedTable, sRecListComparer); for (int i = 0; i < length; i++) { lists[i] = sortedTable[i].Value; } return(true); }
public void GroupByChannel(RecNameSort sortByName, RecSizeSort sortBySize) { if (this.mChannelOID == 0) { int i, channelOID; RecurringRecordingList list; Dictionary <int, RecurringRecordingList> channelTable = new Dictionary <int, RecurringRecordingList>(); for (i = 0; i < this.mList.Count; i++) { channelOID = this.mList[i].ChannelOID; if (!channelTable.TryGetValue(channelOID, out list)) { list = new RecurringRecordingList(); list.mChannelOID = channelOID; list.mChannelName = this.mList[i].ChannelName; list.mList = new List <RecurringRecording>(); channelTable.Add(channelOID, list); } list.mList.Add(this.mList[i]); } if (sortByName != RecNameSort.None || sortBySize != RecSizeSort.None) { KeyValuePair <int, RecurringRecordingList>[] sortedTable = new KeyValuePair <int, RecurringRecordingList> [channelTable.Count]; i = 0; foreach (KeyValuePair <int, RecurringRecordingList> channel in channelTable) { sortedTable[i++] = channel; } sRecListComparer.SortByName = sortByName; sRecListComparer.SortBySize = sortBySize; Array.Sort(sortedTable, sRecListComparer); this.mList.Clear(); for (int j = 0; j < sortedTable.Length; j++) { list = sortedTable[j].Value; for (i = 0; i < list.mList.Count; i++) { this.mList.Add(list.mList[i]); } } } else { this.mList.Clear(); foreach (KeyValuePair <int, RecurringRecordingList> channel in channelTable) { list = channel.Value; for (i = 0; i < list.mList.Count; i++) { this.mList.Add(list.mList[i]); } } } } }
public RecurringRecordingList[] DivideByChannel(RecNameSort sortByName, RecSizeSort sortBySize) { RecurringRecordingList[] channels; if (this.mChannelOID != 0) { channels = new RecurringRecordingList[1]; channels[0] = this; return(channels); } int i, channelOID; RecurringRecordingList list; Dictionary <int, RecurringRecordingList> channelTable = new Dictionary <int, RecurringRecordingList>(); for (i = 0; i < this.mList.Count; i++) { channelOID = this.mList[i].ChannelOID; if (!channelTable.TryGetValue(channelOID, out list)) { list = new RecurringRecordingList(); list.mChannelOID = channelOID; list.mChannelName = this.mList[i].ChannelName; list.mList = new List <RecurringRecording>(); channelTable.Add(channelOID, list); } list.mList.Add(this.mList[i]); } channelOID = 0; channels = new RecurringRecordingList[channelTable.Count]; if (sortByName != RecNameSort.None || sortBySize != RecSizeSort.None) { i = 0; KeyValuePair <int, RecurringRecordingList>[] sortedTable = new KeyValuePair <int, RecurringRecordingList> [channelTable.Count]; foreach (KeyValuePair <int, RecurringRecordingList> channel in channelTable) { sortedTable[i++] = channel; } sRecListComparer.SortByName = sortByName; sRecListComparer.SortBySize = sortBySize; Array.Sort(sortedTable, sRecListComparer); for (i = 0; i < sortedTable.Length; i++) { channels[i] = sortedTable[i].Value; } } else { i = 0; foreach (KeyValuePair <int, RecurringRecordingList> channel in channelTable) { channels[i++] = channel.Value; } } return(channels); }
public RecListComparer(RecNameSort sortByName, RecSizeSort sortBySize) { this.SortByName = sortByName; this.SortBySize = sortBySize; }