private async void Process(object parameter) { IsBusy = true; var result = await Task.Run(() => { using (var reader = MetafileReader.Create(FileName)) { var vmVisitor = new ViewModelBuilderVisitor(); var metafileContext = new MetafileContext(); var apsVisitor = new APSStructureBuilderVisitor(); var apsContext = new APSStructureContext(); var xcfVisitor = new XCFDocumentBuilderVisitor(); var xcfContext = new XCFDocumentContext(); var hotspotVisitor = new HotspotBuilderVisitor(); var hotspotContext = new HotspotContext(); Command command; do { command = reader.Read(); if (command != null) { command.Accept(vmVisitor, metafileContext); command.Accept(apsVisitor, apsContext); command.Accept(xcfVisitor, xcfContext); command.Accept(hotspotVisitor, hotspotContext); } } while (command != null); return(new { MetafileNodes = metafileContext.RootLevel.ToList(), APSNodes = apsContext.RootLevel.ToList(), XCFDocument = xcfContext.XCF, Hotspots = hotspotContext.RootLevel.OfType <HotspotNode>().ToList(), MetafileProperties = reader.Properties, }); } }); IsBusy = false; MetafileNodes = result.MetafileNodes; APSNodes = result.APSNodes; XCFDocument = result.XCFDocument; Hotspots = result.Hotspots; MetafileProperties = result.MetafileProperties; }
static void Main(string[] args) { string target = args.Length >= 1 ? args[0] : @"D:\_dev\_work\standards\webcgm20-ts\static10\ALLELM01.cgm"; var fileNames = new List <string>(); if (File.Exists(target)) { fileNames.Add(target); } else if (Directory.Exists(target)) { fileNames.AddRange(Directory.GetFiles(target, "*.cgm")); } else { Console.WriteLine("Target '{0}' does not exist or is neither file nor folder.", target); return; } var statsProxy = new StatsReplaceProxy <PrintCommandVisitor, PrintContext>(fileNames.Count > 1); var printVisitor = statsProxy.GetTransparentProxy(); foreach (string fileName in fileNames) { statsProxy.Reset(); using (var reader = MetafileReader.Create(fileName)) { var printContext = new PrintContext(fileName); Command command; do { command = reader.Read(); if (command != null) { command.Accept(printVisitor, printContext); } } while (command != null); } statsProxy.Print(fileName); statsProxy.SaveTo(Path.ChangeExtension(fileName, ".stats.txt")); } }