private void ReportLogEntryHelper(string message, XmlLoaderLoggerEntry.EntryType entryType) { string currentXpath = this.ComputeCurrentXPath(); this.logger.LogEntry(new XmlLoaderLoggerEntry() { entryType = entryType, filePath = this.FilePath, xPath = currentXpath, message = message }); if (entryType != XmlLoaderLoggerEntry.EntryType.Error) { return; } ++this.currentErrorCount; if (this.currentErrorCount >= this.maxNumberOfErrors) { if (this.maxNumberOfErrors > 1) { this.logger.LogEntry(new XmlLoaderLoggerEntry() { entryType = XmlLoaderLoggerEntry.EntryType.Error, filePath = this.FilePath, xPath = currentXpath, message = XmlLoadingResourceManager.FormatString("TooManyErrors", (object)this.FilePath) }); ++this.currentErrorCount; } throw new TooManyErrorsException() { errorCount = this.currentErrorCount }; } }
protected bool VerifyNodeHasNoChildren(XmlNode n) { if (n.ChildNodes.Count == 0 || n.ChildNodes.Count == 1 && n.ChildNodes[0] is XmlText) { return(true); } this.ReportError(XmlLoadingResourceManager.FormatString("NoChildrenAllowed", (object)this.ComputeCurrentXPath(), (object)this.FilePath, (object)n.Name)); return(false); }
private bool MatchNodeNameHelper(XmlNode n, string s, bool allowAttributes) { bool flag = false; if (string.Equals(n.Name, s, StringComparison.Ordinal)) { flag = true; } else if (string.Equals(n.Name, s, StringComparison.OrdinalIgnoreCase)) { this.ReportTrace(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "XML tag differ in case only {0} {1}", (object)n.Name, (object)s)); flag = true; } if (flag && !allowAttributes && (n is XmlElement xmlElement && xmlElement.Attributes.Count > 0)) { this.ReportError(XmlLoadingResourceManager.FormatString("AttributesNotAllowed", (object)this.ComputeCurrentXPath(), (object)this.FilePath, (object)n.Name)); } return(flag); }
protected XmlDocument LoadXmlDocumentFromFileLoadingInfo( AuthorizationManager authorizationManager, PSHost host) { ExternalScriptInfo externalScriptInfo = new ExternalScriptInfo(this.FilePath, this.FilePath); string scriptContents = externalScriptInfo.ScriptContents; if (authorizationManager != null) { try { authorizationManager.ShouldRunInternal((CommandInfo)externalScriptInfo, CommandOrigin.Internal, host); } catch (PSSecurityException ex) { this.ReportError(ResourceManagerCache.FormatResourceString("TypesXml", "ValidationException", (object)string.Empty, (object)this.FilePath, (object)ex.Message)); return((XmlDocument)null); } } XmlDocument xmlDocument = new XmlDocument(); xmlDocument.PreserveWhitespace = true; try { using (StringReader stringReader = new StringReader(scriptContents)) xmlDocument.Load((TextReader)stringReader); } catch (XmlException ex) { this.ReportError(XmlLoadingResourceManager.FormatString("ErrorInFile", (object)this.FilePath, (object)ex.Message)); this.ReportTrace("XmlDocument discarded"); return((XmlDocument)null); } catch (Exception ex) { XmlLoaderBase.tracer.TraceException(ex); CommandProcessorBase.CheckForSevereException(ex); throw; } this.ReportTrace("XmlDocument loaded OK"); return(xmlDocument); }
private static TypeInfoDataBase LoadFromFileHelper( Collection <PSSnapInTypeAndFormatErrors> files, MshExpressionFactory expressionFactory, AuthorizationManager authorizationManager, PSHost host, out List <XmlLoaderLoggerEntry> logEntries, out bool success) { success = true; logEntries = new List <XmlLoaderLoggerEntry>(); List <XmlFileLoadInfo> xmlFileLoadInfoList = new List <XmlFileLoadInfo>(); foreach (PSSnapInTypeAndFormatErrors file in files) { xmlFileLoadInfoList.Add(new XmlFileLoadInfo(Path.GetPathRoot(file.FullPath), file.FullPath, file.Errors, file.PSSnapinName)); } TypeInfoDataBase db = new TypeInfoDataBase(); TypeInfoDataBaseManager.AddPreLoadInstrinsics(db); foreach (XmlFileLoadInfo info in xmlFileLoadInfoList) { using (TypeInfoDataBaseLoader infoDataBaseLoader = new TypeInfoDataBaseLoader()) { if (!infoDataBaseLoader.LoadXmlFile(info, db, expressionFactory, authorizationManager, host)) { success = false; } foreach (XmlLoaderLoggerEntry logEntry in infoDataBaseLoader.LogEntries) { if (logEntry.entryType == XmlLoaderLoggerEntry.EntryType.Error) { string str = XmlLoadingResourceManager.FormatString("MshSnapinQualifiedError", (object)info.psSnapinName, (object)logEntry.message); info.errors.Add(str); } } logEntries.AddRange((IEnumerable <XmlLoaderLoggerEntry>)infoDataBaseLoader.LogEntries); } } TypeInfoDataBaseManager.AddPostLoadInstrinsics(db); return(db); }
protected void ReportEmptyAttribute(XmlAttribute a) => this.ReportLogEntryHelper(XmlLoadingResourceManager.FormatString("EmptyAttribute", (object)this.ComputeCurrentXPath(), (object)this.FilePath, (object)a.Name), XmlLoaderLoggerEntry.EntryType.Error);
protected void ReportMissingNodes(string[] names) { string str = string.Join(", ", names); this.ReportLogEntryHelper(XmlLoadingResourceManager.FormatString("MissingNodeFromList", (object)this.ComputeCurrentXPath(), (object)this.FilePath, (object)str), XmlLoaderLoggerEntry.EntryType.Error); }
protected void ReportMissingNode(string name) => this.ReportLogEntryHelper(XmlLoadingResourceManager.FormatString("MissingNode", (object)this.ComputeCurrentXPath(), (object)this.FilePath, (object)name), XmlLoaderLoggerEntry.EntryType.Error);
private void ReportIllegalXmlAttribute(XmlAttribute a) => this.ReportLogEntryHelper(XmlLoadingResourceManager.FormatString("UnknownAttribute", (object)this.ComputeCurrentXPath(), (object)this.FilePath, (object)a.Name), XmlLoaderLoggerEntry.EntryType.Error);
internal void ProcessDuplicateAlternateNode(XmlNode n, string node1, string node2) => this.ReportLogEntryHelper(XmlLoadingResourceManager.FormatString("ThreeMutuallyExclusiveNode", (object)this.ComputeCurrentXPath(), (object)this.FilePath, (object)n.Name, (object)node1, (object)node2), XmlLoaderLoggerEntry.EntryType.Error);
internal void ProcessDuplicateNode(XmlNode n) => this.ReportLogEntryHelper(XmlLoadingResourceManager.FormatString("DuplicatedNode", (object)this.ComputeCurrentXPath(), (object)this.FilePath), XmlLoaderLoggerEntry.EntryType.Error);