//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.RelyingParty {
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Web.UI;
using DotNetOpenAuth.InfoCard;
///
/// A button that appears in the control that
/// activates the Information Card selector on the browser, if one is available.
///
public class SelectorInfoCardButton : SelectorButton, IDisposable {
///
/// The backing field for the property.
///
private InfoCardSelector infoCardSelector;
///
/// Initializes a new instance of the class.
///
public SelectorInfoCardButton() {
Reporting.RecordFeatureUse(this);
}
///
/// Gets or sets the InfoCard selector which may be displayed alongside the OP buttons.
///
[PersistenceMode(PersistenceMode.InnerProperty)]
public InfoCardSelector InfoCardSelector {
get {
if (this.infoCardSelector == null) {
this.infoCardSelector = new InfoCardSelector();
}
return this.infoCardSelector;
}
set {
Requires.NotNull(value, "value");
if (this.infoCardSelector != null) {
Logger.Library.WarnFormat("{0}.InfoCardSelector property is being set multiple times.", GetType().Name);
}
this.infoCardSelector = value;
}
}
#region IDisposable Members
///
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
///
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
///
/// Ensures that this button has been initialized to a valid state.
///
internal override void EnsureValid() {
}
///
/// Renders the leading attributes for the LI tag.
///
/// The writer.
protected internal override void RenderLeadingAttributes(HtmlTextWriter writer) {
writer.AddAttribute(HtmlTextWriterAttribute.Class, "infocard");
}
///
/// Renders the content of the button.
///
/// The writer.
/// The containing selector control.
protected internal override void RenderButtonContent(HtmlTextWriter writer, OpenIdSelector selector) {
this.InfoCardSelector.RenderControl(writer);
}
///
/// Releases unmanaged and - optionally - managed resources
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
protected virtual void Dispose(bool disposing) {
if (disposing) {
if (this.infoCardSelector != null) {
this.infoCardSelector.Dispose();
}
}
}
}
}