public KNWindowController(string windowXamlName)
        {
            try {

                string xamlPath = KNBundle.MainBundle().PathForResourceOfType(windowXamlName, "xaml");
                if (xamlPath != null) {

                    FileStream s = new FileStream(xamlPath, FileMode.Open, FileAccess.Read);

                    XamlXmlReaderSettings settings = new XamlXmlReaderSettings();
                    settings.LocalAssembly = Assembly.GetCallingAssembly();
                    settings.CloseInput = true;

                    XamlXmlReader reader = new XamlXmlReader(s, settings);

                    DependencyObject rootElement = (DependencyObject)XamlServices.Load(reader);

                    Window newWindow = (Window)rootElement;
                    newWindow.SourceInitialized += WindowWasInitialized;
                    Window = newWindow;

                    // Attempt to localise

                    KNBundleGlobalHelpers.AttemptToLocalizeComponent(Window);

                    s.Dispose();

                } else {
                    throw new Exception(windowXamlName + " could not be found");
                }

            } catch {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Loads a XAML or XAMLX file
        /// </summary>
        /// <param name="xamlFile">
        /// The xaml file. 
        /// </param>
        /// <param name="localAssembly">
        /// The local assembly. 
        /// </param>
        /// <returns>
        /// The activity or root activity of a WorkflowService 
        /// </returns>
        public static Activity Load(string xamlFile, Assembly localAssembly)
        {
            Contract.Requires(localAssembly != null);
            if (localAssembly == null)
            {
                throw new ArgumentNullException("localAssembly");
            }

            var readerSettings = new XamlXmlReaderSettings
                {
                    LocalAssembly = localAssembly,
                    AllowProtectedMembersOnRoot = true
                };

            var xamlType = GetXamlType(xamlFile);
            switch (xamlType)
            {
                case WorkflowXamlFileType.Activity:
                    using (var reader = new XamlXmlReader(xamlFile, readerSettings))
                    {
                        return ActivityXamlServices.Load(reader);
                    }

                case WorkflowXamlFileType.WorkflowService:
                    using (var reader = new XamlXmlReader(xamlFile, readerSettings))
                    {
                        return ((WorkflowService)XamlServices.Load(reader)).GetWorkflowRoot();
                    }

                default:
                    throw new ArgumentException("Invalid file extension on xamlFile");
            }
        }
示例#3
0
        public XamlXmlReader(XmlReader xmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
        {
            if (xmlReader == null)
            {
                throw new ArgumentNullException("xmlReader");
            }
            if (schemaContext == null)
            {
                throw new ArgumentNullException("schemaContext");
            }

            sctx          = schemaContext;
            this.settings = settings ?? new XamlXmlReaderSettings();

            // filter out some nodes.
            var xrs = new XmlReaderSettings()
            {
                CloseInput     = this.settings.CloseInput,
                IgnoreComments = true,
                IgnoreProcessingInstructions = true,
                IgnoreWhitespace             = true
            };

            r         = XmlReader.Create(xmlReader, xrs);
            line_info = r as IXmlLineInfo;
            xaml_namespace_resolver = new NamespaceResolver(r as IXmlNamespaceResolver);
        }
示例#4
0
 public XamlXmlReader(TextReader textReader, XamlXmlReaderSettings settings)
 {
     if (textReader == null)
     {
         throw new ArgumentNullException("textReader");
     }
     Initialize(CreateXmlReader(textReader, settings), null, settings);
 }
 public XamlXmlReader(string fileName, XamlXmlReaderSettings settings)
 {
     if (fileName == null)
     {
         throw new ArgumentNullException("fileName");
     }
     this.Initialize(this.CreateXmlReader(fileName, settings), null, settings);
 }
示例#6
0
        private XmlReader CreateXmlReader(TextReader textReader, XamlXmlReaderSettings settings)
        {
            bool closeInput = (settings != null) && settings.CloseInput;

            return(XmlReader.Create(textReader, new XmlReaderSettings {
                CloseInput = closeInput, DtdProcessing = DtdProcessing.Prohibit
            }));
        }
示例#7
0
        private XmlReader CreateXmlReader(string fileName, XamlXmlReaderSettings settings)
        {
            bool closeInput = (settings == null) ? true : settings.CloseInput;

            return(XmlReader.Create(fileName, new XmlReaderSettings {
                CloseInput = closeInput, DtdProcessing = DtdProcessing.Prohibit
            }));
        }
 public XamlXmlReader(XmlReader xmlReader, XamlXmlReaderSettings settings)
 {
     if (xmlReader == null)
     {
         throw new ArgumentNullException("xmlReader");
     }
     this.Initialize(xmlReader, null, settings);
 }
示例#9
0
		public void DefaultValues ()
		{
			var s = new XamlXmlReaderSettings ();
			Assert.IsFalse (s.CloseInput, "#1");
			Assert.IsFalse (s.SkipXmlCompatibilityProcessing, "#2");
			Assert.IsNull (s.XmlLang, "#3");
			Assert.IsFalse (s.XmlSpacePreserve, "#4");
		}
示例#10
0
 public XamlXmlReader(Stream stream, XamlXmlReaderSettings settings)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     Initialize(CreateXmlReader(stream, settings), null, settings);
 }
示例#11
0
        public XamlXmlReader(string fileName, XamlXmlReaderSettings settings)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            Initialize(CreateXmlReader(fileName, settings), null, settings);
        }
示例#12
0
        static XmlReader CreateReader(TextReader reader, XamlXmlReaderSettings settings)
        {
            if (settings?.RequiresXmlContext != true)
            {
                return(XmlReader.Create(reader, CreateReaderSettings(settings)));
            }

            return(XmlReader.Create(reader, CreateReaderSettings(settings, ConformanceLevel.Fragment), settings.CreateXmlContext()));
        }
示例#13
0
        public XamlXmlReader(XmlReader xmlReader, XamlXmlReaderSettings settings)
        {
            if (xmlReader == null)
            {
                throw new ArgumentNullException(nameof(xmlReader));
            }

            Initialize(xmlReader, null, settings);
        }
        private XmlReader CreateXmlReader(TextReader textReader, XamlXmlReaderSettings settings)
        {
            bool flag = (settings != null) && settings.CloseInput;
            XmlReaderSettings settings2 = new XmlReaderSettings {
                CloseInput    = flag,
                DtdProcessing = DtdProcessing.Prohibit
            };

            return(XmlReader.Create(textReader, settings2));
        }
        private XmlReader CreateXmlReader(string fileName, XamlXmlReaderSettings settings)
        {
            bool flag = (settings == null) || settings.CloseInput;
            XmlReaderSettings settings2 = new XmlReaderSettings {
                CloseInput    = flag,
                DtdProcessing = DtdProcessing.Prohibit
            };

            return(XmlReader.Create(fileName, settings2));
        }
示例#16
0
 static XmlReaderSettings CreateReaderSettings(XamlXmlReaderSettings settings, ConformanceLevel conformance = ConformanceLevel.Document, bool?closeInput = null)
 {
     return(new XmlReaderSettings
     {
         CloseInput = closeInput ?? settings?.CloseInput ?? false,
         IgnoreComments = true,
         IgnoreProcessingInstructions = true,
         ConformanceLevel = conformance
     });
 }
		public XamlXmlReaderSettings (XamlXmlReaderSettings settings)
			: base (settings)
		{
			var s = settings;
			if (s == null)
				return;
			CloseInput = s.CloseInput;
			SkipXmlCompatibilityProcessing = s.SkipXmlCompatibilityProcessing;
			XmlLang = s.XmlLang;
			XmlSpacePreserve = s.XmlSpacePreserve;
		}
 public XamlXmlReader(Stream stream, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
 {
     if (stream == null)
     {
         throw new ArgumentNullException("stream");
     }
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     this.Initialize(this.CreateXmlReader(stream, settings), schemaContext, settings);
 }
 public XamlXmlReader(string fileName, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
 {
     if (fileName == null)
     {
         throw new ArgumentNullException("fileName");
     }
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     this.Initialize(this.CreateXmlReader(fileName, settings), schemaContext, settings);
 }
 public XamlXmlReader(XmlReader xmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
 {
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     if (xmlReader == null)
     {
         throw new ArgumentNullException("xmlReader");
     }
     this.Initialize(xmlReader, schemaContext, settings);
 }
 public XamlXmlReader(TextReader textReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
 {
     if (textReader == null)
     {
         throw new ArgumentNullException("textReader");
     }
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     this.Initialize(this.CreateXmlReader(textReader, settings), schemaContext, settings);
 }
示例#22
0
        public XamlXmlReader(XmlReader xmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
        {
            if (schemaContext == null)
            {
                throw new ArgumentNullException(nameof(schemaContext));
            }
            if (xmlReader == null)
            {
                throw new ArgumentNullException(nameof(xmlReader));
            }

            Initialize(xmlReader, schemaContext, settings);
        }
 internal XamlScanner(XamlParserContext context, XmlReader xmlReader, XamlXmlReaderSettings settings)
 {
     this._xmlReader = xmlReader;
     this._xmlLineInfo = settings.ProvideLineInfo ? (xmlReader as IXmlLineInfo) : null;
     this._parserContext = context;
     this._scannerStack = new XamlScannerStack();
     this._readNodesQueue = new Queue<XamlScannerNode>();
     this._settings = settings;
     if (settings.XmlSpacePreserve)
     {
         this._scannerStack.CurrentXmlSpacePreserve = true;
     }
 }
示例#24
0
        public XamlXmlReader(Stream stream, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (schemaContext == null)
            {
                throw new ArgumentNullException(nameof(schemaContext));
            }

            Initialize(CreateXmlReader(stream, settings), schemaContext, settings);
        }
 public XamlXmlReaderSettings(XamlXmlReaderSettings settings) : base(settings)
 {
     if (settings != null)
     {
         if (settings._xmlnsDictionary != null)
         {
             this._xmlnsDictionary = new Dictionary<string, string>(settings._xmlnsDictionary);
         }
         this.XmlLang = settings.XmlLang;
         this.XmlSpacePreserve = settings.XmlSpacePreserve;
         this.SkipXmlCompatibilityProcessing = settings.SkipXmlCompatibilityProcessing;
     }
 }
示例#26
0
        public XamlAnalysis(string filename) {
            try {
                var settings = new XamlXmlReaderSettings();
                settings.ProvideLineInfo = true;

                using (XamlXmlReader reader = new XamlXmlReader(filename, settings)) {
                    Analyze(reader);
                }
            } catch {
                // ignore malformed XAML - XamlReader does a bad job of documenting what it throws
                // so we just need to try/catch here.
            }
        }
示例#27
0
 public XamlXmlReaderSettings(XamlXmlReaderSettings settings) : base(settings)
 {
     if (settings != null)
     {
         if (settings._xmlnsDictionary != null)
         {
             this._xmlnsDictionary = new Dictionary <string, string>(settings._xmlnsDictionary);
         }
         this.XmlLang          = settings.XmlLang;
         this.XmlSpacePreserve = settings.XmlSpacePreserve;
         this.SkipXmlCompatibilityProcessing = settings.SkipXmlCompatibilityProcessing;
     }
 }
示例#28
0
        public static XamlDomObject Load(string fileName, XamlSchemaContext schemaContext)
        {
            XamlDomObject rootObject = null;
            using (var xr = XmlReader.Create(fileName))
            {
                var xxrs = new XamlXmlReaderSettings();
                xxrs.ProvideLineInfo = true;
                var xxr = new XamlXmlReader(xr, schemaContext, xxrs);

                rootObject = (XamlDomObject) Load(xxr);
            }
            return rootObject;
        }
示例#29
0
        static XmlReader CreateReader(XmlReader xmlReader, XamlXmlReaderSettings settings)
        {
            if (settings?.RequiresXmlContext != true)
            {
                return(XmlReader.Create(xmlReader, CreateReaderSettings(settings)));
            }

            // need to read from a TextReader to load a fragment, so we copy the xml of the current reader
            xmlReader.Read();
            var reader = new StringReader(xmlReader.ReadOuterXml());

            return(XmlReader.Create(reader, CreateReaderSettings(settings, ConformanceLevel.Fragment), settings.CreateXmlContext()));
        }
示例#30
0
        public XamlXmlReaderSettings(XamlXmlReaderSettings settings)
            : base(settings)
        {
            var s = settings;

            if (s == null)
            {
                return;
            }
            CloseInput = s.CloseInput;
            SkipXmlCompatibilityProcessing = s.SkipXmlCompatibilityProcessing;
            XmlLang          = s.XmlLang;
            XmlSpacePreserve = s.XmlSpacePreserve;
        }
示例#31
0
        public XamlAnalysis(TextReader textReader) {
            try {
                var settings = new XamlXmlReaderSettings();
                settings.ProvideLineInfo = true;

                var context = new XamlSchemaContext(new XamlSchemaContextSettings() { FullyQualifyAssemblyNamesInClrNamespaces = true });

                using (XamlXmlReader reader = new XamlXmlReader(textReader, context, settings)) {
                    Analyze(reader);
                }
            } catch {
                // ignore malformed XAML - XamlReader does a bad job of documenting what it throws
                // so we just need to try/catch here.
            }
        }
示例#32
0
		public void CopyConstructor ()
		{
			var s = new XamlXmlReaderSettings ();
			s.CloseInput = true;
			s.SkipXmlCompatibilityProcessing = true;
			s.XmlLang = "ja-JP";
			s.XmlSpacePreserve = true;

			s = new XamlXmlReaderSettings (s);

			// .NET fails to copy this value.
			//Assert.IsTrue (s.CloseInput, "#1");
			Assert.IsTrue (s.SkipXmlCompatibilityProcessing, "#2");
			Assert.AreEqual ("ja-JP", s.XmlLang, "#3");
			Assert.IsTrue (s.XmlSpacePreserve, "#4");
		}
示例#33
0
        public XamlXmlReaderSettings(XamlXmlReaderSettings settings)
            : base(settings)
        {
            var s = settings;

            if (s == null)
            {
                return;
            }
            CloseInput = s.CloseInput;
            SkipXmlCompatibilityProcessing = s.SkipXmlCompatibilityProcessing;
            XmlLang          = s.XmlLang;
            XmlSpacePreserve = s.XmlSpacePreserve;
            if (s._defaultNamespaces != null)
            {
                _defaultNamespaces = new Dictionary <string, string>(s._defaultNamespaces);
            }
        }
示例#34
0
		public void RootObjectInstance ()
		{
			// bug #689548
			var obj = new RootObjectInstanceTestClass ();
			RootObjectInstanceTestClass result;
			
			var rsettings = new XamlXmlReaderSettings ();
			
			var xml = String.Format (@"<RootObjectInstanceTestClass Property=""Test"" xmlns=""clr-namespace:MonoTests.System.Xaml;assembly={0}""></RootObjectInstanceTestClass>", GetType ().Assembly.GetName ().Name);
			using (var reader = new XamlXmlReader (new StringReader (xml), rsettings)) {
				var wsettings = new XamlObjectWriterSettings ();
				wsettings.RootObjectInstance = obj;
				using (var writer = new XamlObjectWriter (reader.SchemaContext, wsettings)) {
					XamlServices.Transform (reader, writer, false);
					result = (RootObjectInstanceTestClass) writer.Result;
				}
			}
			
			Assert.AreEqual (obj, result, "#1");
			Assert.AreEqual ("Test", obj.Property, "#2");
		}
 private static object Deserialize(byte[] buffer, Assembly localAssembly)
 {
     object obj2;
     using (XmlReader reader = XmlReader.Create(new MemoryStream(buffer)))
     {
         XamlXmlReaderSettings settings = new XamlXmlReaderSettings {
             LocalAssembly = localAssembly,
             ProvideLineInfo = true
         };
         using (XamlXmlReader reader2 = new XamlXmlReader(reader, settings))
         {
             using (XamlDebuggerXmlReader reader3 = new XamlDebuggerXmlReader(reader2, new StreamReader(new MemoryStream(buffer))))
             {
                 using (XamlReader reader4 = ActivityXamlServices.CreateBuilderReader(reader3))
                 {
                     obj2 = XamlServices.Load(reader4);
                 }
             }
         }
     }
     return obj2;
 }
示例#36
0
        public static Activity CreateWorkflowActivityFromXaml(string workflowXaml, Assembly type)
        {
            if (string.IsNullOrEmpty(workflowXaml) || type == null)
            {
                return null;
            }

            var xmlReaderSettings = new XamlXmlReaderSettings { LocalAssembly = type };
            var settings1 = xmlReaderSettings;
            StringReader stringReader = null;
            var settings2 = new ActivityXamlServicesSettings { CompileExpressions = true };
            try
            {
                stringReader = new StringReader(workflowXaml);
                var activity = ActivityXamlServices.Load(new XamlXmlReader(stringReader, settings1), settings2);
                return activity;
            }
            finally
            {
                stringReader?.Dispose();
            }
        }
示例#37
0
        public XamlXmlParser(XmlReader xmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
        {
            if (xmlReader == null)
            {
                throw new ArgumentNullException(nameof(xmlReader));
            }
            if (schemaContext == null)
            {
                throw new ArgumentNullException(nameof(schemaContext));
            }

            sctx          = schemaContext;
            this.settings = settings ?? default_settings;
            if (settings?.SkipXmlCompatibilityProcessing != true)
            {
                xmlReader = new CompatibleXmlReader(xmlReader, schemaContext);
            }

            r         = xmlReader;
            line_info = r as IXmlLineInfo;
            xaml_namespace_resolver = new NamespaceResolver(r as IXmlNamespaceResolver);
        }
示例#38
0
        public KNViewController(string viewXamlName)
        {
            try {
                string xamlPath = KNBundle.MainBundle().PathForResourceOfType(viewXamlName, "xaml");
                if (xamlPath != null) {

                    FileStream s = new FileStream(xamlPath, FileMode.Open, FileAccess.Read);

                    XamlXmlReaderSettings settings = new XamlXmlReaderSettings();
                    settings.LocalAssembly = Assembly.GetCallingAssembly();
                    settings.CloseInput = true;

                    XamlXmlReader reader = new XamlXmlReader(s, settings);

                    DependencyObject rootElement = (DependencyObject)XamlServices.Load(reader);

                    UserControl newView = (UserControl)rootElement;
                    View = newView;
                    View.Initialized += ViewInitialized;

                    // Find our properties, then search for controls with the same name

                    MatchPropertiesToViewTree(rootElement);

                    // Attempt to localise

                    KNBundleGlobalHelpers.AttemptToLocalizeComponent(View);

                    s.Dispose();

                } else {
                    throw new Exception(viewXamlName + " could not be found");
                }

            } catch {
                throw;
            }
        }
示例#39
0
        private object LoadAsync(XmlReader reader, ParserContext parserContext)
        { 
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            } 

            if (parserContext == null) 
            { 
                parserContext = new ParserContext();
            } 

            _xmlReader = reader;
            object rootObject = null;
            if (parserContext.BaseUri == null || 
                 String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
            { 
                if (reader.BaseURI == null || 
                    String.IsNullOrEmpty(reader.BaseURI.ToString()))
                { 
                    parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                }
                else
                { 
                    parserContext.BaseUri = new Uri(reader.BaseURI);
                } 
            } 

            _baseUri = parserContext.BaseUri; 
            System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
            settings.IgnoreUidsOnPropertyElements = true;
            settings.BaseUri = parserContext.BaseUri;
            settings.ProvideLineInfo = true; 
            XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ?
                parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext(); 
 
            try
            { 
                _textReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings);

                _stack = new XamlContextStack<WpfXamlFrame>(() => new WpfXamlFrame());
 
                System.Xaml.XamlObjectWriterSettings objectSettings = XamlReader.CreateObjectWriterSettings();
                objectSettings.AfterBeginInitHandler = delegate(object sender, System.Xaml.XamlObjectEventArgs args) 
                    { 
                        if (rootObject == null)
                        { 
                            rootObject = args.Instance;
                            _styleConnector = rootObject as IStyleConnector;
                        }
 
                        UIElement uiElement = args.Instance as UIElement;
                        if (uiElement != null) 
                        { 
                            uiElement.SetPersistId(_persistId++);
                        } 

                        DependencyObject dObject = args.Instance as DependencyObject;
                        if (dObject != null && _stack.CurrentFrame.XmlnsDictionary != null)
                        { 
                            XmlnsDictionary dictionary = _stack.CurrentFrame.XmlnsDictionary;
                            dictionary.Seal(); 
 
                            XmlAttributeProperties.SetXmlnsDictionary(dObject, dictionary);
                        } 
                    };

                _objectWriter = new System.Xaml.XamlObjectWriter(_textReader.SchemaContext, objectSettings);
                _parseCancelled = false; 
                _skipJournaledProperties = parserContext.SkipJournaledProperties;
 
                XamlMember synchronousModeProperty = _textReader.SchemaContext.GetXamlDirective("http://schemas.microsoft.com/winfx/2006/xaml", "SynchronousMode"); 
                XamlMember synchronousRecordProperty = _textReader.SchemaContext.GetXamlDirective("http://schemas.microsoft.com/winfx/2006/xaml", "AsyncRecords");
 
                System.Xaml.XamlReader xamlReader = _textReader;

                IXamlLineInfo xamlLineInfo = xamlReader as IXamlLineInfo;
                IXamlLineInfoConsumer xamlLineInfoConsumer = _objectWriter as IXamlLineInfoConsumer; 
                bool shouldPassLineNumberInfo = false;
                if ((xamlLineInfo != null && xamlLineInfo.HasLineInfo) 
                    && (xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo)) 
                {
                    shouldPassLineNumberInfo = true; 
                }

                bool async = false;
                bool lastPropWasSyncMode = false; 
                bool lastPropWasSyncRecords = false;
 
                while (!_textReader.IsEof) 
                {
                    WpfXamlLoader.TransformNodes(xamlReader, _objectWriter, true /*onlyLoadOneNode*/, _skipJournaledProperties, shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer, _stack, _styleConnector); 

                    if (xamlReader.NodeType == System.Xaml.XamlNodeType.StartMember)
                    {
                        if (xamlReader.Member == synchronousModeProperty) 
                        {
                            lastPropWasSyncMode = true; 
                        } 
                        else if (xamlReader.Member == synchronousRecordProperty)
                        { 
                            lastPropWasSyncRecords = true;
                        }
                    }
                    else if (xamlReader.NodeType == System.Xaml.XamlNodeType.Value) 
                    {
                        if (lastPropWasSyncMode == true) 
                        { 
                            if (xamlReader.Value as String == "Async")
                            { 
                                async = true;
                            }
                        }
                        else if (lastPropWasSyncRecords == true) 
                        {
                            if (xamlReader.Value is int) 
                            { 
                                _maxAsynxRecords = (int)xamlReader.Value;
                            } 
                            else if (xamlReader.Value is String)
                            {
                                _maxAsynxRecords = Int32.Parse(xamlReader.Value as String, TypeConverterHelper.InvariantEnglishUS);
                            } 
                        }
                    } 
                    else if (xamlReader.NodeType == System.Xaml.XamlNodeType.EndMember) 
                    {
                        lastPropWasSyncMode = false; 
                        lastPropWasSyncRecords = false;
                    }

                    if (async && rootObject != null) 
                        break;
                } 
            } 
            catch (Exception e)
            { 
                // Don't wrap critical exceptions or already-wrapped exceptions.
                if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri))
                {
                    throw; 
                }
                RewrapException(e, parserContext.BaseUri); 
            } 

            if (!_textReader.IsEof) 
            {
                Post();
                //ThreadStart threadStart = new ThreadStart(ReadXamlAsync);
                //Thread thread = new Thread(threadStart); 
                //thread.Start();
            } 
            else 
            {
                TreeBuildComplete(); 
            }

            if (rootObject is DependencyObject)
            { 
                if (parserContext.BaseUri != null && !String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
                    (rootObject as DependencyObject).SetValue(BaseUriHelper.BaseUriProperty, parserContext.BaseUri); 
                //else 
                //    (rootObject as DependencyObject).SetValue(BaseUriHelper.BaseUriProperty, BaseUriHelper.PackAppBaseUri);
                WpfXamlLoader.EnsureXmlNamespaceMaps(rootObject, schemaContext); 
            }

            Application app = rootObject as Application;
            if (app != null) 
            {
                app.ApplicationMarkupBaseUri = GetBaseUri(settings.BaseUri); 
            } 

            return rootObject; 
        }
示例#40
0
        /// <summary> 
        /// Reads XAML from the passed stream, building an object tree and returning the
        /// root of that tree.  Wrap a CompatibilityReader with another XmlReader that 
        /// uses the passed reader settings to allow validation of xaml.
        /// </summary>
        /// <param name="reader">XmlReader to use.  This is NOT wrapped by any
        ///  other reader</param> 
        /// <param name="context">Optional parser context.  May be null </param>
        /// <param name="parseMode">Sets synchronous or asynchronous parsing</param> 
        /// <returns>object root generated after xml parsed</returns> 
        // Note this is the internal entry point for XPS.  XPS calls here so
        // its reader is not wrapped with a Markup Compat Reader. 
        internal static object Load(
            XmlReader reader,
            ParserContext parserContext,
            XamlParseMode parseMode) 
        {
            if (parseMode == XamlParseMode.Uninitialized || 
                parseMode == XamlParseMode.Asynchronous) 
            {
                XamlReader xamlReader = new XamlReader(); 
                return xamlReader.LoadAsync(reader, parserContext);
            }

            if (parserContext == null) 
            {
                parserContext = new ParserContext(); 
            } 

#if DEBUG_CLR_MEM 
            bool clrTracingEnabled = false;
            // Use local pass variable to correctly log nested parses.
            int pass = 0;
 
            if (CLRProfilerControl.ProcessIsUnderCLRProfiler &&
               (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance)) 
            { 
                clrTracingEnabled = true;
                pass = ++_CLRXamlPass; 
                CLRProfilerControl.CLRLogWriteLine("Begin_XamlParse_{0}", pass);
            }
#endif // DEBUG_CLR_MEM
 
            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlBegin, parserContext.BaseUri);
 
            if (TraceMarkup.IsEnabled) 
            {
                TraceMarkup.Trace(TraceEventType.Start, TraceMarkup.Load); 
            }
            object root = null;
            try
            { 

                if (parserContext.BaseUri == null || 
                    String.IsNullOrEmpty(parserContext.BaseUri.ToString())) 
                {
                    if (reader.BaseURI == null || 
                        String.IsNullOrEmpty(reader.BaseURI.ToString()))
                    {
                        parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                    } 
                    else
                    { 
                        parserContext.BaseUri = new Uri(reader.BaseURI); 
                    }
                } 

                System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
                settings.IgnoreUidsOnPropertyElements = true;
                settings.BaseUri = parserContext.BaseUri; 
                settings.ProvideLineInfo = true;
 
                XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ? 
                    parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext();
                System.Xaml.XamlXmlReader xamlXmlReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings); 
                root = Load(xamlXmlReader, parserContext);
                reader.Close();
            }
            catch (Exception e) 
            {
                // Don't wrap critical exceptions or already-wrapped exceptions. 
                if(MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri)) 
                {
                    throw; 
                }
                RewrapException(e, parserContext.BaseUri);
            }
            finally 
            {
                if (TraceMarkup.IsEnabled) 
                { 
                    TraceMarkup.Trace(TraceEventType.Stop, TraceMarkup.Load, root);
                } 

                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlEnd, parserContext.BaseUri);

#if DEBUG_CLR_MEM 
                if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
                { 
                    CLRProfilerControl.CLRLogWriteLine("End_XamlParse_{0}", pass); 
                }
#endif // DEBUG_CLR_MEM 
            }
            return root;
        }
示例#41
0
        /// <summary>
        /// エフェクトをファイルから読み込みます。
        /// </summary>
        /// <remarks>
        /// エフェクトファイルは以下のファイルから検索されます。
        /// 
        /// 1、{ディレクトリ名}/{エフェクト名}/{エフェクト名}.xaml
        /// 2、{ディレクトリ名}/{エフェクト名}/Effect.xaml
        /// 3、{ディレクトリ名}/{エフェクト名}.xaml
        /// </remarks>
        private static EffectObject LoadInternal(string basePath,
                                                 Dictionary<string, object> args)
        {
            try
            {
                // エフェクトファイルの検索
                var path = EnumeratePath(basePath)
                    .FirstOrDefault(_ => File.Exists(_));
                if (string.IsNullOrEmpty(path))
                {
                    throw new FileNotFoundException(
                        basePath + ": エフェクトが見つかりません。");
                }

                // エフェクト引数の置換
                byte[] bytes = null;
                if (args == null || !args.Any())
                {
                    bytes = Util.ReadFile(path);
                }
                else
                {
                    // ファイル中の変数を置き換えます。
                    var text = Util.ReadFile(path, Encoding.UTF8);
                    text = ReplaceTable(text, args);

                    bytes = Encoding.UTF8.GetBytes(text);
                }

                // xamlの読み込みを開始します。
                using (var stream = new MemoryStream(bytes))
                {
                    var settings = new XamlXmlReaderSettings
                    {
                        BaseUri = new Uri(path), //, UriKind.Absolute),
                        CloseInput = false,
                    };
                    var context = new XamlSchemaContext(GetReferenceAssemblies());

					var reader = new XamlXmlReader(stream, context, settings);
                    var obj = XamlServices.Load(reader);

                    var result = obj as EffectObject; 
                    if (result != null)
                    {
                        result.BasePath = Path.GetDirectoryName(path);
                        //result.Name = param.Name;
                    }

                    return result;
                }
            }
            catch (Exception ex)
            {
                Log.ErrorException(ex,
                    "'{0}': エフェクトの読み込みに失敗しました。", basePath);

                return null;
                //throw ex;
            }
        }
示例#42
0
		public XamlXmlReader (XmlReader xmlReader, XamlXmlReaderSettings settings)
			: this (xmlReader, new XamlSchemaContext (null, null), settings)
		{
		}
示例#43
0
        /// <summary>
        /// Reads XAML from the passed stream, building an object tree and returning the
        /// root of that tree.  Wrap a CompatibilityReader with another XmlReader that
        /// uses the passed reader settings to allow validation of xaml.
        /// </summary>
        /// <param name="reader">XmlReader to use.  This is NOT wrapped by any
        ///  other reader</param>
        /// <param name="context">Optional parser context.  May be null </param>
        /// <param name="parseMode">Sets synchronous or asynchronous parsing</param>
        /// <returns>object root generated after xml parsed</returns>
        // Note this is the internal entry point for XPS.  XPS calls here so
        // its reader is not wrapped with a Markup Compat Reader.
        internal static object Load(
            XmlReader reader,
            ParserContext parserContext,
            XamlParseMode parseMode)
        {
            if (parseMode == XamlParseMode.Uninitialized ||
                parseMode == XamlParseMode.Asynchronous)
            {
                XamlReader xamlReader = new XamlReader();
                return(xamlReader.LoadAsync(reader, parserContext));
            }

            if (parserContext == null)
            {
                parserContext = new ParserContext();
            }

#if DEBUG_CLR_MEM
            bool clrTracingEnabled = false;
            // Use local pass variable to correctly log nested parses.
            int pass = 0;

            if (CLRProfilerControl.ProcessIsUnderCLRProfiler &&
                (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
            {
                clrTracingEnabled = true;
                pass = ++_CLRXamlPass;
                CLRProfilerControl.CLRLogWriteLine("Begin_XamlParse_{0}", pass);
            }
#endif // DEBUG_CLR_MEM

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlBegin, parserContext.BaseUri);

            if (TraceMarkup.IsEnabled)
            {
                TraceMarkup.Trace(TraceEventType.Start, TraceMarkup.Load);
            }
            object root = null;
            try
            {
                if (parserContext.BaseUri == null ||
                    String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
                {
                    if (reader.BaseURI == null ||
                        String.IsNullOrEmpty(reader.BaseURI.ToString()))
                    {
                        parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                    }
                    else
                    {
                        parserContext.BaseUri = new Uri(reader.BaseURI);
                    }
                }

                System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
                settings.IgnoreUidsOnPropertyElements = true;
                settings.BaseUri         = parserContext.BaseUri;
                settings.ProvideLineInfo = true;

                XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ?
                                                  parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext();
                System.Xaml.XamlXmlReader xamlXmlReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings);
                root = Load(xamlXmlReader, parserContext);
                reader.Close();
            }
            catch (Exception e)
            {
                // Don't wrap critical exceptions or already-wrapped exceptions.
                if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri))
                {
                    throw;
                }
                RewrapException(e, parserContext.BaseUri);
            }
            finally
            {
                if (TraceMarkup.IsEnabled)
                {
                    TraceMarkup.Trace(TraceEventType.Stop, TraceMarkup.Load, root);
                }

                EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml, EventTrace.Event.WClientParseXmlEnd, parserContext.BaseUri);

#if DEBUG_CLR_MEM
                if (clrTracingEnabled && (CLRProfilerControl.CLRLoggingLevel >= CLRProfilerControl.CLRLogState.Performance))
                {
                    CLRProfilerControl.CLRLogWriteLine("End_XamlParse_{0}", pass);
                }
#endif // DEBUG_CLR_MEM
            }
            return(root);
        }
