Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / DEVDIV / depot / DevDiv / releases / whidbey / QFE / ndp / fx / src / xsp / System / Web / UI / WebParts / PersonalizationProvider.cs / 3 / PersonalizationProvider.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls.WebParts { using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Configuration; using System.Configuration.Provider; using System.Security.Permissions; using System.Security.Principal; using System.Web; using System.Web.Configuration; using System.Web.Hosting; using System.Web.Util; ////// The provider used to access the personalization store for WebPart pages. /// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public abstract class PersonalizationProvider : ProviderBase { private const string scopeFieldName = "__WPPS"; private const string sharedScopeFieldValue = "s"; private const string userScopeFieldValue = "u"; private ICollection _supportedUserCapabilities; ////// Initializes an instance of PersonalizationProvider. /// protected PersonalizationProvider() { } ////// The name of the application that this provider should use to store /// and retrieve personalization data from. /// public abstract string ApplicationName { get; set; } ////// protected virtual IList CreateSupportedUserCapabilities() { ArrayList list = new ArrayList(); list.Add(WebPartPersonalization.EnterSharedScopeUserCapability); list.Add(WebPartPersonalization.ModifyStateUserCapability); return list; } ////// public virtual PersonalizationScope DetermineInitialScope(WebPartManager webPartManager, PersonalizationState loadedState) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } Page page = webPartManager.Page; if (page == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page"), "webPartManager"); } HttpRequest request = page.RequestInternal; if (request == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page.Request"), "webPartManager"); } PersonalizationScope scope = webPartManager.Personalization.InitialScope; IPrincipal user = null; if (request.IsAuthenticated) { user = page.User; } if (user == null) { // if no user has been authenticated, then just load all user data scope = PersonalizationScope.Shared; } else { if (page.IsPostBack) { string postedMode = page.Request[scopeFieldName]; if (postedMode == sharedScopeFieldValue) { scope = PersonalizationScope.Shared; } else if (postedMode == userScopeFieldValue) { scope = PersonalizationScope.User; } } else if ((page.PreviousPage != null) && (page.PreviousPage.IsCrossPagePostBack == false)) { WebPartManager previousWebPartManager = WebPartManager.GetCurrentWebPartManager(page.PreviousPage); if (previousWebPartManager != null) { // Note that we scope = previousWebPartManager.Personalization.Scope; } } // Special-case Web Part Export so it executes in the same security context as the page itself ( else if (page.IsExportingWebPart) { scope = (page.IsExportingWebPartShared ? PersonalizationScope.Shared : PersonalizationScope.User); } if ((scope == PersonalizationScope.Shared) && (webPartManager.Personalization.CanEnterSharedScope == false)) { scope = PersonalizationScope.User; } } string fieldValue = (scope == PersonalizationScope.Shared) ? sharedScopeFieldValue : userScopeFieldValue; page.ClientScript.RegisterHiddenField(scopeFieldName, fieldValue); return scope; } ////// public virtual IDictionary DetermineUserCapabilities(WebPartManager webPartManager) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } Page page = webPartManager.Page; if (page == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page"), "webPartManager"); } HttpRequest request = page.RequestInternal; if (request == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page.Request"), "webPartManager"); } IPrincipal user = null; if (request.IsAuthenticated) { user = page.User; } if (user != null) { if (_supportedUserCapabilities == null) { _supportedUserCapabilities = CreateSupportedUserCapabilities(); } if ((_supportedUserCapabilities != null) && (_supportedUserCapabilities.Count != 0)) { WebPartsSection configSection = RuntimeConfig.GetConfig().WebParts; if (configSection != null) { WebPartsPersonalizationAuthorization authConfig = configSection.Personalization.Authorization; if (authConfig != null) { IDictionary capabilities = new HybridDictionary(); foreach (WebPartUserCapability capability in _supportedUserCapabilities) { if (authConfig.IsUserAllowed(user, capability.Name)) { capabilities[capability] = capability; } } return capabilities; } } } } return new HybridDictionary(); } public abstract PersonalizationStateInfoCollection FindState(PersonalizationScope scope, PersonalizationStateQuery query, int pageIndex, int pageSize, out int totalRecords); public abstract int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query); ////// private void GetParameters(WebPartManager webPartManager, out string path, out string userName) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } Page page = webPartManager.Page; if (page == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page"), "webPartManager"); } HttpRequest request = page.RequestInternal; if (request == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page.Request"), "webPartManager"); } path = request.AppRelativeCurrentExecutionFilePath; userName = null; if ((webPartManager.Personalization.Scope == PersonalizationScope.User) && page.Request.IsAuthenticated) { userName = page.User.Identity.Name; } } ////// Loads the data from the data store for the specified path and user. /// If only shared data is to be loaded, userName is null or empty. /// protected abstract void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob); ////// Allows the provider to load personalization data. The specified /// WebPartManager is used to access the current page, which can be used /// to retrieve the path and user information. /// public virtual PersonalizationState LoadPersonalizationState(WebPartManager webPartManager, bool ignoreCurrentUser) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } string path; string userName; GetParameters(webPartManager, out path, out userName); if (ignoreCurrentUser) { userName = null; } byte[] sharedDataBlob = null; byte[] userDataBlob = null; LoadPersonalizationBlobs(webPartManager, path, userName, ref sharedDataBlob, ref userDataBlob); BlobPersonalizationState blobState = new BlobPersonalizationState(webPartManager); blobState.LoadDataBlobs(sharedDataBlob, userDataBlob); return blobState; } ////// Removes the data from the data store for the specified path and user. /// If userName is null or empty, the shared data is to be reset. /// protected abstract void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName); ////// Allows the provider to reset personalization data. The specified /// WebPartManager is used to access the current page, which can be used /// to retrieve the path and user information. /// public virtual void ResetPersonalizationState(WebPartManager webPartManager) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } string path; string userName; GetParameters(webPartManager, out path, out userName); ResetPersonalizationBlob(webPartManager, path, userName); } public abstract int ResetState(PersonalizationScope scope, string[] paths, string[] usernames); public abstract int ResetUserState(string path, DateTime userInactiveSinceDate); ////// Saves the data into the data store for the specified path and user. /// If only shared data is to be saved, userName is null or empty. /// protected abstract void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob); ////// Allows the provider to save personalization data. The specified information /// contains a reference to the WebPartManager, which is used to access the /// current Page, and its path and user information. /// public virtual void SavePersonalizationState(PersonalizationState state) { if (state == null) { throw new ArgumentNullException("state"); } BlobPersonalizationState blobState = state as BlobPersonalizationState; if (blobState == null) { throw new ArgumentException(SR.GetString(SR.PersonalizationProvider_WrongType), "state"); } WebPartManager webPartManager = blobState.WebPartManager; string path; string userName; GetParameters(webPartManager, out path, out userName); byte[] dataBlob = null; bool reset = blobState.IsEmpty; if (reset == false) { dataBlob = blobState.SaveDataBlob(); reset = (dataBlob == null) || (dataBlob.Length == 0); } if (reset) { ResetPersonalizationBlob(webPartManager, path, userName); } else { SavePersonalizationBlob(webPartManager, path, userName, dataBlob); } } } } // 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. // //----------------------------------------------------------------------------- namespace System.Web.UI.WebControls.WebParts { using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Configuration; using System.Configuration.Provider; using System.Security.Permissions; using System.Security.Principal; using System.Web; using System.Web.Configuration; using System.Web.Hosting; using System.Web.Util; ////// The provider used to access the personalization store for WebPart pages. /// [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)] public abstract class PersonalizationProvider : ProviderBase { private const string scopeFieldName = "__WPPS"; private const string sharedScopeFieldValue = "s"; private const string userScopeFieldValue = "u"; private ICollection _supportedUserCapabilities; ////// Initializes an instance of PersonalizationProvider. /// protected PersonalizationProvider() { } ////// The name of the application that this provider should use to store /// and retrieve personalization data from. /// public abstract string ApplicationName { get; set; } ////// protected virtual IList CreateSupportedUserCapabilities() { ArrayList list = new ArrayList(); list.Add(WebPartPersonalization.EnterSharedScopeUserCapability); list.Add(WebPartPersonalization.ModifyStateUserCapability); return list; } ////// public virtual PersonalizationScope DetermineInitialScope(WebPartManager webPartManager, PersonalizationState loadedState) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } Page page = webPartManager.Page; if (page == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page"), "webPartManager"); } HttpRequest request = page.RequestInternal; if (request == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page.Request"), "webPartManager"); } PersonalizationScope scope = webPartManager.Personalization.InitialScope; IPrincipal user = null; if (request.IsAuthenticated) { user = page.User; } if (user == null) { // if no user has been authenticated, then just load all user data scope = PersonalizationScope.Shared; } else { if (page.IsPostBack) { string postedMode = page.Request[scopeFieldName]; if (postedMode == sharedScopeFieldValue) { scope = PersonalizationScope.Shared; } else if (postedMode == userScopeFieldValue) { scope = PersonalizationScope.User; } } else if ((page.PreviousPage != null) && (page.PreviousPage.IsCrossPagePostBack == false)) { WebPartManager previousWebPartManager = WebPartManager.GetCurrentWebPartManager(page.PreviousPage); if (previousWebPartManager != null) { // Note that we scope = previousWebPartManager.Personalization.Scope; } } // Special-case Web Part Export so it executes in the same security context as the page itself ( else if (page.IsExportingWebPart) { scope = (page.IsExportingWebPartShared ? PersonalizationScope.Shared : PersonalizationScope.User); } if ((scope == PersonalizationScope.Shared) && (webPartManager.Personalization.CanEnterSharedScope == false)) { scope = PersonalizationScope.User; } } string fieldValue = (scope == PersonalizationScope.Shared) ? sharedScopeFieldValue : userScopeFieldValue; page.ClientScript.RegisterHiddenField(scopeFieldName, fieldValue); return scope; } ////// public virtual IDictionary DetermineUserCapabilities(WebPartManager webPartManager) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } Page page = webPartManager.Page; if (page == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page"), "webPartManager"); } HttpRequest request = page.RequestInternal; if (request == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page.Request"), "webPartManager"); } IPrincipal user = null; if (request.IsAuthenticated) { user = page.User; } if (user != null) { if (_supportedUserCapabilities == null) { _supportedUserCapabilities = CreateSupportedUserCapabilities(); } if ((_supportedUserCapabilities != null) && (_supportedUserCapabilities.Count != 0)) { WebPartsSection configSection = RuntimeConfig.GetConfig().WebParts; if (configSection != null) { WebPartsPersonalizationAuthorization authConfig = configSection.Personalization.Authorization; if (authConfig != null) { IDictionary capabilities = new HybridDictionary(); foreach (WebPartUserCapability capability in _supportedUserCapabilities) { if (authConfig.IsUserAllowed(user, capability.Name)) { capabilities[capability] = capability; } } return capabilities; } } } } return new HybridDictionary(); } public abstract PersonalizationStateInfoCollection FindState(PersonalizationScope scope, PersonalizationStateQuery query, int pageIndex, int pageSize, out int totalRecords); public abstract int GetCountOfState(PersonalizationScope scope, PersonalizationStateQuery query); ////// private void GetParameters(WebPartManager webPartManager, out string path, out string userName) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } Page page = webPartManager.Page; if (page == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page"), "webPartManager"); } HttpRequest request = page.RequestInternal; if (request == null) { throw new ArgumentException(SR.GetString(SR.PropertyCannotBeNull, "Page.Request"), "webPartManager"); } path = request.AppRelativeCurrentExecutionFilePath; userName = null; if ((webPartManager.Personalization.Scope == PersonalizationScope.User) && page.Request.IsAuthenticated) { userName = page.User.Identity.Name; } } ////// Loads the data from the data store for the specified path and user. /// If only shared data is to be loaded, userName is null or empty. /// protected abstract void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob); ////// Allows the provider to load personalization data. The specified /// WebPartManager is used to access the current page, which can be used /// to retrieve the path and user information. /// public virtual PersonalizationState LoadPersonalizationState(WebPartManager webPartManager, bool ignoreCurrentUser) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } string path; string userName; GetParameters(webPartManager, out path, out userName); if (ignoreCurrentUser) { userName = null; } byte[] sharedDataBlob = null; byte[] userDataBlob = null; LoadPersonalizationBlobs(webPartManager, path, userName, ref sharedDataBlob, ref userDataBlob); BlobPersonalizationState blobState = new BlobPersonalizationState(webPartManager); blobState.LoadDataBlobs(sharedDataBlob, userDataBlob); return blobState; } ////// Removes the data from the data store for the specified path and user. /// If userName is null or empty, the shared data is to be reset. /// protected abstract void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName); ////// Allows the provider to reset personalization data. The specified /// WebPartManager is used to access the current page, which can be used /// to retrieve the path and user information. /// public virtual void ResetPersonalizationState(WebPartManager webPartManager) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } string path; string userName; GetParameters(webPartManager, out path, out userName); ResetPersonalizationBlob(webPartManager, path, userName); } public abstract int ResetState(PersonalizationScope scope, string[] paths, string[] usernames); public abstract int ResetUserState(string path, DateTime userInactiveSinceDate); ////// Saves the data into the data store for the specified path and user. /// If only shared data is to be saved, userName is null or empty. /// protected abstract void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob); ////// Allows the provider to save personalization data. The specified information /// contains a reference to the WebPartManager, which is used to access the /// current Page, and its path and user information. /// public virtual void SavePersonalizationState(PersonalizationState state) { if (state == null) { throw new ArgumentNullException("state"); } BlobPersonalizationState blobState = state as BlobPersonalizationState; if (blobState == null) { throw new ArgumentException(SR.GetString(SR.PersonalizationProvider_WrongType), "state"); } WebPartManager webPartManager = blobState.WebPartManager; string path; string userName; GetParameters(webPartManager, out path, out userName); byte[] dataBlob = null; bool reset = blobState.IsEmpty; if (reset == false) { dataBlob = blobState.SaveDataBlob(); reset = (dataBlob == null) || (dataBlob.Length == 0); } if (reset) { ResetPersonalizationBlob(webPartManager, path, userName); } else { SavePersonalizationBlob(webPartManager, path, userName, dataBlob); } } } } // 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
- ServiceErrorHandler.cs
- MetadataPropertyCollection.cs
- System.Data_BID.cs
- DataGridViewHeaderCell.cs
- FunctionDetailsReader.cs
- LocatorPart.cs
- DiscoveryDocument.cs
- RectangleHotSpot.cs
- BuildProvider.cs
- EmptyEnumerable.cs
- X509Certificate2Collection.cs
- ManagementPath.cs
- Point3DConverter.cs
- EdmEntityTypeAttribute.cs
- GridView.cs
- PathFigureCollection.cs
- SuppressMergeCheckAttribute.cs
- DetectEofStream.cs
- _AutoWebProxyScriptWrapper.cs
- EncoderNLS.cs
- PagesSection.cs
- AssertFilter.cs
- WindowsTab.cs
- ConstNode.cs
- ActivityExecutorDelegateInfo.cs
- DataGridTableCollection.cs
- CreateUserWizard.cs
- FaultCallbackWrapper.cs
- PrintEvent.cs
- TextFormatterHost.cs
- SqlAliaser.cs
- SqlError.cs
- FloaterParaClient.cs
- ControlIdConverter.cs
- WizardPanelChangingEventArgs.cs
- HtmlTextViewAdapter.cs
- TextSegment.cs
- SqlServices.cs
- PointValueSerializer.cs
- NameValueConfigurationElement.cs
- ZipIORawDataFileBlock.cs
- Brushes.cs
- DBCommand.cs
- SchemaCollectionPreprocessor.cs
- HttpServerProtocol.cs
- TextRangeBase.cs
- KeyConverter.cs
- UIntPtr.cs
- VoiceSynthesis.cs
- wgx_render.cs
- PrivilegeNotHeldException.cs
- TraceSection.cs
- ListItemCollection.cs
- ExpressionBindingsDialog.cs
- ItemChangedEventArgs.cs
- IMembershipProvider.cs
- Stack.cs
- ProxyManager.cs
- UIElementParagraph.cs
- TextParagraphView.cs
- TextEditorSelection.cs
- SkewTransform.cs
- SoapObjectInfo.cs
- OracleDateTime.cs
- MaskedTextProvider.cs
- EntitySetBaseCollection.cs
- OlePropertyStructs.cs
- ImageClickEventArgs.cs
- AssemblyNameProxy.cs
- SqlServer2KCompatibilityAnnotation.cs
- XmlILConstructAnalyzer.cs
- WebRequest.cs
- MultiPageTextView.cs
- QueryOptionExpression.cs
- ConstructorExpr.cs
- LOSFormatter.cs
- CombinedGeometry.cs
- SafeBitVector32.cs
- DataServicePagingProviderWrapper.cs
- WinFormsComponentEditor.cs
- ExtractorMetadata.cs
- ValidationUtility.cs
- SiteMapPath.cs
- Normalization.cs
- AlternateViewCollection.cs
- EdmRelationshipRoleAttribute.cs
- DbParameterHelper.cs
- InstallerTypeAttribute.cs
- ContainerUtilities.cs
- XmlSchemaRedefine.cs
- LayoutEditorPart.cs
- RuntimeArgumentHandle.cs
- DataBinding.cs
- XmlConvert.cs
- ReferentialConstraint.cs
- Keywords.cs
- NullPackagingPolicy.cs
- ImageMapEventArgs.cs
- SelectedGridItemChangedEvent.cs
- OpenFileDialog.cs