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
- FormViewDeletedEventArgs.cs
- GridViewPageEventArgs.cs
- Drawing.cs
- TextRenderer.cs
- KeyInterop.cs
- StreamGeometry.cs
- DataServiceClientException.cs
- XmlNavigatorStack.cs
- WhiteSpaceTrimStringConverter.cs
- FilterableAttribute.cs
- DataChangedEventManager.cs
- TypefaceMap.cs
- StreamingContext.cs
- DetailsViewDeleteEventArgs.cs
- XamlPoint3DCollectionSerializer.cs
- IntranetCredentialPolicy.cs
- WindowsPrincipal.cs
- PeerNode.cs
- RelationshipDetailsCollection.cs
- QueryOperator.cs
- AuthenticationException.cs
- DSASignatureFormatter.cs
- HttpPostProtocolReflector.cs
- autovalidator.cs
- _SpnDictionary.cs
- InheritablePropertyChangeInfo.cs
- HttpDictionary.cs
- FlowSwitchLink.cs
- Visitor.cs
- ManualWorkflowSchedulerService.cs
- ImmutableObjectAttribute.cs
- Executor.cs
- SqlParameterCollection.cs
- Main.cs
- HttpClientCertificate.cs
- WebPartZoneBaseDesigner.cs
- ConnectionsZone.cs
- WindowsGraphicsCacheManager.cs
- XmlCDATASection.cs
- DbMetaDataCollectionNames.cs
- TraceUtility.cs
- List.cs
- Font.cs
- ADMembershipUser.cs
- TypedRowGenerator.cs
- ListMarkerSourceInfo.cs
- SiteMapSection.cs
- CatalogZoneBase.cs
- DataGridViewTopRowAccessibleObject.cs
- RequiredFieldValidator.cs
- BuildProviderAppliesToAttribute.cs
- OperationAbortedException.cs
- UserUseLicenseDictionaryLoader.cs
- COM2ExtendedUITypeEditor.cs
- PeerApplicationLaunchInfo.cs
- ConstraintEnumerator.cs
- InstanceKeyView.cs
- WebBrowserNavigatingEventHandler.cs
- KeyNotFoundException.cs
- DataGridViewTopRowAccessibleObject.cs
- FieldAccessException.cs
- EntityContainerEmitter.cs
- WmlLiteralTextAdapter.cs
- StylusButton.cs
- DataFormats.cs
- CompModSwitches.cs
- AliasGenerator.cs
- ReadOnlyObservableCollection.cs
- TextAutomationPeer.cs
- InternalConfigEventArgs.cs
- RTLAwareMessageBox.cs
- SqlCacheDependencyDatabase.cs
- BypassElementCollection.cs
- WmlFormAdapter.cs
- InstanceView.cs
- AutomationElement.cs
- HttpPostProtocolImporter.cs
- SrgsText.cs
- RefreshPropertiesAttribute.cs
- SystemResources.cs
- IDispatchConstantAttribute.cs
- MetadataAssemblyHelper.cs
- DataFieldCollectionEditor.cs
- Geometry3D.cs
- TabControl.cs
- SpStreamWrapper.cs
- SuppressMergeCheckAttribute.cs
- ProcessModelSection.cs
- DataContract.cs
- FlowDocument.cs
- wgx_render.cs
- EncryptedXml.cs
- XPathPatternBuilder.cs
- ShapeTypeface.cs
- JapaneseCalendar.cs
- ConnectionConsumerAttribute.cs
- ToolStripSystemRenderer.cs
- ImportOptions.cs
- AnnotationResourceChangedEventArgs.cs
- NonVisualControlAttribute.cs