public static XElement TranslateString(string xamlFile) { string translatedWorkflowString = null; using (XamlReader xamlReader = new XamlXmlReader( new StringReader(xamlFile))) { TranslationResults result = ExpressionTranslator.Translate(xamlReader); if (result.Errors.Count == 0) { StringBuilder sb = new StringBuilder(); using (XmlWriter xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true })) { using (XamlXmlWriter writer = new XamlXmlWriter(xmlWriter, result.Output.SchemaContext)) { XamlServices.Transform(result.Output, writer); } } translatedWorkflowString = sb.ToString(); } else { string error = "Translation errors"; for (int i = 0; i < result.Errors.Count; i++ ) { error = error + " :::: [A:" + result.Errors[i].ActivityId + ", Line" + result.Errors[i].StartLine +"] \"" + result.Errors[i].ExpressionText + "\" (" + result.Errors[i].Message + ")"; } throw new InvalidOperationException(error); } } return XElement.Parse(translatedWorkflowString); }
public override Type GetGeneratedType(CompilerResults results) { Type type; try { using (Stream stream = base.OpenStream()) { XamlXmlReader reader2 = new XamlXmlReader(XmlReader.Create(stream)); while (reader2.Read()) { if (reader2.NodeType == XamlNodeType.StartObject) { if (reader2.Type.IsUnknown) { StringBuilder sb = new StringBuilder(); this.AppendTypeName(reader2.Type, sb); throw FxTrace.Exception.AsError(new TypeLoadException(System.Xaml.Hosting.SR.CouldNotResolveType(sb))); } return reader2.Type.UnderlyingType; } } throw FxTrace.Exception.AsError(new HttpCompileException(System.Xaml.Hosting.SR.UnexpectedEof)); } } catch (XamlParseException exception) { throw FxTrace.Exception.AsError(new HttpCompileException(exception.Message, exception)); } return type; }
/// <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"); } }
public static Activity XamlToActivity(string xaml) { StringReader stringReader = new StringReader(xaml); XmlReader xmlReader = XmlReader.Create(stringReader); XamlXmlReader xamlXmlReader = new XamlXmlReader ( xmlReader , new XamlXmlReaderSettings() { LocalAssembly = Assembly.GetExecutingAssembly() } ); XamlReader xamlReader = ActivityXamlServices.CreateReader ( xamlXmlReader ); Activity activity = ActivityXamlServices.Load ( xamlReader , new ActivityXamlServicesSettings() { //CompileExpressions = true } ); return activity; }
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; } }
public void Parse(string input, string[] args = null) { var xxr = new XamlXmlReader(new StringReader(input), new XamlSchemaContext()); var graphReader = new XamlObjectWriter(xxr.SchemaContext); while (xxr.Read()) graphReader.WriteNode(xxr); var page = (Page)graphReader.Result; // Map our generators var g = new Generator(); g.Map<Page, PageGeneratorBlock>(); g.Map<Button, ButtonGeneratorBlock>(); g.Map<StackPanel, StackPanelGeneratorBlock>(); var doc = new HtmlDocument(); var html = doc.CreateElement("html"); g.Generate(html, page); // HTML5 Doc type doc.DocumentNode.AppendChild(doc.CreateComment("<!DOCTYPE html>")); doc.DocumentNode.AppendChild(html); doc.Save("test.htm"); var cssContents = g.GenerateStyles(page); File.WriteAllText("XamlCore.css", cssContents); }
static void InvokeActivity(string serializedActivity) { var stringReader = new StringReader(serializedActivity); var xamlXmlReader = new XamlXmlReader(stringReader, new XamlXmlReaderSettings { LocalAssembly = Assembly.GetExecutingAssembly() }); var xamlReader = ActivityXamlServices.CreateReader(xamlXmlReader); var activity = ActivityXamlServices.Load(xamlReader, new ActivityXamlServicesSettings { CompileExpressions = true }); var settings = new VisualBasicSettings(); settings.ImportReferences.Add(new VisualBasicImportReference { Assembly = typeof (HttpClient).Assembly.GetName().Name, Import = typeof (HttpClient).Namespace }); VisualBasic.SetSettings(activity, settings); WorkflowInvoker.Invoke(activity, new Dictionary<string, object> { {"HttpClient", new HttpClient()} }); }
public static void Load(Stream stream, object component) { DependencyObject dependencyObject = component as DependencyObject; NameScope nameScope = new NameScope(); if (dependencyObject != null) { NameScope.SetNameScope(dependencyObject, nameScope); } XmlReader xml = XmlReader.Create(stream); XamlXmlReader reader = new XamlXmlReader(xml); XamlObjectWriter writer = new XamlObjectWriter( new XamlSchemaContext(), new XamlObjectWriterSettings { RootObjectInstance = component, ExternalNameScope = nameScope, RegisterNamesOnExternalNamescope = true, XamlSetValueHandler = SetValue, }); while (reader.Read()) { writer.WriteNode(reader); } }
public static XElement Translate(string xamlFile) { string translatedWorkflowString = null; using (XamlReader xamlReader = new XamlXmlReader(xamlFile)) { TranslationResults result = ExpressionTranslator.Translate(xamlReader); if (result.Errors.Count == 0) { StringBuilder sb = new StringBuilder(); using (XmlWriter xmlWriter = XmlWriter.Create(sb, new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true })) { using (XamlXmlWriter writer = new XamlXmlWriter(xmlWriter, result.Output.SchemaContext)) { XamlServices.Transform(result.Output, writer); } } translatedWorkflowString = sb.ToString(); } else { throw new InvalidOperationException("Translation errors"); } } return XElement.Parse(translatedWorkflowString); }
static void Main(string[] args) { if (2 != args.Length) { Console.WriteLine("Usage -- ViewStateCleaningWriter <infile> <outfile>"); return; } try { XmlReader xmlReader = XmlReader.Create(args[0]); XamlXmlReader xamlReader = new XamlXmlReader(xmlReader); ActivityBuilder ab = XamlServices.Load(ActivityXamlServices.CreateBuilderReader(xamlReader)) as ActivityBuilder; XmlWriterSettings writerSettings = new XmlWriterSettings { Indent = true }; XmlWriter xmlWriter = XmlWriter.Create(File.OpenWrite(args[1]), writerSettings); XamlXmlWriter xamlWriter = new XamlXmlWriter(xmlWriter, new XamlSchemaContext()); XamlServices.Save(new ViewStateCleaningWriter(ActivityXamlServices.CreateBuilderWriter(xamlWriter)), ab); Console.WriteLine("{0} written without viewstate information", args[1]); } catch (Exception ex) { Console.WriteLine("Exception encountered {0}", ex); } }
/// <summary> /// Loads the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <returns> /// The loaded <see cref="Server"/> instance if the configuration is valid; /// <c>null</c> otherwise. /// </returns> public Server Load(Stream stream) { logger.Debug("Loading configuration from stream"); var reader = new XamlXmlReader(stream, this.context); var writer = this.Writer ?? new XamlObjectWriter(this.context); XamlServices.Transform(reader, writer); var server = writer.Result as Server; return server; }
public static object Load(XmlReader xmlReader) { if (xmlReader == null) { throw new ArgumentNullException("xmlReader"); } using (XamlXmlReader reader = new XamlXmlReader(xmlReader)) { return Load(reader); } }
public static object Load(XmlReader xmlReader) { if (xmlReader == null) { throw new ArgumentNullException("xmlReader"); } using (XamlXmlReader reader = new XamlXmlReader(xmlReader)) { return(Load(reader)); } }
public static Activity Clone(this Activity activity) { StringWriter writer = new StringWriter(); XamlXmlWriter xamlWriter = new XamlXmlWriter(writer, new XamlSchemaContext()); XamlServices.Save(xamlWriter, activity); StringReader reader = new StringReader(writer.ToString()); XamlXmlReader xamlReader = new XamlXmlReader(reader); return XamlServices.Load(xamlReader) as Activity; }
public static object Load(TextReader textReader) { if (textReader == null) { throw new ArgumentNullException("textReader"); } using (XmlReader reader = XmlReader.Create(textReader)) { XamlXmlReader xamlReader = new XamlXmlReader(reader); return Load(xamlReader); } }
public static object Load(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } using (XmlReader reader = XmlReader.Create(fileName)) { XamlXmlReader xamlReader = new XamlXmlReader(reader); return Load(xamlReader); } }
public static object Load(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } using (XmlReader reader = XmlReader.Create(stream)) { XamlXmlReader xamlReader = new XamlXmlReader(reader); return(Load(xamlReader)); } }
public static object Load(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } using (XmlReader reader = XmlReader.Create(fileName)) { XamlXmlReader xamlReader = new XamlXmlReader(reader); return(Load(xamlReader)); } }
public static object Load(TextReader textReader) { if (textReader == null) { throw new ArgumentNullException("textReader"); } using (XmlReader reader = XmlReader.Create(textReader)) { XamlXmlReader xamlReader = new XamlXmlReader(reader); return(Load(xamlReader)); } }
public static object Load(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } using (XmlReader reader = XmlReader.Create(stream)) { XamlXmlReader xamlReader = new XamlXmlReader(reader); return Load(xamlReader); } }
private void Analyze(XamlXmlReader reader) { Stack<XamlType> objectTypes = new Stack<XamlType>(); Stack<MemberType> nameStack = new Stack<MemberType>(); Stack<XamlMember> eventStack = new Stack<XamlMember>(); while (reader.Read()) { switch (reader.NodeType) { case XamlNodeType.StartObject: objectTypes.Push(reader.Type); break; case XamlNodeType.EndObject: if (objectTypes.Count > 0) { objectTypes.Pop(); } break; case XamlNodeType.NamespaceDeclaration: break; case XamlNodeType.StartMember: var property = reader.Member; if (property.Name == "Name" && property.Type.UnderlyingType == typeof(string)) { nameStack.Push(MemberType.XName); } else if (property.IsEvent) { nameStack.Push(MemberType.Event); eventStack.Push(property); } else { nameStack.Push(MemberType.Unknown); } break; case XamlNodeType.EndMember: if (nameStack.Pop() == MemberType.Event) { eventStack.Pop(); } break; case XamlNodeType.GetObject: case XamlNodeType.Value: object value = reader.Value; if (value is string) { switch (nameStack.Peek()) { case MemberType.XName: // we are writing a x:Name, save it so we can later get the name from the scope _knownTypes[(string)value] = new XamlTypeReference(objectTypes.Peek(), reader.LineNumber, reader.LinePosition); break; case MemberType.Event: // we have an event handler, save the method name and the XamlMember for the event _eventInfo[(string)value] = new XamlMemberReference(eventStack.Peek(), reader.LineNumber, reader.LinePosition); break; } } break; } } }
private object Load(XamlXmlReader reader) { XamlObjectWriter writer = new ObjectWriter(); while (reader.Read()) { writer.WriteNode(reader); } writer.Close(); reader.Close(); if (writer.Result is DependencyObject && !(writer is INameScope)) ((DependencyObject)writer.Result).SetValue(NameScope.NameScopeProperty, writer.RootNameScope); return writer.Result; }
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. } }
public object LoadContent() { _Cache.Position = 0; XamlReader reader = new XamlXmlReader(_Cache, _SchemaContext); XamlObjectWriter writer = new Wodsoft.Web.Xaml.ObjectWriter(reader.SchemaContext); while (reader.Read()) { writer.WriteNode(reader); } writer.Close(); reader.Close(); return writer.Result; }
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; }
public static object Parse(string xaml) { if (xaml == null) { throw new ArgumentNullException("xaml"); } StringReader input = new StringReader(xaml); using (XmlReader reader2 = XmlReader.Create(input)) { XamlXmlReader xamlReader = new XamlXmlReader(reader2); return Load(xamlReader); } }
public static IWorkflow Parse(String xaml) { var input = new StringReader(xaml); using (XmlReader reader = XmlReader.Create(input)) { var xamlSchemaContext = new CustomXamlSchemaContext(); using (var xamlReader = new XamlXmlReader(reader, xamlSchemaContext)) { var xamlWriter = new CustomXamlObjectWriter(xamlSchemaContext); XamlServices.Transform(xamlReader, xamlWriter); return xamlWriter.Result as IWorkflow; } } }
public static object Parse(string xaml) { if (xaml == null) { throw new ArgumentNullException("xaml"); } StringReader input = new StringReader(xaml); using (XmlReader reader2 = XmlReader.Create(input)) { XamlXmlReader xamlReader = new XamlXmlReader(reader2); return(Load(xamlReader)); } }
public static void GetNamespacesLineInfo(string sourceXamlFileName, Dictionary<string, int> lineNumbersForNSes, Dictionary<string, int> lineNumbersForNSesForImpl) { // read until StartMember: TextExpression.NamespacesForImplementation OR TextExpression.Namespaces // create a subtree reader, // in the subtree, // look for StartObject nodes of String type. their values are added to either LineNumbersForNSes or LineNumbersForNSesForImpl dictionaries. if (!File.Exists(sourceXamlFileName)) { return; } using (XmlReader xmlReader = XmlReader.Create(sourceXamlFileName)) { using (XamlXmlReader xreader = new XamlXmlReader(xmlReader, new XamlXmlReaderSettings() { ProvideLineInfo = true })) { bool hasHitFirstStartObj = false; while (!hasHitFirstStartObj && xreader.Read()) { if (xreader.NodeType == XamlNodeType.StartObject) { hasHitFirstStartObj = true; } } if (hasHitFirstStartObj) { xreader.Read(); do { if (IsStartMemberTextExprNS(xreader)) { XamlReader subTreeReader = xreader.ReadSubtree(); WalkSubTree(subTreeReader, lineNumbersForNSes); } else if (IsStartMemberTextExprNSForImpl(xreader)) { XamlReader subTreeReader = xreader.ReadSubtree(); WalkSubTree(subTreeReader, lineNumbersForNSesForImpl); } else { xreader.Skip(); } } while (!xreader.IsEof); } } } }
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. } }
// The main function is Load(XamlReader) // all the other helper functions call this. // This allows the policy that the 2nd arg defaults to ObjectWriter // to be in one place. public static object Parse(string xaml) { if (xaml == null) { throw new ArgumentNullException(nameof(xaml)); } StringReader stringReader = new StringReader(xaml); using (XmlReader xmlReader = XmlReader.Create(stringReader)) { XamlXmlReader xamlReader = new XamlXmlReader(xmlReader); return(Load(xamlReader)); } }
public static string TranslateWorkflow(string originalWorkflow) { using (var inputWorkflowReader = new StringReader(originalWorkflow)) using (var xamlReader = new XamlXmlReader(inputWorkflowReader)) { var result = ExpressionTranslator.Translate(xamlReader); if (result.Errors.Count > 0) { var message = CreateErrorMessage(result); throw new ApplicationException(message); } else return CreateXamlString(result.Output); } }
public MainWindow() { InitializeComponent(); using (var reader = new XamlXmlReader("./Button.xaml")) using (var writer = new XamlXmlWriter(new FileStream("./Test.xaml", FileMode.Create), reader.SchemaContext)) { while (reader.Read()) { writer.WriteNode(reader); } } using (var reader = new XamlObjectReader(new Button())) using (var writer = new XamlObjectWriter(reader.SchemaContext)) { while (reader.Read()) { writer.WriteNode(reader); } var button = (Button)writer.Result; } using (var reader = new XamlXmlReader(new StringReader("<Button xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">This is a button</Button>"))) using (var writer = new XamlObjectWriter(reader.SchemaContext)) { while (reader.Read()) { writer.WriteNode(reader); } var button = (Button)writer.Result; } var button1 = (Button)XamlServices.Load("./Button.xaml"); var button2 = XamlServices.Load(new XamlObjectReader(new Button())); var button3 = XamlServices.Load(new StringReader("<Button xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">This is a button</Button>")); var button4 = XamlServices.Parse("<Button xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">This is a button</Button>"); XamlServices.Save("./Test2.xaml", new Button()); //DispatcherObject methods, hidden from intellisense via the EditorBrowsableAttribute button1.CheckAccess(); button1.VerifyAccess(); }
public static object DeserializeString(string text) { var xamlSchemaContextCWithFullyQualifiedNameSupport = new XamlSchemaContext(new XamlSchemaContextSettings { FullyQualifyAssemblyNamesInClrNamespaces = false }); using (XamlXmlReader xamlXmlReader = new XamlXmlReader(XmlReader.Create(new StringReader(text)), xamlSchemaContextCWithFullyQualifiedNameSupport, new XamlXmlReaderSettings { ProvideLineInfo = true })) { using (System.Xaml.XamlReader activityBuilderReader = ActivityXamlServices.CreateBuilderReader(xamlXmlReader, xamlSchemaContextCWithFullyQualifiedNameSupport)) { XamlObjectWriter objectWriter = new XamlObjectWriter(activityBuilderReader.SchemaContext); XamlServices.Transform(activityBuilderReader, objectWriter); return objectWriter.Result; } } }
public void start() { using(new NSAutoreleasePool()) { var frame = window.Frame; var directory = Path.Combine(NSBundle.MainBundle.ResourcePath,"MainPage.xaml"); XamlXmlReader reader = new XamlXmlReader(directory); mainPage = (MainPage)XamlServices.Load(reader); mainPage.Frame = frame; this.InvokeOnMainThread( delegate { loadingLabel.RemoveFromSuperview(); loadingLabel = null; mainvc.View.AddSubview(mainPage); }); TextReader tr = new StreamReader(Path.Combine(NSBundle.MainBundle.ResourcePath,"load.xaml")); var tb = mainPage.FindName("CodeTb"); ((XamlForIphone.UITextView)tb).Text = tr.ReadToEnd() ; } }
/// <summary> /// Loads XAML from the specified XamlXmlReader and returns the deserialized object. Any event handlers /// are bound to methods defined in the provided Scope and converted using the provided DynamicOperations /// object. /// </summary> public static object LoadComponent(dynamic scope, DynamicOperations operations, XamlXmlReader reader) { var settings = new XamlObjectWriterSettings(); settings.RootObjectInstance = scope; var myWriter = new DynamicWriter((object)scope, operations, reader.SchemaContext, settings); while (reader.Read()) { myWriter.WriteNode(reader); } foreach (string name in myWriter.Names) { object value = myWriter.RootNameScope.FindName(name); if (value != null) { operations.SetMember((object)scope, name, value); } } return myWriter.Result; }
//从[ActivityBuilder]对象得到[xaml]字串 public static ActivityBuilder activityBuilderFromXaml(string xaml) { ActivityBuilder activityBuilder = null; System.IO.StringReader stringReader = new System.IO.StringReader(xaml); System.Xaml.XamlXmlReader xamlXmlReader = new System.Xaml.XamlXmlReader(stringReader); System.Xaml.XamlReader xamlReader = ActivityXamlServices.CreateBuilderReader(xamlXmlReader); activityBuilder = System.Xaml.XamlServices.Load(xamlReader) as ActivityBuilder; if (activityBuilder != null) { return(activityBuilder); } else { return(null); } }
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); }