extendedformattime.cs

来自「HeyCacher 高性能缓存方案(带源码) 1. 文件的所有权益归上传用户所有」· CS 代码 · 共 82 行

CS
82
字号
//===============================================================================
// CSDN HeyCache 
//===============================================================================
// 修改记录:[按最后修改时间倒排序]
// 2007.06.11 by tangwei
//
// 代码来源:参考于dotnet企业库3.0版
//===============================================================================
using System;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Permissions;
using Microsoft.Practices.EnterpriseLibrary.Caching.Properties;

namespace HeyCacher.Components.Expirations
{
    /// <summary>
    ///	按特定时间为依赖的失效策略中的时间参数
    /// </summary>
    [Serializable]
    [ComVisible(false)]
    public class ExtendedFormatTime : ICacheItemExpiration
    {
        public string TimeFormat
        {
            get { return extendedFormat; }
        }
        private string extendedFormat;
        private DateTime lastUsedTime;

        public ExtendedFormatTime() { }
        public ExtendedFormatTime(string timeFormat)
        {
            innerCreate(timeFormat);
        }    

        public void Create(params string[] Params)
        {
            innerCreate(Params[0]);
        }
        private void innerCreate(string timeFormat)
        {
            // check arguments
            if (string.IsNullOrEmpty(timeFormat))
            {
                throw new ArgumentException(Resources.ExceptionNullTimeFormat, "timeFormat");
            }

            ExtendedFormat.Validate(timeFormat);

            // Get the modified extended format
            this.extendedFormat = timeFormat;

            // Convert to UTC in order to compensate for time zones		
            this.lastUsedTime = DateTime.Now.ToUniversalTime();
        }

        public bool HasExpired()
        {
            // Convert to UTC in order to compensate for time zones		
            DateTime nowDateTime = DateTime.Now.ToUniversalTime();

            ExtendedFormat format = new ExtendedFormat(extendedFormat);
            // Check expiration
            if (format.IsExpired(lastUsedTime, nowDateTime))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public void Notify()
        {
        }
        public void Initialize(ExpirationItem owningCacheItem)
        {
        } 
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?