예제 #1
0
        private int Scaffold()
        {
            if (string.IsNullOrEmpty(_commandLineSettings.InputAssembly))
            {
                throw new CommandLineSettingsInvalidException("Missing -i parameter");
            }

            if (string.IsNullOrEmpty(_commandLineSettings.AnnotationDirectory))
            {
                throw new CommandLineSettingsInvalidException("Missing -s parameter");
            }

            string input  = Path.GetFullPath(_commandLineSettings.InputAssembly);
            string output = Path.GetFullPath(_commandLineSettings.AnnotationDirectory);

            _logger.LogInformation("Generating scaffold for assembly {assembly} to {scaffoldDir}", input, output);

            AssemblyAnalyzer asm   = new AssemblyAnalyzer(input);
            AnalyzedAssembly types = asm.Analyze();

            GenerateNamespaceDirectories(Path.Combine(output, types.AssemblyName), types.Namespaces);


            File.WriteAllText(Path.Combine(output, $"A_{types.AssemblyName}.json"),
                              JsonSerializer.Serialize(types, new JsonSerializerOptions {
                WriteIndented = true
            }));
            DumpResourceFile(output, "README.md");

            return(0);
        }
예제 #2
0
        private int Generate()
        {
            if (string.IsNullOrEmpty(_commandLineSettings.OutputDirectory))
            {
                throw new CommandLineSettingsInvalidException("Missing -o parameter");
            }

            if (string.IsNullOrEmpty(_commandLineSettings.AnnotationDirectory))
            {
                throw new CommandLineSettingsInvalidException("Missing -s parameter");
            }

            string input  = Path.GetFullPath(_commandLineSettings.AnnotationDirectory);
            string output = Path.GetFullPath(_commandLineSettings.OutputDirectory);

            Directory.CreateDirectory(output);

            var assemblies = new Dictionary <string, AnalyzedAssembly>();

            foreach (string f in Directory.EnumerateFiles(input, "A_*.json"))
            {
                _logger.LogInformation("Loading assembly from {assembly}", f);
                AnalyzedAssembly asm = JsonSerializer.Deserialize <AnalyzedAssembly>(File.ReadAllText(f));
                ReadNamespaceInformation(asm, Path.Combine(input, asm.AssemblyName), asm.Namespaces,
                                         ImmutableArray <int> .Empty, null);

                assemblies[asm.AssemblyName] = asm;
            }

            string dbcon = "window.annotationInfo = " + JsonSerializer.Serialize(new BrowserDatabase
            {
                Assemblies  = assemblies,
                GeneratedOn = DateTime.Now.ToString(),
                Version     = Assembly.GetExecutingAssembly().GetName().Version.ToString()
            }) + ";";

            using SHA1 s = SHA1.Create();

            string hash = Convert.ToBase64String(s.ComputeHash(Encoding.UTF8.GetBytes(dbcon)));


            File.WriteAllText(Path.Combine(output, "db.js"), dbcon);


            _logger.LogInformation("Generating html/javascript browser");
            DumpResourceFile(output, "browser.js");
            DumpResourceFile(output, "README.md");
            DumpResourceFile(output, "index.html", hash);

            return(0);
        }
    private HandleNodes(XmlNodeList[] nodes)
    {
        foreach (XmlNode node in nodelist)
        {
            var file = new FileInfo(node.InnerText);
            AnalyzedAssembly analyzedAssembly = new AnalyzedAssembly
            {
                AssemblyName = file.Name,
                AssemblyFile = file
            };


            Console.WriteLine(analyzedAssembly.AssemblyName);
            Console.WriteLine(analyzedAssembly.AssemblyFile);

            // Get a new nodelist from the inner XML
            // and call HandleNodes on this new nodelist here.
        }
    }
예제 #4
0
        private void ReadNamespaceInformation(AnalyzedAssembly asm, string input,
                                              NamespaceHierarchy types,
                                              ImmutableArray <int> comments, string parent)
        {
            var fullNamespace = parent != null ? parent + "." + types.NamespaceName : types.NamespaceName;

            _logger.LogInformation("Processing {namespace}", fullNamespace);

            string path = Path.Combine(input, types.NamespaceName);

            FileInfo nsInfo = new FileInfo(Path.Combine(path, "_namespace.md"));

            if (nsInfo.Exists && nsInfo.Length > 0)
            {
                asm.Strings.Add(ProcessContent(nsInfo.FullName, "📂 Namespace " + fullNamespace, 1));

                comments = comments.Add(asm.Strings.Count - 1);
            }

            types.Comment = comments.ToArray();

            foreach (TypeInformation type in types.Types)
            {
                FileInfo             typeInfo  = new FileInfo(Path.Combine(path, GetFileNameForType(type.Name)));
                ImmutableArray <int> fcomments = comments;
                if (typeInfo.Exists && typeInfo.Length > 0)
                {
                    asm.Strings.Add(ProcessContent(typeInfo.FullName, "📦 Type " + fullNamespace + "." + type.Name, 2));

                    fcomments = fcomments.Add(asm.Strings.Count - 1);
                }

                type.Comment = fcomments.ToArray();
            }

            foreach (NamespaceHierarchy ns in types.Namespaces)
            {
                ReadNamespaceInformation(asm, path, ns, comments, fullNamespace);
            }
        }