Example #1
0
        /// <summary>
        ///   Convert from Xaml read by a token reader into baml being written
        ///   out by a record writer.  The context gives mapping information.
        /// </summary>
#if !PBTCOMPILER
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
#endif
        internal virtual void ConvertXamlToBaml(
            XamlReaderHelper tokenReader,
            ParserContext context,
            XamlNode xamlNode,
            BamlRecordWriter bamlWriter)
        {
            throw new InvalidOperationException(SR.Get(SRID.InvalidDeSerialize));
        }
Example #2
0
        /// <summary>
        ///   Convert from Xaml read by a token reader into baml being written
        ///   out by a record writer.  The context gives mapping information.
        /// </summary>
#if !PBTCOMPILER
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
#endif        
        internal virtual void ConvertXamlToBaml (
            XamlReaderHelper          tokenReader,
            ParserContext       context,
            XamlNode            xamlNode,
            BamlRecordWriter    bamlWriter)
        {
            throw new InvalidOperationException(SR.Get(SRID.InvalidDeSerialize));
        }
Example #3
0
 /// <summary>
 /// Constructor that takes a stream and creates an XmlCompatibilityReader on it.
 /// </summary>
 public XamlParser(
     ParserContext parserContext,
     BamlRecordWriter bamlWriter,
     Stream xamlStream,
     bool multipleRoots) : this(parserContext, bamlWriter,
                                 new XmlTextReader(xamlStream,
                                 multipleRoots ? XmlNodeType.Element : XmlNodeType.Document,
                                 (XmlParserContext)parserContext)                             )
 {
 }
Example #4
0
 internal ParserExtension(MarkupCompiler compiler,
                          ParserContext parserContext,
                          BamlRecordWriter bamlWriter,
                          Stream xamlStream,
                          bool pass2) :
     base(parserContext, bamlWriter, xamlStream, false)
 {
     _compiler = compiler;
     _pass2    = pass2;
     Debug.Assert(bamlWriter != null, "Need a BamlRecordWriter for compiling to Baml");
 }
 internal ParserExtension(MarkupCompiler compiler, 
     ParserContext parserContext, 
     BamlRecordWriter bamlWriter, 
     Stream xamlStream,
     bool pass2) :
     base(parserContext, bamlWriter, xamlStream, false)
 {
     _compiler = compiler;
     _pass2 = pass2;
     Debug.Assert(bamlWriter != null, "Need a BamlRecordWriter for compiling to Baml");
 }
        /// <summary>
        ///   Convert from Xaml read by a token reader into baml being written
        ///   out by a record writer.  The context gives mapping information.
        /// </summary>
        internal override void ConvertXamlToBaml (
            XamlReaderHelper             tokenReader,
            ParserContext          context,
            XamlNode               xamlNode,
            BamlRecordWriter       bamlWriter)
        {

            TemplateXamlParser templateParser = new TemplateXamlParser(tokenReader, context);
            templateParser.ParserHooks = _parserHooks;
            templateParser.BamlRecordWriter = bamlWriter;

            // Process the xamlNode that is passed in so that the <Template> element is written to baml
            templateParser.WriteElementStart((XamlElementStartNode)xamlNode);

            // Parse the entire Template section now, writing everything out directly to BAML.
            templateParser.Parse();
       }
        /// <summary>
        ///   Convert from Xaml read by a token reader into baml being written
        ///   out by a record writer.  The context gives mapping information.
        /// </summary>
        internal override void ConvertXamlToBaml(
            XamlReaderHelper tokenReader,
            ParserContext context,
            XamlNode xamlNode,
            BamlRecordWriter bamlWriter)
        {
            TemplateXamlParser templateParser = new TemplateXamlParser(tokenReader, context);

            templateParser.ParserHooks      = _parserHooks;
            templateParser.BamlRecordWriter = bamlWriter;

            // Process the xamlNode that is passed in so that the <Template> element is written to baml
            templateParser.WriteElementStart((XamlElementStartNode)xamlNode);

            // Parse the entire Template section now, writing everything out directly to BAML.
            templateParser.Parse();
        }
        private void _Compile(string relativeSourceFile, bool pass2)
        {
            bool error = false;
            Stream bamlStream = null;
            XamlParser xamlParser = null;

            try
            {
                DefinitionNSPrefix = DEFINITION_PREFIX;
                IsCodeNeeded = false;

                _ccRoot = null;
                _hasLocalEvent = false;
                _codeContexts = new Stack();
                _parserContext = new ParserContext();
                _parserContext.XamlTypeMapper = _typeMapper;
                _hasEmittedEventSetterDeclaration = false;

                bamlStream = new MemoryStream();
                BamlRecordWriter bamlWriter = new BamlRecordWriter(bamlStream, _parserContext, true);
                bamlWriter.DebugBamlStream = XamlDebuggingInformation;

                xamlParser = new ParserExtension(this, _parserContext, bamlWriter, SourceFileInfo.Stream, pass2);

                xamlParser.ParserHooks = ParserHooks;

                try
                {
                    xamlParser.Parse();
                }
                finally
                {
                    _typeMapper.ResetMapper();
                }
            }
            catch (XamlParseException e)
            {
                OnError(e);
                error = true;
            }
            // All exceptions including NullRef & SEH need to be caught by the markupcompiler
            // since it is an app and not a component.
#pragma warning suppress 6500
            catch (Exception e)
            {
                OnError(e);
                error = true;
            }
            finally
            {
                if (!error &&
                    xamlParser.BamlRecordWriter == null &&
                    IsBamlNeeded)
                {
                    if (_pendingLocalFiles == null)
                    {
                        _pendingLocalFiles = new ArrayList(10);
                    }

                    _pendingLocalFiles.Add(relativeSourceFile);
                }

                if (_codeContexts != null)
                {
                    _codeContexts.Clear();
                    _codeContexts = null;
                }


                if (SourceFileInfo != null)
                {
                    SourceFileInfo.CloseStream();
                }

                if (bamlStream != null)
                {
                    bamlStream.Close();
                    bamlStream = null;
                }
            }
        }
Example #9
0
        protected XamlParser(
            ParserContext parserContext,
            BamlRecordWriter bamlWriter,
            XmlTextReader textReader) : this(parserContext, bamlWriter)
        {

            // When the XML 1.0 specification was authored, security was not a top concern, and as a result DTDs have the
            // unfortunate capability of severe Denial of Service (DoS) attacks, typically through the use of an internal
            // entity expansion technique. In System.Xml V2.0, in order to provide protection against DTD DoS attacks there
            // is the capability of turning off DTD parsing through the use of the ProhibitDtd property.

            textReader.ProhibitDtd = true;

            XmlCompatibilityReader xcr = new XmlCompatibilityReader(textReader,
                                                                    new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported),
                                                                    _predefinedNamespaces );

            TokenReader = new XamlReaderHelper(this,parserContext,xcr);
        }
Example #10
0
 protected XamlParser(
     ParserContext parserContext,
     BamlRecordWriter bamlWriter)
 {
     _parserContext = parserContext;
     _bamlWriter = bamlWriter;
 }