コード例 #1
0
        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("}");
            }
        }
        /*----< 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
        }