Preferences.cs :  » Bloggers » SubText » Subtext » Web » Admin » 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 » SubText 
SubText » Subtext » Web » Admin » Preferences.cs
#region Disclaimer/Info

///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at subtext@googlegroups.com 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.Web;
using log4net;
using Subtext.Extensibility;
using Subtext.Framework.Components;
using Subtext.Framework.Logging;

namespace Subtext.Web.Admin{
    // This is sort of experimental right now. Not sure it's clean enough/performant enough.
    internal static class Preferences
    {
        const int COOKIE_EXPIRY_MONTHS = 6;
        private const string COOKIES_CREATE_ISACTIVE = "AlwaysCreateItemsAsActive";
        private const string COOKIES_EXPAND_ADVANCED = "AdminCookieAlwaysExpandAdvanced";
        private const string COOKIES_FEEDBACK_FILTER = "AdminCookieFeedbackFilter";
        private const string COOKIES_FEEDBACK_SHOWONLYCOMMENTS = "AdminCookieFeedbackShowOnlyComments"; //obsolete
        private const string COOKIES_PAGE_SIZE_DEFAULT = "AdminCookieListingItemCount";
        private readonly static ILog log = new Log();

        internal static int ListingItemCount
        {
            get
            {
                if(null != HttpContext.Current.Request.Cookies[COOKIES_PAGE_SIZE_DEFAULT])
                {
                    return Int32.Parse(HttpContext.Current.Request.Cookies[COOKIES_PAGE_SIZE_DEFAULT].Value);
                }
                else
                {
                    return Constants.PAGE_SIZE_DEFAULT;
                }
            }
            set
            {
                if(value > 0)
                {
                    CreateCookie(COOKIES_PAGE_SIZE_DEFAULT, value, CookieExpiry);
                }
            }
        }

        internal static bool AlwaysExpandAdvanced
        {
            get
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[COOKIES_EXPAND_ADVANCED];
                if(null != cookie)
                {
                    return String.Equals(cookie.Value, "true", StringComparison.InvariantCultureIgnoreCase)
                               ? true
                               : false;
                }
                else
                {
                    return Constants.ALWAYS_EXPAND_DEFAULT;
                }
            }
            set { CreateCookie(COOKIES_EXPAND_ADVANCED, value, CookieExpiry); }
        }

        internal static bool AlwaysCreateIsActive
        {
            get
            {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[COOKIES_CREATE_ISACTIVE];
                if(null != cookie)
                {
                    return String.Equals(cookie.Value, "true", StringComparison.InvariantCultureIgnoreCase)
                               ? true
                               : false;
                }
                else
                {
                    return Constants.CREATE_ISACTIVE_DEFAULT;
                }
            }
            set
            {
//        if (value != Constants.CREATE_ISACTIVE_DEFAULT)
                CreateCookie(COOKIES_CREATE_ISACTIVE, value, CookieExpiry);
            }
        }

        static DateTime CookieExpiry
        {
            get { return DateTime.Now.AddMonths(COOKIE_EXPIRY_MONTHS); }
        }

        internal static string GetFeedbackItemFilter(FeedbackStatusFlag currentView)
        {
            string cookieName = COOKIES_FEEDBACK_FILTER + currentView;
            if(null != HttpContext.Current.Request.Cookies[cookieName])
            {
                return HttpContext.Current.Request.Cookies[cookieName].Value;
            }
            return FeedbackType.None.ToString();
        }

        internal static void SetFeedbackItemFilter(string value, FeedbackStatusFlag currentView)
        {
            string cookieName = COOKIES_FEEDBACK_FILTER + currentView;

            if(Enum.IsDefined(typeof(FeedbackType), value))
            {
                CreateCookie(cookieName, value, CookieExpiry);
            }
            else
            {
                log.Warn("Could not set FeedbackType value: " + value);
            }
        }

        //This is a helper. Maybe it should go in another class? 13-nov-06 mountain_sf
        internal static FeedbackType ParseFeedbackItemFilter(string value)
        {
            try
            {
                return (FeedbackType)Enum.Parse(typeof(FeedbackType), value, true);
            }
            catch(ArgumentNullException ane)
            {
                log.Warn("Could not parse FeedbackType value. Value was null.", ane);
                return FeedbackType.None;
            }
            catch(ArgumentException ae)
            {
                log.Warn("Could not parse FeedbackType value.", ae);
                return FeedbackType.None;
            }
        }

        static void CreateCookie(string name, object value, DateTime expiry)
        {
            var addingCookie = new HttpCookie(name);
            addingCookie.Value = value.ToString();
            addingCookie.Expires = expiry;
            HttpContext.Current.Response.Cookies.Add(addingCookie);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.