public void Merge(ref Asap2.Asap2File destination, Asap2.Asap2File source) { var destinationProject = destination.elements.First(x => x is Asap2.PROJECT) as Asap2.PROJECT; var sourceProject = source.elements.First(x => x is Asap2.PROJECT) as Asap2.PROJECT; if (options.ModuleMerge == Options.ModuleMergeType.Multiple) { foreach (var module in sourceProject.modules.Values) { try { destinationProject.modules.Add(module.Name, module); } catch (ArgumentException) { if (options.MergeConflict == Options.MergeConflictType.UseFromFirstModuleAndWarn) { Console.Error.WriteLine(String.Format("Warning: Duplicate MODULE with name '{0}' found in {1}", module.Name, source.baseFilename)); } if (options.MergeConflict == Options.MergeConflictType.AbortWithError) { throw new ErrorException(ErrorException.ErrorCodes.MergeError, String.Format("Error: Duplicate MODULE with name '{0}' found in {1}", module.Name, source.baseFilename)); } } } } if (options.ModuleMerge == Options.ModuleMergeType.One) { Asap2.MODULE destinationModule = destinationProject.modules.First().Value; Asap2.MODULE sourceModule = MergeModulesList(sourceProject.modules); MergeModules(ref destinationModule, sourceModule); } }
static void Main(string[] args) { var errorHandler = new ErrorHandler(); var parser = new Asap2.Parser("../../../testFile.a2l", errorHandler); Asap2.FileComment comment = new Asap2.FileComment(Environment.NewLine + "A2l file for testing ASAP2 parser." + Environment.NewLine, true); Asap2.Asap2File tree = parser.DoParse(); if (tree != null) { try { if (errorHandler.warnings == 0) { Console.WriteLine("Parsed file with no warnings."); } else { Console.WriteLine(string.Format("Parsed file with {0} warnings.", errorHandler.warnings)); } errorHandler = new ErrorHandler(); tree.Validate(errorHandler); if (errorHandler.warnings == 0) { Console.WriteLine("Validated parsed data with no warnings."); } else { Console.WriteLine(string.Format("Validated parsed data with {0} warnings.", errorHandler.warnings)); } Console.WriteLine("Press enter to serialise data."); Console.ReadLine(); tree.elements.Insert(0, comment); var ms = new MemoryStream(); StreamWriter stream = new StreamWriter(ms, new UTF8Encoding(true)); parser.Serialise(tree, stream); ms.Position = 0; var sr = new StreamReader(ms); var myStr = sr.ReadToEnd(); Console.WriteLine(myStr); } catch (Asap2.ValidationErrorException e) { Console.WriteLine("Validation of parsed data failed!"); Console.WriteLine(e.ToString()); } } else { Console.WriteLine("Parsing failed!"); } Console.WriteLine("Press enter to close..."); Console.ReadLine(); }