public static void demoRequirement6()
        {
            Console.WriteLine("Now demostrating requirement 6, Run Strong connected component analysis ");
            Console.WriteLine("This ssc analysis is based on tarjon algorithm");
            Console.WriteLine("Now analysis the scc relation between pj3,  This project 3 only contains 1 scc relation which is toker.cs and semi.cs");

            DepAnalysis analyzer = new DepAnalysis();

            analyzer.setpath(path);
            analyzer.analyze();
            Dictionary <String, HashSet <String> > dep = analyzer.DependencyTable;
            StrongComponent scc = new StrongComponent();

            scc.buildgraph(dep);
            List <List <String> > res = scc.tarjan();

            foreach (List <String> list in res)
            {
                Console.Write("{");
                foreach (String file in list)
                {
                    Console.Write(" [" + file + "], ");
                }

                Console.WriteLine("}");
            }
        }
Esempio n. 2
0
            static void Main(string[] args)
            {
                DepAnalysis analyzer = new DepAnalysis();

                analyzer.setpath("../../../");
                analyzer.analyze();
                Dictionary <String, HashSet <String> > dep = analyzer.DependencyTable;
                StrongComponent scc = new StrongComponent();

                scc.buildgraph(dep);
                // scc.display();
                List <List <String> > res = scc.tarjan();

                foreach (List <String> list in res)
                {
                    Console.Write("{");
                    foreach (String file in list)
                    {
                        Console.Write(" [" + file + "] ");
                    }
                    Console.WriteLine("}");
                }

                foreach (CsNode <String, String> node in scc.graph.adjList)
                {
                    Console.WriteLine(node.low_num);
                }
            }
        public static void demoRequirement5()
        {
            Console.WriteLine("Now demostrating requirement 5, Run dependency analysis base on all the user-defined types");
            Console.WriteLine("implemented rules and actions to detect user defined type" +
                              "\n public class DetectClass : ARule" +
                              "\n public class DetectEnum : ARule" +
                              "\n public class DetectNamespace : ARule" +
                              "\n public class DetectDelegate : ARule" +
                              "\n  public class DetectAlias : ARule" +
                              "\n  public class DetectFunction : ARule" +
                              "\n\n And Also designed a facility to detect same type name that defined in different namespace");
            Console.WriteLine("As a demostrating, I will run the analysis on this project dirtory,\n and all the .cs file under this dirtory and subdirtory will be analyzed");
            Console.WriteLine("Run a dependency analysis and display the result");
            Console.WriteLine("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
            DepAnalysis depAnalyser = new DepAnalysis();

            depAnalyser.setpath(path);                                                                  // set path the the project3 dirtory;
            depAnalyser.analyze();
            depAnalyser.display();                                                                      // calling the wraped function  to run dependency analysis
            Console.WriteLine("finish demostrating requirement5");
            Console.WriteLine("----------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n\n");
        }
        /*----< define how each message will be processed >------------*/


        void initializeDispatcher()
        {
            //get top files
            Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) =>
            {
                localFileMgr.currentPath = "";
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "getTopFiles";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                localFileMgr.pathStack.Clear();
                return(reply);
            };

            messageDispatcher["getTopFiles"] = getTopFiles;

            //get top dirs
            Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) =>
            {
                localFileMgr.currentPath = "";
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "getTopDirs";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                localFileMgr.pathStack.Clear();
                reply.arguments.Add(localFileMgr.currentPath);
                return(reply);
            };

            messageDispatcher["getTopDirs"] = getTopDirs;

            //move into folder and get files

            Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) =>
            {
                if (msg.arguments.Count() == 1)
                {
                    localFileMgr.currentPath = msg.arguments[0];
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "moveIntoFolderFiles";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                return(reply);
            };

            messageDispatcher["moveIntoFolderFiles"] = moveIntoFolderFiles;

            //move into dir and get dirs

            Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) =>
            {
                if (msg.arguments.Count() == 1)
                {
                    localFileMgr.pathStack.Push(localFileMgr.currentPath);
                    localFileMgr.currentPath = msg.arguments[0];
                    foreach (string s in localFileMgr.pathStack)
                    {
                        Console.WriteLine("the stack values are " + s);
                    }
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "moveIntoFolderDirs";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                reply.arguments.Add(localFileMgr.currentPath);
                return(reply);
            };

            messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs;

            //move into upper dir and get files and dirs

            Func <CommMessage, CommMessage> moveIntoUpFiles = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "moveIntoUpFiles";


                //localFileMgr.currentPath = localFileMgr.pathStack.Peek();

                reply.arguments = localFileMgr.getFiles().ToList <string>();

                return(reply);
            };

            messageDispatcher["moveIntoUpFiles"] = moveIntoUpFiles;

            Func <CommMessage, CommMessage> moveIntoUpDirs = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "moveIntoUpDirs";
                foreach (string s in localFileMgr.pathStack)
                {
                    Console.WriteLine("the stack values are " + s);
                }
                if (localFileMgr.pathStack.Count == 0)
                {
                    localFileMgr.currentPath = "";
                }
                else
                {
                    localFileMgr.currentPath = localFileMgr.pathStack.Peek();
                    localFileMgr.pathStack.Pop();
                }
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                reply.arguments.Add(localFileMgr.currentPath);
                return(reply);
            };

            messageDispatcher["moveIntoUpDirs"] = moveIntoUpDirs;

            Func <CommMessage, CommMessage> getRemoteFiles = delegate(CommMessage msg){
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "getRemoteFiles";
                string path = ServerEnvironment.root + msg.arguments[0];
                try
                {
                    string content = System.IO.File.ReadAllText(path);
                    reply.arguments.Add(content);
                    reply.arguments.Add(System.IO.Path.GetFileName(path));
                }
                catch
                {
                    Console.WriteLine(msg.arguments[0]);
                }

                return(reply);
            };

            messageDispatcher["getRemoteFiles"] = getRemoteFiles;

            messageDispatcher["analyzeDependency"] = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.from    = msg.to;
                reply.to      = msg.from;
                reply.command = "analyzeDependency";
                analyzer.setpath(ServerEnvironment.root + localFileMgr.currentPath);
                analyzer.analyze();
                reply.dependecy = analyzer.DependencyTable;
                return(reply);
            };

            messageDispatcher["strongComponent"] = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.from    = msg.to;
                reply.to      = msg.from;
                reply.command = "strongComponent";
                StrongComponent strong = new StrongComponent();
                strong.buildgraph(analyzer.DependencyTable);
                reply.strongComponent = strong.tarjan();
                return(reply);
            };


            // define delegate and put them into the dispatcher dictionary finishe
        }