/// <summary> /// Reads and returns a domain object from the specified DDL string. /// </summary> public static DocumentObject ObjectFromString(string ddl, DdlReaderErrors errors) { StringReader stringReader = null; DocumentObject domObj; DdlReader reader = null; try { stringReader = new StringReader(ddl); reader = new DdlReader(stringReader); domObj = reader.ReadObject(); } finally { if (stringReader != null) { #if !NETFX_CORE stringReader.Close(); #else stringReader.Dispose(); #endif } if (reader != null) { reader.Close(); } } return(domObj); }
private void LogErrors(DdlReaderErrors errors, Exception ex, System.IO.Stream mddl) { if (ex != null) { Zetbox.API.Utils.Logging.Log.Error("Exception during report creation", ex); } if (errors != null) { foreach (DdlReaderError e in errors) { switch (e.ErrorLevel) { case DdlErrorLevel.Error: Zetbox.API.Utils.Logging.Log.Error(e.ToString()); break; case DdlErrorLevel.Warning: Zetbox.API.Utils.Logging.Log.Warn(e.ToString()); break; default: Zetbox.API.Utils.Logging.Log.Info(e.ToString()); break; } } } }
private void ReportErrors(DdlReaderErrors errors, Exception ex, System.IO.Stream mddl) { if (ex != null || (errors != null && errors.ErrorCount > 0)) { if (ErrorsAreFatal) { var msg = new StringBuilder("Errors while rendering document:"); if (ex != null) { msg.Append("\n" + ex.ToString()); } foreach (var error in errors) { msg.Append("\n" + error.ToString()); } throw new ApplicationException(msg.ToString()); } if (ex != null) { Logging.Log.Error("Unable to create report:", ex); } if (errors != null && errors.ErrorCount > 0) { StringBuilder sb = new StringBuilder(); foreach (DdlReaderError e in errors) { switch (e.ErrorLevel) { case DdlErrorLevel.Error: sb.Append("E: "); break; case DdlErrorLevel.Warning: sb.Append("W: "); break; default: sb.Append("?: "); break; } sb.AppendLine(e.ToString()); } Logging.Log.Info(sb.ToString()); } } }
/// <summary> /// Initializes a new instance of the DdlReader class with the specified filename and ErrorManager2. /// </summary> public DdlReader(string filename, DdlReaderErrors errors) { _fileName = filename; _errorManager = errors; #if !NETFX_CORE _reader = new StreamReader(filename, Encoding.UTF8); #else _reader = new StreamReader(null, Encoding.UTF8); #endif //#if SILVERLIGHT // _reader = new StreamReader(filename, Encoding.UTF8); //#else // _reader = new StreamReader(filename, Encoding.Default); //#endif }
/// <summary> /// Reads and returns a domain object from the specified file. /// </summary> public static DocumentObject ObjectFromFile(string documentFileName, DdlReaderErrors errors) { DdlReader reader = null; DocumentObject domObj; try { reader = new DdlReader(documentFileName, errors); domObj = reader.ReadObject(); } finally { if (reader != null) { reader.Close(); } } return(domObj); }
private Document GetDocument() { var s = GetMDDLStream(); var errors = new DdlReaderErrors(); DdlReader rd = new DdlReader(s, errors); try { var doc = rd.ReadDocument(); LogErrors(errors, null, s); ReportErrors(errors, null, s); return(doc); } catch (Exception ex) { LogErrors(errors, ex, s); ReportErrors(errors, ex, s); throw; } }
/// <summary> /// Initializes a new instance of the DdlReader class with the specified TextReader and ErrorManager2. /// </summary> public DdlReader(TextReader reader, DdlReaderErrors errors) { _doClose = false; _errorManager = errors; _reader = reader; }
/// <summary> /// Initializes a new instance of the DdlReader class with the specified Stream and ErrorManager2. /// </summary> public DdlReader(Stream stream, DdlReaderErrors errors) { _errorManager = errors; _reader = new StreamReader(stream); }