//----< processing starts here >---------------------------------

        static void Main(string[] args)
        {
            Console.Write("\n  Dependency Analysis");
            Console.Write("\n =====================\n");

            Executive exec = new Executive();

            ShowCommandLine(args);

            // finding files to analyze

            FileUtilities.Navigate nav = new FileUtilities.Navigate();
            nav.Add("*.cs");
            nav.go(args[0]); // read path from command line
            List <string> files = nav.allFiles;

            exec.typeAnalysis(files);

            Console.Write("\n  TypeTable Contents:");
            Console.Write("\n ---------------------");

            Repository repo = Repository.getInstance();

            repo.typeTable.show();
            Console.Write("\n");

            /////////////////////////////////////////////////////////////////
            // Pass #2 - Find Dependencies

            Console.Write("\n  Dependency Analysis:");
            Console.Write("\n ----------------------");

            exec.dependencyAnalysis(files);
            repo.dependencyTable.show();

            Console.Write("\n\n  building dependency graph");
            Console.Write("\n ---------------------------");

            CsGraph <string, string> graph = exec.buildDependencyGraph();

            graph.showDependencies();

            Console.Write("\n\n  Strong Components:");
            Console.Write("\n --------------------");
            graph.strongComponents();
            foreach (var item in graph.strongComp)
            {
                Console.Write("\n  component {0}", item.Key);
                Console.Write("\n    ");
                foreach (var elem in item.Value)
                {
                    Console.Write("{0} ", elem.name);
                }
            }
            Console.Write("\n\n");
        }
        //----< Generate Dependency Graph of the solution >---------------------------------

        public void dependency_graph_test(string[] args)
        {
            Console.Write("\n " + "Dependency Graph for project 3 shows below: \n");
            Console.Write("\n " + "==================================================== \n");
            Console.Write("\n ");

            CsGraph <string, string> csGraph =
                new CsGraph <string, string>("Dep_Table");

            csGraph = csGraph.Creat_Graph(args);
            csGraph.showDependencies();
        }
        //----< build dependency graph from dependency table >-----------

        public CsGraph <string, string> buildDependencyGraph()
        {
            var repo = Repository.getInstance();

            var graph = new CsGraph <string, string>("deps");

            foreach (var item in repo.dependencyTable.dependencies)
            {
                var fileName = item.Key;
                fileName = Path.GetFileName(fileName);

                var node = new CsNode <string, string>(fileName);
                graph.addNode(node);
            }

            var dt = new DependencyTable();

            foreach (var item in repo.dependencyTable.dependencies)
            {
                var fileName = item.Key;
                fileName = Path.GetFileName(fileName);
                if (!dt.dependencies.ContainsKey(fileName))
                {
                    var deps = new List <string>();
                    dt.dependencies.Add(fileName, deps);
                }

                foreach (var elem in item.Value)
                {
                    var childFile = elem;
                    childFile = Path.GetFileName(childFile);
                    dt.dependencies[fileName].Add(childFile);
                }
            }

            foreach (var item in graph.adjList)
            {
                var node     = item;
                var children = dt.dependencies[node.name];
                foreach (var child in children)
                {
                    var index = graph.findNodeByName(child);
                    if (index != -1)
                    {
                        var dep = graph.adjList[index];
                        node.addChild(dep, "edge");
                    }
                }
            }

            return(graph);
        }
        //----< Generate Strong Conponent of the solution >---------------------------------

        public void Strong_Conponent_test(string[] args)
        {
            Console.Write("\n ");
            Console.Write("\n " + "Strong Conponents for project 3 shows below: \n");
            Console.Write("\n " + "==================================================== \n");
            Console.Write("\n ");

            CsGraph <string, string> csGraph =
                new CsGraph <string, string>("Dep_Table");

            csGraph = csGraph.Creat_Graph(args);
            csGraph.sc_finder();
        }
        public void StrongComponentResultFile(List <string> arguments, string sscresult)
        {
            Console.Write("\n------------------------------");
            Console.Write("\n STRONG COMPONENT");
            Console.Write("\n------------------------------");
            Repository rep = Repository.getInstance();

            typeTableAnanlsis(arguments, sscresult, false);
            DependencyResult(arguments, sscresult, false);
            CsGraph <string, string> graph = buildDependencyGraph();

            graph.strongComponents();
            if (File.Exists(sscresult))
            {
                using (var textWriter = new StreamWriter(sscresult, false))
                {
                    foreach (var item in graph.strongComp)
                    {
                        Console.Write("\n  component {0}", item.Key);
                        Console.Write("\n    ");
                        textWriter.Write("\n  component {0}", item.Key);
                        textWriter.Write("\n    ");
                        foreach (var elem in item.Value)
                        {
                            Console.Write("{0} ", elem.name);
                            textWriter.Write("{0} ", elem.name);
                        }
                    }
                }
            }
            else if (!File.Exists(sscresult))
            {
                File.Create(sscresult);
                TextWriter textwriter = new StreamWriter(sscresult);
                foreach (var item in graph.strongComp)
                {
                    Console.Write("\n  component {0}", item.Key);
                    Console.Write("\n    ");
                    textwriter.Write("\n  component {0}", item.Key);
                    textwriter.Write("\n    ");
                    foreach (var elem in item.Value)
                    {
                        Console.Write("{0} ", elem.name);
                        textwriter.Write("{0} ", elem.name);
                    }
                }
                textwriter.Close();
            }
        }
        //performs strong compoenent analysis
        void performStrongComp()
        {
            Func <CommMessage, CommMessage> performStrongComp = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "performStrongComp";
                Executive exe = new Executive();
                foreach (var item in msg.arguments)
                {
                    string path = System.IO.Path.Combine(Environment.root, item);
                    string b    = System.IO.Path.GetFullPath(path);
                    exe.files.Add(b);
                }
                exe.typeAnalysis(exe.files);
                exe.dependencyAnalysis(exe.files);
                Repository repo = Repository.getInstance();
                repo.typeTable.show();
                repo.dependencyTable.show();
                Console.Write("\n\n  Building dependency graph");
                Console.Write("\n ---------------------------");

                CsGraph <string, string> graph = exe.buildDependencyGraph();
                graph.showDependencies();

                Console.Write("\n\n  Strong Components:");
                Console.Write("\n --------------------");
                graph.strongComponents();
                foreach (var item in graph.strongComp)
                {
                    Console.Write("\n  Component {0}", item.Key);
                    Console.Write("\n    ");
                    foreach (var elem in item.Value)
                    {
                        Console.Write("{0} ", elem.name);
                    }
                }
                strongCompToString(graph);
                Console.Write("\n\n");

                reply.arguments = strongCompMessage;

                return(reply);
            };

            messageDispatcher["performStrongComp"] = performStrongComp;
        }
        public void displaystrongcomponent(List <string> arguments, string displaytokenfile)
        {
            Repository repo = Repository.getInstance();

            TypeAnalys(arguments, displaytokenfile, false);
            DependencyAnalys(arguments, displaytokenfile, false);
            CsGraph <string, string> graph = buildDependencyGraph();

            graph.strongComponents();

            if (!File.Exists(displaytokenfile))
            {
                File.Create(displaytokenfile);
                TextWriter wr = new StreamWriter(displaytokenfile);
                foreach (var item in graph.strongComp)
                {
                    Console.Write("\n  component {0}", item.Key);
                    Console.Write("\n    ");
                    wr.Write("\n  component {0}", item.Key);
                    wr.Write("\n    ");
                    foreach (var elem in item.Value)
                    {
                        Console.Write("{0} ", elem.name);
                        wr.Write("{0} ", elem.name);
                    }
                }
                wr.Close();
            }
            else if (File.Exists(displaytokenfile))
            {
                using (var wr = new StreamWriter(displaytokenfile, false))
                {
                    foreach (var item in graph.strongComp)
                    {
                        Console.Write("\n  component {0}", item.Key);
                        Console.Write("\n    ");
                        wr.Write("\n  component {0}", item.Key);
                        wr.Write("\n    ");
                        foreach (var elem in item.Value)
                        {
                            Console.Write("{0} ", elem.name);
                            wr.Write("{0} ", elem.name);
                        }
                    }
                }
            }
        }
        // This is a test method for testing the requirement 5

        public void requirement5()
        {
            Console.WriteLine();
            Console.WriteLine("This is the requirement 5 test");
            Console.WriteLine("Requirement: Find the strong connected component between all files");
            Console.WriteLine("-----------------------------------------------------------------------");
            FileMg get_cs = new FileMg();

            string[] all_files = get_cs.find_solu_all_cs(get_cs.get_solu_path());

            CsGraph <string, string> test = new CsGraph <string, string>("test");

            test.show_strong(all_files);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Conclusion:  Meet the requirement 5 !!!!");
            Console.WriteLine("-----------------------------------------------------------------------");
        }
 public Repository()
 {
     if (graph_ == null)
     {
         graph_ = new CsGraph <string, string>("Dependency Graph");
     }
     if (typeTable == null)
     {
         typeTable = new TypeTable();
     }
     if (aliasTable == null)
     {
         aliasTable = new Dictionary <string, List <string> >();
     }
     if (nameSpace == null)
     {
         nameSpace = new Dictionary <string, List <string> >();
     }
 }
 void strongCompToString(CsGraph <string, string> graph)
 {
     strongCompMessage.Clear();
     foreach (var item in graph.strongComp)
     {
         string file = item.Key.ToString();
         strongCompMessage.Add(file);
         if (item.Value.Count == 0)
         {
             strongCompMessage.Add(";");
             continue;
         }
         strongCompMessage.Add(":");
         foreach (var elem in item.Value)
         {
             strongCompMessage.Add(elem.name.ToString());
             strongCompMessage.Add("\t");
         }
         strongCompMessage.Add(";");
     }
 }
        /*----< define how each message will be processed >------------*/

        void initializeDispatcher()
        {
            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>();
                return(reply);
            };

            messageDispatcher["getTopFiles"] = getTopFiles;

            Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) =>
            {
                if (localFileMgr.pathStack.Count != 1)
                {
                    localFileMgr.pathStack.Clear();
                }

                Console.WriteLine(localFileMgr.currentPath);
                localFileMgr.currentPath = "";
                localFileMgr.pathStack.Push(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>();
                return(reply);
            };

            messageDispatcher["getTopDirs"] = getTopDirs;

            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;

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

            messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs;

            Func <CommMessage, CommMessage> moveUpDirs = (CommMessage msg) =>
            {
                if (localFileMgr.pathStack.Count != 1)
                {
                    localFileMgr.pathStack.Pop();
                    localFileMgr.currentPath = localFileMgr.pathStack.Peek();
                }
                else
                {
                    localFileMgr.pathStack.Pop();
                    localFileMgr.currentPath = Environment.root;
                    localFileMgr.pathStack.Push(localFileMgr.currentPath);
                    localFileMgr.currentPath = localFileMgr.pathStack.Peek();
                }
                Console.WriteLine(localFileMgr.currentPath);
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "moveUpDirs";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                //Console.WriteLine(localFileMgr.pathStack.Count);
                return(reply);
            };

            messageDispatcher["moveUpDirs"] = moveUpDirs;

            Func <CommMessage, CommMessage> moveUpDirsFile = (CommMessage msg) =>
            {
                if (localFileMgr.pathStack.Count != 0)
                {
                    localFileMgr.currentPath = localFileMgr.pathStack.Peek();
                }
                else
                {
                    localFileMgr.currentPath = Environment.root;
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "moveUpDirsFile";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                Console.WriteLine(localFileMgr.pathStack.Count);
                return(reply);
            };

            messageDispatcher["moveUpDirsFile"] = moveUpDirsFile;

            Func <CommMessage, CommMessage> moveSelectedFiles = (CommMessage msg) =>
            {
                int temp = 0;
                foreach (var item in selected)
                {
                    if (item == msg.arguments[0])
                    {
                        temp = 1;
                    }
                }
                if (temp == 0 && Path.GetExtension(msg.arguments[0]) == ".cs")
                {
                    selected.Add(msg.arguments[0]);
                }

                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "moveSelectedFiles";
                foreach (var i in selected)
                {
                    reply.arguments.Add(i);
                }
                return(reply);
            };

            messageDispatcher["moveSelectedFiles"] = moveSelectedFiles;

            Func <CommMessage, CommMessage> Add_all = (CommMessage msg) =>
            {
                foreach (var item in msg.arguments)
                {
                    int temp = 0;
                    foreach (var elem in selected)
                    {
                        if (elem == item)
                        {
                            temp = 1;
                        }
                    }
                    if (temp == 0 && Path.GetExtension(item) == ".cs")
                    {
                        selected.Add(item);
                    }
                }

                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "Add_all";
                foreach (var i in selected)
                {
                    reply.arguments.Add(i);
                }
                // reply.arguments = selected;
                return(reply);
            };

            messageDispatcher["Add_all"] = Add_all;

            Func <CommMessage, CommMessage> removeSelectedFiles = (CommMessage msg) =>
            {
                for (var i = 0; i < selected.Count; i++)
                {
                    Console.WriteLine(selected[i]);
                    if (selected[i] == msg.arguments[0])
                    {
                        selected.Remove(selected[i]);
                    }
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "removeSelectedFiles";
                foreach (var i in selected)
                {
                    reply.arguments.Add(i);
                }
                // reply.arguments = selected;
                return(reply);
            };

            messageDispatcher["removeSelectedFiles"] = removeSelectedFiles;

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

                reply.arguments = selected;
                return(reply);
            };

            messageDispatcher["clearSelectedFiles"] = clearSelectedFiles;

            Func <CommMessage, CommMessage> Generate_TT = (CommMessage msg) => {
                List <string> file_list = new List <string>();
                string        ttt       = Path.GetFullPath(ServerEnvironment.root);
                for (var i = 0; i < msg.arguments.Count; i++)
                {
                    file_list.Add(ttt + msg.arguments[i]);
                }
                TypeTable tt = new TypeTable();
                tt = tt.GetTable(file_list.ToArray());
                for (var i = 0; i < file_list.Count; i++)
                {
                    string temp = Path.GetFileNameWithoutExtension(file_list[i]);

                    file_list[i] = temp;
                    Console.WriteLine(file_list[i]);
                }
                //List<string> type_table = tt.print();
                string      type_table = tt.tt_to_string();
                CommMessage reply      = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "Generate_TT";

                List <string> tt_t = new List <string>();
                tt_t.Add("");
                if (type_table.Length > 1024)
                {
                    string pp = "";
                    for (int i = 0; i < type_table.Length; i++)
                    {
                        pp += type_table[i];
                        if (pp.Length >= 1024)
                        {
                            reply.arguments.Add(pp);
                            pp = "";
                        }
                    }
                    reply.arguments.Add(pp);
                    pp = "";
                }
                else
                {
                    reply.arguments.Add(type_table);
                }
                return(reply);
            };

            messageDispatcher["Generate_TT"] = Generate_TT;

            Func <CommMessage, CommMessage> Generate_DT = (CommMessage msg) => {
                List <string> file_list = new List <string>();
                string        ttt       = Path.GetFullPath(ServerEnvironment.root);
                for (var i = 0; i < msg.arguments.Count; i++)
                {
                    file_list.Add(ttt + msg.arguments[i]);
                }
                DepenAnalysis dp = new DepenAnalysis();
                dp = dp.DepenAnalysises(file_list.ToArray());
                for (var i = 0; i < file_list.Count; i++)
                {
                    string temp = Path.GetFileNameWithoutExtension(file_list[i]);

                    file_list[i] = temp;
                    Console.WriteLine(file_list[i]);
                }

                //List<string> dep_table = dp.asign_table();
                string      dep_table = dp.dep_tostring();
                CommMessage reply     = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "Generate_DT";
                if (dep_table.Length > 1024)
                {
                    string pp = "";
                    for (int i = 0; i < dep_table.Length; i++)
                    {
                        pp += dep_table[i];
                        if (pp.Length >= 1024)
                        {
                            reply.arguments.Add(pp);
                            pp = "";
                        }
                    }
                    reply.arguments.Add(pp);
                    pp = "";
                }
                else
                {
                    reply.arguments.Add(dep_table);
                }
                return(reply);
            };

            messageDispatcher["Generate_DT"] = Generate_DT;

            Func <CommMessage, CommMessage> Generate_SC = (CommMessage msg) =>
            {
                List <string> file_list = new List <string>();
                string        ttt       = Path.GetFullPath(ServerEnvironment.root);
                for (var i = 0; i < msg.arguments.Count; i++)
                {
                    file_list.Add(ttt + msg.arguments[i]);
                }

                CsGraph <string, string> csGraph = new CsGraph <string, string>("Dep_Table");
                csGraph = csGraph.Creat_Graph(file_list.ToArray());
                csGraph.sc_finder();
                for (var i = 0; i < file_list.Count; i++)
                {
                    string temp = Path.GetFileNameWithoutExtension(file_list[i]);

                    file_list[i] = temp;
                    Console.WriteLine(file_list[i]);
                }
                string      SC    = csGraph.SC_tostring();
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "Generate_SC";
                if (SC.Length > 1024)
                {
                    string pp = "";
                    for (int i = 0; i < SC.Length; i++)
                    {
                        pp += SC[i];
                        if (pp.Length >= 1024)
                        {
                            reply.arguments.Add(pp);
                            pp = "";
                        }
                    }
                    reply.arguments.Add(pp);
                    pp = "";
                }
                else
                {
                    reply.arguments.Add(SC);
                }
                return(reply);
            };

            messageDispatcher["Generate_SC"] = Generate_SC;

            Func <CommMessage, CommMessage> importone = (CommMessage msg) => {
                string        path      = Path.GetFullPath(ServerEnvironment.root);
                List <string> dirs_list = new List <string>();
                string        ttt       = Path.GetFullPath(ServerEnvironment.root) + msg.arguments[0];
                Console.WriteLine(msg.arguments[0] + "debuggogogo");
                string        judge     = msg.arguments[0] + "debuggogogo";
                List <string> file_list = new List <string>();
                file_list.AddRange(Directory.GetFiles(ttt).ToList <string>());
                dirs_list.AddRange(Directory.GetDirectories(ttt).ToList <string>());
                int temp1 = path.Length;
                foreach (var i in dirs_list)
                {
                    file_list.AddRange(Directory.GetFiles(i).ToList <string>());
                }
                for (var i = 0; i < file_list.Count; i++)
                {
                    if (judge == "debuggogogo")
                    {
                        file_list[i] = file_list[i].Remove(temp1);
                        Console.WriteLine(file_list[i]);
                        file_list[i] = Path.GetFileName(file_list[i]);
                    }
                    else
                    {
                        file_list[i] = file_list[i].Remove(0, temp1);
                    }
                }
                if (msg.arguments.Count == 0)
                {
                    selected = selected;
                }
                else
                {
                    foreach (var item in file_list)
                    {
                        int temp = 0;
                        foreach (var elem in selected)
                        {
                            if (elem == item)
                            {
                                temp = 1;
                            }
                        }
                        if (temp == 0 && Path.GetExtension(item) == ".cs")
                        {
                            selected.Add(item);
                        }
                    }
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "importone";
                foreach (var i in selected)
                {
                    reply.arguments.Add(i);
                }
                return(reply);
            };

            messageDispatcher["importone"] = importone;

            Func <CommMessage, CommMessage> importall = (CommMessage msg) =>
            {
                localFileMgr.all_files.Clear();
                if (localFileMgr.pathStack.Count == 1)
                {
                    localFileMgr.currentPath = ServerEnvironment.root;
                }
                else
                {
                    localFileMgr.currentPath = ServerEnvironment.root + localFileMgr.pathStack.Peek();
                }
                Console.WriteLine(localFileMgr.currentPath);

                string temp  = Path.GetFullPath(ServerEnvironment.root);
                int    temp2 = temp.Length;


                string        dirPath   = Path.GetFullPath(localFileMgr.currentPath);
                List <string> file_sets = new List <string>();



                localFileMgr.FindFile(dirPath);
                file_sets = localFileMgr.all_files;
                for (var i = 0; i < file_sets.Count; i++)
                {
                    file_sets[i] = file_sets[i].Remove(0, temp2);
                }
                selected = file_sets;



                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "importall";
                reply.arguments = file_sets;
                return(reply);
            };

            messageDispatcher["importall"] = importall;
        }
        /*----< define how each message will be processed >------------*/

        void initializeDispatcher()
        {
            // process the message and reply the new files address
            Func <CommMessage, CommMessage> Start_Browse_Files = (CommMessage msg) =>
            {
                Environment.Environment.root = msg.arguments[0];
                Console.WriteLine(Environment.Environment.root);
                localFileMgr.pathStack.Clear();
                msg.arguments.Clear();
                localFileMgr.currentPath = "";
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "Start_Browse_Files";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                return(reply);
            };

            messageDispatcher["Start_Browse_Files"] = Start_Browse_Files;

            // process the message and reply the new dirs address
            Func <CommMessage, CommMessage> Start_Browse_Dirs = (CommMessage msg) =>
            {
                Environment.Environment.root = msg.arguments[0];
                localFileMgr.pathStack.Clear();
                msg.arguments.Clear();
                localFileMgr.currentPath = "";
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "Start_Browse_Dirs";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                return(reply);
            };

            messageDispatcher["Start_Browse_Dirs"] = Start_Browse_Dirs;
            // process the message and reply the new message to get top files
            Func <CommMessage, CommMessage> getTopFiles = (CommMessage msg) =>
            {
                localFileMgr.pathStack.Clear();
                msg.arguments.Clear();
                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>();
                return(reply);
            };

            messageDispatcher["getTopFiles"] = getTopFiles;
            // process the message and reply the new message to get top dirs
            Func <CommMessage, CommMessage> getTopDirs = (CommMessage msg) =>
            {
                localFileMgr.pathStack.Clear();
                msg.arguments.Clear();
                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>();
                return(reply);
            };

            messageDispatcher["getTopDirs"] = getTopDirs;

            // process the message and reply the new message to move into next files
            Func <CommMessage, CommMessage> moveIntoFolderFiles = (CommMessage msg) =>
            {
                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;

            // process the message and reply the new message to move into next dirs
            Func <CommMessage, CommMessage> moveIntoFolderDirs = (CommMessage msg) =>
            {
                string dirName = msg.arguments.Last().ToString();
                localFileMgr.pathStack.Push(localFileMgr.currentPath);
                localFileMgr.currentPath = dirName;
                Console.WriteLine("now add ress : --------------{0}", dirName);

                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "moveIntoFolderDirs";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                return(reply);
            };

            messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs;

            // process the message and reply the new message to double click files
            Func <CommMessage, CommMessage> DoubleClickFiles = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "DoubleClickFiles";
                reply.arguments = msg.arguments;
                return(reply);
            };

            messageDispatcher["DoubleClickFiles"] = DoubleClickFiles;

            // process the message and reply the new message to go back upper dirs
            Func <CommMessage, CommMessage> GoToUpDir = (CommMessage msg) =>
            {
                if (localFileMgr.currentPath != "")
                {
                    localFileMgr.currentPath = localFileMgr.pathStack.Peek();
                    localFileMgr.pathStack.Pop();
                }
                else
                {
                    localFileMgr.currentPath = "";
                }

                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "GoToUpDir";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                return(reply);
            };

            messageDispatcher["GoToUpDir"] = GoToUpDir;

            // process the message and reply the new message to go back upper files
            Func <CommMessage, CommMessage> GoToUpFiles = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "GoToUpFiles";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                return(reply);
            };

            messageDispatcher["GoToUpFiles"] = GoToUpFiles;

            // process the message and reply the new message to typetable analysis
            Func <CommMessage, CommMessage> Rq_Analysis_Ttable = (CommMessage msg) =>
            {
                List <string> files = new List <string>();
                string        path  = Path.Combine(Environment.Environment.root, localFileMgr.currentPath);
                Console.WriteLine(" string path = Path.Combine(Environment.Environment.root,localFileMgr.currentPath)  --- list:  {0}", path);
                string absPath = Path.GetFullPath(path);
                Console.WriteLine(" string absPath = Path.GetFullPath(path);  --- list:  {0}", absPath);
                localFileMgr.FindFile(absPath);
                files = localFileMgr.all_files;
                string[]  xx      = files.ToArray();
                TypeTable t_table = new TypeTable();
                foreach (var aa in xx)
                {
                    Console.WriteLine(aa);
                }
                t_table = t_table.getTypeTable(files.ToArray());
                string result = t_table.tt_to_string();
                Console.WriteLine("----------------------------------- {0}", result.Length);
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "Rq_Analysis_Ttable";

                reply.arguments.Clear();
                if (result.Length > 1024)
                {
                    string pp = "";
                    for (int i = 0; i < result.Length; i++)
                    {
                        pp += result[i];
                        if (pp.Length >= 1024)
                        {
                            reply.arguments.Add(pp);
                            pp = "";
                        }
                    }
                    reply.arguments.Add(pp);
                    pp = "";
                }
                else
                {
                    reply.arguments.Add(result);
                }

                localFileMgr.all_files.Clear();
                return(reply);
            };

            messageDispatcher["Rq_Analysis_Ttable"] = Rq_Analysis_Ttable;

            // process the message and reply the new message to Dependency analysis
            Func <CommMessage, CommMessage> Rq_Analysis_Depend = (CommMessage msg) =>
            {
                List <string> files = new List <string>();
                string        path  = Path.Combine(Environment.Environment.root, localFileMgr.currentPath);
                Console.WriteLine(" string path = Path.Combine(Environment.Environment.root,localFileMgr.currentPath)  --- list:  {0}", path);
                string absPath = Path.GetFullPath(path);
                Console.WriteLine(" string absPath = Path.GetFullPath(path);  --- list:  {0}", absPath);
                localFileMgr.FindFile(absPath);
                files = localFileMgr.all_files;
                DepAnalysis depend_analysis = new DepAnalysis();
                depend_analysis.match(files.ToArray());
                string      result = depend_analysis.dep_tostring();
                CommMessage reply  = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "Rq_Analysis_Depend";
                reply.arguments.Clear();
                if (result.Length > 1024)
                {
                    string pp = "";
                    for (int i = 0; i < result.Length; i++)
                    {
                        pp += result[i];
                        if (pp.Length >= 1024)
                        {
                            reply.arguments.Add(pp);
                            pp = "";
                        }
                    }
                    reply.arguments.Add(pp);
                    pp = "";
                }
                else
                {
                    reply.arguments.Add(result);
                }


                localFileMgr.all_files.Clear();
                return(reply);
            };

            messageDispatcher["Rq_Analysis_Depend"] = Rq_Analysis_Depend;

            // process the message and reply the new message to Strong componenet analysis
            Func <CommMessage, CommMessage> Rq_Analysis_SCC = (CommMessage msg) =>
            {
                List <string> files = new List <string>();
                string        path  = Path.Combine(Environment.Environment.root, localFileMgr.currentPath);
                Console.WriteLine(" string path = Path.Combine(Environment.Environment.root,localFileMgr.currentPath)  --- list:  {0}", path);
                string absPath = Path.GetFullPath(path);
                Console.WriteLine(" string absPath = Path.GetFullPath(path);  --- list:  {0}", absPath);
                localFileMgr.FindFile(absPath);
                files = localFileMgr.all_files;
                CsGraph <string, string> scc = new CsGraph <string, string>("scc");
                string      result           = scc.show_strong(files.ToArray()).SC_tostring();
                CommMessage reply            = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "Rq_Analysis_SCC";
                reply.arguments.Clear();
                if (result.Length > 1024)
                {
                    string pp = "";
                    for (int i = 0; i < result.Length; i++)
                    {
                        pp += result[i];
                        if (pp.Length >= 1024)
                        {
                            reply.arguments.Add(pp);
                            pp = "";
                        }
                    }
                    reply.arguments.Add(pp);
                    pp = "";
                }
                else
                {
                    reply.arguments.Add(result);
                }


                localFileMgr.all_files.Clear();
                return(reply);
            };

            messageDispatcher["Rq_Analysis_SCC"] = Rq_Analysis_SCC;

            // process the message and reply the new message to connect to server and obtain files
            Func <CommMessage, CommMessage> ConnectToServerFile = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "ConnectToServerFile";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                return(reply);
            };

            messageDispatcher["ConnectToServerFile"] = ConnectToServerFile;

            // process the message and reply the new message to connect to server and obtain dirs
            Func <CommMessage, CommMessage> ConnectToServerDir = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "ConnectToServerDir";
                reply.arguments = localFileMgr.getDirs().ToList <string>();
                return(reply);
            };

            messageDispatcher["ConnectToServerDir"] = ConnectToServerDir;
        }
Exemplo n.º 13
0
 public StrongComponent()
 {
     graph = new CsGraph <string, string>("mygraph");
 }