Beispiel #1
0
        //function that takes care of reading the special .apiproj files
        //returns list of all information from files created
        static List <List <string> > runProject(string file, EngineGovernor engine)
        {
            List <List <string> > compiledInfo = new List <List <string> >();

            int           currentSectionID = -1;
            List <string> sections         = new List <string>();
            //Dictionary<int, string> fileList = new Dictionary<int, string>();  // int is index of section
            List <string> fileList      = new List <string>();
            List <int>    fileListAssoc = new List <int>();

            string headerText = "";
            string destFolder = "";

            Console.WriteLine("Recieved api project file.");
            Console.WriteLine("Attempting to read file....");

            //try to open the file
            StreamReader fileStream = null;

            try { fileStream = new StreamReader(file); }
            catch (IOException e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("ERROR - Failed to open file. Incorrect path?");
                Console.ForegroundColor = ConsoleColor.Gray;
                return(null);
            }
            Console.WriteLine("Got file!");

            //read lines in file
            List <string> fileLines   = new List <string>();
            string        currentLine = "";
            int           lineIndex   = 0;

            while ((currentLine = fileStream.ReadLine()) != null)
            {
                fileLines.Add(currentLine);
                lineIndex++;
            }
            Console.WriteLine("Read in " + lineIndex + " lines");

            //iterate through all lines and analyze them appropriately
            Console.WriteLine("Analyzing project file...");
            for (int i = 0; i < fileLines.Count; i++)
            {
                //if line starts with # sign or if it's blank, ignore it!
                if (fileLines[i].StartsWith("#") || fileLines[i] == "" || fileLines[i] == " ")
                {
                    continue;
                }

                // check for section statement
                if (fileLines[i].StartsWith(":section"))
                {
                    string sectionName = fileLines[i].Substring(fileLines[i].IndexOf(" "));                     // TODO: error checking!
                    sections.Add(sectionName);
                    currentSectionID = sections.Count - 1;
                    continue;
                }

                //first check for properties
                if (fileLines[i].StartsWith("destination=") && fileLines[i].Length > 12)
                {
                    destFolder = fileLines[i].Substring(12);
                }
                else if (fileLines[i].StartsWith("header=") && fileLines[i].Length > 7)
                {
                    headerText = fileLines[i].Substring(7);
                }
                //if line isn't a property, must be file name
                else
                {
                    // first check to see if no sections involved
                    if (currentSectionID == -1)
                    {
                        sections.Add("All"); currentSectionID = 0;
                    }
                    fileList.Add(fileLines[i]);
                    fileListAssoc.Add(currentSectionID);
                }
            }
            Console.WriteLine("Analyzed successfully!");

            g_sProjectTitle  = headerText;
            g_sProjectFolder = destFolder;

            engine.Sections = sections;

            //now go through the file list and generate documentation for all of them
            Console.WriteLine("Running documentation engine on file list...");
            for (int i = 0; i < fileList.Count; i++)
            {
                engine.runAnalysis(fileList[i], fileListAssoc[i]);
            }
            engine.generateAPIDoc(destFolder, headerText);


            Console.WriteLine("Finished running engine!");

            return(compiledInfo);


            //CREATE INDEX FILE (maybe a file name thing should be returned by the generateDoc thing
            //DOC GENERATOR SHOULD RETURN LIST OF STRINGS. FIRST ONE IS NAME OF CLASS, SECOND IS DESCRIPTION
        }