private void Initialize(XamlXmlWriter xamlXmlWriter)
 {
     this.xamlXmlWriter = xamlXmlWriter;
     this.settings = xamlXmlWriter.Settings;
     this.meSettings = this.meSettings ?? new XamlMarkupExtensionWriterSettings();
     this.currentState = Start.State;
     this.sb = new StringBuilder();
     this.nodes = new Stack<Node>();
     this.failed = false;
 }
 private void Initialize(XamlXmlWriter xamlXmlWriter)
 {
     this.xamlXmlWriter = xamlXmlWriter;
     this.settings      = xamlXmlWriter.Settings;
     this.meSettings    = this.meSettings ?? new XamlMarkupExtensionWriterSettings();
     this.currentState  = Start.State;
     this.sb            = new StringBuilder();
     this.nodes         = new Stack <Node>();
     this.failed        = false;
 }
示例#3
0
 void Initialize(XamlXmlWriter xamlXmlWriter)
 {
     this.xamlXmlWriter = xamlXmlWriter;
     this.settings      = xamlXmlWriter.Settings; // This will clone, only want to do this once
     this.meSettings    = this.meSettings ?? new XamlMarkupExtensionWriterSettings();
     currentState       = Start.State;
     sb     = new StringBuilder();
     nodes  = new Stack <Node>();
     failed = false;
 }
示例#4
0
		public XamlXmlWriter (XmlWriter xmlWriter, XamlSchemaContext schemaContext, XamlXmlWriterSettings settings)
		{
			if (xmlWriter == null)
				throw new ArgumentNullException ("xmlWriter");
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");
			this.w = xmlWriter;
			this.sctx = schemaContext;
			this.settings = settings ?? new XamlXmlWriterSettings ();
			this.manager = new XamlWriterStateManager<XamlXmlWriterException, InvalidOperationException> (true);
		}
示例#5
0
 XamlXmlWriterSettings(XamlXmlWriterSettings other)
     : base(other)
 {
     AssumeValidInput = other.AssumeValidInput;
     CloseOutput      = other.CloseOutput;
 }
示例#6
0
		public void DefaultValues ()
		{
			var s = new XamlXmlWriterSettings ();
			Assert.IsFalse (s.AssumeValidInput, "#1");
			Assert.IsFalse (s.CloseOutput, "#2");
		}
        bool ProcessMarkupItem(ITaskItem markupItem, CodeDomProvider codeDomProvider)
        {
            string markupItemFileName = markupItem.ItemSpec;
            XamlBuildTaskServices.PopulateModifiers(codeDomProvider);

            XamlNodeList xamlNodes = ReadXamlNodes(markupItemFileName);
            if (xamlNodes == null)
            {
                return false;
            }

            ClassData classData = ReadClassData(xamlNodes, markupItemFileName);

            string outputFileName = GetFileName(markupItemFileName);
            string codeFileName = Path.ChangeExtension(outputFileName, GetGeneratedSourceExtension(codeDomProvider));
            string markupFileName = Path.ChangeExtension(outputFileName, GeneratedSourceExtension + XamlBuildTaskServices.XamlExtension);
            classData.EmbeddedResourceFileName = Path.GetFileName(markupFileName);
            classData.HelperClassFullName = this.HelperClassFullName;

            // Check if code file with partial class exists
            classData.SourceFileExists = UserProvidedFileExists(markupItemFileName, codeDomProvider);

            // Store the full type name as metadata on the markup item
            string rootNamespacePrefix = null;
            string namespacePrefix = null;
            string typeFullName = null;
            if (this.Language.Equals("VB") && !String.IsNullOrWhiteSpace(classData.RootNamespace))
            {
                rootNamespacePrefix = classData.RootNamespace + ".";
            }

            if (!String.IsNullOrWhiteSpace(classData.Namespace))
            {
                namespacePrefix = classData.Namespace + ".";
            }

            if (rootNamespacePrefix != null)
            {
                if (namespacePrefix != null)
                {
                    typeFullName = rootNamespacePrefix + namespacePrefix + classData.Name;
                }
                else
                {
                    typeFullName = rootNamespacePrefix + classData.Name;
                }
            }
            else
            {
                if (namespacePrefix != null)
                {
                    typeFullName = namespacePrefix + classData.Name;
                }
                else
                {
                    typeFullName = classData.Name;
                }
            }

            markupItem.SetMetadata("typeName", typeFullName);

            // Execute extensions here to give them a chance to mutate the ClassData before we generate code.
            if (this.SupportExtensions)
            {
                if (!ExecuteExtensions(classData, markupItem))
                {
                    return false;
                }
            }

            // Generate code file
            CodeCompileUnit codeUnit = new ClassGenerator(this.BuildLogger, codeDomProvider, this.Language).Generate(classData);         
            WriteCode(codeDomProvider, codeUnit, codeFileName);
            this.GeneratedCodeFiles.Add(codeFileName);

            // Generate resource file
            if (!string.IsNullOrEmpty(this.AssemblyName))
            {
                // Generate xaml "implementation" file
                XmlWriterSettings xmlSettings = new XmlWriterSettings { Indent = true, IndentChars = "  ", CloseOutput = true };
                using (XmlWriter xmlWriter = XmlWriter.Create(File.Open(markupFileName, FileMode.Create), xmlSettings))
                {
                    XamlXmlWriterSettings xamlSettings = new XamlXmlWriterSettings() { CloseOutput = true };
                    
                    // Process EmbeddedResourceXaml to remove xml:space="preserve"
                    // due to a 




                    RemoveXamlSpaceAttribute(classData);

                    using (XamlReader reader = classData.EmbeddedResourceXaml.GetReader())
                    {
                        using (XamlXmlWriter xamlWriter = new XamlXmlWriter(xmlWriter, reader.SchemaContext, xamlSettings))
                        {
                            XamlServices.Transform(reader, xamlWriter);                                                     
                        }
                    }
                }
                this.GeneratedResources.Add(markupFileName);
            }

            if (classData.RequiresCompilationPass2)
            {
                this.RequiresCompilationPass2 = true;
            }
            else
            {
                if (!this.SupportExtensions)
                {
                    if (!ValidateXaml(xamlNodes, markupItemFileName))
                    {
                        this.RequiresCompilationPass2 = true;
                    }
                }
                else
                {
                    // skip validation if we are doing in-proc compile
                    // OR if we have pass 2 extensions hooked up 
                    // as we anyway need to run pass 2 in that case
                    if (!this.IsInProcessXamlMarkupCompile && !this.MarkupCompilePass2ExtensionsPresent)
                    {
                        if (!ValidateXaml(xamlNodes, markupItemFileName))
                        {
                            this.RequiresCompilationPass2 = true;
                        }
                    }
                }
            }
            return true;
        }
示例#8
0
		public XamlXmlWriter (TextWriter textWriter, XamlSchemaContext schemaContext, XamlXmlWriterSettings settings)
			: this (XmlWriter.Create (textWriter), schemaContext, null)
		{
		}
示例#9
0
		public XamlXmlWriter (Stream stream, XamlSchemaContext schemaContext, XamlXmlWriterSettings settings)
			: this (XmlWriter.Create (stream), schemaContext, null)
		{
		}
		XamlXmlWriterSettings (XamlXmlWriterSettings other)
			: base (other)
		{
			AssumeValidInput = other.AssumeValidInput;
			CloseOutput = other.CloseOutput;
		}