Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            String inputMode = args[0];
            String filePath  = args[1];

            if (filePath.EndsWith("\\"))
            {
                filePath = filePath.Remove(filePath.LastIndexOf('\\'));
            }
            IOFile.FolderPath = Path.GetFullPath(filePath);

            Logger.Initialize();
            DateTime StartTime = DateTime.Now;

            Config.Load(IOFile.CompleteFileName("Config.txt"));

            // traverse all the code folder for pattern check
            CodeWalker walker = new CodeWalker();

            walker.LoadByInputMode(inputMode, filePath);

            DateTime EndTime = DateTime.Now;

            Logger.Log("All done. Elapsed time: " + (EndTime - StartTime).ToString());
            Logger.Log("Press any key to terminate!");
            Logger.Close();
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public static void LoadByTxtFile(String folderPath)
        {
            String txtFilePath = IOFile.CompleteFileName("AllSource.txt");

            Logger.Log("Load from txt file: " + txtFilePath);

            String content = "";

            try
            {
                using (StreamReader sr = new StreamReader(txtFilePath))
                {
                    content = sr.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                Logger.Log("Txt file may not exist.");
                Logger.Log(e);
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }

            var tree            = SyntaxTree.ParseText(content);
            var model           = GetSemanticInfo(tree);
            var treeAndModelDic = new Dictionary <SyntaxTree, SemanticModel>();

            treeAndModelDic.Add(tree, model);
            var compilation = BuildCompilation(new List <SyntaxTree> {
                tree
            });

            CodeAnalyzer.AnalyzeAllTrees(treeAndModelDic, compilation);
        }
Ejemplo n.º 3
0
 public static void Initialize()
 {
     LogFileName = IOFile.CompleteFileName(
         DateTime.Today.Date.ToShortDateString().Replace("/", "") + ".log");
     LogWriter = File.AppendText(LogFileName);
     Log("-------------------------------------------------------");
     Log("-------------------------------------------------------");
     Log("New Task.");
 }
Ejemplo n.º 4
0
        public String PrintMetaInfo()
        {
            String metaInfo = null;

            foreach (var key in MetaInfo.Keys)
            {
                metaInfo += (IOFile.DeleteSpace(MetaInfo[key]) + Splitter);
            }
            return(metaInfo);
        }
Ejemplo n.º 5
0
        public void PrintToFile()
        {
            Logger.Log("Writing APICall features into file...");
            StreamWriter sw      = new StreamWriter(IOFile.CompleteFileName("APICall.txt"));
            StreamWriter metaSW  = new StreamWriter(IOFile.CompleteFileName("APICall_Meta.txt"));
            int          callId  = 0;
            String       metaKey = CatchBlock.Splitter;

            foreach (var meta in CatchBlock.MetaKeys)
            {
                metaKey += (meta + CatchBlock.Splitter);
            }
            metaSW.WriteLine(metaKey);
            metaSW.WriteLine("--------------------------------------------------------");
            metaSW.WriteLine("NumCallType: {0}, NumAPICall: {1}, NumLogged: {2}, "
                             + "NumThrown: {3}, NumLoggedAndThrown: {4}, NumLoggedNotThrown: {5}.",
                             this.Count,
                             NumAPICall,
                             NumLogged,
                             NumThrown,
                             NumLoggedAndThrown,
                             NumLoggedNotThrown);
            metaSW.WriteLine();

            foreach (String calltype in this.Keys)
            {
                metaSW.WriteLine("--------------------------------------------------------");
                CallList callList = this[calltype];
                metaSW.WriteLine("Call Type [{0}]: NumAPICall: {1}, NumLogged: {2}, "
                                 + "NumThrown: {3}, NumLoggedAndThrown: {4}, NumLoggedNotThrown: {5}.",
                                 calltype,
                                 callList.Count,
                                 callList.NumLogged,
                                 callList.NumThrown,
                                 callList.NumLoggedAndThrown,
                                 callList.NumLoggedNotThrown
                                 );
                foreach (var apicall in callList)
                {
                    callId++;
                    sw.WriteLine("ID:" + callId + APICall.Splitter + apicall.PrintFeatures());
                    metaSW.WriteLine("ID:" + callId + APICall.Splitter + apicall.PrintMetaInfo());
                }
                metaSW.WriteLine();
                metaSW.WriteLine();
                sw.Flush();
                metaSW.Flush();
            }

            //Print summary
            metaSW.WriteLine("------------------------ Summary -------------------------");
            metaSW.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",
                             "Call Type",
                             "NumAPICall",
                             "NumLogged",
                             "NumThrown",
                             "NumLoggedAndThrown",
                             "NumLoggedNotThrown");

            foreach (String exception in this.Keys)
            {
                var catchList = this[exception];
                metaSW.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",
                                 exception,
                                 catchList.Count,
                                 catchList.NumLogged,
                                 catchList.NumThrown,
                                 catchList.NumLoggedAndThrown,
                                 catchList.NumLoggedNotThrown
                                 );
            }
            sw.Close();
            metaSW.Close();
            Logger.Log("Writing done.");
        }