Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / GetImportedCardRequest.cs / 1 / GetImportedCardRequest.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace Microsoft.InfoCards { using System; using System.Collections; using System.IO; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace; // // This class represents a request to parse a .crd file to create // and infocard and return it to the UI. // class GetImportedCardRequest : UIAgentRequest { public enum ImportCardMatchStatus :byte { MatchNone, // Imported card does not match any existing cards MatchSameVersion, // Imported card matches an existing card with the same version MatchNewerVersion, // Imported card matches an existing card with a newer version MatchOlderVersion // Imported card matches an existing card with an older version }; InfoCard m_card; Recipient m_issuer; string m_filename; String m_policyLink; InfoCardPolicy m_policy; ImportCardMatchStatus m_matchFlag; public GetImportedCardRequest( IntPtr rpcHandle, Stream inArgs, Stream outArgs, ClientUIRequest parent ) : base( rpcHandle, inArgs, outArgs, parent ) { m_matchFlag = ImportCardMatchStatus.MatchNone; } protected override void OnInitializeAsSystem() { base.OnInitializeAsSystem(); m_policy = GetPolicy(); // m_policy is null in manage case } // // Summary // Read the imported filename // protected override void OnMarshalInArgs() { BinaryReader reader = new InfoCardBinaryReader( InArgs, System.Text.Encoding.Unicode ); m_filename = Utility.DeserializeString( reader ); } // // Summary // create an infocard from the card file // protected override void OnProcess() { StoreConnection connection = StoreConnection.GetConnection(); try { IDT.Assert( !String.IsNullOrEmpty( m_filename ), "No file name provided for import" ); InfoCardXmlSerializer serializer = new InfoCardXmlSerializer( connection ); serializer.CheckSignature = true; serializer.Deserialize( m_filename ); m_card = serializer.Card; // // Set the installation date. // m_card.IsImported = true; m_card.InstalledOn = DateTime.Now; X509Certificate2 cert = serializer.Issuer; // // The card and issuer can never be null // if( null != cert && null != m_card && m_card.IsComplete() ) { Recipient.RecipientCertParameters recipientParameters; string recipIdentifier = Recipient.CertGetRecipientIdHash( cert, serializer.AdditionalIssuerCerts, serializer.IsIssuerChainTrusted, out recipientParameters ); string recipOrgIdentifier = Recipient.CertGetRecipientOrganizationIdHash( cert, serializer.AdditionalIssuerCerts, serializer.IsIssuerChainTrusted ); ParentRequest.CertCacheAdd( recipIdentifier, cert ); m_issuer = new Recipient( cert, recipIdentifier, recipOrgIdentifier, true, m_card.PrivacyPolicyVersion, recipientParameters ); // // set the issuer name for the card // if( m_issuer.IsOrganizationVerified() ) { m_card.IssuerName = m_issuer.RecipientParameters.m_organization; } else { m_card.IssuerName = m_issuer.RecipientParameters.m_cn; } m_policyLink = m_card.PrivacyPolicyLink; // // Check if this card will be overwritten // Listparam = new List (); param.Add( new QueryParameter( SecondaryIndexDefinition.ObjectTypeIndex, (Int32)StorableObjectType.InfoCard ) ); param.Add( new QueryParameter( SecondaryIndexDefinition.GlobalIdIndex, GlobalId.DeriveFrom( m_card.Id.ToString() ) ) ); DataRow row = connection.GetSingleRow( QueryDetails.FullRow, param.ToArray() ); if( null != row ) { using( MemoryStream ms = new MemoryStream( row.GetDataField() ) ) { InfoCard existingCard = new InfoCard( ms ); if( existingCard.Epoch == m_card.Epoch ) { m_matchFlag = ImportCardMatchStatus.MatchSameVersion; } else if( existingCard.Epoch < m_card.Epoch ) { m_matchFlag = ImportCardMatchStatus.MatchOlderVersion; } else { m_matchFlag = ImportCardMatchStatus.MatchNewerVersion; } // // Copy the metadata to the new card // m_card.CopyMetaData( existingCard ); } } } else { throw IDT.ThrowHelperError( new ImportException( SR.GetString( SR.InvalidImportFile ) ) ); } } finally { connection.Close(); } } // // Summary // Write the imported card to the out stream. // protected override void OnMarshalOutArgs() { Stream stream = OutArgs; IDT.TraceDebug( "Returning the imported card to the UI" ); if( null != m_card && null != m_issuer && m_card.IsComplete()) { StoreConnection connection = StoreConnection.GetConnection(); try { m_card.AgentSerialize( stream, ( ParentRequest is GetTokenRequest ), m_policy, connection, new System.Globalization.CultureInfo( ParentRequest.UserLanguage ) ); BinaryWriter writer = new BinaryWriter( stream, System.Text.Encoding.Unicode ); m_issuer.Serialize( writer ); Utility.SerializeString( writer, m_policyLink ); writer.Write( (byte)m_matchFlag ); } finally { connection.Close(); } } } } } // 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
- ClientSponsor.cs
- TextUtf8RawTextWriter.cs
- GACMembershipCondition.cs
- ConnectionManagementElement.cs
- ControlPaint.cs
- GridViewActionList.cs
- FixedSOMTextRun.cs
- ControlAdapter.cs
- ManagementOperationWatcher.cs
- AssemblyHash.cs
- DynamicControl.cs
- StringExpressionSet.cs
- DrawingContextWalker.cs
- FontSizeConverter.cs
- HostingPreferredMapPath.cs
- MetadataItem.cs
- VirtualPath.cs
- ObjectItemLoadingSessionData.cs
- Selector.cs
- ConnectionPoolManager.cs
- Helpers.cs
- AudioSignalProblemOccurredEventArgs.cs
- WindowsComboBox.cs
- HttpCapabilitiesEvaluator.cs
- RequestStatusBarUpdateEventArgs.cs
- Point4DConverter.cs
- PictureBoxDesigner.cs
- TemplateLookupAction.cs
- ObjectMemberMapping.cs
- DataPointer.cs
- DataGridBoolColumn.cs
- XmlRawWriter.cs
- XMLUtil.cs
- CompilerResults.cs
- ObjectPersistData.cs
- OutgoingWebRequestContext.cs
- MultiplexingDispatchMessageFormatter.cs
- NonVisualControlAttribute.cs
- panel.cs
- HierarchicalDataBoundControlAdapter.cs
- dsa.cs
- CodeCommentStatementCollection.cs
- PersonalizationEntry.cs
- PolyBezierSegment.cs
- ValidateNames.cs
- PropertyTabChangedEvent.cs
- MarkupProperty.cs
- OutputCacheModule.cs
- StreamSecurityUpgradeAcceptorAsyncResult.cs
- Int64Converter.cs
- MergeFilterQuery.cs
- XmlArrayItemAttributes.cs
- Evaluator.cs
- DBBindings.cs
- TemplateManager.cs
- ExpressionQuoter.cs
- TraceRecords.cs
- SystemColorTracker.cs
- LinqExpressionNormalizer.cs
- MessageSmuggler.cs
- MenuEventArgs.cs
- SkewTransform.cs
- SectionRecord.cs
- MouseGestureConverter.cs
- PageCodeDomTreeGenerator.cs
- DeobfuscatingStream.cs
- Filter.cs
- DbConnectionFactory.cs
- PropertyEntry.cs
- CodeDirectoryCompiler.cs
- TextTreeFixupNode.cs
- CaseInsensitiveOrdinalStringComparer.cs
- QilScopedVisitor.cs
- DynamicEndpointElement.cs
- SchemaHelper.cs
- ProjectionPlan.cs
- ComAdminWrapper.cs
- HttpCapabilitiesEvaluator.cs
- TableCell.cs
- MD5.cs
- BinaryConverter.cs
- InvokeWebService.cs
- DataGridViewCellConverter.cs
- GlyphTypeface.cs
- DataGridRow.cs
- MailDefinition.cs
- PropertyPanel.cs
- LoginUtil.cs
- VoiceChangeEventArgs.cs
- MbpInfo.cs
- MetadataArtifactLoaderFile.cs
- KeyValueConfigurationCollection.cs
- ParameterBuilder.cs
- SimpleType.cs
- ConnectionPoint.cs
- WsatTransactionFormatter.cs
- Content.cs
- Trigger.cs
- TraceRecord.cs
- SimpleColumnProvider.cs