EntryCollectionFilter.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » Runtime » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » dasBlog 
dasBlog » newtelligence » DasBlog » Runtime » EntryCollectionFilter.cs
using System;
using System.Collections.Generic;


namespace newtelligence.DasBlog.Runtime{
    public class EntryCollectionFilter : CollectionFilter<EntryCollection, Entry>
    {

        /// <summary>
        /// Used to generate Predicate&lt;Entry&gt; delegates for default filters.
        /// </summary>
        public static class DefaultFilters
        {

            private class FilterContainer
            {
                public string CategoryName;
                public string UserName;
                public string AcceptLanguages;
                public string EntryId;
                public DateTime StartDateTime;
                public DateTime EndDateTime;
                public DateTime Month;
                public TimeZone TimeZone;
                public EntryCollection EntryCollection;

                public bool IsInCategory(Entry entry)
                {
                    return Entry.IsInCategory(entry, CategoryName);
                }

                public bool IsFromUser(Entry entry)
                {
                    if (entry.Author == null || UserName == null) return false;
                    return (entry.Author.ToUpper() == UserName.ToUpper());
                }

                public bool IsInAcceptedLanguagesOrMultiLingual(Entry entry)
                {
                    return (entry.Language == null) || (entry.Language == string.Empty)
                        || Entry.IsInAcceptedLanguages(entry, AcceptLanguages);
                }

                public bool OccursBefore(Entry entry)
                {
                    return Entry.OccursBefore(entry, TimeZone, EndDateTime);
                }

                public bool OccursBetween(Entry entry)
                {
                    return Entry.OccursBetween(entry, TimeZone, StartDateTime, EndDateTime);
                }

                public bool OccursInMonth(Entry entry)
                {
                    return Entry.OccursInMonth(entry, TimeZone, Month);
                }

                public bool IsInEntryCollection(Entry entry)
                {
                    return EntryCollection.ContainsKey(entry.EntryId);
                }

                public bool HasEntryId(Entry entry)
                {
                    return String.Compare(entry.EntryId, EntryId, StringComparison.InvariantCultureIgnoreCase) == 0;
                }
            }

            public static Predicate<Entry> IsPublic()
            {
                return new Predicate<Entry>(Entry.IsPublicEntry);
            }

            public static Predicate<Entry> IsInCategory(string categoryName)
            {
                FilterContainer container = new FilterContainer();

                container.CategoryName = categoryName;

                return new Predicate<Entry>(container.IsInCategory);
            }

            public static Predicate<Entry> IsFromUser(string userName)
            {
                FilterContainer container = new FilterContainer();
                container.UserName = userName;

                return new Predicate<Entry>(container.IsFromUser);
            }

            public static Predicate<Entry> IsInAcceptedLanguagesOrMultiLingual(string acceptLanguages)
            {
                FilterContainer container = new FilterContainer();

                container.AcceptLanguages = acceptLanguages;

                return new Predicate<Entry>(container.IsInAcceptedLanguagesOrMultiLingual);
            }


            public static Predicate<Entry> OccursBefore(TimeZone timeZone, DateTime dateTime)
            {
                FilterContainer container = new FilterContainer();

                container.TimeZone = timeZone;
                container.EndDateTime = dateTime;

                return new Predicate<Entry>(container.OccursBefore);
            }

            public static Predicate<Entry> OccursBetween(TimeZone timeZone, DateTime startDateTime, DateTime endDateTime)
            {
                FilterContainer container = new FilterContainer();

                container.TimeZone = timeZone;
                container.StartDateTime = startDateTime;
                container.EndDateTime = endDateTime;

                return new Predicate<Entry>(container.OccursBetween);
            }

            public static Predicate<Entry> OccursInMonth(TimeZone timeZone, DateTime month)
            {
                FilterContainer container = new FilterContainer();

                container.TimeZone = timeZone;
                container.Month = month;

                return new Predicate<Entry>(container.OccursInMonth);
            }

            public static Predicate<Entry> IsInEntryIdCacheEntryCollection(EntryCollection collection)
            {
                FilterContainer container = new FilterContainer();

                container.EntryCollection = collection;

                return new Predicate<Entry>(container.IsInEntryCollection);
            }

            public static Predicate<Entry> HasEntryId(string entryId)
            {
                FilterContainer container = new FilterContainer();

                container.EntryId = entryId;

                return new Predicate<Entry>(container.HasEntryId);
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.