Beispiel #1
0
 /// <summary>
 /// Counts the amount of channels which pass the given ChannelSearchArgs filter
 /// </summary>
 /// <param name="filter">ChannelSearchArgs filter to apply to all channels</param>
 /// <returns>The amount of channels passing the filter</returns>
 public int CountChannelsPassingFilter(ChannelSearchArgs filter)
 {
     return _dao.GetChannelsWithFilter(filter).Count;
 }
Beispiel #2
0
 /// <summary>
 /// Gets the channels.
 /// </summary>
 /// <param name="args">The args.</param>
 /// <returns></returns>
 public DatabaseWrapperObjects.Channel[] GetChannels(ChannelSearchArgs args)
 {
     if (args == null) LogAndThrowException(new ArgumentNullException("args"), "GetChannels");
     try
     {
         IEnumerable<Channel> channels = _dao.GetChannelsWithFilter(args);
         return Channel.GetChannels(channels).ToArray();
     }
     catch (Exception e)
     {
         //if (_handler != null)
         //    _handler(this, new RentItEventArgs("GetChannels failed with exception [" + e + "]."));
         string entry = string.Format("GetChannels failed with exception [{0}]. Local variables: args = {1}", e, args);
         if (args != null)
             entry =
                 string.Format(
                     "{0}, args.AmountPlayed = {1}, args.Genres = {2}, args.NumberOfComments = {3}, args.NumberOfSubscriptions = {4}, args.SearchString = {5}, args.SortOption = {6}, args.StartIndex = {7}, args.EndIndex = {8}",
                     entry, args.MinAmountPlayed, args.MinNumberOfComments, args.MinNumberOfSubscriptions, args.SearchString.Equals("") ? "\"\"" : args.SearchString, args.SortOption.Equals("") ? "\"\"" : args.SortOption, args.StartIndex, args.EndIndex);
         _logger.AddEntry(entry);
         throw;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Counts all channels with filter.
 /// </summary>
 /// <param name="filter">The filter.</param>
 /// <returns></returns>
 public int CountAllChannelsWithFilter(ChannelSearchArgs filter)
 {
     filter.StartIndex = 0;
     filter.EndIndex = Int32.MaxValue;
     return GetChannels(filter).Length;
 }
Beispiel #4
0
        /// <summary>
        /// Filters the with respect to the filter arguments:
        /// filter.Name
        /// filter.AmountPlayed
        /// filter.Genres
        /// filter.NumberOfComments
        /// filter.NumberOfSubscriptions
        /// filter.SortOptions
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns>
        /// Channel ids of the channels matching the filter.
        /// </returns>
        public List<Channel> GetChannelsWithFilter(ChannelSearchArgs filter)
        {
            List<Channel> filteredChannels;
            using (RENTIT21Entities context = new RENTIT21Entities())
            {   // get all channels that starts with filter.Name

                var channels = from c in context.Channels
                               where c.Name.Contains(filter.SearchString) || c.Description.Contains(filter.SearchString)
                               select c;

                if (filter.Genres != null && filter.Genres.Length > 0)
                {
                    channels = from channel in channels
                               let ids = (from cg in channel.Genres
                                          select cg.Id)
                               where (from i in ids
                                      where filter.Genres.Contains(i)
                                      select i).Any()
                               select channel;
                }
                if (filter.MinAmountPlayed > -1)
                {   // Apply amount played filter
                    channels = from channel in channels where channel.Hits >= filter.MinAmountPlayed select channel;
                }
                if (filter.MaxAmountPlayed < Int32.MaxValue)
                {   // Apply amount played filter
                    channels = from channel in channels where channel.Hits <= filter.MaxAmountPlayed select channel;
                }
                if (filter.MinNumberOfComments > -1)
                {   // Apply comment filter
                    channels = from channel in channels where channel.Comments.Count >= filter.MinNumberOfComments select channel;
                }
                if (filter.MaxNumberOfComments < Int32.MaxValue)
                {   // Apply comment filter
                    channels = from channel in channels where channel.Comments.Count <= filter.MaxNumberOfComments select channel;
                }
                if (filter.MinNumberOfSubscriptions > -1)
                {   // Apply subscription filter
                    channels = from channel in channels where channel.Subscribers.Count >= filter.MinNumberOfSubscriptions select channel;
                }
                if (filter.MaxNumberOfSubscriptions < Int32.MaxValue)
                {   // Apply subscription filter
                    channels = from channel in channels where channel.Subscribers.Count <= filter.MaxNumberOfSubscriptions select channel;
                }
                if (filter.MinTotalVotes > -1)
                {   // Apply votes filter
                    IQueryable<Channel> noTracksChannels = null;
                    if (filter.MinTotalVotes == 0)
                    {
                        noTracksChannels = from channel in channels
                                           where channel.Tracks.Count == 0
                                           select channel;
                    }

                    channels = from channel in channels
                               where (from track in channel.Tracks
                                      select track.UpVotes + track.DownVotes).Sum() >= filter.MinTotalVotes
                               select channel;

                    if (filter.MinTotalVotes == 0 && noTracksChannels != null)
                    {
                        channels = channels.Concat(noTracksChannels);
                    }
                    channels = channels.Distinct();
                }
                if (filter.MaxTotalVotes < Int32.MaxValue)
                {   // Apply votes filter
                    IQueryable<Channel> noTracksChannels = null;
                    if (filter.MinTotalVotes <= 0)
                    {
                        noTracksChannels = from channel in channels
                                           where channel.Tracks.Count == 0
                                           select channel;
                    }

                    channels = from channel in channels
                               where (from track in channel.Tracks
                                      select track.UpVotes + track.DownVotes).Sum() <= filter.MaxTotalVotes
                               select channel;

                    if (filter.MinTotalVotes <= 0 && noTracksChannels != null)
                    {
                        channels = channels.Concat(noTracksChannels);
                    }
                    channels = channels.Distinct();
                }
                if (!filter.SortOption.Equals(""))
                {   // Apply specific sort order
                    if (filter.SortOption.Equals(filter.HitsAsc))
                    {
                        channels = from channel in channels orderby channel.Hits ascending select channel;
                    }
                    else if (filter.SortOption.Equals(filter.HitsDesc))
                    {
                        channels = from channel in channels orderby channel.Hits descending select channel;
                    }
                    else if (filter.SortOption.Equals(filter.NameAsc))
                    {
                        channels = from channel in channels orderby channel.Name ascending select channel;
                    }
                    else if (filter.SortOption.Equals(filter.NameDesc))
                    {
                        channels = from channel in channels orderby channel.Name descending select channel;
                    }
                    else if (filter.SortOption.Equals(filter.NumberOfCommentsAsc))
                    {
                        channels = from channel in channels orderby channel.Comments.Count ascending select channel;
                    }
                    else if (filter.SortOption.Equals(filter.NumberOfCommentsDesc))
                    {
                        channels = from channel in channels orderby channel.Comments.Count descending select channel;
                    }
                    else if (filter.SortOption.Equals(filter.SubscriptionsAsc))
                    {
                        channels = from channel in channels orderby channel.Subscribers.Count ascending select channel;
                    }
                    else if (filter.SortOption.Equals(filter.SubscriptionsDesc))
                    {
                        channels = from channel in channels orderby channel.Subscribers.Count descending select channel;
                    }
                    else if (filter.SortOption.Equals(filter.NumberOfVotesAsc))
                    {
                        channels = from channel in channels
                                   orderby (from track in channel.Tracks
                                            select track.UpVotes + track.DownVotes).Sum() ascending
                                   select channel;
                    }
                    else if (filter.SortOption.Equals(filter.NumberOfVotesDesc))
                    {
                        channels = from channel in channels
                                   orderby (from track in channel.Tracks
                                            select track.UpVotes + track.DownVotes).Sum() descending
                                   select channel;
                    }
                }
                else
                {
                    // Apply default sort order
                    channels = from channel in channels orderby channel.Name ascending select channel;
                }
                filteredChannels = channels.Any() == false ? new List<Channel>() : channels.ToList();
            }
            if (filter.StartIndex != -1 && filter.EndIndex != -1 && filter.StartIndex <= filter.EndIndex)
            {   // Only get the channels within the specified interval [filter.startIndex, ..., filter.endIndex-1]

                // The amount of channels
                int count;

                if (filter.StartIndex < -1)
                {   // If start index is negative, start from 0
                    count = filter.EndIndex;
                    filter.StartIndex = 0;
                }
                else
                {   // If both start and endindex are positive,
                    count = filter.EndIndex - filter.StartIndex;
                }

                if (filteredChannels.Count < filter.EndIndex) //Check if endindex is higher than the amount of channels found
                {
                    //Set endindex to the amount of channels found
                    filter.EndIndex = filteredChannels.Count;
                }
                if (filteredChannels.Count < filter.StartIndex) //Check if startindex is higher than the amount of channels found
                {
                    //Set startindex to the amount of channels found minus the amount of channels which should be retreived
                    filter.StartIndex = (filteredChannels.Count - count);
                    //Set endindex to the amount of channels found
                    filter.EndIndex = filteredChannels.Count;
                }

                //Create array to contain the result channels
                Channel[] result = new Channel[filter.EndIndex - filter.StartIndex];
                //Copy the channels to the result array
                filteredChannels.CopyTo(filter.StartIndex, result, 0, (filter.EndIndex - filter.StartIndex));
                return result.ToList();
            }
            return filteredChannels;
        }
Beispiel #5
0
 /// <summary>
 /// Counts the amount of channels which pass the given ChannelSearchArgs filter
 /// </summary>
 /// <param name="filter">ChannelSearchArgs filter to apply to all channels</param>
 /// <returns>The amount of channels passing the filter</returns>
 public int CountChannelsPassingFilter(ChannelSearchArgs filter)
 {
     return _controller.CountChannelsPassingFilter(filter);
 }
Beispiel #6
0
 public int CountAllChannelsWithFilter(ChannelSearchArgs filter)
 {
     return _controller.CountAllChannelsWithFilter(filter);
 }
Beispiel #7
0
 /// <summary>
 /// Gets the channel ids matching the given search arguments.
 /// </summary>
 /// <param name="args">The search arguments (used for filtering).</param>
 /// <returns>
 /// An array of channel ids matching search criteria.
 /// </returns>
 public ITU.DatabaseWrapperObjects.Channel[] GetChannels(ChannelSearchArgs args)
 {
     return _controller.GetChannels(args);
 }