private void AddResource(ConverterOutput output)
        {
            if (Log.ShowResources)
            {
                Log.Trace("add resource {0} => {1}", output.Name, output);
            }

            _resources[output.Name] = output;
        }
        private void AddResource(string name, Stream stream)
        {
            var content = new ConverterOutput(stream)
            {
                Name = name,
                Disposition = OutputDisposition.input
            };

            AddResource(content);
        }
        /// <summary>
        /// Converts a XAML resource to HTML.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="xamltext"></param>
        /// <returns></returns>
        public object Convert(string name, Stream stream)
        {
            InitializeModule();

            // check not already exists output
            var filename = name + ".html";
            if (_outputs.ContainsKey(filename))
            {
                throw new Exception("output '" + filename + "' already exists.");
            }

            object result;
            var ms = new MemoryStream();
            using (var writer = XmlWriter.Create(ms, new XmlWriterSettings { Indent = Indent, OmitXmlDeclaration = true }))
            {
                writer.WriteDocType("HTML", null, null, null);
                result = Convert(stream, writer);
            }

            // add to outputs
            ms.Position = 0;
            _outputs[filename] = new ConverterOutput(ms)
            {
                Name = filename,
                Disposition = OutputDisposition.output
            };

            return result;
        }
        public void ConvertToScript(string name)
        {
            var filename = name + ".js";
            if (_outputs.ContainsKey(filename))
            {
                throw new Exception("output '" + filename + "' already exists.");
            }

            var ms = new MemoryStream();
            using (var writer = XmlWriter.Create(ms, new XmlWriterSettings { Indent = Indent, OmitXmlDeclaration = true }))
            {
                writer.WriteStartElement("head");
                GenerateCode();
                EmitScript(writer);
                writer.WriteEndElement();
            }

            ms.Position = 0;
            _outputs[filename] = new ConverterOutput(ms)
            {
                Name = filename,
                Disposition = OutputDisposition.output
            };
        }
        public object Convert(ConverterOutput resource, string name = null)
        {
            try
            {
                CurrentResource = resource;

                return Convert(name ?? resource.Name, resource.GetStream());
            }
            catch (Exception ex)
            {
                ProcessException(ex);
                return null;
            }
            finally
            {
                CurrentResource = null;
            }
        }