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
- SQLDecimalStorage.cs
- _HelperAsyncResults.cs
- SecurityProtocolCorrelationState.cs
- HttpModuleCollection.cs
- IntegrationExceptionEventArgs.cs
- Floater.cs
- DataControlFieldCollection.cs
- GroupBoxDesigner.cs
- MarkedHighlightComponent.cs
- ReadOnlyCollectionBase.cs
- MessageContractMemberAttribute.cs
- PrimitiveCodeDomSerializer.cs
- EditorPartChrome.cs
- ClientSponsor.cs
- DataGridRow.cs
- PrinterUnitConvert.cs
- DataSysAttribute.cs
- PropertyDescriptorCollection.cs
- WSHttpBindingElement.cs
- Oid.cs
- CacheOutputQuery.cs
- WindowCollection.cs
- JsonFaultDetail.cs
- Misc.cs
- SystemNetHelpers.cs
- OleDbErrorCollection.cs
- Emitter.cs
- updateconfighost.cs
- UndoManager.cs
- MetadataArtifactLoaderResource.cs
- GlyphShapingProperties.cs
- Stacktrace.cs
- LocalizationParserHooks.cs
- SqlUDTStorage.cs
- RenderTargetBitmap.cs
- DetailsViewUpdatedEventArgs.cs
- ColorTransform.cs
- DoubleKeyFrameCollection.cs
- SpeakInfo.cs
- FileDataSourceCache.cs
- FacetValueContainer.cs
- HandlerMappingMemo.cs
- EdmTypeAttribute.cs
- SQLInt32.cs
- SoapIgnoreAttribute.cs
- InputLangChangeEvent.cs
- PropertyIDSet.cs
- RequestQueryProcessor.cs
- DBSchemaRow.cs
- ListBase.cs
- FixUp.cs
- CustomTrackingRecord.cs
- ColumnTypeConverter.cs
- ChildDocumentBlock.cs
- Compilation.cs
- RequestSecurityToken.cs
- TextParagraphCache.cs
- WindowsToolbarAsMenu.cs
- XmlNotation.cs
- dsa.cs
- CssClassPropertyAttribute.cs
- ProviderCollection.cs
- Token.cs
- ValidatedControlConverter.cs
- DebuggerService.cs
- TrailingSpaceComparer.cs
- Version.cs
- MemberHolder.cs
- DataGridCellAutomationPeer.cs
- DataRelationPropertyDescriptor.cs
- PackageRelationshipSelector.cs
- XmlElementAttributes.cs
- coordinator.cs
- ToolTipAutomationPeer.cs
- FolderNameEditor.cs
- KeySpline.cs
- DelegateTypeInfo.cs
- SystemIcmpV4Statistics.cs
- ParameterModifier.cs
- ListenerElementsCollection.cs
- MyContact.cs
- FlowchartDesignerCommands.cs
- TemplatePartAttribute.cs
- DesignerHelpers.cs
- ObjectDataSourceSelectingEventArgs.cs
- AssemblyBuilder.cs
- Int16AnimationUsingKeyFrames.cs
- ResXFileRef.cs
- CompareValidator.cs
- ModelPerspective.cs
- Point3DValueSerializer.cs
- StateManagedCollection.cs
- SignedXml.cs
- StrokeNode.cs
- WebServiceErrorEvent.cs
- StringFormat.cs
- RegexCaptureCollection.cs
- RealizationContext.cs
- TextServicesDisplayAttributePropertyRanges.cs
- SqlMethods.cs