Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / ControlCachePolicy.cs / 1305376 / ControlCachePolicy.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Web;
using System.Web.Util;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Security.Permissions;
public sealed class ControlCachePolicy {
private static ControlCachePolicy _cachePolicyStub = new ControlCachePolicy();
private BasePartialCachingControl _pcc;
internal ControlCachePolicy() {
}
internal ControlCachePolicy(BasePartialCachingControl pcc) {
_pcc = pcc;
}
internal static ControlCachePolicy GetCachePolicyStub() {
// Return a stub, which returns SupportsCaching==false and throws on everything else.
return _cachePolicyStub;
}
// Check whether it is valid to access properties on this object
private void CheckValidCallingContext() {
// If it's not being cached, the CachePolicy can't be used
if (_pcc == null) {
throw new HttpException(
SR.GetString(SR.UC_not_cached));
}
// Make sure it's not being used too late
if (_pcc.ControlState >= ControlState.PreRendered) {
throw new HttpException(
SR.GetString(SR.UCCachePolicy_unavailable));
}
}
public bool SupportsCaching {
get {
// Caching is supported if we have a PartialCachingControl
return (_pcc != null);
}
}
public bool Cached {
get {
CheckValidCallingContext();
return !_pcc._cachingDisabled;
}
set {
CheckValidCallingContext();
_pcc._cachingDisabled = !value;
}
}
public TimeSpan Duration {
get {
CheckValidCallingContext();
return _pcc.Duration;
}
set {
CheckValidCallingContext();
_pcc.Duration = value;
}
}
public HttpCacheVaryByParams VaryByParams {
get {
CheckValidCallingContext();
return _pcc.VaryByParams;
}
}
public string VaryByControl {
get {
CheckValidCallingContext();
return _pcc.VaryByControl;
}
set {
CheckValidCallingContext();
_pcc.VaryByControl = value;
}
}
public CacheDependency Dependency {
get {
CheckValidCallingContext();
return _pcc.Dependency;
}
set {
CheckValidCallingContext();
_pcc.Dependency = value;
}
}
public void SetVaryByCustom(string varyByCustom) {
CheckValidCallingContext();
_pcc._varyByCustom = varyByCustom;
}
public void SetSlidingExpiration(bool useSlidingExpiration) {
CheckValidCallingContext();
_pcc._useSlidingExpiration = useSlidingExpiration;
}
public void SetExpires(DateTime expirationTime) {
CheckValidCallingContext();
_pcc._utcExpirationTime = DateTimeUtil.ConvertToUniversalTime(expirationTime);
}
public String ProviderName {
get {
CheckValidCallingContext();
if (_pcc._provider == null) {
return OutputCache.ASPNET_INTERNAL_PROVIDER_NAME;
}
else {
return _pcc._provider;
}
}
set {
CheckValidCallingContext();
if (value == OutputCache.ASPNET_INTERNAL_PROVIDER_NAME) {
value = null;
}
OutputCache.ThrowIfProviderNotFound(value);
_pcc._provider = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Web;
using System.Web.Util;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Security.Permissions;
public sealed class ControlCachePolicy {
private static ControlCachePolicy _cachePolicyStub = new ControlCachePolicy();
private BasePartialCachingControl _pcc;
internal ControlCachePolicy() {
}
internal ControlCachePolicy(BasePartialCachingControl pcc) {
_pcc = pcc;
}
internal static ControlCachePolicy GetCachePolicyStub() {
// Return a stub, which returns SupportsCaching==false and throws on everything else.
return _cachePolicyStub;
}
// Check whether it is valid to access properties on this object
private void CheckValidCallingContext() {
// If it's not being cached, the CachePolicy can't be used
if (_pcc == null) {
throw new HttpException(
SR.GetString(SR.UC_not_cached));
}
// Make sure it's not being used too late
if (_pcc.ControlState >= ControlState.PreRendered) {
throw new HttpException(
SR.GetString(SR.UCCachePolicy_unavailable));
}
}
public bool SupportsCaching {
get {
// Caching is supported if we have a PartialCachingControl
return (_pcc != null);
}
}
public bool Cached {
get {
CheckValidCallingContext();
return !_pcc._cachingDisabled;
}
set {
CheckValidCallingContext();
_pcc._cachingDisabled = !value;
}
}
public TimeSpan Duration {
get {
CheckValidCallingContext();
return _pcc.Duration;
}
set {
CheckValidCallingContext();
_pcc.Duration = value;
}
}
public HttpCacheVaryByParams VaryByParams {
get {
CheckValidCallingContext();
return _pcc.VaryByParams;
}
}
public string VaryByControl {
get {
CheckValidCallingContext();
return _pcc.VaryByControl;
}
set {
CheckValidCallingContext();
_pcc.VaryByControl = value;
}
}
public CacheDependency Dependency {
get {
CheckValidCallingContext();
return _pcc.Dependency;
}
set {
CheckValidCallingContext();
_pcc.Dependency = value;
}
}
public void SetVaryByCustom(string varyByCustom) {
CheckValidCallingContext();
_pcc._varyByCustom = varyByCustom;
}
public void SetSlidingExpiration(bool useSlidingExpiration) {
CheckValidCallingContext();
_pcc._useSlidingExpiration = useSlidingExpiration;
}
public void SetExpires(DateTime expirationTime) {
CheckValidCallingContext();
_pcc._utcExpirationTime = DateTimeUtil.ConvertToUniversalTime(expirationTime);
}
public String ProviderName {
get {
CheckValidCallingContext();
if (_pcc._provider == null) {
return OutputCache.ASPNET_INTERNAL_PROVIDER_NAME;
}
else {
return _pcc._provider;
}
}
set {
CheckValidCallingContext();
if (value == OutputCache.ASPNET_INTERNAL_PROVIDER_NAME) {
value = null;
}
OutputCache.ThrowIfProviderNotFound(value);
_pcc._provider = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TypeUtils.cs
- TrackingMemoryStream.cs
- HostingEnvironment.cs
- RectAnimationBase.cs
- PhysicalFontFamily.cs
- Point.cs
- TextDecorationCollection.cs
- cryptoapiTransform.cs
- BamlRecordReader.cs
- MulticastOption.cs
- DataGridViewElement.cs
- MultilineStringConverter.cs
- DetailsViewRow.cs
- TimeManager.cs
- ExtendedPropertyDescriptor.cs
- OleDbRowUpdatedEvent.cs
- WizardPanelChangingEventArgs.cs
- ValidationErrorCollection.cs
- DataGridTextBox.cs
- SplineKeyFrames.cs
- GraphicsPathIterator.cs
- PageAsyncTask.cs
- CheckableControlBaseAdapter.cs
- CursorConverter.cs
- Codec.cs
- ContentElementAutomationPeer.cs
- CodeAttributeArgument.cs
- ObjectParameterCollection.cs
- IndexExpression.cs
- XamlSerializerUtil.cs
- AnnotationElement.cs
- AccessText.cs
- Geometry.cs
- AnnotationAuthorChangedEventArgs.cs
- VBCodeProvider.cs
- WindowsSecurityTokenAuthenticator.cs
- NamedElement.cs
- ServiceBehaviorElement.cs
- EventSourceCreationData.cs
- Assert.cs
- TcpHostedTransportConfiguration.cs
- UnsafeNetInfoNativeMethods.cs
- StaticExtension.cs
- ListCommandEventArgs.cs
- WebColorConverter.cs
- SettingsPropertyCollection.cs
- DependencyPropertyChangedEventArgs.cs
- ItemCollection.cs
- ListBindingHelper.cs
- FormsAuthenticationModule.cs
- DialogResultConverter.cs
- RoutedEventConverter.cs
- CompilerState.cs
- MetafileHeader.cs
- ProviderCollection.cs
- HeaderUtility.cs
- KerberosSecurityTokenAuthenticator.cs
- ScrollChrome.cs
- HttpCapabilitiesSectionHandler.cs
- SiteIdentityPermission.cs
- PolicyException.cs
- Part.cs
- BooleanExpr.cs
- GACIdentityPermission.cs
- EntityException.cs
- FixedStringLookup.cs
- TypefaceMap.cs
- LineVisual.cs
- DataColumnCollection.cs
- DebugTracing.cs
- ClientBuildManager.cs
- SiteMembershipCondition.cs
- WebPartDescription.cs
- CompressionTransform.cs
- ZipArchive.cs
- XmlReflectionImporter.cs
- DictionaryBase.cs
- ADMembershipUser.cs
- XhtmlConformanceSection.cs
- JsonReaderWriterFactory.cs
- DataGridColumnHeadersPresenter.cs
- SourceChangedEventArgs.cs
- RSAProtectedConfigurationProvider.cs
- DetailsViewInsertEventArgs.cs
- ValidatorCompatibilityHelper.cs
- BlurEffect.cs
- SystemDropShadowChrome.cs
- OperationAbortedException.cs
- TimelineClockCollection.cs
- RequestCachePolicyConverter.cs
- AnnotationAdorner.cs
- DataGridItemCollection.cs
- BindingBase.cs
- Positioning.cs
- EventProviderTraceListener.cs
- CharAnimationUsingKeyFrames.cs
- ImagingCache.cs
- ToolBarDesigner.cs
- SqlDataSourceWizardForm.cs
- WindowsProgressbar.cs