Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / xsp / System / Web / Extensions / ui / ProfileServiceManager.cs / 2 / ProfileServiceManager.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.UI { using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Configuration; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text; using System.Security.Permissions; using System.Web.ApplicationServices; using System.Web; using System.Web.Profile; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Resources; using System.Web.Script.Serialization; using System.Web.Configuration; [ AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), DefaultProperty("Path"), TypeConverter(typeof(EmptyStringExpandableObjectConverter)) ] public class ProfileServiceManager { private string[] _loadProperties; private string _path; internal static void ConfigureProfileService(ref StringBuilder sb, HttpContext context, ScriptManager scriptManager, Listproxies) { string profileServiceUrl = null; ArrayList loadedProperties = null; ProfileServiceManager profileManager; if(scriptManager.HasProfileServiceManager) { profileManager = scriptManager.ProfileService; // get ScriptManager.Path profileServiceUrl = profileManager.Path.Trim(); if(profileServiceUrl.Length > 0) { profileServiceUrl = scriptManager.ResolveClientUrl(profileServiceUrl); } // get ScriptManager.LoadProperties if(profileManager.HasLoadProperties) { loadedProperties = new ArrayList(profileManager._loadProperties); } } // combine proxy Paths (find the first one that has specified one) // combine loadedProperties collection (take the union of all) if(proxies != null) { foreach(ScriptManagerProxy proxy in proxies) { if(proxy.HasProfileServiceManager) { profileManager = proxy.ProfileService; // combine urls profileServiceUrl = ApplicationServiceManager.MergeServiceUrls(profileManager.Path, profileServiceUrl, proxy); // combine LoadProperties if(profileManager.HasLoadProperties) { if(loadedProperties == null) { loadedProperties = new ArrayList(profileManager._loadProperties); } else { loadedProperties = ProfileServiceManager.MergeProperties(loadedProperties, profileManager._loadProperties); } } } } } ProfileServiceManager.GenerateInitializationScript(ref sb, context, scriptManager, profileServiceUrl, loadedProperties); } private static void GenerateInitializationScript(ref StringBuilder sb, HttpContext context, ScriptManager scriptManager, string serviceUrl, ArrayList loadedProperties) { string defaultServicePath = null; bool loadProperties = loadedProperties != null && loadedProperties.Count > 0; if(ApplicationServiceHelper.ProfileServiceEnabled) { if (sb == null) { sb = new StringBuilder(ApplicationServiceManager.StringBuilderCapacity); } // The default path points to the built-in service (if it is enabled) // Note that the client can't default to this path because it doesn't know what the app root is, we must tell it. // We must specify the default path to the proxy even if a custom path is provided, because on the client they could // reset the path back to the default if they want. defaultServicePath = scriptManager.ResolveClientUrl("~/" + System.Web.Script.Services.WebServiceData._profileServiceFileName); sb.Append("Sys.Services._ProfileService.DefaultWebServicePath = '"); sb.Append(JavaScriptString.QuoteString(defaultServicePath)); sb.Append("';\n"); } if(!String.IsNullOrEmpty(serviceUrl)) { // DevDiv Bug 72257:When custom path is set and loadProperties=True, we shouldn't use the default path // loadProperties script always retrieves the properties from default profile provider, which is not correct if ProfileService // points to non default path. Hence throw when non default path and loadProperties both are specified. if (defaultServicePath == null){ defaultServicePath = scriptManager.ResolveClientUrl("~/" + System.Web.Script.Services.WebServiceData._profileServiceFileName); } if (loadProperties && !String.Equals(serviceUrl, defaultServicePath, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(AtlasWeb.ProfileServiceManager_LoadProperitesWithNonDefaultPath); } if (sb == null) { sb = new StringBuilder(ApplicationServiceManager.StringBuilderCapacity); } sb.Append("Sys.Services.ProfileService.set_path('"); sb.Append(JavaScriptString.QuoteString(serviceUrl)); sb.Append("');\n"); } if (loadProperties) { if (sb == null) { sb = new StringBuilder(ApplicationServiceManager.StringBuilderCapacity); } // get values for all properties to be pre-loaded. // GetSettingsProperty puts each property into either the top level settings dictionary or if its part of a group, // it creates an entry for the group in the group collection and puts the setting in the dictionary for the group. SortedList topLevelSettings = new SortedList (loadedProperties.Count); SortedList > profileGroups = null; ProfileBase profile = context.Profile; foreach(string propertyFullName in loadedProperties) { GetSettingsProperty(profile, propertyFullName, topLevelSettings, ref profileGroups, /* ensure exists */ true); } RenderProfileProperties(sb, topLevelSettings, profileGroups); } } internal static ArrayList MergeProperties(ArrayList existingProperties, string[] newProperties) { // foreach(string property in newProperties) { if(!String.IsNullOrEmpty(property)) { string trimmedProperty = property.Trim(); if((trimmedProperty.Length > 0) && !existingProperties.Contains(trimmedProperty)) { existingProperties.Add(trimmedProperty); } } } return existingProperties; } internal static void GetSettingsProperty( ProfileBase profile, string fullPropertyName, SortedList topLevelSettings, ref SortedList > profileGroups, bool ensureExists) { // Gets a setting off the profile, putting top level settings into the topLevelSettings list, // and putting grouped properties into a group-specific list that is contained within a sortedlist of groups. // if ensureExists is true and the given property name doesn't exist on the profile, an exception is thrown. int dotIndex = fullPropertyName.IndexOf('.'); string groupName; string propertyName; SortedList containingObject; if(dotIndex == -1) { groupName = null; propertyName = fullPropertyName; containingObject = topLevelSettings; } else { groupName = fullPropertyName.Substring(0, dotIndex); propertyName = fullPropertyName.Substring(dotIndex + 1); if(profileGroups == null) { profileGroups = new SortedList >(); containingObject = new SortedList (); profileGroups.Add(groupName, containingObject); } else { containingObject = profileGroups[groupName]; if(containingObject == null) { containingObject = new SortedList (); profileGroups.Add(groupName, containingObject); } } } bool exists = ProfileBase.Properties[fullPropertyName] != null; if(ensureExists && !exists) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, AtlasWeb.AppService_UnknownProfileProperty, fullPropertyName)); } if(exists) { containingObject[propertyName] = profile == null ? null : profile[fullPropertyName]; } } private static void RenderProfileProperties(StringBuilder sb, SortedList topLevelSettings, SortedList > profileGroups) { JavaScriptSerializer serializer = new JavaScriptSerializer(); // 1. render top level settings sb.Append("Sys.Services.ProfileService.properties = Sys.Serialization.JavaScriptSerializer.deserialize('"); // // sb.Append(JavaScriptString.QuoteString(serializer.Serialize(topLevelSettings))); sb.Append("');\n"); // 2. render each group as a ProfileGroup object // These could be done as just the value of the PropertyName in topLevelSettings but the serializer wouldn't recognize PropertyGroup. if(profileGroups != null) { foreach(KeyValuePair > group in profileGroups) { sb.Append("Sys.Services.ProfileService.properties."); sb.Append(group.Key); // group name sb.Append(" = new Sys.Services.ProfileGroup(Sys.Serialization.JavaScriptSerializer.deserialize('"); sb.Append(JavaScriptString.QuoteString(serializer.Serialize(group.Value))); sb.Append("'));\n"); } } } internal bool HasLoadProperties { get { return _loadProperties != null && _loadProperties.Length > 0; } } [ DefaultValue(null), Category("Behavior"), NotifyParentProperty(true), TypeConverter(typeof(StringArrayConverter)), ResourceDescription("ProfileServiceManager_LoadProperties"), SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification="Required by ASP.NET parser.") ] public string[] LoadProperties { get { if(_loadProperties == null) { _loadProperties = new string[0]; } return (string[]) _loadProperties.Clone(); } set { if(value != null) { value = (string[])value.Clone(); } _loadProperties = value; } } [ DefaultValue(""), Category("Behavior"), NotifyParentProperty(true), ResourceDescription("ApplicationServiceManager_Path"), UrlProperty() ] public string Path { get { return _path ?? String.Empty; } set { _path = 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.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Configuration; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text; using System.Security.Permissions; using System.Web.ApplicationServices; using System.Web; using System.Web.Profile; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Resources; using System.Web.Script.Serialization; using System.Web.Configuration; [ AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal), DefaultProperty("Path"), TypeConverter(typeof(EmptyStringExpandableObjectConverter)) ] public class ProfileServiceManager { private string[] _loadProperties; private string _path; internal static void ConfigureProfileService(ref StringBuilder sb, HttpContext context, ScriptManager scriptManager, Listproxies) { string profileServiceUrl = null; ArrayList loadedProperties = null; ProfileServiceManager profileManager; if(scriptManager.HasProfileServiceManager) { profileManager = scriptManager.ProfileService; // get ScriptManager.Path profileServiceUrl = profileManager.Path.Trim(); if(profileServiceUrl.Length > 0) { profileServiceUrl = scriptManager.ResolveClientUrl(profileServiceUrl); } // get ScriptManager.LoadProperties if(profileManager.HasLoadProperties) { loadedProperties = new ArrayList(profileManager._loadProperties); } } // combine proxy Paths (find the first one that has specified one) // combine loadedProperties collection (take the union of all) if(proxies != null) { foreach(ScriptManagerProxy proxy in proxies) { if(proxy.HasProfileServiceManager) { profileManager = proxy.ProfileService; // combine urls profileServiceUrl = ApplicationServiceManager.MergeServiceUrls(profileManager.Path, profileServiceUrl, proxy); // combine LoadProperties if(profileManager.HasLoadProperties) { if(loadedProperties == null) { loadedProperties = new ArrayList(profileManager._loadProperties); } else { loadedProperties = ProfileServiceManager.MergeProperties(loadedProperties, profileManager._loadProperties); } } } } } ProfileServiceManager.GenerateInitializationScript(ref sb, context, scriptManager, profileServiceUrl, loadedProperties); } private static void GenerateInitializationScript(ref StringBuilder sb, HttpContext context, ScriptManager scriptManager, string serviceUrl, ArrayList loadedProperties) { string defaultServicePath = null; bool loadProperties = loadedProperties != null && loadedProperties.Count > 0; if(ApplicationServiceHelper.ProfileServiceEnabled) { if (sb == null) { sb = new StringBuilder(ApplicationServiceManager.StringBuilderCapacity); } // The default path points to the built-in service (if it is enabled) // Note that the client can't default to this path because it doesn't know what the app root is, we must tell it. // We must specify the default path to the proxy even if a custom path is provided, because on the client they could // reset the path back to the default if they want. defaultServicePath = scriptManager.ResolveClientUrl("~/" + System.Web.Script.Services.WebServiceData._profileServiceFileName); sb.Append("Sys.Services._ProfileService.DefaultWebServicePath = '"); sb.Append(JavaScriptString.QuoteString(defaultServicePath)); sb.Append("';\n"); } if(!String.IsNullOrEmpty(serviceUrl)) { // DevDiv Bug 72257:When custom path is set and loadProperties=True, we shouldn't use the default path // loadProperties script always retrieves the properties from default profile provider, which is not correct if ProfileService // points to non default path. Hence throw when non default path and loadProperties both are specified. if (defaultServicePath == null){ defaultServicePath = scriptManager.ResolveClientUrl("~/" + System.Web.Script.Services.WebServiceData._profileServiceFileName); } if (loadProperties && !String.Equals(serviceUrl, defaultServicePath, StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(AtlasWeb.ProfileServiceManager_LoadProperitesWithNonDefaultPath); } if (sb == null) { sb = new StringBuilder(ApplicationServiceManager.StringBuilderCapacity); } sb.Append("Sys.Services.ProfileService.set_path('"); sb.Append(JavaScriptString.QuoteString(serviceUrl)); sb.Append("');\n"); } if (loadProperties) { if (sb == null) { sb = new StringBuilder(ApplicationServiceManager.StringBuilderCapacity); } // get values for all properties to be pre-loaded. // GetSettingsProperty puts each property into either the top level settings dictionary or if its part of a group, // it creates an entry for the group in the group collection and puts the setting in the dictionary for the group. SortedList topLevelSettings = new SortedList (loadedProperties.Count); SortedList > profileGroups = null; ProfileBase profile = context.Profile; foreach(string propertyFullName in loadedProperties) { GetSettingsProperty(profile, propertyFullName, topLevelSettings, ref profileGroups, /* ensure exists */ true); } RenderProfileProperties(sb, topLevelSettings, profileGroups); } } internal static ArrayList MergeProperties(ArrayList existingProperties, string[] newProperties) { // foreach(string property in newProperties) { if(!String.IsNullOrEmpty(property)) { string trimmedProperty = property.Trim(); if((trimmedProperty.Length > 0) && !existingProperties.Contains(trimmedProperty)) { existingProperties.Add(trimmedProperty); } } } return existingProperties; } internal static void GetSettingsProperty( ProfileBase profile, string fullPropertyName, SortedList topLevelSettings, ref SortedList > profileGroups, bool ensureExists) { // Gets a setting off the profile, putting top level settings into the topLevelSettings list, // and putting grouped properties into a group-specific list that is contained within a sortedlist of groups. // if ensureExists is true and the given property name doesn't exist on the profile, an exception is thrown. int dotIndex = fullPropertyName.IndexOf('.'); string groupName; string propertyName; SortedList containingObject; if(dotIndex == -1) { groupName = null; propertyName = fullPropertyName; containingObject = topLevelSettings; } else { groupName = fullPropertyName.Substring(0, dotIndex); propertyName = fullPropertyName.Substring(dotIndex + 1); if(profileGroups == null) { profileGroups = new SortedList >(); containingObject = new SortedList (); profileGroups.Add(groupName, containingObject); } else { containingObject = profileGroups[groupName]; if(containingObject == null) { containingObject = new SortedList (); profileGroups.Add(groupName, containingObject); } } } bool exists = ProfileBase.Properties[fullPropertyName] != null; if(ensureExists && !exists) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, AtlasWeb.AppService_UnknownProfileProperty, fullPropertyName)); } if(exists) { containingObject[propertyName] = profile == null ? null : profile[fullPropertyName]; } } private static void RenderProfileProperties(StringBuilder sb, SortedList topLevelSettings, SortedList > profileGroups) { JavaScriptSerializer serializer = new JavaScriptSerializer(); // 1. render top level settings sb.Append("Sys.Services.ProfileService.properties = Sys.Serialization.JavaScriptSerializer.deserialize('"); // // sb.Append(JavaScriptString.QuoteString(serializer.Serialize(topLevelSettings))); sb.Append("');\n"); // 2. render each group as a ProfileGroup object // These could be done as just the value of the PropertyName in topLevelSettings but the serializer wouldn't recognize PropertyGroup. if(profileGroups != null) { foreach(KeyValuePair > group in profileGroups) { sb.Append("Sys.Services.ProfileService.properties."); sb.Append(group.Key); // group name sb.Append(" = new Sys.Services.ProfileGroup(Sys.Serialization.JavaScriptSerializer.deserialize('"); sb.Append(JavaScriptString.QuoteString(serializer.Serialize(group.Value))); sb.Append("'));\n"); } } } internal bool HasLoadProperties { get { return _loadProperties != null && _loadProperties.Length > 0; } } [ DefaultValue(null), Category("Behavior"), NotifyParentProperty(true), TypeConverter(typeof(StringArrayConverter)), ResourceDescription("ProfileServiceManager_LoadProperties"), SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification="Required by ASP.NET parser.") ] public string[] LoadProperties { get { if(_loadProperties == null) { _loadProperties = new string[0]; } return (string[]) _loadProperties.Clone(); } set { if(value != null) { value = (string[])value.Clone(); } _loadProperties = value; } } [ DefaultValue(""), Category("Behavior"), NotifyParentProperty(true), ResourceDescription("ApplicationServiceManager_Path"), UrlProperty() ] public string Path { get { return _path ?? String.Empty; } set { _path = 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
- HuffCodec.cs
- TreeNode.cs
- PrimitiveSchema.cs
- IsolationInterop.cs
- CombinedGeometry.cs
- Duration.cs
- DispatcherObject.cs
- DataGridCellInfo.cs
- Size.cs
- CustomErrorCollection.cs
- ToolStripRenderEventArgs.cs
- DataSourceUtil.cs
- SmiConnection.cs
- DataGridViewAutoSizeModeEventArgs.cs
- BamlCollectionHolder.cs
- QueryGeneratorBase.cs
- HandlerBase.cs
- AuthorizationRule.cs
- ConfigUtil.cs
- CompModHelpers.cs
- ContentElement.cs
- SqlWebEventProvider.cs
- XPathChildIterator.cs
- MgmtConfigurationRecord.cs
- TableParagraph.cs
- AndCondition.cs
- StylusPointPropertyInfo.cs
- FormatSettings.cs
- JsonStringDataContract.cs
- Invariant.cs
- JobCollate.cs
- EventLogPermissionEntryCollection.cs
- XmlCodeExporter.cs
- ResourcePermissionBase.cs
- EmptyStringExpandableObjectConverter.cs
- CategoryAttribute.cs
- MimeReflector.cs
- WebServiceClientProxyGenerator.cs
- XpsColorContext.cs
- TextBoxRenderer.cs
- ExchangeUtilities.cs
- SqlDataSource.cs
- GenericTextProperties.cs
- FacetDescriptionElement.cs
- ELinqQueryState.cs
- FragmentQuery.cs
- WebColorConverter.cs
- Error.cs
- ConnectionStringsExpressionBuilder.cs
- RuleProcessor.cs
- ObjectParameterCollection.cs
- StringValidatorAttribute.cs
- AssemblyBuilderData.cs
- SqlTriggerAttribute.cs
- DataSourceXmlClassAttribute.cs
- StylusEditingBehavior.cs
- RootAction.cs
- CommandConverter.cs
- DataColumnMappingCollection.cs
- OnOperation.cs
- GroupBox.cs
- PassportAuthenticationEventArgs.cs
- RouteUrlExpressionBuilder.cs
- StringFreezingAttribute.cs
- CodeLinePragma.cs
- BinaryObjectInfo.cs
- DataGridRowAutomationPeer.cs
- XmlSchemaSequence.cs
- RightsManagementInformation.cs
- XmlTextReaderImplHelpers.cs
- ExtendedProtectionPolicy.cs
- SynchronizationLockException.cs
- VirtualizingStackPanel.cs
- ObjectHandle.cs
- ClientTargetCollection.cs
- ItemAutomationPeer.cs
- LoginCancelEventArgs.cs
- SqlUdtInfo.cs
- LinkedList.cs
- SafeEventLogWriteHandle.cs
- MethodRental.cs
- ScriptControl.cs
- MinMaxParagraphWidth.cs
- NativeStructs.cs
- SelectionPattern.cs
- DesignerVerbToolStripMenuItem.cs
- InvokeCompletedEventArgs.cs
- InboundActivityHelper.cs
- GeneralTransform3DGroup.cs
- CharacterMetricsDictionary.cs
- AmbiguousMatchException.cs
- DataControlPagerLinkButton.cs
- SemaphoreSecurity.cs
- MetadataUtilsSmi.cs
- SemaphoreSlim.cs
- SQLSingleStorage.cs
- X509Certificate2Collection.cs
- NotificationContext.cs
- BaseTemplateBuildProvider.cs
- SerialErrors.cs