/// <summary> /// Report error when loading formatting data from object model. /// </summary> /// <param name="message"></param> /// <param name="typeName"></param> protected void ReportErrorForLoadingFromObjectModel(string message, string typeName) { XmlLoaderLoggerEntry entry = new XmlLoaderLoggerEntry(); entry.entryType = XmlLoaderLoggerEntry.EntryType.Error; entry.message = message; _logger.LogEntry(entry); _currentErrorCount++; if (_currentErrorCount >= _maxNumberOfErrors) { // we have to log a last error and then bail if (_maxNumberOfErrors > 1) { XmlLoaderLoggerEntry lastEntry = new XmlLoaderLoggerEntry(); lastEntry.entryType = XmlLoaderLoggerEntry.EntryType.Error; lastEntry.message = StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyErrorsInFormattingData, typeName); _logger.LogEntry(lastEntry); _currentErrorCount++; } // NOTE: this exception is an internal one, and it is caught // internally by the calling code. TooManyErrorsException e = new TooManyErrorsException(); e.errorCount = _currentErrorCount; throw e; } }
protected void ReportErrorForLoadingFromObjectModel(string message, string typeName) { XmlLoaderLoggerEntry entry = new XmlLoaderLoggerEntry { entryType = XmlLoaderLoggerEntry.EntryType.Error, message = message }; this.logger.LogEntry(entry); this.currentErrorCount++; if (this.currentErrorCount >= this.maxNumberOfErrors) { if (this.maxNumberOfErrors > 1) { XmlLoaderLoggerEntry entry2 = new XmlLoaderLoggerEntry { entryType = XmlLoaderLoggerEntry.EntryType.Error, message = StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyErrorsInFormattingData, typeName) }; this.logger.LogEntry(entry2); this.currentErrorCount++; } TooManyErrorsException exception = new TooManyErrorsException { errorCount = this.currentErrorCount }; throw exception; } }
internal void LogEntry(XmlLoaderLoggerEntry entry) { if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Error) this.hasErrors = true; if (this.saveInMemory) this.entries.Add(entry); if ((XmlLoaderLogger.formatFileLoadingtracer.Options | PSTraceSourceOptions.WriteLine) == PSTraceSourceOptions.None) return; this.WriteToTracer(entry); }
private void WriteToTracer(XmlLoaderLoggerEntry entry) { if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Error) { formatFileLoadingtracer.WriteLine(string.Format(CultureInfo.InvariantCulture, "ERROR:\r\n FilePath: {0}\r\n XPath: {1}\r\n Message = {2}", new object[] { entry.filePath, entry.xPath, entry.message }), new object[0]); } else if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Trace) { formatFileLoadingtracer.WriteLine(string.Format(CultureInfo.InvariantCulture, "TRACE:\r\n FilePath: {0}\r\n XPath: {1}\r\n Message = {2}", new object[] { entry.filePath, entry.xPath, entry.message }), new object[0]); } }
private void WriteToTracer(XmlLoaderLoggerEntry entry) { if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Error) { s_formatFileLoadingtracer.WriteLine("ERROR:\r\n FilePath: {0}\r\n XPath: {1}\r\n Message = {2}", entry.filePath, entry.xPath, entry.message); } else if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Trace) { s_formatFileLoadingtracer.WriteLine("TRACE:\r\n FilePath: {0}\r\n XPath: {1}\r\n Message = {2}", entry.filePath, entry.xPath, entry.message); } }
private void WriteToTracer(XmlLoaderLoggerEntry entry) { if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Error) { XmlLoaderLogger.formatFileLoadingtracer.WriteLine(string.Format((IFormatProvider) CultureInfo.InvariantCulture, "ERROR:\r\n FilePath: {0}\r\n XPath: {1}\r\n Message = {2}", (object) entry.filePath, (object) entry.xPath, (object) entry.message), new object[0]); } else { if (entry.entryType != XmlLoaderLoggerEntry.EntryType.Trace) return; XmlLoaderLogger.formatFileLoadingtracer.WriteLine(string.Format((IFormatProvider) CultureInfo.InvariantCulture, "TRACE:\r\n FilePath: {0}\r\n XPath: {1}\r\n Message = {2}", (object) entry.filePath, (object) entry.xPath, (object) entry.message), new object[0]); } }
internal void LogEntry(XmlLoaderLoggerEntry entry) { if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Error) { this.hasErrors = true; } if (this.saveInMemory) { this.entries.Add(entry); } if ((formatFileLoadingtracer.Options | PSTraceSourceOptions.WriteLine) != PSTraceSourceOptions.None) { this.WriteToTracer(entry); } }
/// <summary> /// Log an entry. /// </summary> /// <param name="entry">Entry to log.</param> internal void LogEntry(XmlLoaderLoggerEntry entry) { if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Error) { _hasErrors = true; } if (_saveInMemory) { _entries.Add(entry); } if ((s_formatFileLoadingtracer.Options | PSTraceSourceOptions.WriteLine) != 0) { WriteToTracer(entry); } }
private void ReportLogEntryHelper(string message, XmlLoaderLoggerEntry.EntryType entryType, bool failToLoadFile = false) { string currentPath = ComputeCurrentXPath(); XmlLoaderLoggerEntry entry = new XmlLoaderLoggerEntry(); entry.entryType = entryType; entry.filePath = this.FilePath; entry.xPath = currentPath; entry.message = message; if (failToLoadFile) { System.Management.Automation.Diagnostics.Assert(entryType == XmlLoaderLoggerEntry.EntryType.Error, "the entry type should be 'error' when a file cannot be loaded"); entry.failToLoadFile = true; } _logger.LogEntry(entry); if (entryType == XmlLoaderLoggerEntry.EntryType.Error) { _currentErrorCount++; if (_currentErrorCount >= _maxNumberOfErrors) { // we have to log a last error and then bail if (_maxNumberOfErrors > 1) { XmlLoaderLoggerEntry lastEntry = new XmlLoaderLoggerEntry(); lastEntry.entryType = XmlLoaderLoggerEntry.EntryType.Error; lastEntry.filePath = this.FilePath; lastEntry.xPath = currentPath; lastEntry.message = StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyErrors, FilePath); _logger.LogEntry(lastEntry); _currentErrorCount++; } // NOTE: this exception is an internal one, and it is caught // internally by the calling code. TooManyErrorsException e = new TooManyErrorsException(); e.errorCount = _currentErrorCount; throw e; } } }
private void ReportLogEntryHelper(string message, XmlLoaderLoggerEntry.EntryType entryType, bool failToLoadFile = false) { string str = this.ComputeCurrentXPath(); XmlLoaderLoggerEntry entry = new XmlLoaderLoggerEntry { entryType = entryType, filePath = this.FilePath, xPath = str, message = message }; if (failToLoadFile) { entry.failToLoadFile = true; } this.logger.LogEntry(entry); if (entryType == XmlLoaderLoggerEntry.EntryType.Error) { this.currentErrorCount++; if (this.currentErrorCount >= this.maxNumberOfErrors) { if (this.maxNumberOfErrors > 1) { XmlLoaderLoggerEntry entry2 = new XmlLoaderLoggerEntry { entryType = XmlLoaderLoggerEntry.EntryType.Error, filePath = this.FilePath, xPath = str, message = StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyErrors, this.FilePath) }; this.logger.LogEntry(entry2); this.currentErrorCount++; } TooManyErrorsException exception = new TooManyErrorsException { errorCount = this.currentErrorCount }; throw exception; } } }
/// <summary> /// Report error when loading formatting data from object model /// </summary> /// <param name="message"></param> /// <param name="typeName"></param> protected void ReportErrorForLoadingFromObjectModel(string message, string typeName) { XmlLoaderLoggerEntry entry = new XmlLoaderLoggerEntry(); entry.entryType = XmlLoaderLoggerEntry.EntryType.Error; entry.message = message; _logger.LogEntry(entry); _currentErrorCount++; if (_currentErrorCount >= _maxNumberOfErrors) { // we have to log a last error and then bail if (_maxNumberOfErrors > 1) { XmlLoaderLoggerEntry lastEntry = new XmlLoaderLoggerEntry(); lastEntry.entryType = XmlLoaderLoggerEntry.EntryType.Error; lastEntry.message = StringUtil.Format(FormatAndOutXmlLoadingStrings.TooManyErrorsInFormattingData, typeName); _logger.LogEntry(lastEntry); _currentErrorCount++; } // NOTE: this exception is an internal one, and it is caught // internally by the calling code. TooManyErrorsException e = new TooManyErrorsException(); e.errorCount = _currentErrorCount; throw e; } }
/// <summary> /// log an entry /// </summary> /// <param name="entry">entry to log</param> internal void LogEntry(XmlLoaderLoggerEntry entry) { if (entry.entryType == XmlLoaderLoggerEntry.EntryType.Error) _hasErrors = true; if (_saveInMemory) _entries.Add(entry); if ((s_formatFileLoadingtracer.Options | PSTraceSourceOptions.WriteLine) != 0) WriteToTracer(entry); }