public Task <int> InvokeAsync(InvocationContext context) { var console = context.Console.Out; var file = context.ParseResult.ValueForOption <string>("file"); object loaded; try { using (var stream = File.OpenRead(file)) { loaded = SchemaRegistry.ReadStream(stream); } } catch (Exception ex) { console.WriteLine($"Error loading {file}: {ex}"); return(Task.FromResult(1)); } if (!(loaded is Kit kit)) { console.WriteLine($"File did not parse as a kit file"); return(Task.FromResult(1)); } var json = ConvertToJson(kit.KitRoot, kit.Data); console.WriteLine(json.ToString(Formatting.Indented)); return(Task.FromResult(0)); }
private void ImportKitFromFile(object sender, ExecutedRoutedEventArgs e) { var treeNode = (TreeViewItem)e.Parameter; var targetKitNode = (VisualTreeNode)treeNode.Tag; OpenFileDialog dialog = new OpenFileDialog { Multiselect = false, Filter = "Kit files|*.vkit" }; if (dialog.ShowDialog() != true) { return; } object loaded; try { using (var stream = File.OpenRead(dialog.FileName)) { loaded = SchemaRegistry.ReadStream(stream); } } catch (Exception ex) { Logger.Log($"Error loading {dialog.FileName}", ex); return; } if (!(loaded is Kit kit)) { Logger.Log("Loaded file was not a kit"); return; } if (!kit.Schema.Identifier.Equals(Schema.Identifier)) { Logger.Log($"Kit was from {kit.Schema.Identifier.Name}; this module is {Schema.Identifier.Name}"); return; } var clonedData = kit.KitRoot.Context.CloneData(kit.Data, targetKitNode.Context.Address); Data.OverwriteWithDataFrom(clonedData); // OverwriteWithDataFrom doesn't doesn't (currently) raise any events. // We assume that no other ancestor tree nodes will have text based on the kit details, // so just refresh from here downwards. RefreshTreeNodeAndDescendants(treeNode); LoadDetailsPage(); }