// remove key / value pair if the given key exists and has expired
 private void CheckExpiration(TKey key)
 {
     if (LastAccessed.ContainsKey(key) && DateTime.Now - LastAccessed[key] > Timeout)
     {
         Remove(key);
     }
 }
Example #2
0
 public List <string> Properties()
 {
     return(new List <string> {
         FileName, Extension, FileSize.ToString(), FileType, Name, Hidden.ToString(),
         LastModified.ToString(), LastAccessed.ToString(), CreationDate.ToString()
     });
 }
Example #3
0
        public object ReadYaml(IParser parser, Type type)
        {
            // Set to MinValue explicitly - https://stackoverflow.com/a/305169/636.
            var result = new LastAccessed()
            {
                Value = DateTime.MinValue
            };

            // Get the actual value out of the current location in the YAML
            var value = Utilities.GetScalarValue(parser);

            // Put it in our custom type.
            var dateParsed = DateTime.TryParse(value, out var parsedDateValue);

            if (dateParsed)
            {
                result.Value = parsedDateValue;
            }

            // We need to advance to the next event, or the parser gets out of sync!
            parser.MoveNext();

            Console.WriteLine(result);

            return(result);
        }
        public new bool ContainsKey(TKey key)
        {
            CheckExpiration(key);

            if (LastAccessed.ContainsKey(key))
            {
                LastAccessed[key] = DateTime.Now;
            }
            return(base.ContainsKey(key));
        }
        public virtual new bool TryGetValue(TKey key, out TValue value)
        {
            CheckExpiration(key);

            if (LastAccessed.ContainsKey(key))
            {
                LastAccessed[key] = DateTime.Now;
            }
            return(base.TryGetValue(key, out value));
        }
        public virtual new TValue this[TKey key] {
            get {
                CheckExpiration(key);

                if (LastAccessed.ContainsKey(key))
                {
                    LastAccessed[key] = DateTime.Now;
                }
                return(base[key]);
            }
            set {
                LastAccessed[key] = DateTime.Now;
                base[key]         = value;
            }
        }
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew">是否插入</param>
        public override void Valid(Boolean isNew)
        {
            // 如果没有脏数据,则不需要进行任何处理
            if (!HasDirty)
            {
                return;
            }

            // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
            if (Name.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Name), "Name不能为空!");
            }
            if (DisplayName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(DisplayName), "DisplayName不能为空!");
            }
            if (Description.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Description), "Description不能为空!");
            }
            if (Created.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Created), "Created不能为空!");
            }
            if (Updated.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Updated), "Updated不能为空!");
            }
            if (LastAccessed.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(LastAccessed), "LastAccessed不能为空!");
            }

            // 在新插入数据或者修改了指定字段时进行修正

            // 检查唯一索引
            // CheckExist(isNew, __.Name);
        }
 public virtual new void Clear()
 {
     LastAccessed.Clear();
     base.Clear();
 }
 public virtual new bool Remove(TKey key)
 {
     LastAccessed.Remove(key);
     return(base.Remove(key));
 }
Example #10
0
 public virtual new void Add(TKey key, TValue value)
 {
     LastAccessed.Add(key, DateTime.Now);
     base.Add(key, value);
 }
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew">是否插入</param>
        public override void Valid(Boolean isNew)
        {
            // 如果没有脏数据,则不需要进行任何处理
            if (!HasDirty)
            {
                return;
            }

            // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
            if (ClientId.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(ClientId), "ClientId不能为空!");
            }
            if (ProtocolType.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(ProtocolType), "ProtocolType不能为空!");
            }
            if (ClientName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(ClientName), "ClientName不能为空!");
            }
            if (Description.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Description), "Description不能为空!");
            }
            if (ClientUri.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(ClientUri), "ClientUri不能为空!");
            }
            if (LogoUri.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(LogoUri), "LogoUri不能为空!");
            }
            if (FrontChannelLogoutUri.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(FrontChannelLogoutUri), "FrontChannelLogoutUri不能为空!");
            }
            if (BackChannelLogoutUri.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(BackChannelLogoutUri), "BackChannelLogoutUri不能为空!");
            }
            if (ClientClaimsPrefix.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(ClientClaimsPrefix), "ClientClaimsPrefix不能为空!");
            }
            if (PairWiseSubjectSalt.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(PairWiseSubjectSalt), "PairWiseSubjectSalt不能为空!");
            }
            if (Created.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Created), "Created不能为空!");
            }
            if (Updated.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Updated), "Updated不能为空!");
            }
            if (LastAccessed.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(LastAccessed), "LastAccessed不能为空!");
            }
            if (UserCodeType.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(UserCodeType), "UserCodeType不能为空!");
            }

            // 在新插入数据或者修改了指定字段时进行修正

            // 检查唯一索引
            // CheckExist(isNew, __.ClientId);
        }
 public virtual bool Remove(TKey key)
 {
     LastAccessed.Remove(key);
     return(base.TryRemove(key, out _));
 }