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); } } }
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; } } }
public bool Execute() { try { if ((!this.SupportExtensions) && ((this.ApplicationMarkup == null) || this.ApplicationMarkup.Count == 0)) { return true; } else if (this.ApplicationMarkupWithTypeName == null || this.ApplicationMarkupWithTypeName.Count == 0) { return true; } IList<Assembly> loadedAssemblyList = null; if (this.References != null) { loadedAssemblyList = XamlBuildTaskServices.Load(this.References, false); } Assembly localAssembly = null; if (LocalAssemblyReference != null) { try { localAssembly = XamlBuildTaskServices.Load(LocalAssemblyReference); loadedAssemblyList.Add(localAssembly); } catch (FileNotFoundException e) { XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, e.FileName, 0, 0); return false; } } AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(XamlBuildTaskServices.ReflectionOnlyAssemblyResolve); XamlNsReplacingContext wxsc = new XamlNsReplacingContext(loadedAssemblyList, localAssembly.GetName().Name, this.AssemblyName); bool foundValidationErrors = false; if (!this.SupportExtensions) { foreach (string app in ApplicationMarkup) { try { if (!ProcessMarkupItem(app, wxsc, localAssembly)) { foundValidationErrors = true; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, app, 0, 0); return false; } } } else { foreach (ITaskItem app in this.ApplicationMarkupWithTypeName.Values) { string inputMarkupFile = app.ItemSpec; try { if (!ProcessMarkupItem(inputMarkupFile, wxsc, localAssembly)) { foundValidationErrors = true; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, inputMarkupFile, 0, 0); return false; } } if (!foundValidationErrors) { foundValidationErrors = !ExecuteExtensions(); if (!foundValidationErrors) { foundValidationErrors = this.BuildLogger.HasLoggedErrors; } } } return !foundValidationErrors; } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } // Log unknown errors that do not originate from the task. // Assumes that all known errors are logged when the exception is thrown. XamlBuildTaskServices.LogException(this.BuildLogger, e.Message); return false; } }
public bool Execute() { try { if ((!this.SupportExtensions) && ((this.ApplicationMarkup == null) || this.ApplicationMarkup.Count == 0)) { return(true); } else if (this.ApplicationMarkupWithTypeName == null || this.ApplicationMarkupWithTypeName.Count == 0) { return(true); } IList <Assembly> loadedAssemblyList = null; if (this.References != null) { loadedAssemblyList = XamlBuildTaskServices.Load(this.References, false); } Assembly localAssembly = null; if (LocalAssemblyReference != null) { try { localAssembly = XamlBuildTaskServices.Load(LocalAssemblyReference); loadedAssemblyList.Add(localAssembly); } catch (FileNotFoundException e) { XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, e.FileName, 0, 0); return(false); } } AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(XamlBuildTaskServices.ReflectionOnlyAssemblyResolve); XamlNsReplacingContext wxsc = new XamlNsReplacingContext(loadedAssemblyList, localAssembly.GetName().Name, this.AssemblyName); bool foundValidationErrors = false; if (!this.SupportExtensions) { foreach (string app in ApplicationMarkup) { try { if (!ProcessMarkupItem(app, wxsc, localAssembly)) { foundValidationErrors = true; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, app, 0, 0); return(false); } } } else { foreach (ITaskItem app in this.ApplicationMarkupWithTypeName.Values) { string inputMarkupFile = app.ItemSpec; try { if (!ProcessMarkupItem(inputMarkupFile, wxsc, localAssembly)) { foundValidationErrors = true; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } XamlBuildTaskServices.LogException(this.BuildLogger, e.Message, inputMarkupFile, 0, 0); return(false); } } if (!foundValidationErrors) { foundValidationErrors = !ExecuteExtensions(); if (!foundValidationErrors) { foundValidationErrors = this.BuildLogger.HasLoggedErrors; } } } return(!foundValidationErrors); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } // Log unknown errors that do not originate from the task. // Assumes that all known errors are logged when the exception is thrown. XamlBuildTaskServices.LogException(this.BuildLogger, e.Message); return(false); } }