Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Speech / Src / Recognition / SrgsGrammar / SrgsGrammarCompiler.cs / 1 / SrgsGrammarCompiler.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description:
//
// History:
// 6/1/2004 jeanfp
//---------------------------------------------------------------------------
using System;
using System.IO;
using System.Xml;
using System.Speech.Internal;
using System.Speech.Internal.SrgsCompiler;
namespace System.Speech.Recognition.SrgsGrammar
{
///
/// Compiles Xml Srgs data into a CFG
///
public static class SrgsGrammarCompiler
{
//*******************************************************************
//
// Public Methods
//
//*******************************************************************
#region Public Methods
///
/// Compiles a grammar to a file
///
///
///
static public void Compile (string inputPath, Stream outputStream)
{
Helpers.ThrowIfEmptyOrNull (inputPath, "inputPath");
Helpers.ThrowIfNull (outputStream, "outputStream");
using (XmlTextReader reader = new XmlTextReader (new Uri (inputPath, UriKind.RelativeOrAbsolute).ToString ()))
{
SrgsCompiler.CompileStream (new XmlReader [] { reader }, null, outputStream, true, null, null, null);
}
}
///
/// Compiles an Srgs documentto a file
///
///
///
static public void Compile (SrgsDocument srgsGrammar, Stream outputStream)
{
Helpers.ThrowIfNull (srgsGrammar, "srgsGrammar");
Helpers.ThrowIfNull (outputStream, "outputStream");
SrgsCompiler.CompileStream (srgsGrammar, null, outputStream, true, null, null);
}
///
/// Compiles a grammar to a file
///
///
///
static public void Compile (XmlReader reader, Stream outputStream)
{
Helpers.ThrowIfNull (reader, "reader");
Helpers.ThrowIfNull (outputStream, "outputStream");
SrgsCompiler.CompileStream (new XmlReader [] { reader }, null, outputStream, true, null, null, null);
}
#if !NO_STG
///
/// Compiles a grammar to a file
///
///
///
///
///
static public void CompileClassLibrary (string [] inputPaths, string outputPath, string [] referencedAssemblies, string keyFile)
{
Helpers.ThrowIfNull (inputPaths, "inputPaths");
Helpers.ThrowIfEmptyOrNull (outputPath, "outputPath");
XmlTextReader [] readers = new XmlTextReader [inputPaths.Length];
try
{
for (int iFile = 0; iFile < inputPaths.Length; iFile++)
{
if (inputPaths [iFile] == null)
{
throw new ArgumentException (SR.Get (SRID.ArrayOfNullIllegal), "inputPaths");
}
readers [iFile] = new XmlTextReader (new Uri (inputPaths [iFile], UriKind.RelativeOrAbsolute).ToString ());
}
SrgsCompiler.CompileStream (readers, outputPath, null, false, null, referencedAssemblies, keyFile);
}
finally
{
for (int iReader = 0; iReader < readers.Length; iReader++)
{
XmlTextReader srgsGrammar = readers [iReader];
if (srgsGrammar != null)
{
((IDisposable) srgsGrammar).Dispose ();
}
}
}
}
///
/// Compiles an Srgs documentto a file
///
///
///
///
///
static public void CompileClassLibrary (SrgsDocument srgsGrammar, string outputPath, string [] referencedAssemblies, string keyFile)
{
Helpers.ThrowIfNull (srgsGrammar, "srgsGrammar");
Helpers.ThrowIfEmptyOrNull (outputPath, "outputPath");
SrgsCompiler.CompileStream (srgsGrammar, outputPath, null, false, referencedAssemblies, keyFile);
}
///
/// Compiles a grammar to a file
///
///
///
///
///
static public void CompileClassLibrary (XmlReader reader, string outputPath, string [] referencedAssemblies, string keyFile)
{
Helpers.ThrowIfNull (reader, "reader");
Helpers.ThrowIfEmptyOrNull (outputPath, "outputPath");
SrgsCompiler.CompileStream (new XmlReader [] { reader }, outputPath, null, false, null, referencedAssemblies, keyFile);
}
#endif
#endregion
//********************************************************************
//
// Internal Methods
//
//*******************************************************************
#region Internal Methods
// Decide if the input stream is a cfg.
// If not assume it's an xml grammar.
// The stream parameter points to the start of the data on entry and is reset to that point on exit.
static private bool CheckIfCfg (Stream stream, out int cfgLength)
{
long initialPosition = stream.Position;
bool isCfg = CfgGrammar.CfgSerializedHeader.IsCfg (stream, out cfgLength);
// Reset stream position:
stream.Position = initialPosition;
return isCfg;
}
static internal void CompileXmlOrCopyCfg (
Stream inputStream,
Stream outputStream,
Uri orginalUri)
{
// Wrap stream in case Seek is not supported:
SeekableReadStream seekableInputStream = new SeekableReadStream (inputStream);
// See if CFG or XML document:
int cfgLength;
bool isCFG = CheckIfCfg (seekableInputStream, out cfgLength);
seekableInputStream.CacheDataForSeeking = false; // Stop buffering data
if (isCFG)
{
// Just copy the input to the output:
// {We later check the header on the output stream - we could do it on the input stream but it may not be seekable}.
Helpers.CopyStream (seekableInputStream, outputStream, cfgLength);
}
else
{
// Else compile the Xml:
SrgsCompiler.CompileStream (new XmlReader [] { new XmlTextReader (seekableInputStream) }, null, outputStream, true, orginalUri, null, null);
}
}
#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:
// 6/1/2004 jeanfp
//---------------------------------------------------------------------------
using System;
using System.IO;
using System.Xml;
using System.Speech.Internal;
using System.Speech.Internal.SrgsCompiler;
namespace System.Speech.Recognition.SrgsGrammar
{
///
/// Compiles Xml Srgs data into a CFG
///
public static class SrgsGrammarCompiler
{
//*******************************************************************
//
// Public Methods
//
//*******************************************************************
#region Public Methods
///
/// Compiles a grammar to a file
///
///
///
static public void Compile (string inputPath, Stream outputStream)
{
Helpers.ThrowIfEmptyOrNull (inputPath, "inputPath");
Helpers.ThrowIfNull (outputStream, "outputStream");
using (XmlTextReader reader = new XmlTextReader (new Uri (inputPath, UriKind.RelativeOrAbsolute).ToString ()))
{
SrgsCompiler.CompileStream (new XmlReader [] { reader }, null, outputStream, true, null, null, null);
}
}
///
/// Compiles an Srgs documentto a file
///
///
///
static public void Compile (SrgsDocument srgsGrammar, Stream outputStream)
{
Helpers.ThrowIfNull (srgsGrammar, "srgsGrammar");
Helpers.ThrowIfNull (outputStream, "outputStream");
SrgsCompiler.CompileStream (srgsGrammar, null, outputStream, true, null, null);
}
///
/// Compiles a grammar to a file
///
///
///
static public void Compile (XmlReader reader, Stream outputStream)
{
Helpers.ThrowIfNull (reader, "reader");
Helpers.ThrowIfNull (outputStream, "outputStream");
SrgsCompiler.CompileStream (new XmlReader [] { reader }, null, outputStream, true, null, null, null);
}
#if !NO_STG
///
/// Compiles a grammar to a file
///
///
///
///
///
static public void CompileClassLibrary (string [] inputPaths, string outputPath, string [] referencedAssemblies, string keyFile)
{
Helpers.ThrowIfNull (inputPaths, "inputPaths");
Helpers.ThrowIfEmptyOrNull (outputPath, "outputPath");
XmlTextReader [] readers = new XmlTextReader [inputPaths.Length];
try
{
for (int iFile = 0; iFile < inputPaths.Length; iFile++)
{
if (inputPaths [iFile] == null)
{
throw new ArgumentException (SR.Get (SRID.ArrayOfNullIllegal), "inputPaths");
}
readers [iFile] = new XmlTextReader (new Uri (inputPaths [iFile], UriKind.RelativeOrAbsolute).ToString ());
}
SrgsCompiler.CompileStream (readers, outputPath, null, false, null, referencedAssemblies, keyFile);
}
finally
{
for (int iReader = 0; iReader < readers.Length; iReader++)
{
XmlTextReader srgsGrammar = readers [iReader];
if (srgsGrammar != null)
{
((IDisposable) srgsGrammar).Dispose ();
}
}
}
}
///
/// Compiles an Srgs documentto a file
///
///
///
///
///
static public void CompileClassLibrary (SrgsDocument srgsGrammar, string outputPath, string [] referencedAssemblies, string keyFile)
{
Helpers.ThrowIfNull (srgsGrammar, "srgsGrammar");
Helpers.ThrowIfEmptyOrNull (outputPath, "outputPath");
SrgsCompiler.CompileStream (srgsGrammar, outputPath, null, false, referencedAssemblies, keyFile);
}
///
/// Compiles a grammar to a file
///
///
///
///
///
static public void CompileClassLibrary (XmlReader reader, string outputPath, string [] referencedAssemblies, string keyFile)
{
Helpers.ThrowIfNull (reader, "reader");
Helpers.ThrowIfEmptyOrNull (outputPath, "outputPath");
SrgsCompiler.CompileStream (new XmlReader [] { reader }, outputPath, null, false, null, referencedAssemblies, keyFile);
}
#endif
#endregion
//********************************************************************
//
// Internal Methods
//
//*******************************************************************
#region Internal Methods
// Decide if the input stream is a cfg.
// If not assume it's an xml grammar.
// The stream parameter points to the start of the data on entry and is reset to that point on exit.
static private bool CheckIfCfg (Stream stream, out int cfgLength)
{
long initialPosition = stream.Position;
bool isCfg = CfgGrammar.CfgSerializedHeader.IsCfg (stream, out cfgLength);
// Reset stream position:
stream.Position = initialPosition;
return isCfg;
}
static internal void CompileXmlOrCopyCfg (
Stream inputStream,
Stream outputStream,
Uri orginalUri)
{
// Wrap stream in case Seek is not supported:
SeekableReadStream seekableInputStream = new SeekableReadStream (inputStream);
// See if CFG or XML document:
int cfgLength;
bool isCFG = CheckIfCfg (seekableInputStream, out cfgLength);
seekableInputStream.CacheDataForSeeking = false; // Stop buffering data
if (isCFG)
{
// Just copy the input to the output:
// {We later check the header on the output stream - we could do it on the input stream but it may not be seekable}.
Helpers.CopyStream (seekableInputStream, outputStream, cfgLength);
}
else
{
// Else compile the Xml:
SrgsCompiler.CompileStream (new XmlReader [] { new XmlTextReader (seekableInputStream) }, null, outputStream, true, orginalUri, null, null);
}
}
#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
- AddInBase.cs
- PriorityChain.cs
- FrameworkElementFactoryMarkupObject.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- PeerContact.cs
- IInstanceTable.cs
- CommandField.cs
- SerialErrors.cs
- BuildProviderAppliesToAttribute.cs
- ExtentCqlBlock.cs
- _LocalDataStore.cs
- OleDbFactory.cs
- FullTextBreakpoint.cs
- ISFClipboardData.cs
- BuildManagerHost.cs
- XmlObjectSerializerReadContextComplexJson.cs
- XmlCharCheckingWriter.cs
- ForAllOperator.cs
- TextBoxLine.cs
- DispatcherObject.cs
- EntitySetBaseCollection.cs
- FormViewUpdatedEventArgs.cs
- CryptoApi.cs
- SignatureHelper.cs
- MetadataSource.cs
- DictionaryCustomTypeDescriptor.cs
- SequentialWorkflowRootDesigner.cs
- DefaultPropertyAttribute.cs
- XmlCollation.cs
- DesignerTransactionCloseEvent.cs
- _FixedSizeReader.cs
- WebPartDesigner.cs
- GridViewRowEventArgs.cs
- HtmlTextArea.cs
- Permission.cs
- ReceiveDesigner.xaml.cs
- TypedCompletedAsyncResult.cs
- SendSecurityHeader.cs
- QueryNode.cs
- ImagingCache.cs
- XmlnsDefinitionAttribute.cs
- MsmqInputChannelListenerBase.cs
- GAC.cs
- NamespaceList.cs
- XamlPathDataSerializer.cs
- RequestCachePolicyConverter.cs
- Vector3DAnimationBase.cs
- CollectionViewGroupRoot.cs
- CodeAttachEventStatement.cs
- DictionarySectionHandler.cs
- WebPartConnection.cs
- GlobalizationAssembly.cs
- NavigationPropertySingletonExpression.cs
- TableLayoutStyleCollection.cs
- VisualBrush.cs
- SourceItem.cs
- ToolboxItemCollection.cs
- Size3D.cs
- BaseDataListComponentEditor.cs
- NamedObject.cs
- DataGridPagerStyle.cs
- SymbolMethod.cs
- DataControlField.cs
- BamlRecords.cs
- LassoSelectionBehavior.cs
- SystemWebCachingSectionGroup.cs
- ping.cs
- SkinBuilder.cs
- FixedStringLookup.cs
- TextViewElement.cs
- DataGridViewRowConverter.cs
- CodeParameterDeclarationExpression.cs
- Opcode.cs
- LedgerEntry.cs
- SqlNodeAnnotation.cs
- DetailsViewDeletedEventArgs.cs
- UITypeEditor.cs
- Filter.cs
- HostedHttpContext.cs
- MetafileEditor.cs
- DifferencingCollection.cs
- DiscardableAttribute.cs
- QueryableDataSourceEditData.cs
- VirtualizingStackPanel.cs
- BufferAllocator.cs
- SettingsProviderCollection.cs
- WhitespaceRuleLookup.cs
- PackageDigitalSignature.cs
- XamlPathDataSerializer.cs
- TokenizerHelper.cs
- ControlIdConverter.cs
- PenCursorManager.cs
- ImpersonateTokenRef.cs
- serverconfig.cs
- SmtpNegotiateAuthenticationModule.cs
- WindowsImpersonationContext.cs
- TextEditorLists.cs
- ExpressionPrinter.cs
- PropertyMetadata.cs
- HtmlElement.cs