Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Recognition / SrgsGrammar / SrgsRule.cs / 1 / SrgsRule.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description:
//
// History:
// 5/1/2004 jeanfp Created from the Kurosawa Code
//---------------------------------------------------------------------------
using System;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Speech.Internal;
using System.Speech.Internal.SrgsParser;
#pragma warning disable 1634, 1691 // Allows suppression of certain PreSharp messages.
namespace System.Speech.Recognition.SrgsGrammar
{
/// TODOC <_include file='doc\Rule.uex' path='docs/doc[@for="Rule"]/*' />
[Serializable]
[DebuggerDisplay ("Rule={_id.ToString()} Scope={_scope.ToString()}")]
[DebuggerTypeProxy (typeof (SrgsRuleDebugDisplay))]
public class SrgsRule : IRule
{
//*******************************************************************
//
// Constructors
//
//*******************************************************************
#region Constructors
/// TODOC <_include file='doc\Rule.uex' path='docs/doc[@for="Rule.Rule1"]/*' />
private SrgsRule ()
{
_elements = new SrgsElementList ();
}
/// TODOC <_include file='doc\Rule.uex' path='docs/doc[@for="Rule.Rule2"]/*' />
public SrgsRule (string id)
: this ()
{
XmlParser.ValidateRuleId (id);
Id = id;
}
/// TODOC <_include file='doc\Rule.uex' path='docs/doc[@for="Rule.Rule2"]/*' />
public SrgsRule (string id, params SrgsElement [] elements)
: this ()
{
Helpers.ThrowIfNull (elements, "elements");
XmlParser.ValidateRuleId (id);
Id = id;
for (int iElement = 0; iElement < elements.Length; iElement++)
{
if (elements [iElement] == null)
{
throw new ArgumentNullException ("elements", SR.Get (SRID.ParamsEntryNullIllegal));
}
((Collection) _elements).Add (elements [iElement]);
}
}
#endregion
//********************************************************************
//
// Public Methods
//
//*******************************************************************
#region public Method
///
/// TODOC
///
///
public void Add (SrgsElement element)
{
Helpers.ThrowIfNull (element, "element");
Elements.Add (element);
}
#endregion
//********************************************************************
//
// Public Properties
//
//********************************************************************
#region public Properties
/// TODOC <_include file='doc\Rule.uex' path='docs/doc[@for="Rule.Elements"]/*' />
public Collection Elements
{
get
{
return _elements;
}
}
/// TODOC <_include file='doc\Rule.uex' path='docs/doc[@for="Rule.Id"]/*' />
public string Id
{
get
{
return _id;
}
set
{
XmlParser.ValidateRuleId (value);
_id = value;
}
}
/// TODOC <_include file='doc\Rule.uex' path='docs/doc[@for="Rule.Scope"]/*' />
public SrgsRuleScope Scope
{
get
{
return _scope;
}
set
{
_scope = value;
_isScopeSet = true;
}
}
#if !NO_STG
/// |summary|
/// classname
/// |/summary|
public string BaseClass
{
set
{
// base value can be null
#pragma warning disable 56526
_baseclass = value;
#pragma warning restore 56526
}
get
{
return _baseclass;
}
}
/// |summary|
/// OnInit
/// |/summary|
public string Script
{
set
{
Helpers.ThrowIfEmptyOrNull (value, "value");
_script = value;
}
get
{
return _script;
}
}
/// |summary|
/// OnInit
/// |/summary|
public string OnInit
{
set
{
ValidateIdentifier (value);
_onInit = value;
}
get
{
return _onInit;
}
}
/// |summary|
/// OnParse
/// |/summary|
public string OnParse
{
set
{
ValidateIdentifier (value);
_onParse = value;
}
get
{
return _onParse;
}
}
/// |summary|
/// OnError
/// |/summary|
public string OnError
{
set
{
ValidateIdentifier (value);
_onError = value;
}
get
{
return _onError;
}
}
/// |summary|
/// OnRecognition
/// |/summary|
public string OnRecognition
{
set
{
ValidateIdentifier (value);
_onRecognition = value;
}
get
{
return _onRecognition;
}
}
#endif
#endregion
//*******************************************************************
//
// Internal Methods
//
//********************************************************************
#region Internal Methods
internal void WriteSrgs (XmlWriter writer)
{
// Empty rule are not allowed
if (Elements.Count == 0)
{
XmlParser.ThrowSrgsException (SRID.InvalidEmptyRule, "rule", _id);
}
// Write
writer.WriteStartElement ("rule");
writer.WriteAttributeString ("id", _id);
if (_isScopeSet)
{
switch (_scope)
{
case SrgsRuleScope.Private:
writer.WriteAttributeString ("scope", "private");
break;
case SrgsRuleScope.Public:
writer.WriteAttributeString ("scope", "public");
break;
}
}
#if !NO_STG
// Write the 'baseclass' attribute
if (_baseclass != null)
{
writer.WriteAttributeString ("sapi", "baseclass", XmlParser.sapiNamespace, _baseclass);
}
#endif
// Write
if (_dynamic != RuleDynamic.NotSet)
{
writer.WriteAttributeString ("sapi", "dynamic", XmlParser.sapiNamespace, _dynamic == RuleDynamic.True ? "true" : "false");
}
#if !NO_STG
// Write the 'onInit' code snippet
if (OnInit != null)
{
writer.WriteAttributeString ("sapi", "onInit", XmlParser.sapiNamespace, OnInit);
}
// Write
if (OnParse != null)
{
writer.WriteAttributeString ("sapi", "onParse", XmlParser.sapiNamespace, OnParse);
}
// Write
if (OnError != null)
{
writer.WriteAttributeString ("sapi", "onError", XmlParser.sapiNamespace, OnError);
}
// Write
if (OnRecognition != null)
{
writer.WriteAttributeString ("sapi", "onRecognition", XmlParser.sapiNamespace, OnRecognition);
}
#endif
// Write body and footer.
Type previousElementType = null;
foreach (SrgsElement element in _elements)
{
// Insert space between consecutive SrgsText elements.
Type elementType = element.GetType ();
if ((elementType == typeof (SrgsText)) && (elementType == previousElementType))
{
writer.WriteString (" ");
}
previousElementType = elementType;
element.WriteSrgs (writer);
}
writer.WriteEndElement ();
#if !NO_STG
// Write the
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ConfigurationManagerInternal.cs
- NewExpression.cs
- VirtualDirectoryMapping.cs
- ViewValidator.cs
- ToolboxItemCollection.cs
- BitmapEffectGeneralTransform.cs
- NumericUpDownAcceleration.cs
- TextServicesLoader.cs
- Animatable.cs
- RightsManagementManager.cs
- FileDialog.cs
- BaseTemplateCodeDomTreeGenerator.cs
- ActiveXHelper.cs
- ExternalCalls.cs
- Win32.cs
- UIElementAutomationPeer.cs
- DataExpression.cs
- LocationUpdates.cs
- RangeExpression.cs
- HtmlUtf8RawTextWriter.cs
- PartialClassGenerationTask.cs
- unitconverter.cs
- Closure.cs
- HttpCachePolicyWrapper.cs
- RemoteWebConfigurationHost.cs
- DirectoryInfo.cs
- TdsParserSafeHandles.cs
- ECDiffieHellman.cs
- SystemInformation.cs
- PositiveTimeSpanValidatorAttribute.cs
- GeometryDrawing.cs
- DefaultEvaluationContext.cs
- XsdSchemaFileEditor.cs
- Cloud.cs
- XmlHierarchyData.cs
- DbConnectionPoolCounters.cs
- IsolatedStoragePermission.cs
- COM2IDispatchConverter.cs
- ExtentKey.cs
- SSmlParser.cs
- Emitter.cs
- MetadataItemCollectionFactory.cs
- StylusCollection.cs
- HybridWebProxyFinder.cs
- Html32TextWriter.cs
- ReferencedAssembly.cs
- SubpageParagraph.cs
- ErrorWebPart.cs
- MenuItemBindingCollection.cs
- FixedLineResult.cs
- PipelineComponent.cs
- DrawListViewItemEventArgs.cs
- RootBrowserWindowProxy.cs
- HitTestFilterBehavior.cs
- XmlIgnoreAttribute.cs
- ReachVisualSerializer.cs
- VirtualPath.cs
- CheckBoxStandardAdapter.cs
- UnsignedPublishLicense.cs
- InheritanceContextHelper.cs
- RuleInfoComparer.cs
- ContractMapping.cs
- PrintPreviewDialog.cs
- ImmutableObjectAttribute.cs
- DebugView.cs
- ProfileSettings.cs
- ACL.cs
- PerspectiveCamera.cs
- SamlSecurityToken.cs
- JsonReader.cs
- GridEntry.cs
- XdrBuilder.cs
- SystemColors.cs
- MethodCallConverter.cs
- DetailsViewUpdateEventArgs.cs
- CodeLabeledStatement.cs
- BamlLocalizableResourceKey.cs
- ResXFileRef.cs
- WorkflowWebHostingModule.cs
- HttpListenerElement.cs
- TripleDES.cs
- ExceptionHelpers.cs
- UdpRetransmissionSettings.cs
- ClusterSafeNativeMethods.cs
- Error.cs
- StringAnimationUsingKeyFrames.cs
- BooleanExpr.cs
- ColumnMapCopier.cs
- HttpModuleAction.cs
- FlowDocument.cs
- Range.cs
- EntityTemplateFactory.cs
- NullableConverter.cs
- XslUrlEditor.cs
- RootBrowserWindowProxy.cs
- SegmentInfo.cs
- CompletedAsyncResult.cs
- GenericEnumConverter.cs
- SqlFacetAttribute.cs
- ValidatorUtils.cs