Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / MS / Internal / Ink / InkSerializedFormat / GuidTagList.cs / 1 / GuidTagList.cs
using System;
using System.Collections;
using System.IO;
using System.Windows.Ink;
using MS.Internal.IO.Packaging;
namespace MS.Internal.Ink.InkSerializedFormat
{
///
/// Summary description for GuidTagList.
///
internal class GuidList
{
private System.Collections.Generic.List _CustomGuids = new System.Collections.Generic.List();
public GuidList()
{
}
///
/// Adds a guid to the list of Custom Guids if it is not a known guid and is already not
/// in the list of Custom Guids
///
///
///
public bool Add(Guid guid)
{
// If the guid is not found in the known guids list nor in the custom guid list,
// add that to the custom guid list
if (0 == FindTag(guid, true))
{
_CustomGuids.Add(guid);
return true;
}
else
return false;
}
///
/// Finds the tag for a Guid based on the list of Known Guids
///
///
///
public static KnownTagCache.KnownTagIndex FindKnownTag(Guid guid)
{
// Find out if the guid is in the known guid table
for (byte iIndex = 0; iIndex < KnownIdCache.OriginalISFIdTable.Length; ++iIndex)
if (guid == KnownIdCache.OriginalISFIdTable[iIndex])
return KnownIdCache.KnownGuidBaseIndex + iIndex;
// Couldnt find in the known list
return 0;
}
///
/// Finds the tag for a guid based on the list of Custom Guids
///
///
///
KnownTagCache.KnownTagIndex FindCustomTag(Guid guid)
{
int i;
for (i = 0; i < _CustomGuids.Count; i++)
{
if (guid.Equals(_CustomGuids[i]))
return (KnownTagCache.KnownTagIndex)(KnownIdCache.CustomGuidBaseIndex + i);
}
return KnownTagCache.KnownTagIndex.Unknown;
}
///
/// Finds a tag corresponding to a guids
///
///
///
///
public KnownTagCache.KnownTagIndex FindTag(Guid guid, bool bFindInKnownListFirst)
{
KnownTagCache.KnownTagIndex tag = KnownTagCache.KnownTagIndex.Unknown;
if (bFindInKnownListFirst)
{
tag = FindKnownTag(guid);
if (KnownTagCache.KnownTagIndex.Unknown == tag)
tag = FindCustomTag(guid);
}
else
{
tag = FindCustomTag(guid);
if (KnownTagCache.KnownTagIndex.Unknown == tag)
tag = FindKnownTag(guid);
}
return tag;
}
///
/// Finds a known guid based on a Tag
///
///
///
static Guid FindKnownGuid(KnownTagCache.KnownTagIndex tag)
{
if (tag < KnownIdCache.KnownGuidBaseIndex)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Tag is outside of the known guid tag range"));
}
// Get the index in the OriginalISFIdTable array first
uint nIndex = (uint)(tag - KnownIdCache.KnownGuidBaseIndex);
// If invalid, return Guid.Empty
if (KnownIdCache.OriginalISFIdTable.Length <= nIndex)
return Guid.Empty;
// Otherwise, return the guid
return KnownIdCache.OriginalISFIdTable[nIndex];
}
///
/// Finds a Custom Guid based on a Tag
///
///
///
Guid FindCustomGuid(KnownTagCache.KnownTagIndex tag)
{
if ((int)tag < (int)KnownIdCache.CustomGuidBaseIndex)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Tag is outside of the known guid tag range"));
}
// Get the index in the OriginalISFIdTable array first
int nIndex = (int)(tag - KnownIdCache.CustomGuidBaseIndex);
// If invalid, return Guid.Empty
if ((0 > nIndex) || (_CustomGuids.Count <= nIndex))
return Guid.Empty;
// Otherwise, return the guid
return (Guid)_CustomGuids[(int)nIndex];
}
///
/// Finds a guid based on Tag
///
///
///
public Guid FindGuid(KnownTagCache.KnownTagIndex tag)
{
if (tag < (KnownTagCache.KnownTagIndex)KnownIdCache.CustomGuidBaseIndex)
{
Guid guid = FindKnownGuid(tag);
if (Guid.Empty != guid)
return guid;
return FindCustomGuid(tag);
}
else
{
Guid guid = FindCustomGuid(tag);
if (Guid.Empty != guid)
return guid;
return FindKnownGuid(tag);
}
}
///
/// Returns the expected size of data if it is a known guid
///
///
///
public static uint GetDataSizeIfKnownGuid(Guid guid)
{
for (uint i = 0; i < KnownIdCache.OriginalISFIdTable.Length; ++i)
{
if (guid == KnownIdCache.OriginalISFIdTable[i])
{
return KnownIdCache.OriginalISFIdPersistenceSize[i];
}
}
return 0;
}
///
/// Serializes the GuidList in the memory stream and returns the size
///
/// If null, calculates the size only
///
public uint Save(Stream stream)
{
// calculate the number of custom guids to persist
// custom guids are those which are not reserved in ISF via 'tags'
uint ul = (uint)(_CustomGuids.Count * Native.SizeOfGuid);
// if there are no custom guids, then the guid list can be persisted
// without any cost ('tags' are freely storeable)
if (ul == 0)
{
return 0;
}
// if only the size was requested, return it
if (null == stream)
{
return (uint)(ul + SerializationHelper.VarSize(ul) + SerializationHelper.VarSize((uint)KnownTagCache.KnownTagIndex.GuidTable));
}
// encode the guid table tag in the output stream
uint cbWrote = SerializationHelper.Encode(stream, (uint)KnownTagCache.KnownTagIndex.GuidTable);
// encode the size of the guid table
cbWrote += SerializationHelper.Encode(stream, ul);
// encode each guid in the table
for (int i = 0; i < _CustomGuids.Count; i++)
{
Guid guid = (Guid)_CustomGuids[i];
stream.Write(guid.ToByteArray(), 0, (int)Native.SizeOfGuid);
}
cbWrote += ul;
return cbWrote;
}
///
/// Deserializes the GuidList from the memory stream
///
///
///
///
public uint Load(Stream strm, uint size)
{
uint cbsize = 0;
_CustomGuids.Clear();
uint count = size / Native.SizeOfGuid;
byte[] guids = new byte[Native.SizeOfGuid];
for (uint i = 0; i < count; i++)
{
// NTRAID:WINDOWSOS#1622775-2006/04/26-WAYNEZEN,
// Stream.Read could read less number of bytes than the request. We call ReliableRead that
// reads the bytes in a loop until all requested bytes are received or reach the end of the stream.
uint bytesRead = StrokeCollectionSerializer.ReliableRead(strm, guids, Native.SizeOfGuid);
cbsize += bytesRead;
if ( bytesRead == Native.SizeOfGuid )
{
_CustomGuids.Add(new Guid(guids));
}
else
{
// If Stream.Read cannot return the expected number of bytes, we should break here.
// The caller - StrokeCollectionSerializer.DecodeRawISF will check our return value.
// An exception might be thrown if reading is failed.
break;
}
}
return cbsize;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections;
using System.IO;
using System.Windows.Ink;
using MS.Internal.IO.Packaging;
namespace MS.Internal.Ink.InkSerializedFormat
{
///
/// Summary description for GuidTagList.
///
internal class GuidList
{
private System.Collections.Generic.List _CustomGuids = new System.Collections.Generic.List();
public GuidList()
{
}
///
/// Adds a guid to the list of Custom Guids if it is not a known guid and is already not
/// in the list of Custom Guids
///
///
///
public bool Add(Guid guid)
{
// If the guid is not found in the known guids list nor in the custom guid list,
// add that to the custom guid list
if (0 == FindTag(guid, true))
{
_CustomGuids.Add(guid);
return true;
}
else
return false;
}
///
/// Finds the tag for a Guid based on the list of Known Guids
///
///
///
public static KnownTagCache.KnownTagIndex FindKnownTag(Guid guid)
{
// Find out if the guid is in the known guid table
for (byte iIndex = 0; iIndex < KnownIdCache.OriginalISFIdTable.Length; ++iIndex)
if (guid == KnownIdCache.OriginalISFIdTable[iIndex])
return KnownIdCache.KnownGuidBaseIndex + iIndex;
// Couldnt find in the known list
return 0;
}
///
/// Finds the tag for a guid based on the list of Custom Guids
///
///
///
KnownTagCache.KnownTagIndex FindCustomTag(Guid guid)
{
int i;
for (i = 0; i < _CustomGuids.Count; i++)
{
if (guid.Equals(_CustomGuids[i]))
return (KnownTagCache.KnownTagIndex)(KnownIdCache.CustomGuidBaseIndex + i);
}
return KnownTagCache.KnownTagIndex.Unknown;
}
///
/// Finds a tag corresponding to a guids
///
///
///
///
public KnownTagCache.KnownTagIndex FindTag(Guid guid, bool bFindInKnownListFirst)
{
KnownTagCache.KnownTagIndex tag = KnownTagCache.KnownTagIndex.Unknown;
if (bFindInKnownListFirst)
{
tag = FindKnownTag(guid);
if (KnownTagCache.KnownTagIndex.Unknown == tag)
tag = FindCustomTag(guid);
}
else
{
tag = FindCustomTag(guid);
if (KnownTagCache.KnownTagIndex.Unknown == tag)
tag = FindKnownTag(guid);
}
return tag;
}
///
/// Finds a known guid based on a Tag
///
///
///
static Guid FindKnownGuid(KnownTagCache.KnownTagIndex tag)
{
if (tag < KnownIdCache.KnownGuidBaseIndex)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Tag is outside of the known guid tag range"));
}
// Get the index in the OriginalISFIdTable array first
uint nIndex = (uint)(tag - KnownIdCache.KnownGuidBaseIndex);
// If invalid, return Guid.Empty
if (KnownIdCache.OriginalISFIdTable.Length <= nIndex)
return Guid.Empty;
// Otherwise, return the guid
return KnownIdCache.OriginalISFIdTable[nIndex];
}
///
/// Finds a Custom Guid based on a Tag
///
///
///
Guid FindCustomGuid(KnownTagCache.KnownTagIndex tag)
{
if ((int)tag < (int)KnownIdCache.CustomGuidBaseIndex)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Tag is outside of the known guid tag range"));
}
// Get the index in the OriginalISFIdTable array first
int nIndex = (int)(tag - KnownIdCache.CustomGuidBaseIndex);
// If invalid, return Guid.Empty
if ((0 > nIndex) || (_CustomGuids.Count <= nIndex))
return Guid.Empty;
// Otherwise, return the guid
return (Guid)_CustomGuids[(int)nIndex];
}
///
/// Finds a guid based on Tag
///
///
///
public Guid FindGuid(KnownTagCache.KnownTagIndex tag)
{
if (tag < (KnownTagCache.KnownTagIndex)KnownIdCache.CustomGuidBaseIndex)
{
Guid guid = FindKnownGuid(tag);
if (Guid.Empty != guid)
return guid;
return FindCustomGuid(tag);
}
else
{
Guid guid = FindCustomGuid(tag);
if (Guid.Empty != guid)
return guid;
return FindKnownGuid(tag);
}
}
///
/// Returns the expected size of data if it is a known guid
///
///
///
public static uint GetDataSizeIfKnownGuid(Guid guid)
{
for (uint i = 0; i < KnownIdCache.OriginalISFIdTable.Length; ++i)
{
if (guid == KnownIdCache.OriginalISFIdTable[i])
{
return KnownIdCache.OriginalISFIdPersistenceSize[i];
}
}
return 0;
}
///
/// Serializes the GuidList in the memory stream and returns the size
///
/// If null, calculates the size only
///
public uint Save(Stream stream)
{
// calculate the number of custom guids to persist
// custom guids are those which are not reserved in ISF via 'tags'
uint ul = (uint)(_CustomGuids.Count * Native.SizeOfGuid);
// if there are no custom guids, then the guid list can be persisted
// without any cost ('tags' are freely storeable)
if (ul == 0)
{
return 0;
}
// if only the size was requested, return it
if (null == stream)
{
return (uint)(ul + SerializationHelper.VarSize(ul) + SerializationHelper.VarSize((uint)KnownTagCache.KnownTagIndex.GuidTable));
}
// encode the guid table tag in the output stream
uint cbWrote = SerializationHelper.Encode(stream, (uint)KnownTagCache.KnownTagIndex.GuidTable);
// encode the size of the guid table
cbWrote += SerializationHelper.Encode(stream, ul);
// encode each guid in the table
for (int i = 0; i < _CustomGuids.Count; i++)
{
Guid guid = (Guid)_CustomGuids[i];
stream.Write(guid.ToByteArray(), 0, (int)Native.SizeOfGuid);
}
cbWrote += ul;
return cbWrote;
}
///
/// Deserializes the GuidList from the memory stream
///
///
///
///
public uint Load(Stream strm, uint size)
{
uint cbsize = 0;
_CustomGuids.Clear();
uint count = size / Native.SizeOfGuid;
byte[] guids = new byte[Native.SizeOfGuid];
for (uint i = 0; i < count; i++)
{
// NTRAID:WINDOWSOS#1622775-2006/04/26-WAYNEZEN,
// Stream.Read could read less number of bytes than the request. We call ReliableRead that
// reads the bytes in a loop until all requested bytes are received or reach the end of the stream.
uint bytesRead = StrokeCollectionSerializer.ReliableRead(strm, guids, Native.SizeOfGuid);
cbsize += bytesRead;
if ( bytesRead == Native.SizeOfGuid )
{
_CustomGuids.Add(new Guid(guids));
}
else
{
// If Stream.Read cannot return the expected number of bytes, we should break here.
// The caller - StrokeCollectionSerializer.DecodeRawISF will check our return value.
// An exception might be thrown if reading is failed.
break;
}
}
return cbsize;
}
}
}
// 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
- LogicalTreeHelper.cs
- AnnotationMap.cs
- AccessDataSourceView.cs
- CertificateManager.cs
- WebDescriptionAttribute.cs
- ClientUtils.cs
- controlskin.cs
- WebBrowserBase.cs
- FullTrustAssembly.cs
- PtsPage.cs
- XmlCustomFormatter.cs
- Model3D.cs
- SessionParameter.cs
- IxmlLineInfo.cs
- CommunicationObjectFaultedException.cs
- EventHandlerList.cs
- BufferedConnection.cs
- OleDbDataAdapter.cs
- TransformConverter.cs
- ViewManager.cs
- CustomAttributeSerializer.cs
- VisualTreeUtils.cs
- PublishLicense.cs
- DrawingGroup.cs
- CodeMethodInvokeExpression.cs
- FixedFindEngine.cs
- InlinedAggregationOperator.cs
- BooleanSwitch.cs
- ButtonPopupAdapter.cs
- DependencyObjectType.cs
- EpmTargetPathSegment.cs
- RoutedCommand.cs
- SerializationHelper.cs
- ErrorFormatter.cs
- MemberJoinTreeNode.cs
- FirstQueryOperator.cs
- ReadWriteObjectLock.cs
- SingleAnimation.cs
- ErrorFormatterPage.cs
- DataGridTextBox.cs
- XmlReaderSettings.cs
- RewritingSimplifier.cs
- UpDownEvent.cs
- ComAdminWrapper.cs
- SectionUpdates.cs
- ParserStreamGeometryContext.cs
- TimelineGroup.cs
- XmlQueryContext.cs
- ThreadSafeList.cs
- DataTableClearEvent.cs
- oledbmetadatacollectionnames.cs
- KeyboardNavigation.cs
- Polyline.cs
- WeakEventTable.cs
- ZoneLinkButton.cs
- TypeCodeDomSerializer.cs
- CompoundFileDeflateTransform.cs
- SqlError.cs
- IsolationInterop.cs
- SafeNativeMethodsOther.cs
- CalendarDay.cs
- NumberFormatInfo.cs
- ObjectView.cs
- NameScope.cs
- XPathExpr.cs
- BaseDataBoundControl.cs
- CopyOnWriteList.cs
- CapabilitiesState.cs
- EntityViewGenerator.cs
- __Error.cs
- NativeMethods.cs
- DesignerForm.cs
- MetadataPropertyAttribute.cs
- WorkflowQueuingService.cs
- SemaphoreFullException.cs
- TablePatternIdentifiers.cs
- MessageFormatterConverter.cs
- StaticFileHandler.cs
- ConfigurationManagerHelperFactory.cs
- TransactionInterop.cs
- NamedPipeTransportSecurityElement.cs
- GroupBox.cs
- Tag.cs
- PackageDigitalSignatureManager.cs
- DelegateOutArgument.cs
- FixedSOMSemanticBox.cs
- ParsedRoute.cs
- SamlSerializer.cs
- CompositionAdorner.cs
- MetadataUtil.cs
- HeaderedItemsControl.cs
- CapabilitiesPattern.cs
- ApplicationHost.cs
- TextElementCollectionHelper.cs
- UnitySerializationHolder.cs
- ObsoleteAttribute.cs
- CorrelationScope.cs
- diagnosticsswitches.cs
- QuotedPrintableStream.cs
- CredentialManagerDialog.cs