Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Recognition / SrgsGrammar / SrgsToken.cs / 1 / SrgsToken.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description:
//
// History:
// 5/1/2004 jeanfp Created from the Kurosawa Code
//---------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Speech.Internal;
using System.Speech.Internal.SrgsParser;
using System.Text;
using System.Xml;
namespace System.Speech.Recognition.SrgsGrammar
{
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token"]/*' />
// Note that currently if multiple words are stored in a Token they are treated internally
// and in the result as multiple tokens.
[Serializable]
[DebuggerDisplay ("{DebuggerDisplayString ()}")]
public class SrgsToken : SrgsElement, IToken
{
//*******************************************************************
//
// Constructors
//
//*******************************************************************
#region Constructors
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token.Token2"]/*' />
public SrgsToken (string text)
{
Helpers.ThrowIfEmptyOrNull (text, "text");
Text = text;
}
#endregion
//********************************************************************
//
// Public Properties
//
//*******************************************************************
#region public Properties
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token.Text"]/*' />
public string Text
{
get
{
return _text;
}
set
{
Helpers.ThrowIfEmptyOrNull (value, "value");
// remove all spaces if any
string text = value.Trim (Helpers._achTrimChars);
if (string.IsNullOrEmpty (text) || text.IndexOf ('\"') >= 0)
{
throw new ArgumentException (SR.Get (SRID.InvalidTokenString), "value");
}
_text = text;
}
}
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token.Pronunciation"]/*' />
public string Pronunciation
{
get
{
return _pronunciation;
}
set
{
Helpers.ThrowIfEmptyOrNull (value, "value");
_pronunciation = value;
}
}
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token.Display"]/*' />
public string Display
{
get
{
return _display;
}
set
{
Helpers.ThrowIfEmptyOrNull (value, "value");
_display = value;
}
}
#endregion
//********************************************************************
//
// Internal methods
//
//********************************************************************
#region Internal methods
internal override void WriteSrgs (XmlWriter writer)
{
// Write _text
writer.WriteStartElement ("token");
if (_display != null)
{
writer.WriteAttributeString ("sapi", "display", XmlParser.sapiNamespace, _display);
}
if (_pronunciation != null)
{
writer.WriteAttributeString ("sapi", "pron", XmlParser.sapiNamespace, _pronunciation);
}
// If an empty string is provided, skip the WriteString
// to have the XmlWrite to put rather than
if (_text != null && _text.Length > 0)
{
writer.WriteString (_text);
}
writer.WriteEndElement ();
}
internal override void Validate (SrgsGrammar grammar)
{
if (_pronunciation != null || _display != null)
{
grammar.HasPronunciation = true;
}
// Validate the pronunciation if any
if (_pronunciation != null)
{
for (int iCurPron = 0, iDeliminator = 0; iCurPron < _pronunciation.Length; iCurPron = iDeliminator + 1)
{
// Find semi-colon deliminator and replace with null
iDeliminator = _pronunciation.IndexOf (';', iCurPron);
if (iDeliminator == -1)
{
iDeliminator = _pronunciation.Length;
}
string subPronunciation = _pronunciation.Substring (iCurPron, iDeliminator - iCurPron);
// Convert the pronunciation, will throw if error
switch (grammar.PhoneticAlphabet)
{
case AlphabetType.Sapi:
PhonemeConverter.ConvertPronToId (subPronunciation, grammar.Culture.LCID);
break;
case AlphabetType.Ups:
PhonemeConverter.UpsConverter.ConvertPronToId (subPronunciation);
break;
case AlphabetType.Ipa:
PhonemeConverter.ValidateUpsIds (subPronunciation.ToCharArray ());
break;
}
}
}
base.Validate (grammar);
}
internal override string DebuggerDisplayString ()
{
StringBuilder sb = new StringBuilder ("Token '");
sb.Append (_text);
sb.Append ("'");
if (_pronunciation != null)
{
sb.Append (" Pronunciation '");
sb.Append (_pronunciation);
sb.Append ("'");
}
return sb.ToString ();
}
#endregion
//*******************************************************************
//
// Private Fields
//
//********************************************************************
#region Private Fields
private string _text = string.Empty;
private string _pronunciation;
private string _display;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description:
//
// History:
// 5/1/2004 jeanfp Created from the Kurosawa Code
//---------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Speech.Internal;
using System.Speech.Internal.SrgsParser;
using System.Text;
using System.Xml;
namespace System.Speech.Recognition.SrgsGrammar
{
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token"]/*' />
// Note that currently if multiple words are stored in a Token they are treated internally
// and in the result as multiple tokens.
[Serializable]
[DebuggerDisplay ("{DebuggerDisplayString ()}")]
public class SrgsToken : SrgsElement, IToken
{
//*******************************************************************
//
// Constructors
//
//*******************************************************************
#region Constructors
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token.Token2"]/*' />
public SrgsToken (string text)
{
Helpers.ThrowIfEmptyOrNull (text, "text");
Text = text;
}
#endregion
//********************************************************************
//
// Public Properties
//
//*******************************************************************
#region public Properties
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token.Text"]/*' />
public string Text
{
get
{
return _text;
}
set
{
Helpers.ThrowIfEmptyOrNull (value, "value");
// remove all spaces if any
string text = value.Trim (Helpers._achTrimChars);
if (string.IsNullOrEmpty (text) || text.IndexOf ('\"') >= 0)
{
throw new ArgumentException (SR.Get (SRID.InvalidTokenString), "value");
}
_text = text;
}
}
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token.Pronunciation"]/*' />
public string Pronunciation
{
get
{
return _pronunciation;
}
set
{
Helpers.ThrowIfEmptyOrNull (value, "value");
_pronunciation = value;
}
}
/// TODOC <_include file='doc\Token.uex' path='docs/doc[@for="Token.Display"]/*' />
public string Display
{
get
{
return _display;
}
set
{
Helpers.ThrowIfEmptyOrNull (value, "value");
_display = value;
}
}
#endregion
//********************************************************************
//
// Internal methods
//
//********************************************************************
#region Internal methods
internal override void WriteSrgs (XmlWriter writer)
{
// Write _text
writer.WriteStartElement ("token");
if (_display != null)
{
writer.WriteAttributeString ("sapi", "display", XmlParser.sapiNamespace, _display);
}
if (_pronunciation != null)
{
writer.WriteAttributeString ("sapi", "pron", XmlParser.sapiNamespace, _pronunciation);
}
// If an empty string is provided, skip the WriteString
// to have the XmlWrite to put rather than
if (_text != null && _text.Length > 0)
{
writer.WriteString (_text);
}
writer.WriteEndElement ();
}
internal override void Validate (SrgsGrammar grammar)
{
if (_pronunciation != null || _display != null)
{
grammar.HasPronunciation = true;
}
// Validate the pronunciation if any
if (_pronunciation != null)
{
for (int iCurPron = 0, iDeliminator = 0; iCurPron < _pronunciation.Length; iCurPron = iDeliminator + 1)
{
// Find semi-colon deliminator and replace with null
iDeliminator = _pronunciation.IndexOf (';', iCurPron);
if (iDeliminator == -1)
{
iDeliminator = _pronunciation.Length;
}
string subPronunciation = _pronunciation.Substring (iCurPron, iDeliminator - iCurPron);
// Convert the pronunciation, will throw if error
switch (grammar.PhoneticAlphabet)
{
case AlphabetType.Sapi:
PhonemeConverter.ConvertPronToId (subPronunciation, grammar.Culture.LCID);
break;
case AlphabetType.Ups:
PhonemeConverter.UpsConverter.ConvertPronToId (subPronunciation);
break;
case AlphabetType.Ipa:
PhonemeConverter.ValidateUpsIds (subPronunciation.ToCharArray ());
break;
}
}
}
base.Validate (grammar);
}
internal override string DebuggerDisplayString ()
{
StringBuilder sb = new StringBuilder ("Token '");
sb.Append (_text);
sb.Append ("'");
if (_pronunciation != null)
{
sb.Append (" Pronunciation '");
sb.Append (_pronunciation);
sb.Append ("'");
}
return sb.ToString ();
}
#endregion
//*******************************************************************
//
// Private Fields
//
//********************************************************************
#region Private Fields
private string _text = string.Empty;
private string _pronunciation;
private string _display;
#endregion
}
}
// 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
- Tablet.cs
- WebConfigurationHostFileChange.cs
- HtmlShim.cs
- DataControlFieldTypeEditor.cs
- StrokeNode.cs
- AutomationPropertyInfo.cs
- PageOutputColor.cs
- AdapterSwitches.cs
- ApplicationDirectoryMembershipCondition.cs
- SafeBitVector32.cs
- DesignerOptionService.cs
- ZipIOLocalFileHeader.cs
- GroupBoxAutomationPeer.cs
- LateBoundBitmapDecoder.cs
- PeerNameRecordCollection.cs
- dataobject.cs
- SemanticBasicElement.cs
- ConfigXmlAttribute.cs
- IListConverters.cs
- TdsParserStaticMethods.cs
- SineEase.cs
- HtmlHead.cs
- ViewCellSlot.cs
- ExpressionHelper.cs
- ConfigurationConverterBase.cs
- StorageMappingFragment.cs
- TrustManagerPromptUI.cs
- SoapCodeExporter.cs
- GlobalizationAssembly.cs
- AspProxy.cs
- HostedElements.cs
- RuntimeConfig.cs
- SponsorHelper.cs
- StreamResourceInfo.cs
- WebPartTransformerAttribute.cs
- SortAction.cs
- ServiceDurableInstance.cs
- PrintPreviewControl.cs
- XmlSerializerNamespaces.cs
- RpcCryptoContext.cs
- GridProviderWrapper.cs
- BoundingRectTracker.cs
- ToolStripItemBehavior.cs
- PropertyInformationCollection.cs
- ProfileEventArgs.cs
- XmlLoader.cs
- BufferModesCollection.cs
- StrokeRenderer.cs
- filewebresponse.cs
- categoryentry.cs
- DBDataPermissionAttribute.cs
- PrimaryKeyTypeConverter.cs
- FileUpload.cs
- ImportContext.cs
- BamlVersionHeader.cs
- Win32MouseDevice.cs
- ListDataHelper.cs
- CodeCatchClause.cs
- HotSpotCollection.cs
- HttpCachePolicyElement.cs
- ClientBuildManager.cs
- RTLAwareMessageBox.cs
- DeploymentSectionCache.cs
- MasterPageBuildProvider.cs
- Model3DCollection.cs
- ConfigurationPropertyCollection.cs
- XmlTextReaderImpl.cs
- BoolLiteral.cs
- BlurBitmapEffect.cs
- CriticalFinalizerObject.cs
- EncoderReplacementFallback.cs
- Int32Converter.cs
- SafeFileHandle.cs
- TogglePattern.cs
- Utils.cs
- WebExceptionStatus.cs
- GradientBrush.cs
- DiscoveryRequestHandler.cs
- embossbitmapeffect.cs
- SystemWebExtensionsSectionGroup.cs
- HtmlShim.cs
- HebrewCalendar.cs
- PropertyInfoSet.cs
- VectorAnimationUsingKeyFrames.cs
- StyleBamlTreeBuilder.cs
- DiscriminatorMap.cs
- WebPartEventArgs.cs
- RefType.cs
- OptimalBreakSession.cs
- InlineUIContainer.cs
- LoadGrammarCompletedEventArgs.cs
- ToolStripDropDownMenu.cs
- AsymmetricKeyExchangeDeformatter.cs
- ExtensionElementCollection.cs
- DataPointer.cs
- TraceSection.cs
- LocatorPart.cs
- TextParagraphProperties.cs
- NativeMethods.cs
- VersionedStream.cs