Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / InfocardExtendedInformationCollection.cs / 1 / InfocardExtendedInformationCollection.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.InfoCards
{
using System;
using System.Xml;
using System.Collections.Generic;
using System.Collections;
using System.Xml.Serialization;
using System.Xml.Schema;
using System.IO;
using System.Text;
using Microsoft.InfoCards.Diagnostics;
using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace;
//
// Summary
// Additional information contained in the card as part of xs:any
// We store all this information as raw xml. At present we only store
// IssuerInformation element as part of this object. In future this
// object can be used to store any information which is supplied in the crd file
//
internal class InfocardExtendedInformationCollection : List
{
const Int32 InvalidRow = 0;
Uri m_infoCardId;
Int32 m_rowId = InvalidRow;
public InfocardExtendedInformationCollection( Uri infoCardId )
{
if( null == infoCardId )
{
throw IDT.ThrowHelperArgumentNull( "infoCardId" );
}
m_infoCardId = infoCardId;
}
//
// Summary
// Retrieves the extended information from the store and populates the collection
// with it. The InfoCard Id specified in the constructor is used as the parent key.
//
// Parameters
// con - Connection to the store to be used to retrieve the extended information object.
//
public void Get( StoreConnection con )
{
if( null == con )
{
throw IDT.ThrowHelperArgumentNull( "con" );
}
IDT.TraceDebug( "Retrieving the issuer information for infocard({0})", m_infoCardId );
//
// Find the row for the object from the database, returns null if not exists
//
DataRow row = TryGetRow( con, QueryDetails.FullRow );
if( null != row )
{
Deserialize( new MemoryStream( row.GetDataField() ) );
m_rowId = row.LocalId;
}
}
//
// Summary
// Serialize the InfocardExtendedInformation object
//
// Parameter
// writer - binary stream conforming to the serialization format supported by this class.
//
public void Serialize( System.IO.Stream stream )
{
//
// Setup a BinaryWriter to serialize the bytes of each member to the provided stream
//
System.IO.BinaryWriter writer = new BinaryWriter( stream, Encoding.Unicode );
writer.Write( this.Count );
for( int i = 0; i < this.Count; i++ )
{
this[ i ].Serialize( writer );
}
}
//
// Summary
// Deserialize the InfocardExtendedInformation object
//
// Parameter
// reader - binary stream conforming to the serialization format supported by this class.
//
public void Deserialize( System.IO.Stream stream )
{
System.IO.BinaryReader reader = new BinaryReader( stream, Encoding.Unicode );
int count = reader.ReadInt32();
for( int i = 0; i < count; i++ )
{
InfocardExtendedInformationEntry entry = new InfocardExtendedInformationEntry();
entry.Deserialize( reader );
this.Add( entry );
}
}
//
// Summary
// Writes a serialized collection of InfocardExtendedInformation objects to the
// store.
//
// Remarks
// The parentId index field is set to the Id of the associated InfoCard.
//
// Parameters
// con - Connection to the store to be used to store the extended information object.
//
public void Save( StoreConnection con )
{
if( null == con )
{
throw IDT.ThrowHelperArgumentNull( "con" );
}
//
// Write the extended information to the store associated
// this collection with the infocard id specified.
//
IDT.TraceDebug( "Saving the claims collection..." );
IDT.TraceDebug( ToString() );
//
// Try and get the database header information to
// see if this is an insert or update.
//
// Note: The datafield is not part of the projection
// in order to avoid unnecessary decryption.
//
DataRow row = TryGetRow( con, QueryDetails.FullHeader );
if( null == row )
{
row = new DataRow();
row.ObjectType = (Int32)StorableObjectType.InfocardExtendedInformation;
row.GlobalId = Guid.NewGuid();
}
//
// Populate the parentId index field
//
row.SetIndexValue( SecondaryIndexDefinition.ParentIdIndex,
GlobalId.DeriveFrom( m_infoCardId.ToString() ) );
//
// Populate the data object
//
MemoryStream ms = new MemoryStream();
Serialize( ms );
row.SetDataField( ms.ToArray() );
//
// Save the row to the database
//
con.Save( row );
//
// Update the row id in the object in case
// this was an insert.
//
m_rowId = row.LocalId;
}
public string GetIssuerInformationElement()
{
for( int i = 0; i < this.Count; i++ )
{
XmlReader reader = InfoCardSchemas.CreateReader( this[ i ].GetXml() );
reader.Read();
if( reader.IsStartElement( XmlNames.WSIdentity07.IssuerInformation, XmlNames.WSIdentity07.Namespace ) )
{
reader.Close();
return this[ i ].GetXml();
}
reader.Close();
}
return string.Empty;
}
//
// Summary
// Queries the store for the claims object associated with the InfoCard Id
// currently in m_infoCardId.
//
// Remarks
// This function will return null if no object is found in the store.
//
// Parameters
// con - Connection to the store to be used to find the claims collection object.
// details - The projection of the store information to be returned.
//
protected DataRow TryGetRow( StoreConnection con, QueryDetails details )
{
IDT.Assert( null != m_infoCardId, "null infocard id" );
//
// Retrieve a single object from the database
//
DataRow row =
con.GetSingleRow( details,
new QueryParameter( SecondaryIndexDefinition.ObjectTypeIndex,
(Int32)StorableObjectType.InfocardExtendedInformation ),
new QueryParameter( SecondaryIndexDefinition.ParentIdIndex,
GlobalId.DeriveFrom( m_infoCardId.ToString() ) ) );
return row;
}
}
}
// 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
- TaiwanCalendar.cs
- XmlSchemaAnyAttribute.cs
- ClearCollection.cs
- Vertex.cs
- TableLayoutSettingsTypeConverter.cs
- WindowsEditBoxRange.cs
- CryptographicAttribute.cs
- HandlerFactoryCache.cs
- ReliabilityContractAttribute.cs
- HelpKeywordAttribute.cs
- DirectoryNotFoundException.cs
- CheckPair.cs
- EntityType.cs
- ServiceChannelManager.cs
- PlatformNotSupportedException.cs
- shaper.cs
- ZipIOLocalFileDataDescriptor.cs
- GlobalizationAssembly.cs
- DispatcherHookEventArgs.cs
- LabelLiteral.cs
- LabelAutomationPeer.cs
- OutputCacheProfileCollection.cs
- DataGridTableCollection.cs
- AdRotator.cs
- TimeStampChecker.cs
- DataStreamFromComStream.cs
- X509ImageLogo.cs
- documentsequencetextpointer.cs
- SocketException.cs
- AnnotationHelper.cs
- AuthorizationSection.cs
- XmlKeywords.cs
- WebReferencesBuildProvider.cs
- SoapDocumentServiceAttribute.cs
- EntityDataSourceUtil.cs
- MediaTimeline.cs
- WorkflowOwnershipException.cs
- InternalEnumValidator.cs
- SocketInformation.cs
- SQLBytes.cs
- IriParsingElement.cs
- CodeArrayCreateExpression.cs
- GeneralTransform2DTo3DTo2D.cs
- updatecommandorderer.cs
- FileClassifier.cs
- FrameworkObject.cs
- COSERVERINFO.cs
- _AutoWebProxyScriptWrapper.cs
- InputProcessorProfilesLoader.cs
- AnimationClockResource.cs
- AssemblyNameProxy.cs
- RegexWorker.cs
- PostBackTrigger.cs
- LineServices.cs
- MapPathBasedVirtualPathProvider.cs
- StickyNoteContentControl.cs
- XmlNullResolver.cs
- altserialization.cs
- MsmqTransportSecurityElement.cs
- SqlDataSource.cs
- StaticTextPointer.cs
- SmtpMail.cs
- PerformanceCountersBase.cs
- MetadataStore.cs
- ExternalFile.cs
- SelectionRangeConverter.cs
- RecipientInfo.cs
- XPathNodeInfoAtom.cs
- KeyFrames.cs
- ProviderSettings.cs
- DesignTimeXamlWriter.cs
- RightsManagementEncryptedStream.cs
- ConfigUtil.cs
- elementinformation.cs
- Timer.cs
- HtmlDocument.cs
- dataprotectionpermissionattribute.cs
- XmlUtil.cs
- PackageDigitalSignature.cs
- TextBox.cs
- CompilationLock.cs
- Authorization.cs
- Panel.cs
- DBCSCodePageEncoding.cs
- XPathNavigatorReader.cs
- WebPartCloseVerb.cs
- ParallelEnumerable.cs
- DbQueryCommandTree.cs
- control.ime.cs
- InvalidCastException.cs
- PieceNameHelper.cs
- SqlFileStream.cs
- QilTernary.cs
- XmlToDatasetMap.cs
- TranslateTransform.cs
- TrackingRecordPreFilter.cs
- TextTreeText.cs
- hwndwrapper.cs
- HtmlTableRowCollection.cs
- ByteStream.cs