Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / CheckStoreFileValidityRequest.cs / 1 / CheckStoreFileValidityRequest.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; // // Opens a store file and checks the first element to make sure that this is // a valid infocard store file. // class CheckStoreFileValidityRequest :UIAgentRequest { string m_filename; bool m_valid = true; public CheckStoreFileValidityRequest( IntPtr rpcHandle, Stream inArgs, Stream outArgs, ClientUIRequest parent ) : base( rpcHandle, inArgs, outArgs, parent ) { } protected override void OnInitializeAsSystem() { base.OnInitializeAsSystem(); } // // Summary // Read the marshalled arguments // protected override void OnMarshalInArgs() { BinaryReader reader = new InfoCardBinaryReader( InArgs, System.Text.Encoding.Unicode ); m_filename = Utility.DeserializeString( reader ); } // // Summary // Read the first element of the file // protected override void OnProcess() { try { try { using ( FileStream file = File.OpenRead( m_filename ) ) { // // Use a stream that validates the xml against internally stored schemas. // XmlReaderSettings settings = InfoCardSchemas.CreateDefaultReaderSettings(); settings.IgnoreWhitespace = false; using( XmlReader reader = InfoCardSchemas.CreateReader( file, settings ) ) { IDT.TraceDebug( " Roaming: Check if the store file is valid" ); if( !reader.IsStartElement( XmlNames.WSIdentity.EncryptedStoreElement, XmlNames.WSIdentity.Namespace ) ) { m_valid = false; } } } } 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 ) { // // Translate ImportException to the boolean value indicating an invalid file // m_valid = false; } } // // Summary // Write the boolean value to be returned // protected override void OnMarshalOutArgs() { Stream stream = OutArgs; BinaryWriter writer = new BinaryWriter( stream ); writer.Write( m_valid ); } } } // 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
- MaskedTextProvider.cs
- DataGridItemCollection.cs
- InternalConfigConfigurationFactory.cs
- MemoryMappedFileSecurity.cs
- SHA1.cs
- ComboBoxDesigner.cs
- StringUtil.cs
- CultureTableRecord.cs
- DrawingAttributeSerializer.cs
- PointAnimation.cs
- ConfigurationPropertyCollection.cs
- ModuleConfigurationInfo.cs
- WindowsPrincipal.cs
- DeadCharTextComposition.cs
- BindingGraph.cs
- SqlDataRecord.cs
- OleDbError.cs
- Span.cs
- HttpConfigurationSystem.cs
- ChannelCacheDefaults.cs
- CommandID.cs
- TypeForwardedToAttribute.cs
- StickyNote.cs
- QuaternionKeyFrameCollection.cs
- PropertiesTab.cs
- UInt32Storage.cs
- FixedSOMElement.cs
- SqlCommand.cs
- ContainerUIElement3D.cs
- ListViewAutomationPeer.cs
- ControlPaint.cs
- FunctionUpdateCommand.cs
- XmlSchemaValidationException.cs
- XmlNamespaceMappingCollection.cs
- StructuredType.cs
- DataBoundControlAdapter.cs
- ParameterElement.cs
- MsmqInputChannelBase.cs
- BindToObject.cs
- QilGenerator.cs
- UpdateTracker.cs
- HandleCollector.cs
- TableStyle.cs
- TextDecorationCollection.cs
- FixedSOMPageConstructor.cs
- XmlSiteMapProvider.cs
- SqlClientWrapperSmiStream.cs
- KeyFrames.cs
- BaseTemplateCodeDomTreeGenerator.cs
- SaveLedgerEntryRequest.cs
- BinHexEncoder.cs
- BamlMapTable.cs
- FormCollection.cs
- HttpRawResponse.cs
- StackBuilderSink.cs
- NativeMethodsOther.cs
- SafeBitVector32.cs
- DesignBindingEditor.cs
- CompoundFileDeflateTransform.cs
- RegisteredHiddenField.cs
- DesignTimeTemplateParser.cs
- DataGridSortCommandEventArgs.cs
- PartialClassGenerationTaskInternal.cs
- XmlSerializer.cs
- QueryRewriter.cs
- StandardToolWindows.cs
- UseManagedPresentationBindingElementImporter.cs
- ExceptionHelpers.cs
- HTTPNotFoundHandler.cs
- HttpCachePolicy.cs
- StreamGeometry.cs
- TimeoutException.cs
- ConfigXmlSignificantWhitespace.cs
- SlotInfo.cs
- QueryableDataSource.cs
- RelationshipConstraintValidator.cs
- AbstractDataSvcMapFileLoader.cs
- GuidConverter.cs
- ContentFileHelper.cs
- TableChangeProcessor.cs
- DataGridViewAutoSizeModeEventArgs.cs
- Size3DValueSerializer.cs
- ProjectionPathSegment.cs
- ColorAnimationBase.cs
- OuterGlowBitmapEffect.cs
- DeflateStream.cs
- PolyBezierSegmentFigureLogic.cs
- TransactionOptions.cs
- ColumnWidthChangingEvent.cs
- Wizard.cs
- CodePageUtils.cs
- TreeViewEvent.cs
- FrameworkContentElementAutomationPeer.cs
- CompressEmulationStream.cs
- TargetInvocationException.cs
- AuthenticatingEventArgs.cs
- WorkflowInstanceQuery.cs
- CodeTypeDeclaration.cs
- TransactionContextManager.cs
- TreeNodeCollectionEditorDialog.cs