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
- DesignTimeVisibleAttribute.cs
- EventSourceCreationData.cs
- SizeAnimationClockResource.cs
- DateTimeStorage.cs
- PrePostDescendentsWalker.cs
- WebMessageFormatHelper.cs
- GeometryGroup.cs
- ControlPropertyNameConverter.cs
- FastEncoderWindow.cs
- AppDomain.cs
- DeobfuscatingStream.cs
- ClientBuildManager.cs
- ContextQuery.cs
- FormsIdentity.cs
- SymbolType.cs
- unitconverter.cs
- DockPanel.cs
- WindowsFormsDesignerOptionService.cs
- ProxyWebPartManager.cs
- StylusOverProperty.cs
- OdbcException.cs
- Transform3DGroup.cs
- BaseInfoTable.cs
- StateRuntime.cs
- SplineKeyFrames.cs
- DefaultSettingsSection.cs
- CompilationRelaxations.cs
- StyleXamlParser.cs
- ECDsa.cs
- DesignerSerializationVisibilityAttribute.cs
- PointUtil.cs
- RegexTree.cs
- ErrorHandler.cs
- TextServicesCompartment.cs
- ToolStripDropDownClosedEventArgs.cs
- TypedDataSetSchemaImporterExtensionFx35.cs
- FormatterServices.cs
- SmiRequestExecutor.cs
- Imaging.cs
- WebPartCatalogAddVerb.cs
- MultiplexingDispatchMessageFormatter.cs
- CaretElement.cs
- ModuleBuilderData.cs
- ProviderSettings.cs
- HebrewNumber.cs
- _AutoWebProxyScriptEngine.cs
- ListGeneralPage.cs
- Message.cs
- ToolStripDropDownMenu.cs
- DbTransaction.cs
- BridgeDataRecord.cs
- OutputCacheProfileCollection.cs
- RawContentTypeMapper.cs
- Soap12ProtocolImporter.cs
- MarkedHighlightComponent.cs
- HopperCache.cs
- PersistencePipeline.cs
- PageThemeCodeDomTreeGenerator.cs
- ViewgenContext.cs
- SettingsSection.cs
- FormViewRow.cs
- BitmapCacheBrush.cs
- WhitespaceRule.cs
- ThousandthOfEmRealDoubles.cs
- IssuanceLicense.cs
- XmlAttributeOverrides.cs
- CapabilitiesSection.cs
- RenderData.cs
- PrintingPermissionAttribute.cs
- MetadataPropertyAttribute.cs
- EntityWithKeyStrategy.cs
- CustomErrorCollection.cs
- DbConvert.cs
- StreamUpgradeAcceptor.cs
- WebPartVerbCollection.cs
- ByteViewer.cs
- AsymmetricKeyExchangeFormatter.cs
- JournalEntryListConverter.cs
- ShaperBuffers.cs
- ClientUrlResolverWrapper.cs
- HttpChannelListener.cs
- IDReferencePropertyAttribute.cs
- RandomNumberGenerator.cs
- ExpressionBindingCollection.cs
- TextEffectResolver.cs
- ApplicationActivator.cs
- X500Name.cs
- MonitorWrapper.cs
- Rect3D.cs
- SignatureHelper.cs
- BuilderPropertyEntry.cs
- SchemaManager.cs
- KernelTypeValidation.cs
- ModelUIElement3D.cs
- MarginCollapsingState.cs
- StackBuilderSink.cs
- PasswordDeriveBytes.cs
- HashCodeCombiner.cs
- XPathMultyIterator.cs
- RoleManagerSection.cs