Esempio n. 1
0
        public static void Main(string[] args)
        {
            if (args.Length == 0 || args.Any(a => a.Equals("-h") || a.Equals("--help")))
            {
                WriteHelp();
            }
            else
            {
                string path = null;

                for (int i = 0; i < args.Length - 1; i++)
                {
                    bool argument = true;
                    if (args[i].Equals("-p") || args[i].Equals("--path"))
                    {
                        path = args[i + 1];
                    }
                    else if (args[i].Equals("-r") || args[i].Equals("--ramlVersion"))
                    {
                        DocumentationSerialiserFactory.RAMLVersion = args[i + 1];
                    }
                    else
                    {
                        argument = false;
                    }
                    if (argument)
                    {
                        List<string> temp = args.ToList();
                        temp.RemoveRange(i, 2);
                        args = temp.ToArray();
                        i--;
                    }
                }

                if (path == null)
                {
                    path = FindAssemblyPath();
                }

                if (string.IsNullOrEmpty(path))
                {
                    Console.WriteLine("Could not find Device Server Executable. ");
                    Console.Out.Flush();
                }
                else
                {
                    Assembly assembly = null;
                    try
                    {
                        assembly = AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path));
                    }
                    catch (Exception exception)
                    {
                        SerialisationLog.Error(string.Concat("Failed to load assembly at ", path, ": ", exception));
                    }

                    if (assembly != null)
                    {
                        ResourceNode resourceTree = null;
                        try
                        {
                            Console.WriteLine("Gathering resources from assembly...");
                            resourceTree = AssemblyReader.ReadAssembly(assembly);
                        }
                        catch (Exception exception)
                        {
                            SerialisationLog.Error(string.Concat("Failed to generate resource tree from assembly at ", path, ": ", exception));
                        }

                        if (resourceTree != null)
                        {
                            IConfigurationBuilder builder = new ConfigurationBuilder()
                            .SetBasePath(Directory.GetCurrentDirectory())
                            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                            .AddEnvironmentVariables();
                            //.AddCommandLine(args);

                            IConfigurationRoot root = builder.Build();
                            DocumentationHeaderSettings headerSettings = new DocumentationHeaderSettings();
                            root.GetSection("HeaderSettings").Bind(headerSettings);

                            SchemaStore schemaStore = new SchemaStore(resourceTree);
                            ExampleStore exampleStore = new ExampleStore(string.Concat(GetRootDirectory(), "/doc/"), resourceTree);

                            args = args.Where(a => !a.StartsWith("-")).ToArray();  // remove options
                            int numSuccess = 0;
                            for (int i = 0; i < args.Length; i++)
                            {
                                try
                                {
                                    Console.WriteLine(string.Concat("Generating documentation file: ", args[i]));
                                    GenerateDocumentation(resourceTree, headerSettings, schemaStore, exampleStore, args[i]);
                                    numSuccess++;
                                }
                                catch(Exception exception)
                                {
                                    SerialisationLog.Error(string.Concat("Failed to generate documentation for ", args[i], ": ", exception));
                                }
                            }

                            Console.WriteLine(string.Concat(numSuccess, "/", args.Length, " documentation files generated successfully."));
                            Console.WriteLine(string.Concat(SerialisationLog.Errors, " errors, ", SerialisationLog.Warnings, " warnings."));
                        }
                    }
                }
            }
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            if (args.Length == 0 || args.Any(a => a.Equals("-h") || a.Equals("--help")))
            {
                WriteHelp();
            }
            else
            {
                string path = null;

                for (int i = 0; i < args.Length - 1; i++)
                {
                    bool argument = true;
                    if (args[i].Equals("-p") || args[i].Equals("--path"))
                    {
                        path = args[i + 1];
                    }
                    else if (args[i].Equals("-r") || args[i].Equals("--ramlVersion"))
                    {
                        DocumentationSerialiserFactory.RAMLVersion = args[i + 1];
                    }
                    else
                    {
                        argument = false;
                    }
                    if (argument)
                    {
                        List <string> temp = args.ToList();
                        temp.RemoveRange(i, 2);
                        args = temp.ToArray();
                        i--;
                    }
                }


                if (path == null)
                {
                    path = FindAssemblyPath();
                }

                if (string.IsNullOrEmpty(path))
                {
                    Console.WriteLine("Could not find Device Server Executable. ");
                    Console.Out.Flush();
                }
                else
                {
                    Assembly assembly = null;
                    try
                    {
                        assembly = AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path));
                    }
                    catch (Exception exception)
                    {
                        SerialisationLog.Error(string.Concat("Failed to load assembly at ", path, ": ", exception));
                    }

                    if (assembly != null)
                    {
                        ResourceNode resourceTree = null;
                        try
                        {
                            Console.WriteLine("Gathering resources from assembly...");
                            resourceTree = AssemblyReader.ReadAssembly(assembly);
                        }
                        catch (Exception exception)
                        {
                            SerialisationLog.Error(string.Concat("Failed to generate resource tree from assembly at ", path, ": ", exception));
                        }

                        if (resourceTree != null)
                        {
                            IConfigurationBuilder builder = new ConfigurationBuilder()
                                                            .SetBasePath(Directory.GetCurrentDirectory())
                                                            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                                                            .AddEnvironmentVariables();
                            //.AddCommandLine(args);

                            IConfigurationRoot          root           = builder.Build();
                            DocumentationHeaderSettings headerSettings = new DocumentationHeaderSettings();
                            root.GetSection("HeaderSettings").Bind(headerSettings);

                            SchemaStore  schemaStore  = new SchemaStore(resourceTree);
                            ExampleStore exampleStore = new ExampleStore(string.Concat(GetRootDirectory(), "/doc/"), resourceTree);

                            args = args.Where(a => !a.StartsWith("-")).ToArray();  // remove options
                            int numSuccess = 0;
                            for (int i = 0; i < args.Length; i++)
                            {
                                try
                                {
                                    Console.WriteLine(string.Concat("Generating documentation file: ", args[i]));
                                    GenerateDocumentation(resourceTree, headerSettings, schemaStore, exampleStore, args[i]);
                                    numSuccess++;
                                }
                                catch (Exception exception)
                                {
                                    SerialisationLog.Error(string.Concat("Failed to generate documentation for ", args[i], ": ", exception));
                                }
                            }

                            Console.WriteLine(string.Concat(numSuccess, "/", args.Length, " documentation files generated successfully."));
                            Console.WriteLine(string.Concat(SerialisationLog.Errors, " errors, ", SerialisationLog.Warnings, " warnings."));
                        }
                    }
                }
            }
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Esempio n. 3
0
 private static void GenerateDocumentation(ResourceNode resourceTree, DocumentationHeaderSettings headerSettings, SchemaStore schemaStore, ExampleStore exampleStore, string outputFilename)
 {
     IDocumentationSerialiser serialiser = DocumentationSerialiserFactory.GetSerialiser(outputFilename);
     using (FileStream stream = new FileStream(outputFilename, FileMode.Create, FileAccess.Write))
     {
         StreamWriter streamWriter = new StreamWriter(stream);
         serialiser.Serialise(streamWriter, resourceTree, headerSettings, schemaStore, exampleStore);
         streamWriter.Flush();
     }
 }
Esempio n. 4
0
        private static void GenerateDocumentation(ResourceNode resourceTree, DocumentationHeaderSettings headerSettings, SchemaStore schemaStore, ExampleStore exampleStore, string outputFilename)
        {
            IDocumentationSerialiser serialiser = DocumentationSerialiserFactory.GetSerialiser(outputFilename);

            using (FileStream stream = new FileStream(outputFilename, FileMode.Create, FileAccess.Write))
            {
                StreamWriter streamWriter = new StreamWriter(stream);
                serialiser.Serialise(streamWriter, resourceTree, headerSettings, schemaStore, exampleStore);
                streamWriter.Flush();
            }
        }