Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / TransactionBridge / Microsoft / Transactions / Wsat / Recovery / LogEntrySerialization.cs / 1 / LogEntrySerialization.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
// This file contains the main entry points for the rest of log entry serialization
// and deserialization
using System;
using System.Diagnostics;
using System.IO;
using System.ServiceModel;
using Microsoft.Transactions.Bridge;
using Microsoft.Transactions.Wsat.Messaging;
using Microsoft.Transactions.Wsat.Protocol;
using DiagnosticUtility = Microsoft.Transactions.Bridge.DiagnosticUtility;
namespace Microsoft.Transactions.Wsat.Recovery
{
class LogEntrySerialization
{
ProtocolState state;
ProtocolVersion protocolVersion;
int maxLogEntrySize;
public LogEntrySerialization(ProtocolState state)
{
if(state == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException ("state"));
this.state = state;
this.protocolVersion = state.ProtocolVersion;
this.maxLogEntrySize = this.state.TransactionManager.MaxLogEntrySize;
}
public LogEntrySerialization(int maxLogEntrySize, ProtocolVersion protocolVersion)
{
this.protocolVersion = protocolVersion;
this.maxLogEntrySize = maxLogEntrySize;
}
public byte[] Serialize(CoordinatorEnlistment coordinator)
{
Enlistment enlistment = coordinator.Enlistment;
LogEntry logEntry = new LogEntry(enlistment.RemoteTransactionId,
enlistment.LocalTransactionId,
coordinator.EnlistmentId,
coordinator.CoordinatorProxy.To);
return SerializeLogEntry(logEntry);
}
public byte[] Serialize(ParticipantEnlistment participant)
{
Enlistment enlistment = participant.Enlistment;
LogEntry logEntry = new LogEntry(enlistment.RemoteTransactionId,
enlistment.LocalTransactionId,
participant.EnlistmentId,
participant.ParticipantProxy.To);
return SerializeLogEntry(logEntry);
}
public ParticipantEnlistment DeserializeParticipant(Enlistment enlistment)
{
byte[] buffer = enlistment.GetRecoveryData();
LogEntry logEntry = DeserializeLogEntry(buffer, enlistment.LocalTransactionId);
enlistment.RemoteTransactionId = logEntry.RemoteTransactionId;
return new ParticipantEnlistment(state,
enlistment,
logEntry.LocalEnlistmentId,
logEntry.Endpoint);
}
public CoordinatorEnlistment DeserializeCoordinator(Enlistment enlistment)
{
byte[] buffer = enlistment.GetRecoveryData();
LogEntry logEntry = DeserializeLogEntry(buffer, enlistment.LocalTransactionId);
enlistment.RemoteTransactionId = logEntry.RemoteTransactionId;
return new CoordinatorEnlistment(state,
enlistment,
logEntry.LocalEnlistmentId,
logEntry.Endpoint);
}
//
// Implementation
//
byte[] SerializeLogEntry(LogEntry logEntry)
{
LogEntrySerializer serializer = new WsATv1LogEntrySerializer(logEntry, this.protocolVersion);
byte[] buffer = serializer.Serialize();
if (DebugTrace.Verbose)
{
DebugTrace.Trace(TraceLevel.Verbose, "Serialized {0} byte buffer", buffer.Length);
}
if (buffer.Length > this.maxLogEntrySize)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
new SerializationException(SR.GetString(SR.SerializationLogEntryTooBig, buffer.Length)));
}
return buffer;
}
LogEntry DeserializeLogEntry(byte[] buffer, Guid localTransactionId)
{
if (DebugTrace.Verbose)
{
DebugTrace.Trace(TraceLevel.Verbose, "Deserializing {0} byte buffer", buffer.Length);
}
// Deserialize the header
MemoryStream mem = new MemoryStream(buffer, 0, buffer.Length, false, true);
LogEntry logEntry = DeserializeHeader(mem, localTransactionId);
// Find a deserializer for the extended endpoint information
LogEntryDeserializer deserializer = CreateDeserializer(mem, logEntry);
return deserializer.Deserialize();
}
LogEntry DeserializeHeader(MemoryStream mem, Guid localTransactionId)
{
// Find the right header deserializer
LogEntryHeaderDeserializer headerDeserializer;
LogEntryHeaderVersion headerVersion = (LogEntryHeaderVersion) SerializationUtils.ReadByte(mem);
switch (headerVersion)
{
case LogEntryHeaderVersion.v1:
headerDeserializer = new LogEntryHeaderv1Deserializer(mem, localTransactionId);
break;
default:
// An invalid Enum value on this internal code path indicates
// a product bug and violates assumptions about
// valid values in MSDTC.
DiagnosticUtility.FailFast("Log entry with unsupported major version");
headerDeserializer = null; // Keep the compiler happy
break;
}
// Deserialize the header
return headerDeserializer.DeserializeHeader();
}
LogEntryDeserializer CreateDeserializer(MemoryStream mem, LogEntry logEntry)
{
return new WsATv1LogEntryDeserializer(mem, logEntry, this.protocolVersion);
}
}
}
// 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
- NetMsmqBindingElement.cs
- RouteItem.cs
- FindCriteriaElement.cs
- Application.cs
- SchemaNamespaceManager.cs
- StickyNote.cs
- QilExpression.cs
- SetterBase.cs
- SplitterEvent.cs
- RijndaelManagedTransform.cs
- AuthenticationModuleElementCollection.cs
- DesignTimeData.cs
- WindowVisualStateTracker.cs
- ToolStripControlHost.cs
- TextEffectCollection.cs
- ThreadPool.cs
- SelectionProcessor.cs
- ScriptingWebServicesSectionGroup.cs
- DiagnosticsElement.cs
- Roles.cs
- CroppedBitmap.cs
- MSG.cs
- RoleManagerModule.cs
- XmlSchemaProviderAttribute.cs
- DiscreteKeyFrames.cs
- OutputScope.cs
- ClientBuildManager.cs
- ScrollContentPresenter.cs
- TraceLevelStore.cs
- SQLBoolean.cs
- TextRangeAdaptor.cs
- PropertyMapper.cs
- RequiredAttributeAttribute.cs
- COM2ExtendedBrowsingHandler.cs
- GuidTagList.cs
- odbcmetadatacolumnnames.cs
- PersistNameAttribute.cs
- BindingManagerDataErrorEventArgs.cs
- DataColumnChangeEvent.cs
- MenuDesigner.cs
- EntityContainerAssociationSet.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- JsonWriterDelegator.cs
- CodeDelegateCreateExpression.cs
- ConfigPathUtility.cs
- BindingsCollection.cs
- RepeatButton.cs
- Activation.cs
- _Events.cs
- ClockController.cs
- sitestring.cs
- AttributeData.cs
- FormattedText.cs
- ProvidePropertyAttribute.cs
- ObjectDataSource.cs
- DataGridViewCheckBoxColumn.cs
- StylusPlugin.cs
- SourceItem.cs
- Cell.cs
- VirtualPathProvider.cs
- CompositeCollectionView.cs
- SystemIcons.cs
- HotSpotCollection.cs
- SecurityUniqueId.cs
- DrawingVisualDrawingContext.cs
- COM2Enum.cs
- BitmapEffectGroup.cs
- VectorCollection.cs
- FieldAccessException.cs
- SafeUserTokenHandle.cs
- GeometryDrawing.cs
- CompilerResults.cs
- XmlConvert.cs
- LazyTextWriterCreator.cs
- PathFigureCollection.cs
- SolidBrush.cs
- FlowDocumentPageViewerAutomationPeer.cs
- SearchForVirtualItemEventArgs.cs
- XMLUtil.cs
- WpfGeneratedKnownProperties.cs
- sitestring.cs
- _FtpControlStream.cs
- WorkflowApplicationTerminatedException.cs
- GlobalizationAssembly.cs
- ActivityWithResultWrapper.cs
- TraceHwndHost.cs
- HtmlInputText.cs
- StyleSheetDesigner.cs
- TypeBrowserDialog.cs
- DeflateEmulationStream.cs
- XmlComplianceUtil.cs
- Variable.cs
- SqlUdtInfo.cs
- Rectangle.cs
- TextBoxBaseDesigner.cs
- TemplateControlCodeDomTreeGenerator.cs
- CodeDOMProvider.cs
- PtsContext.cs
- _HeaderInfo.cs
- Metafile.cs