Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / MS / Internal / IO / Packaging / CompoundFile / UserUseLicenseDictionaryLoader.cs / 1 / UserUseLicenseDictionaryLoader.cs
//------------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description:
// This class is a helper to load a set of associations between a user and the use license
// granted to that user.
//
// History:
// 04/19/2005: LGolding: Initial implementation.
// 03/08/2006: IgorBel: switch from a dictionary to a Load helper
//
//
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.IO;
using System.IO.Packaging;
using System.Windows;
using System.Security.RightsManagement;
using MS.Internal;
namespace MS.Internal.IO.Packaging.CompoundFile
{
internal class UserUseLicenseDictionaryLoader
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Constructor.
///
internal UserUseLicenseDictionaryLoader(RightsManagementEncryptionTransform rmet)
{
_dict = new Dictionary(ContentUser._contentUserComparer);
//
// This constructor is only called from RightsManagementEncryptionTransform
// .GetEmbeddedUseLicenses. That method passes "this" as the parameter.
// So it can't possibly be null.
//
Invariant.Assert(rmet != null);
Load(rmet);
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
#region Internal Properties
internal Dictionary LoadedDictionary
{
get
{
return _dict;
}
}
#endregion Internal Properties
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
///
/// Load the contents of the dictionary from the compound file.
///
///
/// The object that knows how to load use license data from the compound file.
///
///
/// If is null.
///
private void Load(RightsManagementEncryptionTransform rmet )
{
rmet.EnumUseLicenseStreams(
new RightsManagementEncryptionTransform.UseLicenseStreamCallback(
this.AddUseLicenseFromStreamToDictionary
),
null
);
}
///
/// Callback function used by Load. Called once for each use license stream
/// in the compound file. Extracts the user and use license from the specified
/// stream.
///
///
/// The object that knows how to extract license information from the compound file.
///
///
/// The stream containing the user/user license pair to be added to the dictionary.
///
///
/// Caller-supplied parameter to EnumUseLicenseStreams. Not used.
///
///
/// Set to true if the callback function wants to stop the enumeration. This callback
/// function never wants to stop the enumeration, so this parameter is not used.
///
private void
AddUseLicenseFromStreamToDictionary(
RightsManagementEncryptionTransform rmet,
StreamInfo si,
object param,
ref bool stop
)
{
ContentUser user;
using (Stream stream = si.GetStream(FileMode.Open, FileAccess.Read))
{
using(BinaryReader utf8Reader = new BinaryReader(stream, _utf8Encoding))
{
UseLicense useLicense = rmet.LoadUseLicenseAndUserFromStream(utf8Reader, out user);
_dict.Add(user, useLicense);
}
}
}
#endregion Private Methods
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
//
// The object that provides the implementation of the IDictionary methods.
//
private Dictionary _dict;
//
// Text encoding object used to read or write publish licenses and use licenses.
//
private UTF8Encoding _utf8Encoding = new UTF8Encoding();
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// Description:
// This class is a helper to load a set of associations between a user and the use license
// granted to that user.
//
// History:
// 04/19/2005: LGolding: Initial implementation.
// 03/08/2006: IgorBel: switch from a dictionary to a Load helper
//
//
//-----------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.IO;
using System.IO.Packaging;
using System.Windows;
using System.Security.RightsManagement;
using MS.Internal;
namespace MS.Internal.IO.Packaging.CompoundFile
{
internal class UserUseLicenseDictionaryLoader
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
///
/// Constructor.
///
internal UserUseLicenseDictionaryLoader(RightsManagementEncryptionTransform rmet)
{
_dict = new Dictionary(ContentUser._contentUserComparer);
//
// This constructor is only called from RightsManagementEncryptionTransform
// .GetEmbeddedUseLicenses. That method passes "this" as the parameter.
// So it can't possibly be null.
//
Invariant.Assert(rmet != null);
Load(rmet);
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Properties
//
//-----------------------------------------------------
#region Internal Properties
internal Dictionary LoadedDictionary
{
get
{
return _dict;
}
}
#endregion Internal Properties
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
#region Private Methods
///
/// Load the contents of the dictionary from the compound file.
///
///
/// The object that knows how to load use license data from the compound file.
///
///
/// If is null.
///
private void Load(RightsManagementEncryptionTransform rmet )
{
rmet.EnumUseLicenseStreams(
new RightsManagementEncryptionTransform.UseLicenseStreamCallback(
this.AddUseLicenseFromStreamToDictionary
),
null
);
}
///
/// Callback function used by Load. Called once for each use license stream
/// in the compound file. Extracts the user and use license from the specified
/// stream.
///
///
/// The object that knows how to extract license information from the compound file.
///
///
/// The stream containing the user/user license pair to be added to the dictionary.
///
///
/// Caller-supplied parameter to EnumUseLicenseStreams. Not used.
///
///
/// Set to true if the callback function wants to stop the enumeration. This callback
/// function never wants to stop the enumeration, so this parameter is not used.
///
private void
AddUseLicenseFromStreamToDictionary(
RightsManagementEncryptionTransform rmet,
StreamInfo si,
object param,
ref bool stop
)
{
ContentUser user;
using (Stream stream = si.GetStream(FileMode.Open, FileAccess.Read))
{
using(BinaryReader utf8Reader = new BinaryReader(stream, _utf8Encoding))
{
UseLicense useLicense = rmet.LoadUseLicenseAndUserFromStream(utf8Reader, out user);
_dict.Add(user, useLicense);
}
}
}
#endregion Private Methods
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
#region Private Fields
//
// The object that provides the implementation of the IDictionary methods.
//
private Dictionary _dict;
//
// Text encoding object used to read or write publish licenses and use licenses.
//
private UTF8Encoding _utf8Encoding = new UTF8Encoding();
#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
- TextDocumentView.cs
- DbFunctionCommandTree.cs
- DocumentGrid.cs
- DataPagerCommandEventArgs.cs
- HtmlImage.cs
- MatrixAnimationUsingKeyFrames.cs
- TransformGroup.cs
- MenuItem.cs
- HtmlForm.cs
- FloaterBaseParagraph.cs
- AdvancedBindingEditor.cs
- DataPagerCommandEventArgs.cs
- DispatchOperation.cs
- ComponentEvent.cs
- LocalFileSettingsProvider.cs
- ImageAttributes.cs
- SQLGuidStorage.cs
- QueryContext.cs
- MaterialGroup.cs
- CompositeActivityValidator.cs
- EditableLabelControl.cs
- DtdParser.cs
- BoolExpressionVisitors.cs
- FileDialog_Vista.cs
- ValueConversionAttribute.cs
- RecognitionEventArgs.cs
- InvokePattern.cs
- MachineKeyConverter.cs
- Int32Collection.cs
- MultipartContentParser.cs
- _DomainName.cs
- Parameter.cs
- CodeMethodReturnStatement.cs
- DrawingVisualDrawingContext.cs
- FlatButtonAppearance.cs
- PageHandlerFactory.cs
- BulletedListEventArgs.cs
- SslStream.cs
- ProbeMatchesMessageCD1.cs
- URL.cs
- TransactionContext.cs
- WebPartEditorOkVerb.cs
- Vector3DKeyFrameCollection.cs
- FreezableCollection.cs
- XmlSchemaSimpleContentRestriction.cs
- CompoundFileReference.cs
- TextComposition.cs
- MetadataSource.cs
- DeclaredTypeValidatorAttribute.cs
- SerializationObjectManager.cs
- LOSFormatter.cs
- LoginDesigner.cs
- DynamicValidatorEventArgs.cs
- SessionPageStatePersister.cs
- Separator.cs
- WebServiceFault.cs
- TableAdapterManagerGenerator.cs
- Matrix3D.cs
- PageParserFilter.cs
- sqlstateclientmanager.cs
- TypeConstant.cs
- MonitoringDescriptionAttribute.cs
- DateTimeUtil.cs
- Pair.cs
- CheckBoxRenderer.cs
- ModifiableIteratorCollection.cs
- TreeNodeBinding.cs
- ServiceDescriptionSerializer.cs
- CodeDOMProvider.cs
- DataSet.cs
- DrawListViewItemEventArgs.cs
- MembershipUser.cs
- ItemMap.cs
- DesignBinding.cs
- SecurityBindingElement.cs
- AnonymousIdentificationModule.cs
- RenamedEventArgs.cs
- CommandValueSerializer.cs
- HttpCookiesSection.cs
- SecurityContextSecurityToken.cs
- ParsedRoute.cs
- TransformerTypeCollection.cs
- SortKey.cs
- RoutingExtensionElement.cs
- _NestedMultipleAsyncResult.cs
- HttpApplication.cs
- ParsedAttributeCollection.cs
- TrustSection.cs
- BitmapFrame.cs
- NameValueConfigurationCollection.cs
- TypeBrowser.xaml.cs
- PropertyTabChangedEvent.cs
- ConditionalAttribute.cs
- CodeGen.cs
- DataGridViewImageCell.cs
- XsltCompileContext.cs
- hwndwrapper.cs
- OleDbParameterCollection.cs
- HttpCookiesSection.cs
- UnsafeNativeMethodsTablet.cs