Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / HttpCacheParams.cs / 2 / HttpCacheParams.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* Cache Vary class. Wraps Vary header
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web {
using System.Text;
using System.Runtime.InteropServices;
using System.Web.Util;
using System.Security.Permissions;
///
/// Indicates that a cache should contain multiple
/// representations for a particular Uri. This class is an encapsulation that
/// provides a rich, type-safe way to set the Vary header.
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class HttpCacheVaryByParams {
HttpDictionary _parameters;
int _ignoreParams;
bool _isModified;
bool _paramsStar;
internal HttpCacheVaryByParams() {
Reset();
}
internal void Reset() {
_isModified = false;
_paramsStar = false;
_parameters = null;
_ignoreParams = -1;
}
/*
* Reset based on the cached vary headers.
*/
internal void ResetFromParams(String[] parameters) {
int i, n;
Reset();
if (parameters != null) {
_isModified = true;
if (parameters[0].Length == 0) {
Debug.Assert(parameters.Length == 1, "parameters.Length == 1");
IgnoreParams = true;
}
else if (parameters[0].Equals("*")) {
Debug.Assert(parameters.Length == 1, "parameters.Length == 1");
_paramsStar = true;
}
else {
_parameters = new HttpDictionary();
for (i = 0, n = parameters.Length; i < n; i++) {
_parameters.SetValue(parameters[i], parameters[i]);
}
}
}
}
internal bool IsModified() {
return _isModified;
}
internal bool AcceptsParams() {
return _ignoreParams == 1 || _paramsStar || _parameters != null;
}
internal String[] GetParams() {
String[] s = null;
Object item;
int i, j, c, n;
if (_ignoreParams == 1) {
s = new String[1] {String.Empty};
}
else if (_paramsStar) {
s = new String[1] {"*"};
}
else if (_parameters != null) {
n = _parameters.Size;
c = 0;
for (i = 0; i < n; i++) {
item = _parameters.GetValue(i);
if (item != null) {
c++;
}
}
if (c > 0) {
s = new string[c];
j = 0;
for (i = 0; i < n; i++) {
item = _parameters.GetValue(i);
if (item != null) {
s[j] = (String) item;
j++;
}
}
Debug.Assert(j == c, "j == c");
}
}
return s;
}
//
// Public methods and properties
//
///
/// Default property.
/// Indexed property indicating that a cache should (or should not) vary according
/// to a custom header.
///
public bool this[String header]
{
get {
if (header == null) {
throw new ArgumentNullException("header");
}
if (header.Length == 0) {
return _ignoreParams == 1;
}
else {
return _paramsStar ||
(_parameters != null && _parameters.GetValue(header) != null);
}
}
set {
if (header == null) {
throw new ArgumentNullException("header");
}
if (header.Length == 0) {
IgnoreParams = value;
}
/*
* Since adding a Vary parameter is more restrictive, we don't
* want components to be able to set a Vary parameter to false
* if another component has set it to true.
*/
else if (value) {
_isModified = true;
_ignoreParams = 0;
if (header.Equals("*")) {
_paramsStar = true;
_parameters = null;
}
else {
// set value to header if true or null if false
if (!_paramsStar) {
if (_parameters == null) {
_parameters = new HttpDictionary();
}
_parameters.SetValue(header, header);
}
}
}
}
}
public bool IgnoreParams {
get {
return _ignoreParams == 1;
}
set {
// Don't ignore if params have been added
if (_paramsStar || _parameters != null) {
return;
}
if (_ignoreParams == -1 || _ignoreParams == 1) {
_ignoreParams = value ? 1 : 0;
_isModified = true;
}
}
}
internal bool IsVaryByStar {
get {
return _paramsStar;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
* Cache Vary class. Wraps Vary header
*
* Copyright (c) 1998 Microsoft Corporation
*/
namespace System.Web {
using System.Text;
using System.Runtime.InteropServices;
using System.Web.Util;
using System.Security.Permissions;
///
/// Indicates that a cache should contain multiple
/// representations for a particular Uri. This class is an encapsulation that
/// provides a rich, type-safe way to set the Vary header.
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class HttpCacheVaryByParams {
HttpDictionary _parameters;
int _ignoreParams;
bool _isModified;
bool _paramsStar;
internal HttpCacheVaryByParams() {
Reset();
}
internal void Reset() {
_isModified = false;
_paramsStar = false;
_parameters = null;
_ignoreParams = -1;
}
/*
* Reset based on the cached vary headers.
*/
internal void ResetFromParams(String[] parameters) {
int i, n;
Reset();
if (parameters != null) {
_isModified = true;
if (parameters[0].Length == 0) {
Debug.Assert(parameters.Length == 1, "parameters.Length == 1");
IgnoreParams = true;
}
else if (parameters[0].Equals("*")) {
Debug.Assert(parameters.Length == 1, "parameters.Length == 1");
_paramsStar = true;
}
else {
_parameters = new HttpDictionary();
for (i = 0, n = parameters.Length; i < n; i++) {
_parameters.SetValue(parameters[i], parameters[i]);
}
}
}
}
internal bool IsModified() {
return _isModified;
}
internal bool AcceptsParams() {
return _ignoreParams == 1 || _paramsStar || _parameters != null;
}
internal String[] GetParams() {
String[] s = null;
Object item;
int i, j, c, n;
if (_ignoreParams == 1) {
s = new String[1] {String.Empty};
}
else if (_paramsStar) {
s = new String[1] {"*"};
}
else if (_parameters != null) {
n = _parameters.Size;
c = 0;
for (i = 0; i < n; i++) {
item = _parameters.GetValue(i);
if (item != null) {
c++;
}
}
if (c > 0) {
s = new string[c];
j = 0;
for (i = 0; i < n; i++) {
item = _parameters.GetValue(i);
if (item != null) {
s[j] = (String) item;
j++;
}
}
Debug.Assert(j == c, "j == c");
}
}
return s;
}
//
// Public methods and properties
//
///
/// Default property.
/// Indexed property indicating that a cache should (or should not) vary according
/// to a custom header.
///
public bool this[String header]
{
get {
if (header == null) {
throw new ArgumentNullException("header");
}
if (header.Length == 0) {
return _ignoreParams == 1;
}
else {
return _paramsStar ||
(_parameters != null && _parameters.GetValue(header) != null);
}
}
set {
if (header == null) {
throw new ArgumentNullException("header");
}
if (header.Length == 0) {
IgnoreParams = value;
}
/*
* Since adding a Vary parameter is more restrictive, we don't
* want components to be able to set a Vary parameter to false
* if another component has set it to true.
*/
else if (value) {
_isModified = true;
_ignoreParams = 0;
if (header.Equals("*")) {
_paramsStar = true;
_parameters = null;
}
else {
// set value to header if true or null if false
if (!_paramsStar) {
if (_parameters == null) {
_parameters = new HttpDictionary();
}
_parameters.SetValue(header, header);
}
}
}
}
}
public bool IgnoreParams {
get {
return _ignoreParams == 1;
}
set {
// Don't ignore if params have been added
if (_paramsStar || _parameters != null) {
return;
}
if (_ignoreParams == -1 || _ignoreParams == 1) {
_ignoreParams = value ? 1 : 0;
_isModified = true;
}
}
}
internal bool IsVaryByStar {
get {
return _paramsStar;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- NamespaceCollection.cs
- ImageMapEventArgs.cs
- Mutex.cs
- WSTrust.cs
- TargetFrameworkUtil.cs
- Decoder.cs
- SimpleTypesSurrogate.cs
- XamlSerializerUtil.cs
- TrackingProfileCache.cs
- HttpFileCollection.cs
- BitmapSourceSafeMILHandle.cs
- SourceFileBuildProvider.cs
- ToolboxItemLoader.cs
- WebPartCatalogAddVerb.cs
- SmiGettersStream.cs
- DataControlFieldCell.cs
- SqlWorkflowPersistenceService.cs
- NativeObjectSecurity.cs
- WmlTextViewAdapter.cs
- ConfigXmlElement.cs
- DynamicDataResources.Designer.cs
- ProfileProvider.cs
- Metadata.cs
- SqlBulkCopy.cs
- MultiView.cs
- OdbcDataReader.cs
- Header.cs
- ActivationArguments.cs
- DbException.cs
- XmlWriterSettings.cs
- ProcessRequestArgs.cs
- ColumnHeader.cs
- StateWorkerRequest.cs
- BuildProviderCollection.cs
- SerialPinChanges.cs
- Control.cs
- TableLayoutSettings.cs
- TableCell.cs
- DataGridViewRowEventArgs.cs
- PersonalizationState.cs
- CryptoProvider.cs
- TreeIterator.cs
- CapabilitiesState.cs
- FormsAuthenticationCredentials.cs
- StreamWithDictionary.cs
- ExpressionsCollectionConverter.cs
- DrawingGroup.cs
- XmlSchemaObjectTable.cs
- BaseTreeIterator.cs
- DataGridViewTopRowAccessibleObject.cs
- HostingEnvironmentException.cs
- IMembershipProvider.cs
- CacheMemory.cs
- ExecutedRoutedEventArgs.cs
- TextEndOfSegment.cs
- ValidatorCompatibilityHelper.cs
- GB18030Encoding.cs
- OleDbParameter.cs
- BinaryFormatter.cs
- AddInIpcChannel.cs
- DisplayNameAttribute.cs
- DiffuseMaterial.cs
- ToolBarTray.cs
- Page.cs
- XPathDocumentNavigator.cs
- ADRole.cs
- GlyphRunDrawing.cs
- OdbcFactory.cs
- WebPartConnectionsDisconnectVerb.cs
- ExpressionEditor.cs
- ServiceSecurityAuditElement.cs
- BinaryKeyIdentifierClause.cs
- SqlTypesSchemaImporter.cs
- FontConverter.cs
- DBCommandBuilder.cs
- Matrix3D.cs
- MarkupObject.cs
- CompilerState.cs
- NetworkInterface.cs
- SystemResources.cs
- Point3DCollectionValueSerializer.cs
- OracleInternalConnection.cs
- CellIdBoolean.cs
- MetadataItem.cs
- RepeaterCommandEventArgs.cs
- EdmFunctions.cs
- OutputCacheSettingsSection.cs
- DodSequenceMerge.cs
- RepeaterDesigner.cs
- DataGridViewRowHeaderCell.cs
- RuleSet.cs
- SmiContextFactory.cs
- SrgsRulesCollection.cs
- TextWriter.cs
- DataSet.cs
- InvokeProviderWrapper.cs
- HwndSourceParameters.cs
- InplaceBitmapMetadataWriter.cs
- InvalidPropValue.cs
- _SafeNetHandles.cs