Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Transactions / WhereaboutsReader.cs / 1 / WhereaboutsReader.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Transactions { using System; using System.IO; using System.Net; using System.Text; using Microsoft.Transactions.Wsat.Protocol; using Microsoft.Transactions.Wsat.Recovery; class WhereaboutsReader { string hostName; ProtocolInformationReader protocolInfo; // Whereabouts internals static Guid GuidWhereaboutsInfo = new Guid("{2adb4462-bd41-11d0-b12e-00c04fc2f3ef}"); const long STmToTmProtocolSize = 4 + 4; enum TmProtocol { TmProtocolNone = 0, TmProtocolTip = 1, TmProtocolMsdtcV1 = 2, TmProtocolMsdtcV2 = 3, // unicode host names in nameobject blobs etc TmProtocolExtended = 4 // other stuff (e.g., WS-AT) } public WhereaboutsReader(byte[] whereabouts) { MemoryStream mem = new MemoryStream(whereabouts, 0, whereabouts.Length, false, true); // Enable calls to GetBuffer() DeserializeWhereabouts(mem); } public string HostName { get { return this.hostName; } } public ProtocolInformationReader ProtocolInformation { get { return this.protocolInfo; } } void DeserializeWhereabouts(MemoryStream mem) { // guidSignature Guid signature = SerializationUtils.ReadGuid(mem); if (signature != GuidWhereaboutsInfo) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SerializationException(SR.GetString(SR.WhereaboutsSignatureMissing))); } // cTmToTmProtocols uint cTmToTmProtocols = SerializationUtils.ReadUInt(mem); // Make sure that cTmToTmProtocols is at least plausible if (cTmToTmProtocols * STmToTmProtocolSize > mem.Length - mem.Position) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SerializationException(SR.GetString(SR.WhereaboutsImplausibleProtocolCount))); } // Loop through each protocol for (uint i = 0; i < cTmToTmProtocols; i++) { DeserializeWhereaboutsProtocol(mem); } // Require a host name if (string.IsNullOrEmpty(this.hostName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SerializationException(SR.GetString(SR.WhereaboutsNoHostName))); } } void DeserializeWhereaboutsProtocol(MemoryStream mem) { // tmprotDescribed TmProtocol tmprotDescribed = (TmProtocol)SerializationUtils.ReadInt(mem); // cbTmProtocolData uint cbTmProtocolData = SerializationUtils.ReadUInt(mem); switch (tmprotDescribed) { case TmProtocol.TmProtocolMsdtcV2: ReadMsdtcV2Protocol(mem, cbTmProtocolData); break; case TmProtocol.TmProtocolExtended: ReadExtendedProtocol(mem, cbTmProtocolData); break; default: // We don't care about this protocol SerializationUtils.IncrementPosition(mem, cbTmProtocolData); break; } // Align the cursor to a 4-byte boundary SerializationUtils.AlignPosition(mem, 4); } void ReadMsdtcV2Protocol(MemoryStream mem, uint cbTmProtocolData) { const int MaxComputerName = 15; // // The host name is encoded in unicode format // It is followed by a null-terminating unicode character, // plus some padding to align on 4 // // Reject host names of disproportionate size if (cbTmProtocolData > (MaxComputerName + 1) * 2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SerializationException(SR.GetString(SR.WhereaboutsImplausibleHostNameByteCount))); } byte[] chars = SerializationUtils.ReadBytes(mem, (int)cbTmProtocolData); // Count the bytes until the first null terminating character int cbString = 0; while (cbString < cbTmProtocolData - 1 && (chars[cbString] != 0 || chars[cbString + 1] != 0)) { cbString += 2; } if (cbString == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SerializationException(SR.GetString(SR.WhereaboutsInvalidHostName))); } try { this.hostName = Encoding.Unicode.GetString(chars, 0, cbString); } catch (ArgumentException e) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new SerializationException(SR.GetString(SR.WhereaboutsInvalidHostName), e)); } } void ReadExtendedProtocol(MemoryStream mem, uint cbTmProtocolData) { // Read the WSAT1.0 protoocol identifier Guid guid = SerializationUtils.ReadGuid(mem); if ( guid == PluggableProtocol10.ProtocolGuid || guid == PluggableProtocol11.ProtocolGuid) { // This is the WS-AT extended whereabouts blob this.protocolInfo = new ProtocolInformationReader(mem); } else { // Some other gateway protocol... Skip the rest of the data SerializationUtils.IncrementPosition(mem, cbTmProtocolData - 16); } } } } // 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
- ComponentChangedEvent.cs
- SegmentInfo.cs
- SecurityContextKeyIdentifierClause.cs
- WebPartCloseVerb.cs
- ProxyFragment.cs
- KeyGestureValueSerializer.cs
- FlowDocument.cs
- HttpBindingExtension.cs
- InitializerFacet.cs
- Enum.cs
- LineBreak.cs
- DataGridCommandEventArgs.cs
- ResourcePermissionBaseEntry.cs
- _UriSyntax.cs
- ToolboxBitmapAttribute.cs
- UnknownMessageReceivedEventArgs.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- PasswordBox.cs
- ContextBase.cs
- FieldAccessException.cs
- C14NUtil.cs
- FtpWebResponse.cs
- WindowsListViewGroupHelper.cs
- AnnotationHighlightLayer.cs
- XmlNodeChangedEventManager.cs
- StringWriter.cs
- HTMLTextWriter.cs
- PeerApplicationLaunchInfo.cs
- WebServiceFaultDesigner.cs
- InstanceOwnerException.cs
- EncodingStreamWrapper.cs
- Compilation.cs
- ExpressionConverter.cs
- Int32Rect.cs
- ArrayElementGridEntry.cs
- SymDocumentType.cs
- TraceUtility.cs
- _Win32.cs
- SocketAddress.cs
- DoubleLink.cs
- MatrixStack.cs
- COM2PropertyDescriptor.cs
- TransformConverter.cs
- UrlPropertyAttribute.cs
- CodeAttachEventStatement.cs
- XmlCharacterData.cs
- Opcode.cs
- ObjectHandle.cs
- SqlRowUpdatingEvent.cs
- PropertyStore.cs
- RuleSettingsCollection.cs
- TextViewElement.cs
- RestrictedTransactionalPackage.cs
- MappingSource.cs
- Point3DCollection.cs
- Part.cs
- PropertiesTab.cs
- ContentPresenter.cs
- WebBrowserSiteBase.cs
- ComponentCollection.cs
- KeyTimeConverter.cs
- XmlArrayItemAttributes.cs
- AssemblyAssociatedContentFileAttribute.cs
- MSHTMLHost.cs
- AttachedPropertyBrowsableAttribute.cs
- RegexTypeEditor.cs
- RepeaterCommandEventArgs.cs
- Transform3DCollection.cs
- HwndHostAutomationPeer.cs
- ScriptBehaviorDescriptor.cs
- SecurityTokenSpecification.cs
- EndCreateSecurityTokenRequest.cs
- Executor.cs
- LayoutEngine.cs
- BamlStream.cs
- BinHexEncoder.cs
- TypedElement.cs
- TrackingDataItem.cs
- WebPartPersonalization.cs
- ThicknessAnimationUsingKeyFrames.cs
- ScriptResourceAttribute.cs
- MeasureItemEvent.cs
- SelectionPattern.cs
- ToolboxItemAttribute.cs
- BitmapSizeOptions.cs
- SpStreamWrapper.cs
- Graph.cs
- sortedlist.cs
- StringOutput.cs
- Membership.cs
- PersonalizationDictionary.cs
- TypeSystemProvider.cs
- PageAdapter.cs
- x509store.cs
- TableLayoutColumnStyleCollection.cs
- TransformerInfo.cs
- BinaryWriter.cs
- WindowsPrincipal.cs
- WmlControlAdapter.cs
- EpmCustomContentWriterNodeData.cs