private Stream LoadCfgFromResource(bool stgInit) { Type t = typeof(SR); Assembly assembly = t.Assembly; Stream manifestResourceStream = assembly.GetManifestResourceStream(t.Namespace + "." + this.ResourceName); if (manifestResourceStream == null) { throw new FormatException(SR.Get(SRID.RecognizerInvalidBinaryGrammar)); } try { ScriptRef[] array = CfgGrammar.LoadIL(manifestResourceStream); if (array == null) { throw new ArgumentException(SR.Get(SRID.CannotLoadDotNetSemanticCode)); } _scripts = array; } catch (Exception innerException) { throw new ArgumentException(SR.Get(SRID.CannotLoadDotNetSemanticCode), innerException); } manifestResourceStream.Position = 0L; _ruleName = CheckRuleName(manifestResourceStream, GetType().Name, false, stgInit, out _sapi53Only, out _semanticTag); _isStg = true; return(manifestResourceStream); }
// Loads a strongly typed grammar from a resource in the Assembly. private Stream LoadCfgFromResource(bool stgInit) { // Strongly typed grammar get the Cfg data Assembly assembly = Assembly.GetAssembly(GetType()); Stream stream = assembly.GetManifestResourceStream(ResourceName); if (stream == null) { throw new FormatException(SR.Get(SRID.RecognizerInvalidBinaryGrammar)); } try { ScriptRef[] scripts = CfgGrammar.LoadIL(stream); if (scripts == null) { throw new ArgumentException(SR.Get(SRID.CannotLoadDotNetSemanticCode)); } _scripts = scripts; } catch (Exception e) { throw new ArgumentException(SR.Get(SRID.CannotLoadDotNetSemanticCode), e); } stream.Position = 0; // Update the rule name _ruleName = CheckRuleName(stream, GetType().Name, false, stgInit, out _sapi53Only, out _semanticTag); _isStg = true; return(stream); }
private void CreateSandbox(MemoryStream stream) { stream.Position = 0L; byte[] assemblyContent; byte[] assemblyDebugSymbols; ScriptRef[] scripts; if (CfgGrammar.LoadIL(stream, out assemblyContent, out assemblyDebugSymbols, out scripts)) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); _appDomain = AppDomain.CreateDomain("sandbox"); _proxy = (AppDomainGrammarProxy)_appDomain.CreateInstanceFromAndUnwrap(executingAssembly.GetName().CodeBase, "System.Speech.Internal.SrgsCompiler.AppDomainGrammarProxy"); _proxy.Init(_ruleName, assemblyContent, assemblyDebugSymbols); _scripts = scripts; } }