示例#44
0
 public XamlXmlReader(XmlReader xmlReader, XamlXmlReaderSettings settings)
     : this(xmlReader, new XamlSchemaContext(null, null), settings)
 {
 }
示例#45
0
        static void testReadXaml()
        {
            string[] resources = typeof(SESampleProcess2).Assembly.GetManifestResourceNames();
            string resourceName = null;
            for (int i = 0; (i < resources.Length); i = (i + 1))
            {
                resourceName = resources[i];
                if ((resourceName.Contains(".SESampleProcess2.g.xaml") || resourceName.Equals("SESampleProcess2.g.xaml")))
                {
                    break;
                }
            }
            //resourceName=@"D:\WorkSpaces\Tracking\TrackingStateMachine\SESampleProcess2.xaml";

            //System.IO.Stream initializeXaml = new FileStream(resourceName,FileMode.Open);// typeof(SESampleProcess2).Assembly.GetManifestResourceStream(resourceName);
            System.IO.Stream initializeXaml = typeof(SESampleProcess2).Assembly.GetManifestResourceStream(resourceName);
            StreamReader sr = new StreamReader(initializeXaml);
            Console.WriteLine(sr.ReadToEnd());
            //System.Xml.XmlReader xmlReader = null;
            System.Xaml.XamlReader reader = null;

            System.Xaml.XamlSchemaContext schemaContext = XamlStaticHelperNamespace._XamlStaticHelper.SchemaContext;
            //xmlReader = System.Xml.XmlReader.Create(initializeXaml);
            System.Xaml.XamlXmlReaderSettings readerSettings = new System.Xaml.XamlXmlReaderSettings();
            readerSettings.LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly();

            reader = new XamlXmlReader(initializeXaml,schemaContext, readerSettings);

            Activity a = ActivityXamlServices.Load(reader);
            StateMachine sm = (StateMachine)a;

            Console.WriteLine();
            //ShitProcess sp = new ShitProcess();
            //SESampleProcess2 ss = new SESampleProcess2();
            //StateMachine sm = new StateMachine();

            //string[] resources = typeof(SESampleProcess2).Assembly.GetManifestResourceNames();
            //string resourceName = null;
            //for (int i = 0; (i < resources.Length); i = (i + 1))
            //{
            //    resourceName = resources[i];
            //    if ((resourceName.Contains(".SESampleProcess2.g.xaml") || resourceName.Equals("SESampleProcess2.g.xaml")))
            //    {
            //        break;
            //    }
            //}
            //System.IO.Stream initializeXaml = typeof(SESampleProcess2).Assembly.GetManifestResourceStream(resourceName);
            //Console.WriteLine(initializeXaml.ToString());
            //System.Xml.XmlReader xmlReader = null;
            //System.Xaml.XamlReader reader = null;
            //System.Xaml.XamlObjectWriter objectWriter = null;
            //try
            //{
            //    System.Xaml.XamlSchemaContext schemaContext = XamlStaticHelperNamespace._XamlStaticHelper.SchemaContext;
            //    xmlReader = System.Xml.XmlReader.Create(initializeXaml);
            //    System.Xaml.XamlXmlReaderSettings readerSettings = new System.Xaml.XamlXmlReaderSettings();
            //    readerSettings.LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            //    readerSettings.AllowProtectedMembersOnRoot = true;
            //    reader = new System.Xaml.XamlXmlReader(xmlReader, schemaContext, readerSettings);
            //    System.Xaml.XamlObjectWriterSettings writerSettings = new System.Xaml.XamlObjectWriterSettings();
            //    writerSettings.RootObjectInstance = sm;
            //    writerSettings.AccessLevel = System.Xaml.Permissions.XamlAccessLevel.PrivateAccessTo(typeof(SESampleProcess2));
            //    objectWriter = new System.Xaml.XamlObjectWriter(schemaContext, writerSettings);
            //    System.Xaml.XamlServices.Transform(reader, objectWriter);
            //}
            //finally
            //{
            //    if ((xmlReader != null))
            //    {
            //        ((System.IDisposable)(xmlReader)).Dispose();
            //    }
            //    if ((reader != null))
            //    {
            //        ((System.IDisposable)(reader)).Dispose();
            //    }
            //    if ((objectWriter != null))
            //    {
            //        ((System.IDisposable)(objectWriter)).Dispose();
            //    }
            //}

            Console.WriteLine();
            //string resourceName = this.FindResource();
            //System.IO.Stream initializeXaml = typeof(SESampleProcess2).Assembly.GetManifestResourceStream(resourceName);
        }
