if ( ( webPart != null ) && ( ( base.WebPartManager == null ) || base.WebPartManager.IsAuthorized ( webPart ) ) )
{
if ( this._loadedWebparts.Count == 0 || this._loadedWebparts == null )
{
this.LoadExistingWebParts ();
}
WebPartDescription description = new WebPartDescription ( webPart );
if ( !( ((Dictionary<string, string>)HttpContext.Current.Session["loadedWebParts"]).ContainsKey ( description.Title ) ))
{
descriptions.Add ( description );
}
availableWebparts.Add ( description.ID, webPart );
}
}
public override WebPartDescriptionCollection GetAvailableWebPartDescriptions ()
{
if ( this._loadedWebparts == null || this._loadedWebparts.Count == 0 )
{
this.LoadExistingWebParts ();
}
if ( this._descriptions == null )
this.LoadAvailableWebParts ();
return this._descriptions;
}
public override WebPart GetWebPart ( WebPartDescription description )
{
if ( description == null )
throw new ArgumentNullException ( "description" );
if ( !this.GetAvailableWebPartDescriptions ().Contains ( description ) )
throw new ArgumentException ( "CatalogPart_UnknownDescription", "description" );
((Dictionary<string, string>)HttpContext.Current.Session["loadedWebParts"]).Add ( description.Title, description.ID );
return this._availableWebparts[description.ID];
}
public void LoadExistingWebParts ()
{
WebPartDescription description = null;
if ( HttpContext.Current.Session["loadedWebParts"] != null )
this._loadedWebparts = ( Dictionary<string, string> ) HttpContext.Current.Session["loadedWebParts"];
if ( this._loadedWebparts == null || this._loadedWebparts.Count == 0)
this._loadedWebparts = new Dictionary<string, string> ();
WebPartCollection webparts = base.WebPartManager.WebParts;
foreach ( WebPart webPart in webparts )
{
description = new WebPartDescription ( webPart );
if ( !( this._loadedWebparts.ContainsKey ( description.Title ) ) && description.Title != "" )
this._loadedWebparts.Add ( description.Title, description.ID );
}
if(this._loadedWebparts.Count > 0)
HttpContext.Current.Session["loadedWebParts"] = this._loadedWebparts;
}
private void LoadAvailableWebParts ()
{
ArrayList descriptions = new ArrayList ();
Dictionary<string, WebPart> availableWebparts = new Dictionary<string, WebPart> ();
if ( this.WebPartsTemplate != null )
{
Control container = new CustomNonParentingControl ();
this.WebPartsTemplate.InstantiateIn ( container );
if ( container.HasControls () )
{
Control[] array = new Control[container.Controls.Count];
container.Controls.CopyTo ( array, 0 );
foreach ( Control control2 in array )
{
this.AddControlToDescriptions ( control2, descriptions, availableWebparts );
}
}
}
string webPartsListUserControlPath = this.WebPartsListUserControlPath;
if ( !string.IsNullOrEmpty ( webPartsListUserControlPath ) && !base.DesignMode )
{
Control control3 = this.Page.LoadControl ( webPartsListUserControlPath );
if ( ( control3 != null ) && control3.HasControls () )
{
Control[] controlArray2 = new Control[control3.Controls.Count];
control3.Controls.CopyTo ( controlArray2, 0 );
foreach ( Control control4 in controlArray2 )
{
this.AddControlToDescriptions ( control4, descriptions, availableWebparts );
}
}
}
this._availableWebparts = availableWebparts;
this._descriptions = new WebPartDescriptionCollection ( descriptions );
}
protected override void Render ( HtmlTextWriter writer )
{
}
#region Properties
// Properties
[EditorBrowsable ( EditorBrowsableState.Never ), Themeable ( false ), Browsable ( false )]
public override string AccessKey
{
get
{
return base.AccessKey;
}
set
{
base.AccessKey = value;
}
}
[Themeable ( false ), Browsable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override Color BackColor
{
get
{
return base.BackColor;
}
set
{
base.BackColor = value;
}
}
[Browsable ( false ), Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override string BackImageUrl
{
get
{
return base.BackImageUrl;
}
set
{
base.BackImageUrl = value;
}
}
[Browsable ( false ), EditorBrowsable ( EditorBrowsableState.Never ), Themeable ( false )]
public override Color BorderColor
{
get
{
return base.BorderColor;
}
set
{
base.BorderColor = value;
}
}
[Browsable ( false ), Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override BorderStyle BorderStyle
{
get
{
return base.BorderStyle;
}
set
{
base.BorderStyle = value;
}
}
[Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never ), Browsable ( false )]
public override Unit BorderWidth
{
get
{
return base.BorderWidth;
}
set
{
base.BorderWidth = value;
}
}
[Themeable ( false ), Browsable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override string CssClass
{
get
{
return base.CssClass;
}
set
{
base.CssClass = value;
}
}
[Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never ), Browsable ( false )]
public override string DefaultButton
{
get
{
return base.DefaultButton;
}
set
{
base.DefaultButton = value;
}
}
[EditorBrowsable ( EditorBrowsableState.Never ), Browsable ( false ), Themeable ( false )]
public override ContentDirection Direction
{
get
{
return base.Direction;
}
set
{
base.Direction = value;
}
}
[EditorBrowsable ( EditorBrowsableState.Never ), Themeable ( false ), Browsable ( false )]
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
}
}
[Browsable ( false ), Themeable ( false ), DefaultValue ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override bool EnableTheming
{
get
{
return false;
}
set
{
throw new NotSupportedException ( "Theming Not Supported" );
}
}
[EditorBrowsable ( EditorBrowsableState.Never ), Themeable ( false ), Browsable ( false )]
public override FontInfo Font
{
get
{
return base.Font;
}
}
[EditorBrowsable ( EditorBrowsableState.Never ), Browsable ( false ), Themeable ( false )]
public override Color ForeColor
{
get
{
return base.ForeColor;
}
set
{
base.ForeColor = value;
}
}
[Browsable ( false ), Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override string GroupingText
{
get
{
return base.GroupingText;
}
set
{
base.GroupingText = value;
}
}
[Browsable ( false ), Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override Unit Height
{
get
{
return base.Height;
}
set
{
base.Height = value;
}
}
[Browsable ( false ), EditorBrowsable ( EditorBrowsableState.Never ), Themeable ( false )]
public override HorizontalAlign HorizontalAlign
{
get
{
return base.HorizontalAlign;
}
set
{
base.HorizontalAlign = value;
}
}
[Browsable ( false ), Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override ScrollBars ScrollBars
{
get
{
return base.ScrollBars;
}
set
{
base.ScrollBars = value;
}
}
[DefaultValue ( "" ), Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never ), Browsable ( false )]
public override string SkinID
{
get
{
return string.Empty;
}
set
{
throw new NotSupportedException ( "SkinID Not Supported" );
}
}
[Browsable ( false ), Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override short TabIndex
{
get
{
return base.TabIndex;
}
set
{
base.TabIndex = value;
}
}
[DefaultValueAttribute ( "DeclarativeCatalogPart_PartTitle" )]
public override string Title
{
get
{
string text = ( string ) this.ViewState["Title"];
if ( text == null )
{
return "Unknown";
}
return text;
}
set
{
this.ViewState["Title"] = value;
}
}
[Browsable ( false ), EditorBrowsable ( EditorBrowsableState.Never ), Themeable ( false )]
public override string ToolTip
{
get
{
return base.ToolTip;
}
set
{
base.ToolTip = value;
}
}
[EditorBrowsable ( EditorBrowsableState.Never ), Themeable ( false ), Browsable ( false )]
public override bool Visible
{
get
{
return base.Visible;
}
set
{
base.Visible = value;
}
}
[DefaultValue ( "" ), Editor ( "System.Web.UI.Design.UserControlFileEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof ( UITypeEditor ) ), CategoryAttribute ( "Behavior" ), Themeable ( false ), UrlProperty, DescriptionAttribute ( "DeclarativeCatlaogPart_WebPartsListUserControlPath" )]
public string WebPartsListUserControlPath
{
get
{
if ( this._webPartsListUserControlPath == null )
{
return string.Empty;
}
return this._webPartsListUserControlPath;
}
set
{
this._webPartsListUserControlPath = value;
this._descriptions = null;
}
}
[TemplateContainer ( typeof ( DeclarativeCatalogPart ) ), Browsable ( false ), DefaultValue ( ( string ) null ), PersistenceMode ( PersistenceMode.InnerProperty )]
public ITemplate WebPartsTemplate
{
get
{
return this._webPartsTemplate;
}
set
{
this._webPartsTemplate = value;
this._descriptions = null;
}
}
[Themeable ( false ), EditorBrowsable ( EditorBrowsableState.Never ), Browsable ( false )]
public override Unit Width
{
get
{
return base.Width;
}
set
{
base.Width = value;
}
}
[Themeable ( false ), Browsable ( false ), EditorBrowsable ( EditorBrowsableState.Never )]
public override bool Wrap
{
get
{
return base.Wrap;
}
set
{
base.Wrap = value;
}
}
#endregion
}
public class CustomNonParentingControl : Control
{
protected override void AddedControl ( Control control, int index ){}
protected override void RemovedControl ( Control control ){}
}