The Labs \ Source Viewer \ SSCLI \ System.Net.Configuration \ HttpCachePolicyElement

  1. //------------------------------------------------------------------------------
  2. // <copyright file="HttpCachePolicyElement.cs" company="Microsoft Corporation">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.Net.Configuration
  16. {
  17.     using System;
  18.     using System.Configuration;
  19.     using System.Net.Cache;
  20.     using System.Xml;
  21.     using System.Security.Permissions;
  22.    
  23.     public sealed class HttpCachePolicyElement : ConfigurationElement
  24.     {
  25.         public HttpCachePolicyElement()
  26.         {
  27.             this.properties.Add(this.maximumAge);
  28.             this.properties.Add(this.maximumStale);
  29.             this.properties.Add(this.minimumFresh);
  30.             this.properties.Add(this.policyLevel);
  31.         }
  32.        
  33.         protected override ConfigurationPropertyCollection Properties {
  34.             get { return this.properties; }
  35.         }
  36.        
  37.         [ConfigurationProperty(ConfigurationStrings.MaximumAge, DefaultValue = TimeSpanValidatorAttribute.TimeSpanMaxValue)]
  38.         public TimeSpan MaximumAge {
  39.             get { return (TimeSpan)this[this.maximumAge]; }
  40.             set { this[this.maximumAge] = value; }
  41.         }
  42.        
  43.         [ConfigurationProperty(ConfigurationStrings.MaximumStale, DefaultValue = TimeSpanValidatorAttribute.TimeSpanMinValue)]
  44.         public TimeSpan MaximumStale {
  45.             get { return (TimeSpan)this[this.maximumStale]; }
  46.             set { this[this.maximumStale] = value; }
  47.         }
  48.        
  49.         [ConfigurationProperty(ConfigurationStrings.MinimumFresh, DefaultValue = TimeSpanValidatorAttribute.TimeSpanMinValue)]
  50.         public TimeSpan MinimumFresh {
  51.             get { return (TimeSpan)this[this.minimumFresh]; }
  52.             set { this[this.minimumFresh] = value; }
  53.         }
  54.        
  55.         [ConfigurationProperty(ConfigurationStrings.PolicyLevel, IsRequired = true, DefaultValue = (HttpRequestCacheLevel)HttpRequestCacheLevel.Default)]
  56.         public HttpRequestCacheLevel PolicyLevel {
  57.             get { return (HttpRequestCacheLevel)this[this.policyLevel]; }
  58.             set { this[this.policyLevel] = value; }
  59.         }
  60.        
  61.        
  62.         protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
  63.         {
  64.             wasReadFromConfig = true;
  65.             base.DeserializeElement(reader, serializeCollectionKey);
  66.         }
  67.        
  68.         protected override void Reset(ConfigurationElement parentElement)
  69.         {
  70.             if (parentElement != null) {
  71.                 HttpCachePolicyElement http = (HttpCachePolicyElement)parentElement;
  72.                 this.wasReadFromConfig = http.wasReadFromConfig;
  73.             }
  74.             base.Reset(parentElement);
  75.         }
  76.        
  77.         internal bool WasReadFromConfig {
  78.             get { return this.wasReadFromConfig; }
  79.         }
  80.        
  81.         bool wasReadFromConfig = false;
  82.         ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection();
  83.        
  84.         readonly ConfigurationProperty maximumAge = new ConfigurationProperty(ConfigurationStrings.MaximumAge, typeof(TimeSpan), TimeSpan.MaxValue, ConfigurationPropertyOptions.None);
  85.        
  86.         readonly ConfigurationProperty maximumStale = new ConfigurationProperty(ConfigurationStrings.MaximumStale, typeof(TimeSpan), TimeSpan.MinValue, ConfigurationPropertyOptions.None);
  87.        
  88.         readonly ConfigurationProperty minimumFresh = new ConfigurationProperty(ConfigurationStrings.MinimumFresh, typeof(TimeSpan), TimeSpan.MinValue, ConfigurationPropertyOptions.None);
  89.        
  90.         readonly ConfigurationProperty policyLevel = new ConfigurationProperty(ConfigurationStrings.PolicyLevel, typeof(HttpRequestCacheLevel), HttpRequestCacheLevel.Default, ConfigurationPropertyOptions.None);
  91.        
  92.     }
  93.    
  94. }

Developer Fusion