Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / ListCardsInFileRequest.cs / 1 / ListCardsInFileRequest.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace Microsoft.InfoCards { using System; using System.Collections.Generic; using System.IO; using System.Xml; using System.Security.Cryptography; using System.Xml.Schema; using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace; // // Open the file using the password and retrieves all the cards // in an import file. // class ListCardsInFileRequest :UIAgentRequest { InfoCardPolicy m_policy; RoamingStoreFile m_roamingFile; string m_filename; string m_passphrase; public ListCardsInFileRequest( IntPtr rpcHandle, Stream inArgs, Stream outArgs, ClientUIRequest parent ) : base( rpcHandle, inArgs, outArgs, parent ) { m_roamingFile = new RoamingStoreFile(); } protected override void OnInitializeAsSystem() { base.OnInitializeAsSystem(); m_policy = GetPolicy(); } // // Summary // Read the marshalled arguments // protected override void OnMarshalInArgs() { BinaryReader reader = new InfoCardBinaryReader( InArgs, System.Text.Encoding.Unicode ); m_filename = Utility.DeserializeString( reader ); m_passphrase = Utility.DeserializeString( reader ); } // // Summary // Read the list of cards from the store // protected override void OnProcess() { // // clean up any existing card data. // Cleanup(false,true); try { try { try { using ( FileStream fileStream = new FileStream( m_filename, FileMode.Open, FileAccess.Read, FileShare.Read ) ) { // // Use a stream that validates the xml against internally stored schemas. // XmlReaderSettings settings = InfoCardSchemas.CreateDefaultReaderSettings(); settings.IgnoreWhitespace = false; using ( XmlReader reader = InfoCardSchemas.CreateReader( fileStream, settings ) ) { IDT.TraceDebug( " Roaming: Decrypting the roaming store" ); m_roamingFile.ReadFrom( m_passphrase, reader ); // // Store a pointer to the original content from the file. // this is the content that contains the private key info // for each infocard. This is required as persist time. // ParentRequest.SetContext( m_roamingFile ); } } } catch( ImportException ) { throw; } catch ( CryptographicException e ) { throw IDT.ThrowHelperError( new PasswordValidationException( SR.GetString( SR.InvalidImportFile ), e ) ); } catch ( XmlSchemaValidationException e ) { throw IDT.ThrowHelperError( new ImportException( SR.GetString( SR.SchemaValidationFailed ), e ) ); } catch ( UnauthorizedAccessException e ) { throw IDT.ThrowHelperError( new ImportException( SR.GetString( SR.ImportInaccesibleFile ), e ) ); } catch ( IOException e ) { throw IDT.ThrowHelperError( new ImportException( SR.GetString( SR.InvalidImportFile ), e ) ); } catch ( XmlException e ) { throw IDT.ThrowHelperError( new ImportException( SR.GetString( SR.InvalidImportFile ), e ) ); } } catch ( ImportException ie ) { // // clear the cards, pwd will be cleared below. // Cleanup(false, true); // // Translate ImportException to ImportStoreException since this is a .crds file // // // Using ie.Message as opposed to SR.GetString( SR.InvalidStoreImportFile ) // for more accurate error information. // throw IDT.ThrowHelperError( new ImportStoreException( ie.Message ) ); } } finally { // // clear the pwd not the cards // Cleanup(true, false); } } // // Summary // Write the cards to the stream to be returned // protected override void OnMarshalOutArgs() { Stream stream = OutArgs; BinaryWriter writer = new BinaryWriter( stream ); StoreConnection connection = StoreConnection.GetConnection(); try { if( null != m_roamingFile && 0 != m_roamingFile.Cards.Count ) { IDT.TraceDebug( " Roaming: Returning {0} cards to the UI", m_roamingFile.Cards.Count ); // // write the count of the array. // try { writer.Write( m_roamingFile.Cards.Count ); for( int i = 0; i < m_roamingFile.Cards.Count; i++ ) { // // Flush the writer to ensure that all data // is committed to the base stream before // we pass the base stream into the card. // writer.Flush(); m_roamingFile.Cards[ i ].AgentSerialize( stream, ( ParentRequest is GetTokenRequest ), m_policy, connection, new System.Globalization.CultureInfo( ParentRequest.UserLanguage ) ); } } catch( Exception e ) { Cleanup( true, true ); if( IDT.IsFatal( e ) ) { throw; } throw IDT.ThrowHelperError( new ImportStoreException( SR.GetString( SR.InvalidImportFile ), e ) ); } } else { // // write the count of the array as 0. // writer.Write( 0 ); } } finally { connection.Close(); } } // // Summary: Clear out sensitive data present in an infocard // private void Cleanup( bool clearPwd, bool clearRoamingFile ) { if( clearRoamingFile ) { if( null != m_roamingFile ) { m_roamingFile.Clear(); } if( null != ParentRequest ) { ParentRequest.ClearContext (); } } if( clearPwd ) { m_passphrase = null; } } } } // 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
- UserPreferenceChangedEventArgs.cs
- SerialPort.cs
- NavigationWindowAutomationPeer.cs
- DataSourceProvider.cs
- DataStreamFromComStream.cs
- hwndwrapper.cs
- Processor.cs
- HttpServerVarsCollection.cs
- DSASignatureDeformatter.cs
- PeerNameRecord.cs
- CodeTypeReferenceCollection.cs
- DefaultEventAttribute.cs
- Pair.cs
- CellParagraph.cs
- PeerInvitationResponse.cs
- ObjectNotFoundException.cs
- TemplateBindingExpressionConverter.cs
- GenericUriParser.cs
- IssuanceLicense.cs
- SoapSchemaImporter.cs
- UnmanagedMemoryStreamWrapper.cs
- IDictionary.cs
- EventWaitHandleSecurity.cs
- Padding.cs
- LeftCellWrapper.cs
- StylusButtonCollection.cs
- ManipulationVelocities.cs
- GenericPrincipal.cs
- PixelFormats.cs
- MsmqInputMessagePool.cs
- ProfilePropertyNameValidator.cs
- FixUpCollection.cs
- SimpleTypeResolver.cs
- FixedTextPointer.cs
- PageCodeDomTreeGenerator.cs
- TextProperties.cs
- CatalogPartChrome.cs
- InputReportEventArgs.cs
- DefaultPrintController.cs
- Container.cs
- HttpWrapper.cs
- OleDbDataReader.cs
- Point4D.cs
- FragmentQuery.cs
- DesignerAdapterUtil.cs
- StateDesigner.TransitionInfo.cs
- SchemaType.cs
- OdbcEnvironment.cs
- FilteredSchemaElementLookUpTable.cs
- FormViewCommandEventArgs.cs
- RSACryptoServiceProvider.cs
- InternalMappingException.cs
- ButtonPopupAdapter.cs
- DrawingCollection.cs
- DataServiceHostFactory.cs
- UriGenerator.cs
- XsltLibrary.cs
- ObjectHandle.cs
- SafeLibraryHandle.cs
- AliasGenerator.cs
- AppDomainAttributes.cs
- CacheSection.cs
- TextElementAutomationPeer.cs
- SetState.cs
- AssemblyHash.cs
- ClientCultureInfo.cs
- EdmItemError.cs
- QilSortKey.cs
- ZipIOLocalFileDataDescriptor.cs
- Matrix.cs
- FixUp.cs
- ParseNumbers.cs
- EndpointAddressMessageFilterTable.cs
- PointF.cs
- DbProviderConfigurationHandler.cs
- NavigatingCancelEventArgs.cs
- RuntimeArgumentHandle.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- ServiceModelEnumValidatorAttribute.cs
- CssTextWriter.cs
- MimeWriter.cs
- WindowsScrollBar.cs
- AuthenticationModuleElementCollection.cs
- FileRecordSequenceCompletedAsyncResult.cs
- DataControlReferenceCollection.cs
- SqlDataSourceView.cs
- DirectoryObjectSecurity.cs
- UnicastIPAddressInformationCollection.cs
- StringConcat.cs
- ToolStripItemEventArgs.cs
- SurrogateChar.cs
- MemberCollection.cs
- ItemAutomationPeer.cs
- XsltLoader.cs
- Types.cs
- NumberEdit.cs
- LogLogRecord.cs
- SchemaSetCompiler.cs
- Icon.cs
- SmtpFailedRecipientsException.cs