Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / Markup / XamlTreeBuilderBamlRecordWriter.cs / 1 / XamlTreeBuilderBamlRecordWriter.cs
/****************************************************************************\
*
* File: XamlTreeBuilderBamlRecordWriter.cs
*
* Purpose: Class that writes baml records when building a tree directly
* from xaml
*
* History:
* 6/06/01: rogerg Created
* 5/29/03: peterost Ported to wcp
* 11/13/03: peterost split from XamlTreeBuilder.cs
*
* Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
*
\***************************************************************************/
using System;
using System.Xml;
using System.IO;
using System.Windows;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Threading;
using MS.Utility;
namespace System.Windows.Markup
{
///
/// Override class for BamlRecordWriter when building tree Directly from XAML.
/// We do this so in the [....] case we can build the tree directly instead
/// of writing to a BAMLStream. Note that building a tree directly from xaml
/// DOES NOT support defer loaded content
///
internal class XamlTreeBuilderBamlRecordWriter : BamlRecordWriter
{
#region Constructors
internal XamlTreeBuilderBamlRecordWriter(
XamlTreeBuilder treeBuilder,
Stream stream,
ParserContext parserContext,
bool isSerializer )
: base(stream,parserContext,false)
{
_treeBuilder = treeBuilder;
_writerStream = stream as WriterStream;
// If we're in a nested parser, then we need to track it in our
// _customSerializerNestingLevel counter. Otherwise we'll flush
// Baml records to the reader thread too soon in WriteBamlRecord.
if( isSerializer )
{
_customSerializerNestingLevel = 1;
}
Debug.Assert(null != _writerStream,"Stream for Writer is not a WriterStream");
}
#endregion Constructors
#region Overrides
internal override void WriteBamlRecord(
BamlRecord bamlRecord,
int lineNumber,
int linePosition)
{
bool bamlRecordHandled = false;
// Try to load the Baml record. This will work if we're in [....] mode
// (default case), or if we're in async mode and processing the root.
bamlRecordHandled = TreeBuilder.BamlRecordWriterSyncUpdate(bamlRecord,
lineNumber, linePosition);
// If it didn't get handled, write the baml record to the baml stream.
if (!bamlRecordHandled)
{
// Write the record.
base.WriteBamlRecord(bamlRecord, lineNumber, linePosition);
// Nowe we see if we can let the reader see this record. We can't if we're within
// a custom serializer. (This was added so that templates & styles wouldn't get sealed
// before being fully loaded, an alternative would be to use ISupportInitialize.)
// Is this a start record?
BamlElementStartRecord bamlElementStartRecord = bamlRecord as BamlElementStartRecord;
if (bamlElementStartRecord != null)
{
// Yes, it's a start record. If we're not already under a custom serializer,
// but this element has one, then start nesting.
if (_customSerializerNestingLevel == 0
&&
MapTable.HasSerializerForTypeId(bamlElementStartRecord.TypeId))
{
_customSerializerNestingLevel = 1;
}
// Or, if we're already under a custom serializer, increment the nesting level.
else if (_customSerializerNestingLevel > 0)
{
++_customSerializerNestingLevel;
}
}
// This isn't a start record. But if we're under a custom serializer,
// we might need to update the nesting level.
else if (_customSerializerNestingLevel != 0)
{
// If this is an end element record, decrement the nesting level.
BamlElementEndRecord bamlElementEndRecord = bamlRecord as BamlElementEndRecord;
if (bamlElementEndRecord != null)
{
--_customSerializerNestingLevel;
}
}
// If we're not (now) under a custom serializer context, tell the reader
// about all of the records we've written.
if (_customSerializerNestingLevel == 0)
{
WriterStream.UpdateReaderLength(WriterStream.Length );
}
}
}
///
/// sets the number of Records that can be read at a time
/// in async mode. main use is for debugging.
///
/// number of Records we are allowed to read
internal override void SetMaxAsyncRecords(int maxAsyncRecords)
{
TreeBuilder.MaxAsyncRecords = maxAsyncRecords;
}
///
/// Called to determine if it is okay for ParentNodes to be updated
/// since building the tree directly we can't seek back to update
/// the parent nodes so false is always returned.
///
internal override bool UpdateParentNodes
{
get
{
return false;
}
}
// If building a tree directly, just store the strings directly in the BAML record.
// Don't have to precreate the DP object, stream it out and then re-create it as this
// is extra work, so custom serialization is not allowed.
internal override void WriteProperty(XamlPropertyNode xamlPropertyNode)
{
BaseWriteProperty(xamlPropertyNode);
}
#endregion Overrides
#region Properties
///
/// TreeBuilder associated with this class
///
internal XamlTreeBuilder TreeBuilder
{
get { return _treeBuilder; }
}
///
/// Writer stream records are written to.
/// Hold onto this so we can updateThe Reader length to keep the
/// BamlRecords class unaware of the ReaderWriter Stream
///
private WriterStream WriterStream
{
get { return _writerStream; }
}
///
/// When creating a tree directly from Xaml, use the record reader's
/// BamlRecordManager, since its record releasing behavior is modified
/// based on the markup it is reading in
///
internal override BamlRecordManager BamlRecordManager
{
get { return _treeBuilder.RecordReader.BamlRecordManager; }
}
#endregion Properties
#region Data
XamlTreeBuilder _treeBuilder;
WriterStream _writerStream;
int _customSerializerNestingLevel = 0;
#endregion Data
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
/****************************************************************************\
*
* File: XamlTreeBuilderBamlRecordWriter.cs
*
* Purpose: Class that writes baml records when building a tree directly
* from xaml
*
* History:
* 6/06/01: rogerg Created
* 5/29/03: peterost Ported to wcp
* 11/13/03: peterost split from XamlTreeBuilder.cs
*
* Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
*
\***************************************************************************/
using System;
using System.Xml;
using System.IO;
using System.Windows;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Threading;
using MS.Utility;
namespace System.Windows.Markup
{
///
/// Override class for BamlRecordWriter when building tree Directly from XAML.
/// We do this so in the [....] case we can build the tree directly instead
/// of writing to a BAMLStream. Note that building a tree directly from xaml
/// DOES NOT support defer loaded content
///
internal class XamlTreeBuilderBamlRecordWriter : BamlRecordWriter
{
#region Constructors
internal XamlTreeBuilderBamlRecordWriter(
XamlTreeBuilder treeBuilder,
Stream stream,
ParserContext parserContext,
bool isSerializer )
: base(stream,parserContext,false)
{
_treeBuilder = treeBuilder;
_writerStream = stream as WriterStream;
// If we're in a nested parser, then we need to track it in our
// _customSerializerNestingLevel counter. Otherwise we'll flush
// Baml records to the reader thread too soon in WriteBamlRecord.
if( isSerializer )
{
_customSerializerNestingLevel = 1;
}
Debug.Assert(null != _writerStream,"Stream for Writer is not a WriterStream");
}
#endregion Constructors
#region Overrides
internal override void WriteBamlRecord(
BamlRecord bamlRecord,
int lineNumber,
int linePosition)
{
bool bamlRecordHandled = false;
// Try to load the Baml record. This will work if we're in [....] mode
// (default case), or if we're in async mode and processing the root.
bamlRecordHandled = TreeBuilder.BamlRecordWriterSyncUpdate(bamlRecord,
lineNumber, linePosition);
// If it didn't get handled, write the baml record to the baml stream.
if (!bamlRecordHandled)
{
// Write the record.
base.WriteBamlRecord(bamlRecord, lineNumber, linePosition);
// Nowe we see if we can let the reader see this record. We can't if we're within
// a custom serializer. (This was added so that templates & styles wouldn't get sealed
// before being fully loaded, an alternative would be to use ISupportInitialize.)
// Is this a start record?
BamlElementStartRecord bamlElementStartRecord = bamlRecord as BamlElementStartRecord;
if (bamlElementStartRecord != null)
{
// Yes, it's a start record. If we're not already under a custom serializer,
// but this element has one, then start nesting.
if (_customSerializerNestingLevel == 0
&&
MapTable.HasSerializerForTypeId(bamlElementStartRecord.TypeId))
{
_customSerializerNestingLevel = 1;
}
// Or, if we're already under a custom serializer, increment the nesting level.
else if (_customSerializerNestingLevel > 0)
{
++_customSerializerNestingLevel;
}
}
// This isn't a start record. But if we're under a custom serializer,
// we might need to update the nesting level.
else if (_customSerializerNestingLevel != 0)
{
// If this is an end element record, decrement the nesting level.
BamlElementEndRecord bamlElementEndRecord = bamlRecord as BamlElementEndRecord;
if (bamlElementEndRecord != null)
{
--_customSerializerNestingLevel;
}
}
// If we're not (now) under a custom serializer context, tell the reader
// about all of the records we've written.
if (_customSerializerNestingLevel == 0)
{
WriterStream.UpdateReaderLength(WriterStream.Length );
}
}
}
///
/// sets the number of Records that can be read at a time
/// in async mode. main use is for debugging.
///
/// number of Records we are allowed to read
internal override void SetMaxAsyncRecords(int maxAsyncRecords)
{
TreeBuilder.MaxAsyncRecords = maxAsyncRecords;
}
///
/// Called to determine if it is okay for ParentNodes to be updated
/// since building the tree directly we can't seek back to update
/// the parent nodes so false is always returned.
///
internal override bool UpdateParentNodes
{
get
{
return false;
}
}
// If building a tree directly, just store the strings directly in the BAML record.
// Don't have to precreate the DP object, stream it out and then re-create it as this
// is extra work, so custom serialization is not allowed.
internal override void WriteProperty(XamlPropertyNode xamlPropertyNode)
{
BaseWriteProperty(xamlPropertyNode);
}
#endregion Overrides
#region Properties
///
/// TreeBuilder associated with this class
///
internal XamlTreeBuilder TreeBuilder
{
get { return _treeBuilder; }
}
///
/// Writer stream records are written to.
/// Hold onto this so we can updateThe Reader length to keep the
/// BamlRecords class unaware of the ReaderWriter Stream
///
private WriterStream WriterStream
{
get { return _writerStream; }
}
///
/// When creating a tree directly from Xaml, use the record reader's
/// BamlRecordManager, since its record releasing behavior is modified
/// based on the markup it is reading in
///
internal override BamlRecordManager BamlRecordManager
{
get { return _treeBuilder.RecordReader.BamlRecordManager; }
}
#endregion Properties
#region Data
XamlTreeBuilder _treeBuilder;
WriterStream _writerStream;
int _customSerializerNestingLevel = 0;
#endregion Data
}
}
// 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
- HttpClientCertificate.cs
- NavigationExpr.cs
- DataGridViewTopRowAccessibleObject.cs
- WebPartPersonalization.cs
- ScriptReferenceEventArgs.cs
- BufferAllocator.cs
- DataGridViewLinkColumn.cs
- ComboBoxRenderer.cs
- VisualTreeHelper.cs
- XmlAttributeAttribute.cs
- ItemsControl.cs
- BoundingRectTracker.cs
- DataGridViewSelectedRowCollection.cs
- XmlElementAttribute.cs
- StringValueConverter.cs
- RemotingConfigParser.cs
- StylusTouchDevice.cs
- DataSourceSelectArguments.cs
- WebPartMinimizeVerb.cs
- LineServicesCallbacks.cs
- ServiceHttpHandlerFactory.cs
- ThemeDirectoryCompiler.cs
- CodeDelegateCreateExpression.cs
- MetadataFile.cs
- DesigntimeLicenseContextSerializer.cs
- AdapterUtil.cs
- Point3DKeyFrameCollection.cs
- EmptyEnumerator.cs
- VirtualDirectoryMapping.cs
- KeyboardNavigation.cs
- ConnectionOrientedTransportElement.cs
- ClipboardData.cs
- DataGridViewCellParsingEventArgs.cs
- Function.cs
- MessageEnumerator.cs
- ToolBarButton.cs
- DistributedTransactionPermission.cs
- RSAOAEPKeyExchangeFormatter.cs
- QueryStringConverter.cs
- Blend.cs
- CodeCatchClause.cs
- PerfProviderCollection.cs
- MaskDesignerDialog.cs
- SharedPersonalizationStateInfo.cs
- Image.cs
- ContentDisposition.cs
- EvidenceBase.cs
- ComboBoxAutomationPeer.cs
- XmlChildNodes.cs
- XmlCodeExporter.cs
- SettingsPropertyValueCollection.cs
- DurationConverter.cs
- StrokeNodeOperations.cs
- Helper.cs
- EdmToObjectNamespaceMap.cs
- DesignerSerializationOptionsAttribute.cs
- LinqDataSourceDeleteEventArgs.cs
- ConditionBrowserDialog.cs
- OleDbReferenceCollection.cs
- IndexerNameAttribute.cs
- FlowPosition.cs
- RotateTransform.cs
- HtmlImageAdapter.cs
- DiscreteKeyFrames.cs
- VerticalAlignConverter.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- IdSpace.cs
- BindingNavigatorDesigner.cs
- HttpRuntime.cs
- GraphicsPathIterator.cs
- RuntimeArgumentHandle.cs
- SpeakCompletedEventArgs.cs
- RoleManagerEventArgs.cs
- AutomationAttributeInfo.cs
- ConfigurationValue.cs
- CatalogPartChrome.cs
- SafeArrayTypeMismatchException.cs
- DataGridParentRows.cs
- ControlPropertyNameConverter.cs
- EventlogProvider.cs
- WsdlImporterElementCollection.cs
- EventMappingSettings.cs
- SafeFindHandle.cs
- CLSCompliantAttribute.cs
- invalidudtexception.cs
- FixedSOMPageElement.cs
- Timer.cs
- GeometryGroup.cs
- FrameworkReadOnlyPropertyMetadata.cs
- InheritanceAttribute.cs
- ResolveNameEventArgs.cs
- StandardCommands.cs
- ApplicationSecurityInfo.cs
- TokenBasedSetEnumerator.cs
- CapabilitiesPattern.cs
- WindowsSolidBrush.cs
- GridViewCancelEditEventArgs.cs
- PageParser.cs
- TemplateControlBuildProvider.cs
- SHA1.cs