GetPolicyDetailsRequest.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / GetPolicyDetailsRequest.cs / 1 / GetPolicyDetailsRequest.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.InfoCards
{ 
    using System;
    using System.IO; 
    using System.Security; 
    using System.Security.Cryptography.X509Certificates;
    using System.Collections; 
    using System.Collections.Generic;
    using Microsoft.InfoCards.Diagnostics;
    using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace;
    // 
    // This class handles a UI request for recipient information
    // 
    class GetPolicyDetailsRequest : UIAgentRequest 
    {
        InfoCardPolicy m_policy; 
        Recipient m_recipient;
        String m_privacyPolicyLink = String.Empty;

        // 
        // Summary
        //  Create a new request to return recipient related information 
        // 
        public GetPolicyDetailsRequest( IntPtr rpcHandle, Stream inArgs, Stream outArgs, ClientUIRequest parent )
            : base( rpcHandle, inArgs, outArgs, parent ) 
        {

        }
 
        protected override void OnInitializeAsSystem()
        { 
            base.OnInitializeAsSystem(); 
            m_policy = GetPolicy();
        } 
        protected override void OnMarshalInArgs()
        {

        } 

 
        protected override void OnProcess() 
        {
            IDT.Assert( null != m_policy, "Null policy" ); 


            StoreConnection connection = StoreConnection.GetConnection();
            try 
            {
 
                // 
                // Retrieve the recipient object from the store
                // 
                List paramList = new List();
                QueryParameter query = new QueryParameter(
                                                          SecondaryIndexDefinition.ObjectTypeIndex,
                                                          ( Int32 )StorableObjectType.Recipient ); 
                paramList.Add( query );
                query = new QueryParameter( 
                                          SecondaryIndexDefinition.RecipientIdIndex, 
                                          m_policy.Recipient.GetIdentifier() );
                paramList.Add( query ); 
                DataRow row = connection.GetSingleRow( paramList.ToArray() );
                X509RecipientIdentity recipient = m_policy.Recipient as  X509RecipientIdentity;
                if( null != recipient )
                { 
                    ParentRequest.CertCacheAdd( m_policy.Recipient.GetIdentifier(), recipient.LeafCertificate );
                } 
                if( null != row ) 
                {
                    m_recipient = new Recipient( new MemoryStream( row.GetDataField() ), m_policy.Recipient, true ); 

                    if ( m_recipient.Trust == Recipient.TrustDecision.IsTrusted
                        && m_recipient.PrivacyPolicyVersion != m_policy.PrivacyPolicyVersion )
                    { 
                        m_recipient.Trust = Recipient.TrustDecision.PolicyVersionChange;
                    } 
 
                    //
                    // update the recipient privacy policy version 
                    //
                    m_recipient.PrivacyPolicyVersion = m_policy.PrivacyPolicyVersion;
                }
                else 
                {
                    m_recipient = new Recipient( 
                                          m_policy.Recipient, 
                                          true,
                                          m_policy.PrivacyPolicyVersion ); 
                    m_recipient.Trust = Recipient.TrustDecision.NoTrustDecision;
                }

                m_privacyPolicyLink = m_policy.PrivacyPolicyLink; 
            }
            finally 
            { 
                connection.Close();
            } 

        }

        // 
        // Summary
        //  Serialize the output in the following order 
        //    requiresManagedCard ( bool ) 
        //    requiresSelfIssuedCard ( bool )
        //    if browser scenario ( bool ) 
        //    recipient certificate - recipient id
        //    count of required claims ( int32 )
        //    each claim ( string )
        //    count of optional claims ( int32 ) 
        //    each claim ( string )
        // 
        // 
        protected override void OnMarshalOutArgs()
        { 
            IDT.Assert( null != m_policy, "Null policy" );
            BinaryWriter writer = new BinaryWriter( OutArgs, System.Text.Encoding.Unicode );

            writer.Write( m_policy.RequiresManagedCard ); 

            writer.Write( m_policy.RequiresSelfIssuedCard ); 
 
            writer.Write( this.ParentRequest is GetBrowserTokenRequest );
 
            IDT.TraceDebug( "Serialize the recipient" );
            m_recipient.Serialize( writer );

            IDT.TraceDebug( "Serialize the privacy information" ); 
            Utility.SerializeString( writer, m_privacyPolicyLink );
 
 

            IDT.TraceDebug( "Retrieve the requested claim uri's from the policy" ); 
            if( null != m_policy.RequiredClaims )
            {
                writer.Write( ( Int32 )m_policy.RequiredClaims.Length );
                for( int i = 0; i < m_policy.RequiredClaims.Length; i++ ) 
                {
                    Utility.SerializeString( writer, m_policy.RequiredClaims[ i ] ); 
                } 

            } 
            else
            {
                writer.Write( ( Int32 )0 );
            } 

            IDT.TraceDebug( "Retrieve the optional claim uri's from the policy" ); 
            if( null != m_policy.OptionalClaims ) 
            {
                writer.Write( ( Int32 )m_policy.OptionalClaims.Length ); 
                for( int i = 0; i < m_policy.OptionalClaims.Length; i++ )
                {
                    Utility.SerializeString( writer, m_policy.OptionalClaims[ i ] );
                } 

            } 
            else 
            {
                writer.Write( ( Int32 )0 ); 
            }
        }

    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK