Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / TrustUi / MS / Internal / documents / CredentialManagerDialog.cs / 1 / CredentialManagerDialog.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description:
// CredentialManagerDialog is the Forms dialog that allows users to select RM Creds.
//
// History:
// 08/15/05 - [....] created
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.TrustUI;
using System.Security;
using System.Security.RightsManagement;
namespace MS.Internal.Documents
{
///
/// CredentialManagerDialog is used for choose RM credentials.
///
internal sealed partial class CredentialManagerDialog : DialogBaseForm
{
#region Constructors
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// The constructor
///
internal CredentialManagerDialog( IList accountList,
string defaultAccount,
DocumentRightsManagementManager docRightsManagementManager
)
{
if ((docRightsManagementManager != null))
{
_docRightsManagementManager = docRightsManagementManager;
}
else
{
throw new ArgumentNullException("DocumentRightsManagementManager");
}
//Set the data source for the listbox
SetCredentialManagementList(accountList, defaultAccount);
//Enable or disable remove button depending on whether there is anything to remove
_credListBox_SelectedIndexChanged(this, EventArgs.Empty);
}
#endregion Constructors
#region Public Methods
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
///
/// SetCredentialManagementList.
///
internal void SetCredentialManagementList(
IList accountList,
string defaultAccount
)
{
//now we need to refresh everything.
//Set the data source
_credListBox.DataSource = accountList;
if (defaultAccount != null)
{
//Now we need to get and select the default.
_credListBox.SelectedIndex = _credListBox.Items.IndexOf(defaultAccount);
}
}
#endregion Public Methods
#region Private Methods
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
///
/// Called when the selected item changes on the listbox.
///
private void _credListBox_SelectedIndexChanged(object sender, EventArgs e)
{
//Check to see if something is selected.
if (_credListBox.SelectedIndex >= 0)
{
_removeButton.Enabled = true;
}
else
{
_removeButton.Enabled = false;
}
}
///
/// OK button handler.
///
///
/// Critical - Calls a critical method _docRightsManagementManager::OnCredentialManagementSetDefault.
/// TreatAsSafe - The data we are passing into the critical call is strictly user supplied text
/// directly from the UI for list box.
///
[SecurityCritical, SecurityTreatAsSafe]
private void _okButton_Click(object sender, EventArgs e)
{
//Check to see if something is selected.
if (_credListBox.SelectedIndex >= 0)
{
//Call Manager to set the default.
_docRightsManagementManager.OnCredentialManagementSetDefault(
(string) _credListBox.Items[_credListBox.SelectedIndex]);
}
}
///
/// Remove button handler.
///
///
/// Critical - Calls a critical method _docRightsManagementManager::OnCredentialManagementRemove.
/// TreatAsSafe - The data we are passing into the critical call is strictly user supplied text
/// directly from the UI for list box.
///
[SecurityCritical, SecurityTreatAsSafe]
private void _removeButton_Click(object sender, EventArgs e)
{
//Check to see if something is selected.
if (_credListBox.SelectedIndex >= 0)
{
//Call Manager to remove selected user.
_docRightsManagementManager.OnCredentialManagementRemove(
(string)_credListBox.Items[_credListBox.SelectedIndex]);
//Enable or disable remove button depending on whether there is anything to remove
_credListBox_SelectedIndexChanged(this, EventArgs.Empty);
}
}
///
/// Add button handler.
///
///
/// Critical - Calls a critical method _docRightsManagementManager::OnCredentialManagementShowEnrollment.
/// TreatAsSafe - No data is being passed into the critical method and only invoked when the UI button is clicked.
///
[SecurityCritical, SecurityTreatAsSafe]
private void _addButton_Click(object sender, EventArgs e)
{
//to add new user just call enrollment
_docRightsManagementManager.OnCredentialManagementShowEnrollment();
//Enable or disable remove button depending on whether there is anything to remove
_credListBox_SelectedIndexChanged(this, EventArgs.Empty);
}
#endregion Private Methods
#region Protected Methods
//-----------------------------------------------------
//
// Protected Methods
//
//------------------------------------------------------
///
/// ApplyResources override. Called to apply dialog resources.
///
protected override void ApplyResources()
{
base.ApplyResources();
_cancelButton.Text = SR.Get(SRID.RMCredManagementCancel);
_okButton.Text = SR.Get(SRID.RMCredManagementOk);
_addButton.Text = SR.Get(SRID.RMCredManagementAdd);
_removeButton.Text = SR.Get(SRID.RMCredManagementRemove);
_instructionLabel.Text = SR.Get(SRID.RMCredManagementInstruction);
Text = SR.Get(SRID.RMCredManagementDialog);
// Setup matching Add/Remove button widths
int maxWidth = Math.Max(_addButton.Width, _removeButton.Width);
_addButton.Width = maxWidth;
_removeButton.Width = maxWidth;
}
#endregion Protected Methods
#region Private Fields
//-----------------------------------------------------
//
// Private Fields
//
//-----------------------------------------------------
private DocumentRightsManagementManager _docRightsManagementManager;
#endregion Private Fields
}
}
// 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
- BooleanKeyFrameCollection.cs
- DesignUtil.cs
- PeerTransportListenAddressConverter.cs
- HandlerMappingMemo.cs
- MultiBinding.cs
- AstTree.cs
- CompilerErrorCollection.cs
- XsltCompileContext.cs
- DesignTimeType.cs
- ConsoleEntryPoint.cs
- ProfileSettingsCollection.cs
- PasswordTextContainer.cs
- SymbolType.cs
- MsmqBindingFilter.cs
- ContentWrapperAttribute.cs
- RangeValuePattern.cs
- IntSecurity.cs
- TypeUsageBuilder.cs
- DBPropSet.cs
- XmlSchemaParticle.cs
- GiveFeedbackEventArgs.cs
- ResourceDictionaryCollection.cs
- AttachedPropertyBrowsableAttribute.cs
- WebPartTransformerCollection.cs
- CompModSwitches.cs
- StylusPointPropertyId.cs
- HtmlMeta.cs
- NavigationWindowAutomationPeer.cs
- EntityContainerAssociationSet.cs
- LogEntryHeaderv1Deserializer.cs
- PersonalizationStateInfoCollection.cs
- PackageFilter.cs
- KnownTypeAttribute.cs
- StubHelpers.cs
- SAPIEngineTypes.cs
- DataServiceExpressionVisitor.cs
- GeometryConverter.cs
- TextRangeEditLists.cs
- HttpHandlersSection.cs
- RegexGroupCollection.cs
- TreeWalker.cs
- VerticalAlignConverter.cs
- BasicViewGenerator.cs
- DisplayNameAttribute.cs
- figurelengthconverter.cs
- UpdateExpressionVisitor.cs
- MessageBox.cs
- XmlTextReader.cs
- ResourcesChangeInfo.cs
- Section.cs
- CompilerGeneratedAttribute.cs
- LogRecordSequence.cs
- ConstraintConverter.cs
- FilterQuery.cs
- SoapAttributes.cs
- GlobalProxySelection.cs
- METAHEADER.cs
- WsdlBuildProvider.cs
- DynamicUpdateCommand.cs
- DataKey.cs
- FastPropertyAccessor.cs
- SoapInteropTypes.cs
- LongMinMaxAggregationOperator.cs
- XamlParser.cs
- FormatterServices.cs
- AuthenticationModulesSection.cs
- shaperfactory.cs
- SecurityContext.cs
- RegisteredScript.cs
- ColumnResult.cs
- DefaultCompensation.cs
- QuaternionAnimationBase.cs
- TextRangeEdit.cs
- ArglessEventHandlerProxy.cs
- DataGridViewRowHeaderCell.cs
- MapPathBasedVirtualPathProvider.cs
- GridEntryCollection.cs
- Main.cs
- ResourcePart.cs
- DataTableReader.cs
- VisualStyleTypesAndProperties.cs
- cookiecollection.cs
- SoapIgnoreAttribute.cs
- WindowPattern.cs
- InputReportEventArgs.cs
- EventLogTraceListener.cs
- InputBinding.cs
- XPathNode.cs
- AutomationProperty.cs
- Image.cs
- ICspAsymmetricAlgorithm.cs
- MailWebEventProvider.cs
- ListSortDescription.cs
- MemoryStream.cs
- ToolStripDropDownItem.cs
- FixedSchema.cs
- DoubleConverter.cs
- SynchronizingStream.cs
- HostedHttpContext.cs
- SocketAddress.cs