protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob) { PageBase page = webPartManager.Page as PageBase; if (page != null && page.CurrentUserSession != null) { userName = page.CurrentUserSession.Username; User user = User.Load(userName); PersonalizationInfo info = user.PersonalizationInfo; if (info != null) { string key = String.Format("{0}_{1}_{2}", webPartManager.ID, path, userName); byte[] data = null; try { if (info.userPersonalizationData.ContainsKey(key)) data = info.userPersonalizationData[key]; } catch (KeyNotFoundException) { //info is somehow corrupted //user.ResetPersonalization(); } if (data != null) { userDataBlob = data; } } } }
public WebPartChrome(WebPartZoneBase zone, WebPartManager manager) { if (zone == null) { throw new ArgumentNullException("zone"); } _zone = zone; _page = zone.Page; _designMode = zone.DesignMode; _manager = manager; if (_designMode) { // Consider personalization to be enabled at design-time _personalizationEnabled = true; } else { _personalizationEnabled = (manager != null && manager.Personalization.IsModifiable); } if (manager != null) { _personalizationScope = manager.Personalization.Scope; } else { // Consider scope to be shared at design-time _personalizationScope = PersonalizationScope.Shared; } }
public virtual new bool IsEnabled (WebPartManager webPartManager) { Contract.Requires (webPartManager != null); Contract.Requires (webPartManager.Personalization != null); return default(bool); }
/// <devdoc> /// </devdoc> protected PersonalizationState(WebPartManager webPartManager) { if (webPartManager == null) { throw new ArgumentNullException("webPartManager"); } _webPartManager = webPartManager; }
public virtual bool IsEnabled(WebPartManager webPartManager) { if (this.RequiresPersonalization) { return webPartManager.Personalization.IsModifiable; } return true; }
/// <devdoc> /// </devdoc> public WebPartPersonalization(WebPartManager owner) { if (owner == null) { throw new ArgumentNullException("owner"); } _owner = owner; _enabled = true; }
protected override void OnInit(EventArgs e) { base.OnInit(e); _wpm = WebPartManager.GetCurrentWebPartManager(this.Page); if (this.Page is BasePage) ((BasePage)this.Page).ToolboxPanel = pnlToolboxMain; ltlInfo.Text = String.Format("MonoX v{0} [{1}], DB v{2}", MonoSoftware.MonoX.Utilities.MonoXUtility.AssemblyVersion, MonoSoftware.MonoX.Utilities.MonoXUtility.AssemblyDate.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern), MonoSoftware.MonoX.Utilities.MonoXUtility.DBVersion); SetRefreshCacheUrl(); CheckCacheRefresh(); }
private SqlCommand BuildCommand(IConfigurationElement commandElement, IBinder binder, WebPartManager manager) { SqlCommand command = new SqlCommand(); foreach (IConfigurationElementAttribute attribute in commandElement.Attributes.Values) { ReflectionServices.SetValue(command, attribute.ConfigKey, attribute.Value); } IBindingItemsCollection bindingParams = binder.NewBindingItemCollectionInstance(); binder.BindingSet.Add(commandElement.ConfigKey, bindingParams); foreach (IConfigurationElement parameterElement in commandElement.Elements.Values) { SqlParameter parameter = new SqlParameter(); foreach (IConfigurationElementAttribute parameterAttribute in parameterElement.Attributes.Values) { if ("bind" == parameterAttribute.ConfigKey) { string bindstring = parameterAttribute.Value.ToString(); bool isOutput = parameterElement.Attributes.ContainsKey("Direction") && ("Output" == parameterElement.GetAttributeReference("Direction").Value.ToString() || "InputOutput" == parameterElement.GetAttributeReference("Direction").Value.ToString()); if (bindstring.Contains(".")) { string sourcestring = bindstring.Substring(0, bindstring.IndexOf(".")); IBindingItem bindingItem = binder.NewBindingItemInstance(); if (!isOutput) { bindingItem.Source = manager.FindControl(sourcestring); bindingItem.SourceProperty = bindstring.Substring(sourcestring.Length + 1); bindingItem.Target = parameter; bindingItem.TargetProperty = "Value"; } else { bindingItem.Target = manager.FindControl(sourcestring); bindingItem.TargetProperty = bindstring.Substring(sourcestring.Length + 1); bindingItem.Source = parameter; bindingItem.SourceProperty = "Value"; } bindingParams.Add(bindingItem); } } else { ReflectionServices.SetValue(parameter, parameterAttribute.ConfigKey, parameterAttribute.Value); } } if (null == parameter.Value) { parameter.Value = DBNull.Value; } command.Parameters.Add(parameter); } return command; }
/// <devdoc> /// </devdoc> public BlobPersonalizationState(WebPartManager webPartManager) : base(webPartManager) { // // Note that we don't use the IsPostBack property of Page because that // is based on the presence of view state, which could be on the query string // in a non-POST request as well. Instead we use the actual verb associated // with the request. // Note that there are other types of HttpVerb besides GET and POST. We only // save personalization data for POST requests. (VSWhidbey 423433) _isPostRequest = (webPartManager.Page.Request.HttpVerb == HttpVerb.POST); }
/// <summary> /// Loads the personalization data bytes. /// </summary> /// <param name="webPartManager"></param> /// <param name="path"></param> /// <param name="userName"></param> /// <param name="sharedDataBlob"></param> /// <param name="userDataBlob"></param> protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob) { userName = Workflow.CurrentUser.UserBase.LoginName; OUserWebPartsPersonalization p = OUserWebPartsPersonalization.GetPersonalization("", path, userName); if (p != null) { if (String.IsNullOrEmpty(userName)) sharedDataBlob = p.Bytes; else userDataBlob = p.Bytes; } }
/// <summary> /// Saves raw personalization data to the underlying data store. /// </summary> /// <param name="webPartManager">The WebPartManager managing the personalization data.</param> /// <param name="path">The path for personalization information to be used as the data store key.</param> /// <param name="userName">The user name for personalization information to be used as the key.</param> /// <param name="dataBlob">The byte array of data to be saved.</param> protected override void SavePersonalizationBlob(System.Web.UI.WebControls.WebParts.WebPartManager webPartManager, string path, string userName, byte[] dataBlob) { if (userName == null) { SharedPersonalization sharedPersonalization = SharedPersonalizationDataSource.LoadForPath(path, true); sharedPersonalization.PageSettings = dataBlob; sharedPersonalization.Save(); } else { UserPersonalization userPersonalization = UserPersonalizationDataSource.LoadForPath(path, userName, true); userPersonalization.PageSettings = dataBlob; userPersonalization.Save(); } }
public override void Create(Control container, IConfigurationType config, ITemplatable templatable, IEnumerable registry, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } if (!(registry is Dictionary<string, Control>)) { throw new ArgumentException("registry must be a Dictionary<string,Control>"); } Dictionary<string, Control> commanders = registry as Dictionary<string, Control>; commanders.Clear(); IDictionary<string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; if (itemElements.ContainsKey("commanders")) { Table table; if (container is Table) { table = (container as Table); } else { table = new Table(); } if (string.IsNullOrEmpty(table.ID)) { table.ID = container.ID + "commanders"; } table.ApplyStyle(templatable.CommandersStyle); foreach (IConfigurationElement element in itemElements["commanders"].Elements.Values) { this.DisplayItem(table, element, element.ConfigKey, null, null, templatable.CommandersRowStyle, templatable.InvalidItemStyle, commanders, manager); } if (!(container is Table)) { container.Controls.Add(table); } } }
public override void Create(Control container, IConfigurationType config, ITemplatable templatable, IEnumerable registry, IBinder binder, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } if (!(registry is ITemplatingItemsCollection)) { throw new ArgumentException("registry must be an ITemplatingItemsCollection"); } ITemplatingItemsCollection filters = registry as ITemplatingItemsCollection; IDictionary<string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; if (itemElements.ContainsKey("filter")) { Table table; if (container is Table) { table = (container as Table); } else { table = new Table(); table.ID = container.ID + "filter"; } table.ApplyStyle(templatable.FilterStyle); for (int i = 0; i < filters.Count; i++) { foreach (IConfigurationElement element in itemElements["filter"].Elements.Values) { string prefix = "filter" + element.ConfigKey + i.ToString(); this.DisplayItem(table, element, prefix, binder, filters[i], templatable.FilterRowStyle, templatable.InvalidItemStyle, manager); } } if (!(container is Table)) { container.Controls.Add(table); } } }
/// <summary> /// Saves the personalization data into the database. /// </summary> /// <param name="webPartManager"></param> /// <param name="path"></param> /// <param name="userName"></param> /// <param name="dataBlob"></param> protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob) { using (Connection c = new Connection()) { userName = Workflow.CurrentUser.UserBase.LoginName; OUserWebPartsPersonalization p = OUserWebPartsPersonalization.GetPersonalization("", path, userName); if (p == null) p = TablesLogic.tUserWebPartsPersonalization.Create(); p.ApplicationName = ""; p.Path = path; p.UserName = userName; p.Bytes = dataBlob; p.Save(); c.Commit(); } }
public override IDictionary DetermineUserCapabilities(WebPartManager webPartManager) { //return base.DetermineUserCapabilities(webPartManager); ICollection supportedUserCapabilities = CreateSupportedUserCapabilities(); if ((supportedUserCapabilities != null) && (supportedUserCapabilities.Count != 0)) { IDictionary capabilities = new HybridDictionary(); foreach (WebPartUserCapability capability in supportedUserCapabilities) { capabilities[capability] = capability; } return capabilities; } else return new HybridDictionary(); }
public static void LoadPersonalizationBlobs( SiteSettings siteSettings, WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob) { if (siteSettings != null) { if ((userName != null) && (userName.Length > 0)) { SiteUser siteUser = new SiteUser(siteSettings, userName); Guid userID = Guid.Empty; if (siteUser.UserId > 0) { userID = siteUser.UserGuid; } if (userID != Guid.Empty) { userDataBlob = SitePersonalization.GetPersonalizationBlob( siteSettings.SiteId, path, userID); siteUser.UpdateLastActivityTime(); sharedDataBlob = SitePersonalization.GetPersonalizationBlobAllUsers( siteSettings.SiteId, path); } } else { //TODO: tracking/personalization for unauthenticated users? sharedDataBlob = SitePersonalization.GetPersonalizationBlobAllUsers( siteSettings.SiteId, path); } } }
/// <summary> /// Loads raw personalization data from the underlying data store. /// </summary> /// <param name="webPartManager">The WebPartManager managing the personalization data.</param> /// <param name="path">The path for personalization information to be used as the retrieval key.</param> /// <param name="userName">The user name for personalization information to be used as the retrieval key.</param> /// <param name="sharedDataBlob">The returned data for the Shared scope.</param> /// <param name="userDataBlob">The returned data for the User scope.</param> protected override void LoadPersonalizationBlobs(System.Web.UI.WebControls.WebParts.WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob) { sharedDataBlob = null; userDataBlob = null; SharedPersonalization sharedPersonalization = SharedPersonalizationDataSource.LoadForPath(path, false); if (sharedPersonalization != null) { sharedDataBlob = sharedPersonalization.PageSettings; } UserPersonalization UserPersonalization = UserPersonalizationDataSource.LoadForPath(path, userName, false); if (UserPersonalization != null) { userDataBlob = UserPersonalization.PageSettings; } }
/// <summary> /// Deletes raw personalization data from the underlying data store. /// </summary> /// <param name="webPartManager">The WebPartManager managing the personalization data.</param> /// <param name="path">The path for personalization information to be used as the data store key.</param> /// <param name="userName">The user name for personalization information to be used as the data store key.</param> protected override void ResetPersonalizationBlob(System.Web.UI.WebControls.WebParts.WebPartManager webPartManager, string path, string userName) { if (string.IsNullOrEmpty(userName)) { SharedPersonalization sharedPersonalization = SharedPersonalizationDataSource.LoadForPath(path, false); if (sharedPersonalization != null) { sharedPersonalization.Delete(); } } else { UserPersonalization userPersonalization = UserPersonalizationDataSource.LoadForPath(path, userName, false); if (userPersonalization != null) { userPersonalization.Delete(); } } }
private DataTable GetPersonalizationBlobs(WebPartManager webPartManager, string username) { // // Verifies if still has a DataTable loaded // DataTable personalizationBlobs = null; if (HttpContext.Current.Items[cookiesName] != null) return HttpContext.Current.Items[cookiesName] as DataTable; switch (GetScope(webPartManager, username)) { case PersonalizationScope.User: HttpCookie cookie = webPartManager.Page.Request.Cookies[cookiesName]; if (cookie != null) { personalizationBlobs = cookie.Value.Deserialize() as DataTable; } break; case PersonalizationScope.Shared: personalizationBlobs = webPartManager.Page.Cache[cookiesName] as DataTable; if (personalizationBlobs == null) { if (File.Exists(xmlFile)) { DataSet ds = new DataSet(); ds.ReadXml(xmlFile); personalizationBlobs = ds.Tables[cookiesName]; ds.Tables.Remove(personalizationBlobs); ; } } break; } if (personalizationBlobs == null) personalizationBlobs = CreatePersonalizationBlobs(); HttpContext.Current.Items[cookiesName] = personalizationBlobs; return personalizationBlobs; }
public override void Create(Control container, IConfigurationType config, ITemplatable templatable, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } IDictionary<string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; if (itemElements.ContainsKey("header")) { Table table; if (container is Table) { table = (container as Table); } else { table = new Table(); table.ID = container.ID + "header"; } table.ApplyStyle(templatable.HeaderStyle); foreach (IConfigurationElement element in itemElements["header"].Elements.Values) { this.DisplayItem(table, element, "header-" + element.ConfigKey, null, null, templatable.HeaderRowStyle, templatable.InvalidItemStyle, manager); } if (!(container is Table)) { container.Controls.Add(table); } } }
public override void Create(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, ITemplatingItem item, int itemIndex, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } if ((config as IConfigurationSection).Elements.ContainsKey("totals")) { Table table; if (container is Table) { table = (container as Table); } else { table = new Table(); table.ApplyStyle(templatable.TotalsStyle); } IConfigurationElement element = (config as IConfigurationSection).GetElementReference("totals"); foreach (IConfigurationElement rowElement in element.Elements.Values) { this.DisplayItem(table, rowElement, "totals" + itemIndex.ToString(), binder, item, templatable.TotalsRowStyle, templatable.InvalidItemStyle, manager); } if (!(container is Table)) { container.Controls.Add(table); } } }
private bool ShouldRenderVerb(WebPartVerb verb, WebPart webPart) { // PERF: Consider caching the Zone.*Verb properties // Can have null verbs in the CreateVerbs or WebPart.Verbs collections if (verb == null) { return(false); } if (!verb.Visible) { return(false); } if (verb == Zone.CloseVerb) { if (!_personalizationEnabled || !webPart.AllowClose || !Zone.AllowLayoutChange) { return(false); } } if (verb == Zone.ConnectVerb) { if (WebPartManager != null) { if ((WebPartManager.DisplayMode != WebPartManager.ConnectDisplayMode) || (webPart == WebPartManager.SelectedWebPart) || !webPart.AllowConnect) { return(false); } // Don't render Connect verb if web part has no connection points ConsumerConnectionPointCollection consumerConnectionPoints = WebPartManager.GetEnabledConsumerConnectionPoints(webPart); ProviderConnectionPointCollection providerConnectionPoints = WebPartManager.GetEnabledProviderConnectionPoints(webPart); if ((consumerConnectionPoints == null || consumerConnectionPoints.Count == 0) && (providerConnectionPoints == null || providerConnectionPoints.Count == 0)) { return(false); } } } if (verb == Zone.DeleteVerb) { if (!_personalizationEnabled || !Zone.AllowLayoutChange || webPart.IsStatic || (webPart.IsShared && _personalizationScope == PersonalizationScope.User) || (WebPartManager != null && !WebPartManager.DisplayMode.AllowPageDesign)) { return(false); } } if (verb == Zone.EditVerb) { if (WebPartManager != null && ((WebPartManager.DisplayMode != WebPartManager.EditDisplayMode) || (webPart == WebPartManager.SelectedWebPart))) { return(false); } } if (verb == Zone.HelpVerb) { if (String.IsNullOrEmpty(webPart.HelpUrl)) { return(false); } } if (verb == Zone.MinimizeVerb) { if (!_personalizationEnabled || webPart.ChromeState == PartChromeState.Minimized || !webPart.AllowMinimize || !Zone.AllowLayoutChange) { return(false); } } if (verb == Zone.RestoreVerb) { if (!_personalizationEnabled || webPart.ChromeState == PartChromeState.Normal || !Zone.AllowLayoutChange) { return(false); } } if (verb == Zone.ExportVerb) { if (!_personalizationEnabled || webPart.ExportMode == WebPartExportMode.None) { return(false); } } return(true); }
public WebPartChrome(WebPartZoneBase zone, WebPartManager manager) { }
protected abstract void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName);
protected abstract void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob);
public virtual new PersonalizationScope DetermineInitialScope(WebPartManager webPartManager, PersonalizationState loadedState) { return(default(PersonalizationScope)); }
/// <devdoc> /// </devdoc> 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 WebPartPersonalization(WebPartManager owner) { }
protected override void ResetPersonalizationBlob( WebPartManager webPartManager, string path, string userName) { SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { return; } PersonalizationHelper.ResetPersonalizationBlob( siteSettings, webPartManager, GetUserPagePath(path), userName); }
public override void ResetPersonalizationState(WebPartManager webPartManager) { base.ResetPersonalizationState(webPartManager); }
/// <internalonly /> protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob) { SqlConnectionHolder connectionHolder = null; SqlConnection connection = null; // Extra try-catch block to prevent elevation of privilege attack via exception filter try { try { connectionHolder = GetConnectionHolder(); connection = connectionHolder.Connection; CheckSchemaVersion( connection ); SavePersonalizationState(connection, path, userName, dataBlob); } catch(SqlException sqlEx) { // Check if it failed due to duplicate user name if (userName != null && (sqlEx.Number == 2627 || sqlEx.Number == 2601 || sqlEx.Number == 2512)) { // Try again, because it failed first time with duplicate user name SavePersonalizationState(connection, path, userName, dataBlob); } else { throw; } } finally { if (connectionHolder != null) { connectionHolder.Close(); connectionHolder = null; } } } catch { throw; } }
/// <internalonly /> protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob) { sharedDataBlob = null; userDataBlob = null; SqlConnectionHolder connectionHolder = null; SqlConnection connection = null; // Extra try-catch block to prevent elevation of privilege attack via exception filter try { try { connectionHolder = GetConnectionHolder(); connection = connectionHolder.Connection; CheckSchemaVersion( connection ); sharedDataBlob = LoadPersonalizationBlob(connection, path, null); if (!String.IsNullOrEmpty(userName)) { userDataBlob = LoadPersonalizationBlob(connection, path, userName); } } finally { if (connectionHolder != null) { connectionHolder.Close(); connectionHolder = null; } } } catch { throw; } }
public BlobPersonalizationState(WebPartManager webPartManager) : base(webPartManager) { this._isPostRequest = webPartManager.Page.Request.HttpVerb == HttpVerb.POST; }
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(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "Page" }), "webPartManager"); } HttpRequest requestInternal = page.RequestInternal; if (requestInternal == null) { throw new ArgumentException(System.Web.SR.GetString("PropertyCannotBeNull", new object[] { "Page.Request" }), "webPartManager"); } PersonalizationScope initialScope = webPartManager.Personalization.InitialScope; IPrincipal user = null; if (requestInternal.IsAuthenticated) { user = page.User; } if (user == null) { initialScope = PersonalizationScope.Shared; } else { if (page.IsPostBack) { switch (page.Request["__WPPS"]) { case "s": initialScope = PersonalizationScope.Shared; break; case "u": initialScope = PersonalizationScope.User; break; } } else if ((page.PreviousPage != null) && !page.PreviousPage.IsCrossPagePostBack) { WebPartManager currentWebPartManager = WebPartManager.GetCurrentWebPartManager(page.PreviousPage); if (currentWebPartManager != null) { initialScope = currentWebPartManager.Personalization.Scope; } } else if (page.IsExportingWebPart) { initialScope = page.IsExportingWebPartShared ? PersonalizationScope.Shared : PersonalizationScope.User; } if ((initialScope == PersonalizationScope.Shared) && !webPartManager.Personalization.CanEnterSharedScope) { initialScope = PersonalizationScope.User; } } string hiddenFieldInitialValue = (initialScope == PersonalizationScope.Shared) ? "s" : "u"; page.ClientScript.RegisterHiddenField("__WPPS", hiddenFieldInitialValue); return(initialScope); }
protected abstract void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob);
public override PersonalizationScope DetermineInitialScope( WebPartManager webPartManager, PersonalizationState loadedState) { return base.DetermineInitialScope(webPartManager, loadedState); }
/// <devdoc> /// </devdoc> 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 check the types of the page, so we don't // look the at the PreviousPage in a cross-page posting scenario scope = previousWebPartManager.Personalization.Scope; } } // Special-case Web Part Export so it executes in the same security context as the page itself (VSWhidbey 426574) // Setting the initial scope from what's been asked for in the export parameters 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); }
internal WebPartManagerInternals(WebPartManager manager) { this._manager = manager; }
internal WebPartConnectionCollection(WebPartManager webPartManager) { this._webPartManager = webPartManager; }
protected PersonalizationState(WebPartManager webPartManager) { }
public virtual new System.Collections.IDictionary DetermineUserCapabilities(WebPartManager webPartManager) { return(default(System.Collections.IDictionary)); }
public virtual new bool IsEnabled(WebPartManager webPartManager) { return(default(bool)); }
public virtual new PersonalizationState LoadPersonalizationState(WebPartManager webPartManager, bool ignoreCurrentUser) { return(default(PersonalizationState)); }
private void CreateAvailableWebPartDescriptions() { if (_availableWebPartDescriptions != null) { return; } if (WebPartManager == null || String.IsNullOrEmpty(_importedPartDescription)) { _availableWebPartDescriptions = new WebPartDescriptionCollection(); return; } // Run in minimal trust PermissionSet pset = new PermissionSet(PermissionState.None); // add in whatever perms are appropriate pset.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); pset.AddPermission(new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal)); pset.PermitOnly(); bool permitOnly = true; string title = null; string description = null; string icon = null; // Extra try-catch block to prevent elevation of privilege attack via exception filter try { try { // Get the WebPart description from its saved XML description. using (StringReader sr = new StringReader(_importedPartDescription)) { using (XmlReader reader = XmlUtils.CreateXmlReader(sr)) { if (reader != null) { reader.MoveToContent(); // Check if imported part is authorized // Get to the metadata reader.MoveToContent(); reader.ReadStartElement(WebPartManager.ExportRootElement); reader.ReadStartElement(WebPartManager.ExportPartElement); reader.ReadStartElement(WebPartManager.ExportMetaDataElement); // Get the type name string partTypeName = null; string userControlTypeName = null; while (reader.Name != WebPartManager.ExportTypeElement) { reader.Skip(); if (reader.EOF) { throw new EndOfStreamException(); } } if (reader.Name == WebPartManager.ExportTypeElement) { partTypeName = reader.GetAttribute(WebPartManager.ExportTypeNameAttribute); userControlTypeName = reader.GetAttribute(WebPartManager.ExportUserControlSrcAttribute); } // If we are in shared scope, we are importing a shared WebPart bool isShared = (WebPartManager.Personalization.Scope == PersonalizationScope.Shared); if (!String.IsNullOrEmpty(partTypeName)) { // Need medium trust to call BuildManager.GetType() PermissionSet mediumPset = new PermissionSet(PermissionState.None); mediumPset.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); mediumPset.AddPermission(new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium)); CodeAccessPermission.RevertPermitOnly(); permitOnly = false; mediumPset.PermitOnly(); permitOnly = true; Type partType = WebPartUtil.DeserializeType(partTypeName, true); CodeAccessPermission.RevertPermitOnly(); permitOnly = false; pset.PermitOnly(); permitOnly = true; // First check if the type is authorized if (!WebPartManager.IsAuthorized(partType, null, null, isShared)) { _importErrorMessage = SR.GetString(SR.WebPartManager_ForbiddenType); return; } // If the type is not a webpart, create a generic Web Part if (!partType.IsSubclassOf(typeof(WebPart)) && !partType.IsSubclassOf(typeof(Control))) { // We only allow for Controls (VSWhidbey 428511) _importErrorMessage = SR.GetString(SR.WebPartManager_TypeMustDeriveFromControl); return; } } else { // Check if the path is authorized if (!WebPartManager.IsAuthorized(typeof(UserControl), userControlTypeName, null, isShared)) { _importErrorMessage = SR.GetString(SR.WebPartManager_ForbiddenType); return; } } while (!reader.EOF) { while (!reader.EOF && !(reader.NodeType == XmlNodeType.Element && reader.Name == WebPartManager.ExportPropertyElement)) { reader.Read(); } if (reader.EOF) { break; } string name = reader.GetAttribute(WebPartManager.ExportPropertyNameAttribute); if (name == TitlePropertyName) { title = reader.ReadElementString(); } else if (name == DescriptionPropertyName) { description = reader.ReadElementString(); } else if (name == IconPropertyName) { string url = reader.ReadElementString().Trim(); if (!CrossSiteScriptingValidation.IsDangerousUrl(url)) { icon = url; } } else { reader.Read(); continue; } if (title != null && description != null && icon != null) { break; } reader.Read(); } } } if (String.IsNullOrEmpty(title)) { title = SR.GetString(SR.Part_Untitled); } _availableWebPartDescriptions = new WebPartDescriptionCollection( new WebPartDescription[] { new WebPartDescription(ImportedWebPartID, title, description, icon) }); } } catch (XmlException) { _importErrorMessage = SR.GetString(SR.WebPartManager_ImportInvalidFormat); return; } catch { _importErrorMessage = (!String.IsNullOrEmpty(_importErrorMessage)) ? _importErrorMessage : SR.GetString(SR.WebPart_DefaultImportErrorMessage); return; } finally { if (permitOnly) { // revert if you're not just exiting the stack frame anyway CodeAccessPermission.RevertPermitOnly(); } } } catch { throw; } }
protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob) { }
public WebPartChrome(WebPartZoneBase zone, WebPartManager manager) { Contract.Requires(manager.Personalization != null); }
/// <internalonly /> protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName) { SqlConnectionHolder connectionHolder = null; SqlConnection connection = null; // Extra try-catch block to prevent elevation of privilege attack via exception filter try { try { connectionHolder = GetConnectionHolder(); connection = connectionHolder.Connection; CheckSchemaVersion( connection ); ResetPersonalizationState(connection, path, userName); } finally { if (connectionHolder != null) { connectionHolder.Close(); connectionHolder = null; } } } catch { throw; } }
protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName) { }
public override PersonalizationState LoadPersonalizationState( WebPartManager webPartManager, bool ignoreCurrentUser) { return base.LoadPersonalizationState(webPartManager, ignoreCurrentUser); }
protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob) { }
protected override void LoadPersonalizationBlobs( WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob) { SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings != null) { PersonalizationHelper.LoadPersonalizationBlobs( siteSettings, webPartManager, GetUserPagePath(path), userName, ref sharedDataBlob, ref userDataBlob); } }
private void RenderMenuPopup(HtmlTextWriter writer, ICollection verbs, string clientID, WebPart associatedWebPart, WebPartManager webPartManager) { writer.AddAttribute(HtmlTextWriterAttribute.Id, clientID + "Menu"); writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); writer.RenderBeginTag(HtmlTextWriterTag.Div); bool isEmpty = true; WebPartMenuStyle menuPopupStyle = this._menuUser.MenuPopupStyle; if (menuPopupStyle != null) { menuPopupStyle.AddAttributesToRender(writer, this._menuUser as WebControl); isEmpty = menuPopupStyle.Width.IsEmpty; } else { writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "1"); writer.AddStyleAttribute(HtmlTextWriterStyle.BorderCollapse, "collapse"); } if (isEmpty) { writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); } writer.RenderBeginTag(HtmlTextWriterTag.Table); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap"); writer.RenderBeginTag(HtmlTextWriterTag.Td); bool isEnabled = associatedWebPart.Zone.IsEnabled; foreach (WebPartVerb verb in verbs) { string description; writer.RenderBeginTag(HtmlTextWriterTag.Div); if (associatedWebPart != null) { description = string.Format(CultureInfo.CurrentCulture, verb.Description, new object[] { associatedWebPart.DisplayTitle }); } else { description = verb.Description; } if (description.Length != 0) { writer.AddAttribute(HtmlTextWriterAttribute.Title, description); } bool flag3 = isEnabled && verb.Enabled; if (verb is WebPartHelpVerb) { string str2 = associatedWebPart.ResolveClientUrl(associatedWebPart.HelpUrl); writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)"); if (flag3) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "document.body.__wpm.ShowHelp('" + Util.QuoteJScriptString(str2) + "', " + ((int)associatedWebPart.HelpMode).ToString(CultureInfo.InvariantCulture) + ")"); } } else if (verb is WebPartExportVerb) { string exportUrl = webPartManager.GetExportUrl(associatedWebPart); writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)"); if (flag3) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "document.body.__wpm.ExportWebPart('" + Util.QuoteJScriptString(exportUrl) + ((associatedWebPart.ExportMode == WebPartExportMode.All) ? "', true, false)" : "', false, false)")); } } else { string postBackTarget = this._menuUser.PostBackTarget; writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)"); if (flag3) { string eventArgument = verb.EventArgument; if (associatedWebPart != null) { eventArgument = verb.GetEventArgument(associatedWebPart.ID); } string str6 = null; if (!string.IsNullOrEmpty(eventArgument)) { str6 = "document.body.__wpm.SubmitPage('" + Util.QuoteJScriptString(postBackTarget) + "', '" + Util.QuoteJScriptString(eventArgument) + "');"; this._menuUser.Page.ClientScript.RegisterForEventValidation(postBackTarget, eventArgument); } string str7 = null; if (!string.IsNullOrEmpty(verb.ClientClickHandler)) { str7 = "document.body.__wpm.Execute('" + Util.QuoteJScriptString(Util.EnsureEndWithSemiColon(verb.ClientClickHandler)) + "')"; } string str8 = string.Empty; if ((str6 != null) && (str7 != null)) { str8 = "if(" + str7 + "){" + str6 + "}"; } else if (str6 != null) { str8 = str6; } else if (str7 != null) { str8 = str7; } if (verb is WebPartCloseVerb) { ProviderConnectionPointCollection providerConnectionPoints = webPartManager.GetProviderConnectionPoints(associatedWebPart); if (((providerConnectionPoints != null) && (providerConnectionPoints.Count > 0)) && webPartManager.Connections.ContainsProvider(associatedWebPart)) { str8 = "if(document.body.__wpmCloseProviderWarning.length == 0 || confirm(document.body.__wpmCloseProviderWarning)){" + str8 + "}"; } } else if (verb is WebPartDeleteVerb) { str8 = "if(document.body.__wpmDeleteWarning.length == 0 || confirm(document.body.__wpmDeleteWarning)){" + str8 + "}"; } writer.AddAttribute(HtmlTextWriterAttribute.Onclick, str8); } } string str9 = "menuItem"; if (!verb.Enabled) { if (associatedWebPart.Zone.RenderingCompatibility < VersionUtil.Framework40) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); } else if (!string.IsNullOrEmpty(WebControl.DisabledCssClass)) { str9 = WebControl.DisabledCssClass + " " + str9; } } writer.AddAttribute(HtmlTextWriterAttribute.Class, str9); writer.RenderBeginTag(HtmlTextWriterTag.A); string imageUrl = verb.ImageUrl; if (imageUrl.Length != 0) { imageUrl = this._menuUser.UrlResolver.ResolveClientUrl(imageUrl); } else if (verb.Checked) { imageUrl = this._menuUser.CheckImageUrl; if (imageUrl.Length == 0) { imageUrl = DefaultCheckImageUrl; } } else { imageUrl = webPartManager.SpacerImageUrl; } writer.AddAttribute(HtmlTextWriterAttribute.Src, imageUrl); writer.AddAttribute(HtmlTextWriterAttribute.Alt, description, true); writer.AddAttribute(HtmlTextWriterAttribute.Width, "16"); writer.AddAttribute(HtmlTextWriterAttribute.Height, "16"); writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "none"); writer.AddStyleAttribute("vertical-align", "middle"); if (verb.Checked) { Style checkImageStyle = this._menuUser.CheckImageStyle; if (checkImageStyle != null) { checkImageStyle.AddAttributesToRender(writer, this._menuUser as WebControl); } } writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); writer.Write(" "); writer.Write(verb.Text); writer.Write(" "); writer.RenderEndTag(); writer.RenderEndTag(); } writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderEndTag(); writer.RenderEndTag(); }
protected override void SavePersonalizationBlob( WebPartManager webPartManager, string path, string userName, byte[] dataBlob) { SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings != null) { PersonalizationHelper.SavePersonalizationBlob( siteSettings, webPartManager, GetUserPagePath(path), userName, dataBlob); } }
public void Render(HtmlTextWriter writer, ICollection verbs, string clientID, WebPart associatedWebPart, WebPartManager webPartManager) { this.RegisterStartupScript(clientID); this.RenderLabel(writer, clientID, associatedWebPart); this.RenderMenuPopup(writer, verbs, clientID, associatedWebPart, webPartManager); }
public override IDictionary DetermineUserCapabilities( WebPartManager webPartManager) { return base.DetermineUserCapabilities(webPartManager); }
internal void SetWebPartManager(WebPartManager webPartManager) { _webPartManager = webPartManager; }
public WebPartManagerControlCollection(WebPartManager owner) : base(owner) { this._manager = owner; base.SetCollectionReadOnly("WebPartManager_CannotModify"); }
private void RenderMenuPopup(HtmlTextWriter writer, ICollection verbs, string clientID, WebPart associatedWebPart, WebPartManager webPartManager) { writer.AddAttribute(HtmlTextWriterAttribute.Id, clientID + "Menu"); writer.AddStyleAttribute(HtmlTextWriterStyle.Display, "none"); writer.RenderBeginTag(HtmlTextWriterTag.Div); bool popupSpansFullExtent = true; WebPartMenuStyle menuStyle = _menuUser.MenuPopupStyle; if (menuStyle != null) { menuStyle.AddAttributesToRender(writer, _menuUser as WebControl); popupSpansFullExtent = menuStyle.Width.IsEmpty; } else { // generate attributes corresponding to defaults on WebPartMenuStyle writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0"); writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "1"); writer.AddStyleAttribute(HtmlTextWriterStyle.BorderCollapse, "collapse"); } if (popupSpansFullExtent) { writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%"); } writer.RenderBeginTag(HtmlTextWriterTag.Table); writer.RenderBeginTag(HtmlTextWriterTag.Tr); writer.AddStyleAttribute(HtmlTextWriterStyle.WhiteSpace, "nowrap"); writer.RenderBeginTag(HtmlTextWriterTag.Td); bool isParentEnabled = associatedWebPart.Zone.IsEnabled; foreach (WebPartVerb verb in verbs) { Debug.Assert(verb != null); writer.RenderBeginTag(HtmlTextWriterTag.Div); string alt; if (associatedWebPart != null) { alt = String.Format(CultureInfo.CurrentCulture, verb.Description, associatedWebPart.DisplayTitle); } else { alt = verb.Description; } if (alt.Length != 0) { writer.AddAttribute(HtmlTextWriterAttribute.Title, alt); } bool isEnabled = isParentEnabled && verb.Enabled; // Special case help, export, etc. if (verb is WebPartHelpVerb) { Debug.Assert(associatedWebPart != null); string resolvedHelpUrl = ((IUrlResolutionService)associatedWebPart).ResolveClientUrl(associatedWebPart.HelpUrl); writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)"); if (isEnabled) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "document.body.__wpm.ShowHelp('" + Util.QuoteJScriptString(resolvedHelpUrl) + "', " + ((int)associatedWebPart.HelpMode).ToString(CultureInfo.InvariantCulture) + ")"); } } else if (verb is WebPartExportVerb) { Debug.Assert(associatedWebPart != null); string exportUrl = webPartManager.GetExportUrl(associatedWebPart); writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)"); if (isEnabled) { writer.AddAttribute(HtmlTextWriterAttribute.Onclick, "document.body.__wpm.ExportWebPart('" + Util.QuoteJScriptString(exportUrl) + ((associatedWebPart.ExportMode == WebPartExportMode.All) ? "', true, false)" : "', false, false)")); } } else { string target = _menuUser.PostBackTarget; writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:void(0)"); if (isEnabled) { string eventArgument = verb.EventArgument; if (associatedWebPart != null) { eventArgument = verb.GetEventArgument(associatedWebPart.ID); } string submitScript = null; if (!String.IsNullOrEmpty(eventArgument)) { submitScript = "document.body.__wpm.SubmitPage('" + Util.QuoteJScriptString(target) + "', '" + Util.QuoteJScriptString(eventArgument) + "');"; _menuUser.Page.ClientScript.RegisterForEventValidation(target, eventArgument); } string clientClickScript = null; if (!String.IsNullOrEmpty(verb.ClientClickHandler)) { clientClickScript = "document.body.__wpm.Execute('" + Util.QuoteJScriptString(Util.EnsureEndWithSemiColon(verb.ClientClickHandler)) + "')"; } // There must be either an EventArgument or a ClientClickHandler Debug.Assert(submitScript != null || clientClickScript != null); string onclick = String.Empty; if (submitScript != null && clientClickScript != null) { onclick = "if(" + clientClickScript + "){" + submitScript + "}"; } else if (submitScript != null) { onclick = submitScript; } else if (clientClickScript != null) { onclick = clientClickScript; } if (verb is WebPartCloseVerb) { Debug.Assert(associatedWebPart != null); // PERF: First check if this WebPart even has provider connection points ProviderConnectionPointCollection connectionPoints = webPartManager.GetProviderConnectionPoints(associatedWebPart); if (connectionPoints != null && connectionPoints.Count > 0 && webPartManager.Connections.ContainsProvider(associatedWebPart)) { onclick = "if(document.body.__wpmCloseProviderWarning.length == 0 || " + "confirm(document.body.__wpmCloseProviderWarning)){" + onclick + "}"; } } else if (verb is WebPartDeleteVerb) { onclick = "if(document.body.__wpmDeleteWarning.length == 0 || " + "confirm(document.body.__wpmDeleteWarning)){" + onclick + "}"; } writer.AddAttribute(HtmlTextWriterAttribute.Onclick, onclick); } } string disabledClass = "menuItem"; if (!verb.Enabled) { if (associatedWebPart.Zone.RenderingCompatibility < VersionUtil.Framework40) { writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled"); } else if (!String.IsNullOrEmpty(WebControl.DisabledCssClass)) { disabledClass = WebControl.DisabledCssClass + " " + disabledClass; } } writer.AddAttribute(HtmlTextWriterAttribute.Class, disabledClass); writer.RenderBeginTag(HtmlTextWriterTag.A); string img = verb.ImageUrl; if (img.Length != 0) { img = _menuUser.UrlResolver.ResolveClientUrl(img); } else { if (verb.Checked) { img = _menuUser.CheckImageUrl; if (img.Length == 0) { img = DefaultCheckImageUrl; } } else { img = webPartManager.SpacerImageUrl; } } writer.AddAttribute(HtmlTextWriterAttribute.Src, img); writer.AddAttribute(HtmlTextWriterAttribute.Alt, alt, true); writer.AddAttribute(HtmlTextWriterAttribute.Width, "16"); writer.AddAttribute(HtmlTextWriterAttribute.Height, "16"); writer.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle, "none"); writer.AddStyleAttribute("vertical-align", "middle"); if (verb.Checked) { Style checkImageStyle = _menuUser.CheckImageStyle; if (checkImageStyle != null) { checkImageStyle.AddAttributesToRender(writer, _menuUser as WebControl); } } writer.RenderBeginTag(HtmlTextWriterTag.Img); writer.RenderEndTag(); // Img writer.Write(" "); writer.Write(verb.Text); writer.Write(" "); writer.RenderEndTag(); // A writer.RenderEndTag(); // Div } writer.RenderEndTag(); // Td writer.RenderEndTag(); // Tr writer.RenderEndTag(); // Table writer.RenderEndTag(); // Div }