Mercurial > pub > bltoolkit
comparison Source/Aspects/CacheAttribute.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using BLToolkit.Properties; | |
3 using BLToolkit.Reflection; | |
4 using BLToolkit.TypeBuilder.Builders; | |
5 | |
6 namespace BLToolkit.Aspects | |
7 { | |
8 /// <summary> | |
9 /// http://www.bltoolkit.net/Doc/Aspects/index.htm | |
10 /// </summary> | |
11 [AttributeUsage( | |
12 AttributeTargets.Class | | |
13 AttributeTargets.Interface | | |
14 AttributeTargets.Property | | |
15 AttributeTargets.Method, | |
16 AllowMultiple=true)] | |
17 public class CacheAttribute : InterceptorAttribute | |
18 { | |
19 #region Constructors | |
20 | |
21 public CacheAttribute() | |
22 : this(typeof(CacheAspect), null) | |
23 { | |
24 } | |
25 | |
26 public CacheAttribute(Type cacheAspectType, string configString) | |
27 : base( | |
28 cacheAspectType, | |
29 InterceptType.BeforeCall | InterceptType.AfterCall, | |
30 configString, | |
31 TypeBuilderConsts.Priority.CacheAspect) | |
32 { | |
33 if (!TypeHelper.IsSameOrParent(typeof(CacheAspect), cacheAspectType)) | |
34 throw new ArgumentException(Resources.CacheAttribute_ParentTypeConstraintViolated); | |
35 } | |
36 | |
37 public CacheAttribute(Type interceptorType) | |
38 : this(interceptorType, null) | |
39 { | |
40 } | |
41 | |
42 public CacheAttribute(Type interceptorType, int maxCacheTime) | |
43 : this(interceptorType, null) | |
44 { | |
45 MaxCacheTime = maxCacheTime; | |
46 } | |
47 | |
48 public CacheAttribute(Type interceptorType, bool isWeak) | |
49 : this(interceptorType, null) | |
50 { | |
51 IsWeak = isWeak; | |
52 } | |
53 | |
54 public CacheAttribute(Type interceptorType, int maxCacheTime, bool isWeak) | |
55 : this(interceptorType, null) | |
56 { | |
57 MaxCacheTime = maxCacheTime; | |
58 IsWeak = isWeak; | |
59 } | |
60 | |
61 public CacheAttribute(string configString) | |
62 : this(typeof(CacheAspect), configString) | |
63 { | |
64 } | |
65 | |
66 public CacheAttribute(int maxCacheTime) | |
67 : this(typeof(CacheAspect), maxCacheTime) | |
68 { | |
69 } | |
70 | |
71 public CacheAttribute(bool isWeak) | |
72 : this(typeof(CacheAspect), isWeak) | |
73 { | |
74 } | |
75 | |
76 public CacheAttribute(int maxCacheTime, bool isWeak) | |
77 : this(typeof(CacheAspect), maxCacheTime, isWeak) | |
78 { | |
79 } | |
80 | |
81 #endregion | |
82 | |
83 #region Properties | |
84 | |
85 private bool _hasMaxCacheTime; | |
86 private int _maxCacheTime; | |
87 public int MaxCacheTime | |
88 { | |
89 get { return _maxCacheTime; } | |
90 set { _maxCacheTime = value; _hasMaxCacheTime = true; } | |
91 } | |
92 | |
93 public int MaxSeconds | |
94 { | |
95 get { return MaxCacheTime / 1000; } | |
96 set { MaxCacheTime = value * 1000; } | |
97 } | |
98 | |
99 public int MaxMinutes | |
100 { | |
101 get { return MaxCacheTime / 60 / 1000; } | |
102 set { MaxCacheTime = value * 60 * 1000; } | |
103 } | |
104 | |
105 private bool _hasIsWeak; | |
106 private bool _isWeak; | |
107 public bool IsWeak | |
108 { | |
109 get { return _isWeak; } | |
110 set { _isWeak = value; _hasIsWeak = true; } | |
111 } | |
112 | |
113 public override string ConfigString | |
114 { | |
115 get | |
116 { | |
117 string s = base.ConfigString; | |
118 | |
119 if (_hasMaxCacheTime) s += ";MaxCacheTime=" + MaxCacheTime; | |
120 if (_hasIsWeak) s += ";IsWeak=" + IsWeak; | |
121 | |
122 if (!string.IsNullOrEmpty(s) && s[0] == ';') | |
123 s = s.Substring(1); | |
124 | |
125 return s; | |
126 } | |
127 } | |
128 | |
129 #endregion | |
130 } | |
131 } |