示例#46
0
		public XamlXmlReader (TextReader textReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
			: this (XmlReader.Create (textReader), schemaContext, settings)
		{
		}
示例#47
0
 public XamlXmlReader(string fileName, XamlXmlReaderSettings settings)
     : this(fileName, new XamlSchemaContext(null, null), settings)
 {
 }
示例#48
0
		public XamlXmlReader (XmlReader xmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
		{
			if (xmlReader == null)
				throw new ArgumentNullException ("xmlReader");
			if (schemaContext == null)
				throw new ArgumentNullException ("schemaContext");

			sctx = schemaContext;
			this.settings = settings ?? new XamlXmlReaderSettings ();

			// filter out some nodes.
			var xrs = new XmlReaderSettings () {
				CloseInput = this.settings.CloseInput,
				IgnoreComments = true,
				IgnoreProcessingInstructions = true,
				IgnoreWhitespace = true };

			r = XmlReader.Create (xmlReader, xrs);
			line_info = r as IXmlLineInfo;
			xaml_namespace_resolver = new NamespaceResolver (r as IXmlNamespaceResolver);
		}
示例#49
0
		public XamlXmlReader (Stream stream, XamlXmlReaderSettings settings)
			: this (stream, new XamlSchemaContext (null, null), settings)
		{
		}
示例#50
0
		public XamlXmlReader (Stream stream, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
			: this (XmlReader.Create (stream), schemaContext, settings)
		{
		}
示例#51
0
		public XamlXmlReader (XmlReader xmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
		{
			parser = new XamlXmlParser (xmlReader, schemaContext, settings);
		}
示例#52
0
 public XamlXmlReader(Stream stream, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
     : this(XmlReader.Create(stream), schemaContext, settings)
 {
 }
 internal static object LoadXaml(Stream activityStream)
 {
     object serviceObject;
     XamlXmlReaderSettings xamlXmlReaderSettings = new XamlXmlReaderSettings();
     xamlXmlReaderSettings.ProvideLineInfo = true;
     XamlReader wrappedReader = ActivityXamlServices.CreateReader(new XamlXmlReader(XmlReader.Create(activityStream), xamlXmlReaderSettings));
     if (TD.XamlServicesLoadStartIsEnabled())
     {
         TD.XamlServicesLoadStart();
     }
     serviceObject = XamlServices.Load(wrappedReader);
     if (TD.XamlServicesLoadStopIsEnabled())
     {
         TD.XamlServicesLoadStop();
     }
     return serviceObject;
 }
示例#54
0
		public XamlXmlReader (string fileName, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
			: this (XmlReader.Create (fileName, file_reader_settings), schemaContext, settings)
		{
		}
示例#55
0
        private void Initialize(XmlReader givenXmlReader, XamlSchemaContext schemaContext, XamlXmlReaderSettings settings)
        {
            XmlReader myXmlReader;

            _mergedSettings = (settings == null) ? new XamlXmlReaderSettings() : new XamlXmlReaderSettings(settings);
            //Wrap the xmlreader with a XmlCompatReader instance to apply MarkupCompat rules.
            if (!_mergedSettings.SkipXmlCompatibilityProcessing)
            {
                XmlCompatibilityReader mcReader =
                    new XmlCompatibilityReader(givenXmlReader,
                                               new IsXmlNamespaceSupportedCallback(IsXmlNamespaceSupported)
                                               );
                mcReader.Normalization = true;
                myXmlReader            = mcReader;
            }
            else
            {   //Don't wrap the xmlreader with XmlCompatReader.
                // Useful for uses where users want to keep mc: content in the XamlNode stream.
                // Or have already processed the markup compat and want that extra perf.
                myXmlReader = givenXmlReader;
            }
            // Pick up the XmlReader settings to override the "settings" defaults.
            if (!String.IsNullOrEmpty(myXmlReader.BaseURI))
            {
                _mergedSettings.BaseUri = new Uri(myXmlReader.BaseURI);
            }
            if (myXmlReader.XmlSpace == XmlSpace.Preserve)
            {
                _mergedSettings.XmlSpacePreserve = true;
            }
            if (!String.IsNullOrEmpty(myXmlReader.XmlLang))
            {
                _mergedSettings.XmlLang = myXmlReader.XmlLang;
            }
            IXmlNamespaceResolver       myXmlReaderNS   = myXmlReader as IXmlNamespaceResolver;
            Dictionary <string, string> xmlnsDictionary = null;

            if (myXmlReaderNS != null)
            {
                IDictionary <string, string> rootNamespaces = myXmlReaderNS.GetNamespacesInScope(XmlNamespaceScope.Local);
                if (rootNamespaces != null)
                {
                    foreach (KeyValuePair <string, string> ns in rootNamespaces)
                    {
                        if (xmlnsDictionary == null)
                        {
                            xmlnsDictionary = new Dictionary <string, string>();
                        }
                        xmlnsDictionary[ns.Key] = ns.Value;
                    }
                }
            }

            if (schemaContext == null)
            {
                schemaContext = new XamlSchemaContext();
            }

            _endOfStreamNode = new XamlNode(XamlNode.InternalNodeType.EndOfStream);

            _context = new XamlParserContext(schemaContext, _mergedSettings.LocalAssembly);
            _context.AllowProtectedMembersOnRoot = _mergedSettings.AllowProtectedMembersOnRoot;
            _context.AddNamespacePrefix(KnownStrings.XmlPrefix, XamlLanguage.Xml1998Namespace);

            Func <string, string> namespaceResolver = myXmlReader.LookupNamespace;

            _context.XmlNamespaceResolver = namespaceResolver;

            XamlScanner    xamlScanner = new XamlScanner(_context, myXmlReader, _mergedSettings);
            XamlPullParser parser      = new XamlPullParser(_context, xamlScanner, _mergedSettings);

            _nodeStream      = new NodeStreamSorter(_context, parser, _mergedSettings, xmlnsDictionary);
            _current         = new XamlNode(XamlNode.InternalNodeType.StartOfStream); // user must call Read() before using properties.
            _currentLineInfo = new LineInfo(0, 0);
        }
        XamlNodeList ReadXamlNodes(string xamlFileName)
        {
            XamlNodeList nodeList = new XamlNodeList(this.SchemaContext);

            try
            {
                XamlXmlReaderSettings settings = new XamlXmlReaderSettings
                {
                    AllowProtectedMembersOnRoot = true,
                    ProvideLineInfo = true
                };

                using (StreamReader streamReader = new StreamReader(xamlFileName))
                {
                    XamlReader reader = new XamlXmlReader(XmlReader.Create(streamReader), this.SchemaContext, settings);
                    XamlServices.Transform(reader, nodeList.Writer);
                }
            }
            catch (XmlException e)
            {
                XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, xamlFileName, e.LineNumber, e.LinePosition); 
                return null;
            }
            catch (XamlException e)
            {
                XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, xamlFileName, e.LineNumber, e.LinePosition);
                return null;
            }
            
            if (nodeList.Count > 0)
            {
                return nodeList;
            }
            else
            {
                return null;
            }
        }
示例#57
0
        private object LoadAsync(XmlReader reader, ParserContext parserContext)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (parserContext == null)
            {
                parserContext = new ParserContext();
            }

            _xmlReader = reader;
            object rootObject = null;

            if (parserContext.BaseUri == null ||
                String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
            {
                if (reader.BaseURI == null ||
                    String.IsNullOrEmpty(reader.BaseURI.ToString()))
                {
                    parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                }
                else
                {
                    parserContext.BaseUri = new Uri(reader.BaseURI);
                }
            }
            _baseUri = parserContext.BaseUri;
            System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
            settings.IgnoreUidsOnPropertyElements = true;
            settings.BaseUri         = parserContext.BaseUri;
            settings.ProvideLineInfo = true;
            XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ?
                                              parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext();

            try
            {
                _textReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings);

                _stack = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame());

                System.Xaml.XamlObjectWriterSettings objectSettings = XamlReader.CreateObjectWriterSettings();
                objectSettings.AfterBeginInitHandler = delegate(object sender, System.Xaml.XamlObjectEventArgs args)
                {
                    if (rootObject == null)
                    {
                        rootObject      = args.Instance;
                        _styleConnector = rootObject as IStyleConnector;
                    }

                    UIElement uiElement = args.Instance as UIElement;
                    if (uiElement != null)
                    {
                        uiElement.SetPersistId(_persistId++);
                    }

                    DependencyObject dObject = args.Instance as DependencyObject;
                    if (dObject != null && _stack.CurrentFrame.XmlnsDictionary != null)
                    {
                        XmlnsDictionary dictionary = _stack.CurrentFrame.XmlnsDictionary;
                        dictionary.Seal();

                        XmlAttributeProperties.SetXmlnsDictionary(dObject, dictionary);
                    }
                };

                _objectWriter            = new System.Xaml.XamlObjectWriter(_textReader.SchemaContext, objectSettings);
                _parseCancelled          = false;
                _skipJournaledProperties = parserContext.SkipJournaledProperties;

                XamlMember synchronousModeProperty   = _textReader.SchemaContext.GetXamlDirective("http://schemas.microsoft.com/winfx/2006/xaml", "SynchronousMode");
                XamlMember synchronousRecordProperty = _textReader.SchemaContext.GetXamlDirective("http://schemas.microsoft.com/winfx/2006/xaml", "AsyncRecords");

                System.Xaml.XamlReader xamlReader = _textReader;

                IXamlLineInfo         xamlLineInfo         = xamlReader as IXamlLineInfo;
                IXamlLineInfoConsumer xamlLineInfoConsumer = _objectWriter as IXamlLineInfoConsumer;
                bool shouldPassLineNumberInfo = false;
                if ((xamlLineInfo != null && xamlLineInfo.HasLineInfo) &&
                    (xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo))
                {
                    shouldPassLineNumberInfo = true;
                }

                bool async = false;
                bool lastPropWasSyncMode    = false;
                bool lastPropWasSyncRecords = false;

                while (!_textReader.IsEof)
                {
                    WpfXamlLoader.TransformNodes(xamlReader, _objectWriter, true /*onlyLoadOneNode*/, _skipJournaledProperties, shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer, _stack, _styleConnector);

                    if (xamlReader.NodeType == System.Xaml.XamlNodeType.StartMember)
                    {
                        if (xamlReader.Member == synchronousModeProperty)
                        {
                            lastPropWasSyncMode = true;
                        }
                        else if (xamlReader.Member == synchronousRecordProperty)
                        {
                            lastPropWasSyncRecords = true;
                        }
                    }
                    else if (xamlReader.NodeType == System.Xaml.XamlNodeType.Value)
                    {
                        if (lastPropWasSyncMode == true)
                        {
                            if (xamlReader.Value as String == "Async")
                            {
                                async = true;
                            }
                        }
                        else if (lastPropWasSyncRecords == true)
                        {
                            if (xamlReader.Value is int)
                            {
                                _maxAsynxRecords = (int)xamlReader.Value;
                            }
                            else if (xamlReader.Value is String)
                            {
                                _maxAsynxRecords = Int32.Parse(xamlReader.Value as String, TypeConverterHelper.InvariantEnglishUS);
                            }
                        }
                    }
                    else if (xamlReader.NodeType == System.Xaml.XamlNodeType.EndMember)
                    {
                        lastPropWasSyncMode    = false;
                        lastPropWasSyncRecords = false;
                    }

                    if (async && rootObject != null)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                // Don't wrap critical exceptions or already-wrapped exceptions.
                if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri))
                {
                    throw;
                }
                RewrapException(e, parserContext.BaseUri);
            }

            if (!_textReader.IsEof)
            {
                Post();
                //ThreadStart threadStart = new ThreadStart(ReadXamlAsync);
                //Thread thread = new Thread(threadStart);
                //thread.Start();
            }
            else
            {
                TreeBuildComplete();
            }

            if (rootObject is DependencyObject)
            {
                if (parserContext.BaseUri != null && !String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
                {
                    (rootObject as DependencyObject).SetValue(BaseUriHelper.BaseUriProperty, parserContext.BaseUri);
                }
                //else
                //    (rootObject as DependencyObject).SetValue(BaseUriHelper.BaseUriProperty, BaseUriHelper.PackAppBaseUri);
                WpfXamlLoader.EnsureXmlNamespaceMaps(rootObject, schemaContext);
            }

            Application app = rootObject as Application;

            if (app != null)
            {
                app.ApplicationMarkupBaseUri = GetBaseUri(settings.BaseUri);
            }

            return(rootObject);
        }
 bool ProcessMarkupItem(string markupItem, XamlNsReplacingContext wxsc, Assembly localAssembly)
 {
     XamlXmlReaderSettings settings = new XamlXmlReaderSettings() { LocalAssembly = localAssembly, ProvideLineInfo = true, AllowProtectedMembersOnRoot = true };
     using (StreamReader streamReader = new StreamReader(markupItem))
     {
         var xamlReader = new XamlXmlReader(XmlReader.Create(streamReader), wxsc, settings);
         ClassValidator validator = new ClassValidator(markupItem, localAssembly, this.RootNamespace);
         IList<LogData> validationErrors = null;
         if (validator.ValidateXaml(xamlReader, false, this.AssemblyName, out validationErrors))
         {
             return true;
         }
         else
         {
             foreach (LogData logData in validationErrors)
             {
                 this.LogData.Add(logData);
             }
             return false;
         }
     }
 }
示例#59
0
        internal static Activity ConvertXamlToActivity(string xaml, string[] dependentWorkflows,
                                                       Dictionary<string, string> requiredAssemblies,
                                                       ref string compiledAssemblyPath, ref Assembly compiledAssembly,
                                                       ref string compiledAssemblyName)
        {
            _structuredTracer.ImportedWorkflowFromXaml(Guid.Empty, string.Empty);
            Tracer.WriteMessage("Trying to convert Xaml into Activity and using additional xamls assembly.");

            if (string.IsNullOrEmpty(xaml))
            {
                ArgumentNullException exception = new ArgumentNullException("xaml", Resources.XamlNotNull);
                Tracer.TraceException(exception);
                _structuredTracer.ErrorImportingWorkflowFromXaml(Guid.Empty, exception.Message);
                throw exception;
            }

            Activity workflow;
            XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings();

            // If they passed in an assembly path, use it
            if (!String.IsNullOrEmpty(compiledAssemblyPath))
            {
                if (compiledAssembly == null && String.IsNullOrEmpty(compiledAssemblyName))
                {
                    compiledAssembly = Assembly.LoadFrom(compiledAssemblyPath);
                    compiledAssemblyName = compiledAssembly.GetName().Name;
                }

                readerSettings.LocalAssembly = compiledAssembly;
            }
            else if ((dependentWorkflows != null) && (dependentWorkflows.Length > 0))
            {
                // Otherwise, it's a first-time compilation
                string assemblyPath = CompileDependentWorkflowsToAssembly(dependentWorkflows, requiredAssemblies);
                readerSettings.LocalAssembly = Assembly.LoadFrom(assemblyPath);
                compiledAssemblyPath = assemblyPath;
                compiledAssembly = Assembly.LoadFrom(compiledAssemblyPath);
                compiledAssemblyName = compiledAssembly.GetName().Name;

                readerSettings.LocalAssembly = compiledAssembly;
            }

            using (StringReader sReader = new StringReader(xaml))
            {
                XamlXmlReader reader = new XamlXmlReader(sReader, readerSettings);
                workflow = ActivityXamlServices.Load(reader);
            }

            _structuredTracer.ImportedWorkflowFromXaml(Guid.Empty, string.Empty);

            return workflow;
        }
示例#60
0
		public XamlXmlReader (string fileName, XamlXmlReaderSettings settings)
			: this (fileName, new XamlSchemaContext (null, null), settings)
		{
		}