public override void Execute() { if (!_serviceOption.HasValue() && _files.Values == null) { throw new ArgumentException("Service option or files argument must be specified.", "service"); } IEnumerable <string> skipInterfaces = new [] { "org.freedesktop.DBus.Introspectable", "org.freedesktop.DBus.Peer", "org.freedesktop.DBus.Properties" }; if (_skipOptions.HasValue()) { skipInterfaces = skipInterfaces.Concat(_skipOptions.Values); } Dictionary <string, string> interfaces = null; if (_interfaceOptions.HasValue()) { interfaces = new Dictionary <string, string>(); foreach (var interf in _interfaceOptions.Values) { if (interf.Contains(':')) { var split = interf.Split(new[] { ':' }); interfaces.Add(split[0], split[1]); } else { interfaces.Add(interf, null); } } } var address = ParseBusAddress(_busOption); var service = _serviceOption.Value(); string ns = _namespaceOption.Value(); if (service != null) { var serviceSplit = service.Split(new [] { '.' }); ns = ns ?? $"{serviceSplit[serviceSplit.Length - 1]}.DBus"; } else { ns = ns ?? "DBus"; } var codeGenArguments = new CodeGenArguments { Namespace = ns, Service = service, Path = _pathOption.HasValue() ? _pathOption.Value() : "/", Address = address, Recurse = !_norecurseOption.HasValue(), NoInternalsVisibleTo = _noInternalsVisibleToOption.HasValue(), OutputFileName = _catOption.HasValue() ? null : _outputOption.Value() ?? $"{ns}.cs", SkipInterfaces = skipInterfaces, Interfaces = interfaces, TypesAccessModifier = _publicOption.HasValue() ? Accessibility.Public : Accessibility.NotApplicable, Files = _files.Values }; GenerateCodeAsync(codeGenArguments).Wait(); }
private async Task GenerateCodeAsync(CodeGenArguments codeGenArguments) { var visitor = new Visitor(codeGenArguments); if (codeGenArguments.Service != null) { using (var connection = new Connection(codeGenArguments.Address)) { await connection.ConnectAsync(); await NodeVisitor.VisitAsync(connection, codeGenArguments.Service, codeGenArguments.Path, codeGenArguments.Recurse, visitor.VisitNode); } } if (codeGenArguments.Files != null) { foreach (var file in codeGenArguments.Files) { await NodeVisitor.VisitAsync(file, visitor.VisitNode); } } var descriptions = visitor.Descriptions; var generator = new Generator( new GeneratorSettings { Namespace = codeGenArguments.Namespace, NoInternalsVisibleTo = codeGenArguments.NoInternalsVisibleTo, TypesAccessModifier = codeGenArguments.TypesAccessModifier }); var code = generator.Generate(descriptions); if (codeGenArguments.OutputFileName != null) { File.WriteAllText(codeGenArguments.OutputFileName, code); Console.WriteLine($"Generated: {Path.GetFullPath(codeGenArguments.OutputFileName)}"); } else { System.Console.WriteLine(code); } }
public Visitor(CodeGenArguments codeGenArguments) { _introspections = new Dictionary <string, InterfaceDescription>(); _names = new HashSet <string>(); _arguments = codeGenArguments; }