Click here to Skip to main content
15,896,457 members
Articles / Desktop Programming / WPF

WPF Print Engine: Part I

Rate me:
Please Sign up or sign in to vote.
4.87/5 (99 votes)
27 Aug 2011CPOL10 min read 287.8K   13.7K   176  
WPF Print Engine makes it easier for .NET developers working with WPF applications to leverage printing facility.
/**
 * File name: CacheHelper.cs 
 * Author: Mosfiqur.Rahman
 * Date: 9/6/2009 4:53:09 PM format: MM/dd/yyyy
 * 
 * 
 * Modification history:
 * Name				Date					Desc
 * 
 *  
 * Version: 1.0
 * Copyright (c) 2008: Orbitax LLC.
 * */

#region Using Directives

using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

#endregion

namespace SUT.PrintEngine.Utils
{
    /// <summary>
    /// This is a wrapper of Microsoft Patterns & Practices CachingManager class.
    /// Currently it has been configured only to cache in memory.
    /// </summary>
    public class CacheHelper
    {
        #region Member Variables

        private ICacheManager _cacheManager;

        #endregion

        #region Constructors

        #endregion

        #region Properties
        #endregion

        #region Methods

        private void InitializeCacheManager()
        {
            if (null == _cacheManager)
            {
                var fileSource = new FileConfigurationSource("SUT.PrintEngine.App.config");
                var factory = new CacheManagerFactory(fileSource);
                _cacheManager = factory.CreateDefault();
            }
        }

        #endregion


        #region CacheHelper Members

        public void Add(string key, object data)
        {
            InitializeCacheManager();
            _cacheManager.Add(key, data);
        }

        public bool Contains(string key)
        {
            InitializeCacheManager();
            return _cacheManager.Contains(key);
        }

        public void Flush()
        {
            InitializeCacheManager();
            _cacheManager.Flush();
        }

        public object GetData(string key)
        {
            InitializeCacheManager();
            return _cacheManager.GetData(key);
        }

        public void Remove(string key)
        {
            InitializeCacheManager();
            _cacheManager.Remove(key);
        }

        public int Count
        {
            get 
            {
                InitializeCacheManager();
                return _cacheManager.Count; 
            }
        }

        public object this[string key]
        {
            get 
            {
                InitializeCacheManager();
                return _cacheManager[key]; 
            }
        }

        #endregion
    }
}

// end of namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
Currently living and working in London. He is an enthusiastic software developer passionate about microsoft technologies, specially C#, WPF, Silverlight WCF and windows Azure. Contributes to several open source project and msdn forums.

My Blog
twitter : @sarafuddin

Comments and Discussions