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
- EntityParameterCollection.cs
- CodeDirectionExpression.cs
- Mutex.cs
- Repeater.cs
- RectAnimationUsingKeyFrames.cs
- DataSourceExpression.cs
- VoiceSynthesis.cs
- WebPartHelpVerb.cs
- EncryptedKeyHashIdentifierClause.cs
- SecurityKeyType.cs
- ReachDocumentPageSerializer.cs
- StorageAssociationTypeMapping.cs
- SecurityDocument.cs
- OdbcConnectionFactory.cs
- ClientEndpointLoader.cs
- FacetValues.cs
- HwndProxyElementProvider.cs
- ContainerControl.cs
- XmlUtilWriter.cs
- Point4D.cs
- IndicFontClient.cs
- HtmlTernaryTree.cs
- VarRemapper.cs
- SmiRequestExecutor.cs
- NumberEdit.cs
- PopupRoot.cs
- ParentQuery.cs
- WorkflowServiceAttributesTypeConverter.cs
- Timer.cs
- Vector3D.cs
- LoadRetryHandler.cs
- XmlUtil.cs
- CssTextWriter.cs
- DocumentScope.cs
- DataTemplateKey.cs
- ToolBarTray.cs
- CodeExpressionCollection.cs
- IItemProperties.cs
- Int64Storage.cs
- RegisteredScript.cs
- IteratorDescriptor.cs
- EntityPropertyMappingAttribute.cs
- BamlLocalizableResourceKey.cs
- XhtmlConformanceSection.cs
- ContextStack.cs
- ContentPropertyAttribute.cs
- ResourceBinder.cs
- LinqDataSourceInsertEventArgs.cs
- RegexGroup.cs
- ScriptResourceAttribute.cs
- TreeNodeConverter.cs
- MexTcpBindingCollectionElement.cs
- QuaternionConverter.cs
- ReflectTypeDescriptionProvider.cs
- MissingSatelliteAssemblyException.cs
- SspiNegotiationTokenProviderState.cs
- BindingBase.cs
- TextRangeProviderWrapper.cs
- ForeignKeyConstraint.cs
- SortAction.cs
- _ConnectionGroup.cs
- RegexBoyerMoore.cs
- Region.cs
- panel.cs
- IIS7WorkerRequest.cs
- FlowSwitchLink.cs
- InnerItemCollectionView.cs
- SendMailErrorEventArgs.cs
- ConfigurationConverterBase.cs
- SystemMulticastIPAddressInformation.cs
- Stackframe.cs
- CatalogPartCollection.cs
- ContentPosition.cs
- SafeNativeMethods.cs
- Bitmap.cs
- TableParaClient.cs
- TextElement.cs
- XmlLoader.cs
- PersonalizablePropertyEntry.cs
- HexParser.cs
- XmlSchemaAnnotation.cs
- SqlDataAdapter.cs
- ComboBox.cs
- WebPartEditVerb.cs
- KeyboardInputProviderAcquireFocusEventArgs.cs
- documentsequencetextview.cs
- FileLevelControlBuilderAttribute.cs
- SystemColors.cs
- TextRangeSerialization.cs
- DependencyPropertyKey.cs
- WinFormsComponentEditor.cs
- ControlDesigner.cs
- DynamicMethod.cs
- FeatureSupport.cs
- PointCollectionValueSerializer.cs
- Base64Encoder.cs
- MachineSettingsSection.cs
- ResourceDictionaryCollection.cs
- QilScopedVisitor.cs
- QilPatternVisitor.cs