public PrintFile ProcessPrintPath(PrintFile printFile, string printFilePath) { if (string.IsNullOrWhiteSpace(printFilePath)) { printFilePath = Global.GetOutputPath(PrintFile.DEFAULT_PRINT_FILENAME); } if (string.IsNullOrWhiteSpace(printFilePath)) { printFilePath = Global.GetOutputPath(PrintFile.DEFAULT_PRINT_FILENAME); } printFilePath.CreateDirectory(); //create printfile directory if needed printFile = new PrintFile(printFilePath, Global.Configuration); Write(Global.Configuration, printFile); return(printFile); }
private void WriteFromXml(PrintFile printFile, PropertyInfo[] properties) { using (var stream = _file.Open(FileMode.Open, FileAccess.Read, FileShare.Read)) { var document = XDocument.Load(stream); var attributes = document.Root == null ? new List <string>() : document .Root .Attributes() .Select(x => x.Name.LocalName) .ToList(); WriteInvalidAttributes(printFile, properties, attributes); WriteUnusedProperties(printFile, properties, attributes); } }
private static void WriteInvalidAttributes(PrintFile printFile, IEnumerable <PropertyInfo> properties, IEnumerable <string> attributes) { var list = attributes .Where(attribute => attribute != "xsd" && attribute != "xsi" && properties.All(x => x.Name != attribute)) .ToList(); if (list.Count == 0) { return; } printFile.WriteLine("The following attributes in the configuration file are invalid:"); printFile.IncrementIndent(); foreach (var item in list) { printFile.WriteLine("* {0}", item); } printFile.DecrementIndent(); printFile.WriteLine(); }
private static void WriteUnusedProperties(PrintFile printFile, IEnumerable <PropertyInfo> properties, IEnumerable <string> attributes) { var list = properties .Where(property => attributes.All(x => x != property.Name)) .Select(property => property.Name) .ToList(); if (list.Count == 0) { return; } printFile.WriteLine("The following properties in the configuration file were not set:"); printFile.IncrementIndent(); foreach (var item in list) { printFile.WriteLine("* {0}", item); } printFile.DecrementIndent(); printFile.WriteLine(); }
public void Write(Configuration configuration, PrintFile printFile) { var properties = typeof(Configuration).GetProperties(BindingFlags.Public | BindingFlags.Instance); if (_extension == ".xml") { WriteFromXml(printFile, properties); } if (_extension == ".properties") { WriteFromProperties(printFile, properties); } var list = properties .Select(property => { var value = property.GetValue(configuration, null); var metadata = property .GetCustomAttributes(typeof(MetadataAttribute), true) .Cast <MetadataAttribute>() .SingleOrDefault(); var description = metadata == null || string.IsNullOrEmpty(metadata.Value) ? property.Name.ToSentenceCase() : metadata.Value; string format; if (value == null) { format = string.Empty; } else { if (value is char) { var b = (byte)(char)value; format = string.Format("{0} - {1}", b, AsciiTable.GetDescription(b)); } else { format = value.ToString().Trim(); } } return(new { property.Name, Value = format, Description = description }); }) .ToList(); var maxKeyLength = list .Select(x => x.Name.Length) .Max(); var maxValueLength = list .Select(x => x.Value.Length) .Max(); foreach (var property in list) { printFile .WriteLine("{0}> {1} // {2}.", property.Name.PadLeft(maxKeyLength), property.Value.PadRight(maxValueLength), property.Description); } printFile.WriteLine(); }
private void WriteFromProperties(PrintFile printFile, PropertyInfo[] properties) { }