Пример #1
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 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("}");
            }
        }
Пример #3
0
        public void req4(string[] args)
        {
            StringBuilder msg = new StringBuilder();

            msg.Append("\n4. These packages shall evaluate all the dependencies between files in a specified file set. Please support specifying the collection as all C# files in a sub-directory tree, rooted at a specified path. You may elect to also provide an alternate means to specify the collection as a list of filenames, but you are not required to do so.");
            msg.Append("\n  Have fulfilled Requirements 4 as the following:");
            Console.WriteLine(msg);
            DepAnalysis.ShowCommandLine(args);
        }
Пример #4
0
        public StringBuilder req5F(List <string> files)
        {
            StringBuilder msg = new StringBuilder();

            //msg.Append(Environment.NewLine + "5. Your dependency analysis shall be based on identification of all the user-defined types in the specified set of files. That means you will need to identify all of the Types defined within that code, e.g., interfaces, classes, structs, enums, and delegates. You will also need to consider aliases, since an alias may refer to a type defined in another file. One last obligation - you need to account for namespaces.");
            //msg.Append(Environment.NewLine + "  Have fulfilled Requirements 5 as the following:");
            msg.Append(DepAnalysis.demoTypeTableF(files));
            msg.Append(DepAnalysis.usageDetailsF(files));
            return(msg);
        }
        // show the result of SCC
        public CsGraph <string, string> show_strong(string[] args)
        {
            DepAnalysis test = new DepAnalysis();

            test.match(args);
            CsGraph <string, string>        dep_graph        = new CsGraph <string, string>("dep_name");
            CsNode <string, string>         graph_start_node = new CsNode <string, string>("start_graph");
            List <CsNode <string, string> > allnode          = new List <CsNode <string, string> >();

            for (int i = 0; i < args.Length; ++i)
            {
                CsNode <string, string> nodes = new CsNode <string, string>(Path.GetFileName(args[i]));
                graph_start_node = nodes;
                allnode.Add(nodes);
            }

            foreach (var ele in test.depentable)
            {
                foreach (var ls in allnode)
                {
                    if (ls.name == ele.Key)
                    {
                        foreach (var item in ele.Value)
                        {
                            foreach (var ls2 in allnode)
                            {
                                if (ls2.name == item)
                                {
                                    ls.addChild(ls2, "XXX");
                                }
                            }
                        }
                    }
                }
            }
            foreach (var ls in allnode)
            {
                dep_graph.addNode(ls);
            }
            //    dep_graph.showDependencies();
            dep_graph.startNode = graph_start_node;

            //   Console.WriteLine("\n\n");
            Console.WriteLine("\n----------------------------show strong component -----------------------");

            dep_graph.tarjan();
            return(dep_graph);
        }
        // This is a test method for testing the requirement 4

        public void requirement4()
        {
            Console.WriteLine();
            Console.WriteLine("This is the requirement 4 test");
            Console.WriteLine("Requirement: Analysis the dependency between all files");
            Console.WriteLine("-----------------------------------------------------------------------");
            FileMg get_cs = new FileMg();

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

            DepAnalysis depana = new DepAnalysis();

            depana.match(all_files);
            depana.show_gra_depent();
            depana.show_rela_result();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Conclusion:  Meet the requirement 4 !!!!");
            Console.WriteLine("-----------------------------------------------------------------------");
        }
        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");
        }
Пример #8
0
        static void Main(string[] args)
        {
            Console.Write("This project contains 13 packages demonstrating requirement 3:\n");
            Console.Write("1) DemoExecutive\n");
            Console.Write("2) DemoReqs\n");
            Console.Write("3) DependencyAnalysis\n");
            Console.Write("4) Display\n");
            Console.Write("5) Element\n");
            Console.Write("6) FileMgr\n");
            Console.Write("7) Parser\n");
            Console.Write("8) SemiExp\n");
            Console.Write("9) StrongComponent\n");
            Console.Write("10) TestHarness\n");
            Console.Write("11) Toker\n");
            Console.Write("12) TypeTable\n");
            Console.Write("13) AutomatedTestUnit\n");
            Console.Write("\n ======================\n");
            Console.Write("\n  Demonstrating Parser");
            Console.Write("\n ======================\n");

            ShowCommandLine(args);

            List <string> files = ProcessCommandline(args);
            DepAnalysis   da    = new DepAnalysis();

            foreach (string file in files)
            {
                Console.Write("\n  Processing file {0}\n", System.IO.Path.GetFileName(file));

                ITokenCollection semi = Factory.create();
                //semi.displayNewLines = false;
                if (!semi.open(file as string))
                {
                    Console.Write("\n  Can't open {0}\n\n", args[0]);
                    return;
                }

                Console.Write("\n  Type and Function Analysis");
                Console.Write("\n ----------------------------");

                BuildCodeAnalyzer builder = new BuildCodeAnalyzer(semi);
                Parser            parser  = builder.build();

                try
                {
                    while (semi.get().Count > 0)
                    {
                        parser.parse(semi);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write("\n\n  {0}\n", ex.Message);
                }
                Repository          rep   = Repository.getInstance();
                List <Elem>         table = rep.locations;
                TypeTable.TypeTable tt    = new TypeTable.TypeTable();
                ///shows typetable
                foreach (Elem e in table)
                {
                    tt.add(e.type, e.name);
                    if (e.type == "using")
                    {
                        da.add(System.IO.Path.GetFileName(file), e.name);
                    }
                }
                tt.show();
                Console.WriteLine("Showing TypeTables of files demonstrating requirement 5:\n");
                Console.Write("\n  TypeTable contains types: ");
                foreach (var elem in tt.table)
                {
                    Console.Write("{0} ", elem.Key);
                }
                ////Display.showMetricsTable(table);

                Console.Write("\n");
                semi.close();
            }
            var nodes = new List <CsNode <string, string> >();

            foreach (var elem in da.table)
            {
                nodes.Add(new CsNode <string, string>(elem.Key));
                //Console.Write("\n  {0} depends on", elem.Key);
            }
            nodes.ToArray();

            //foreach (var elem in da.table)
            //{
            //    foreach (var item in elem.Value)
            //    {
            //        //nodes[IndexOf(elem.Key)].addChild(nodes[IndexOf(item.file)], "edge" + elem.Key + " " + item.file);
            //        //nodes[0].addChild(item.file, "edge" + elem.Key + " " + item.file);
            //        //nodes[nodes.IndexOf(elem.Value)].addChild(nodes[nodes.IndexOf(item.file)], "edge" + elem.Key + " " + item.file);

            //        Console.Write("\n    {0}.cs", item.file);
            //    }
            //}
            //iterate through list of list elements of a file
            //da.table --gets table,
            for (int i = 0; i < da.table.Count; i++)
            {
                var item = da.table.ElementAt(i);
                for (int j = 0; j < item.Value.Count; j++)
                {
                    //Console.WriteLine(i+"^"+ da.table.Values);
                    nodes[i].addChild(nodes[j], "edge" + i + j);
                }
            }
            Graph <string, string> graph = new Graph <string, string>("Fred");

            for (int i = 0; i < da.table.Count; i++)
            {
                graph.addNode(nodes[i]);
            }

            graph.startNode = nodes[0];
            //Console.WriteLine("\n Showing graph walk starting at node[0]\n");
            //Console.Write("\n\n  starting walk at {0}", graph.startNode.name);
            //Console.Write("\n  not showing backtracks");
            //graph.walk();

            Console.WriteLine("Showing dependencies between files demonstrating requrement 4:\n\n");
            //shows dependency analysis
            da.show();
            Console.Write("\n\n");
            Console.Write("Showing all strong components, if any, in the file collection, based on the dependency analysis demonstrating requirement 6:\n\n");
            graph.startNode = nodes[0];
            graph.Tarjan();
            Console.Write("\n\n");
            Console.WriteLine("This demo executive file demonstrates all the outputs and is well formatted as per requirement 7 and 8\n");
            Console.ReadLine();
        }
        /*----< 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;
        }
Пример #10
0
        /*----< 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) =>
            {
                localFileMgr.currentPath = "";
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "getTopDirs";

                string path = System.IO.Path.Combine(Environment.root, localFileMgr.currentPath);

                reply.arguments = new List <string>();
                reply.arguments.Add(path);
                foreach (var dir in localFileMgr.getDirs().ToList <string>())
                {
                    reply.arguments.Add(dir);
                }

                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];
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "moveIntoFolderDirs";

                string path = System.IO.Path.Combine(Environment.root, localFileMgr.currentPath);

                reply.arguments = new List <string>();
                reply.arguments.Add(path);
                foreach (var dir in localFileMgr.getDirs().ToList <string>())
                {
                    reply.arguments.Add(dir);
                }

                localFileMgr.pathStack.Push(localFileMgr.currentPath);
                return(reply);
            };

            messageDispatcher["moveIntoFolderDirs"] = moveIntoFolderDirs;


            Func <CommMessage, CommMessage> moveUpFiles = (CommMessage msg) =>
            {
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to        = msg.from;
                reply.from      = msg.to;
                reply.command   = "moveUpFiles";
                reply.arguments = localFileMgr.getFiles().ToList <string>();
                return(reply);
            };

            messageDispatcher["moveUpFiles"] = moveUpFiles;

            Func <CommMessage, CommMessage> moveUpDirs = (CommMessage msg) =>
            {
                if (localFileMgr.currentPath != "")
                {
                    localFileMgr.pathStack.Pop();
                    localFileMgr.currentPath = localFileMgr.pathStack.Peek();
                }
                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "moveUpDirs";

                string path = System.IO.Path.Combine(Environment.root, localFileMgr.currentPath);

                reply.arguments = new List <string>();
                reply.arguments.Add(path);
                foreach (var dir in localFileMgr.getDirs().ToList <string>())
                {
                    reply.arguments.Add(dir);
                }

                return(reply);
            };

            messageDispatcher["moveUpDirs"] = moveUpDirs;


            Func <CommMessage, CommMessage> getFileDetails = (CommMessage msg) =>
            {
                string path = System.IO.Path.Combine(Environment.root, msg.arguments[0]);

                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "getFileDetails";
                reply.arguments.Add(System.IO.Path.GetFullPath(path));
                return(reply);
            };

            messageDispatcher["getFileDetails"] = getFileDetails;

            Func <CommMessage, CommMessage> analysePath = (CommMessage msg) =>
            {
                /*
                 * Do analysis using path
                 * here message argument is path to directory
                 */

                string[] args = msg.arguments.ToArray();

                string an   = "result.txt";
                string sc   = "strongCom.txt";
                string path = "../../../result/";
                path = System.IO.Path.GetFullPath(path);
                System.IO.Directory.CreateDirectory(path);

                StringBuilder result = new StringBuilder();
                result.Append(DepAnalysis.demoTypeTable(args));
                result.Append(DepAnalysis.usageDetails(args));

                StringBuilder strongcom = new StringBuilder();
                strongcom.Append(DepAnalysis.demoStrongComp(args));

                System.IO.File.WriteAllText(path + an, result.ToString());
                System.IO.File.WriteAllText(path + sc, strongcom.ToString());



                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "displayAnalysis";
                reply.arguments.Add(path + an);
                reply.arguments.Add(path + sc);

                return(reply);
            };

            messageDispatcher["analysePath"] = analysePath;

            Func <CommMessage, CommMessage> analyseFiles = (CommMessage msg) =>
            {
                /*
                 * Do analysis using files
                 * here message arguments are files
                 */
                List <string> files = msg.arguments;

                string an   = "result.txt";
                string sc   = "strongCom.txt";
                string path = "../../../result/";
                path = System.IO.Path.GetFullPath(path);
                System.IO.Directory.CreateDirectory(path);

                StringBuilder result = new StringBuilder();
                result.Append(DepAnalysis.demoTypeTableF(files));
                result.Append(DepAnalysis.usageDetailsF(files));

                StringBuilder strongcom = new StringBuilder();
                strongcom.Append(DepAnalysis.demoStrongCompF(files));

                System.IO.File.WriteAllText(path + an, result.ToString());
                System.IO.File.WriteAllText(path + sc, strongcom.ToString());



                CommMessage reply = new CommMessage(CommMessage.MessageType.reply);
                reply.to      = msg.from;
                reply.from    = msg.to;
                reply.command = "displayAnalysis";
                reply.arguments.Add(path + an);
                reply.arguments.Add(path + sc);

                return(reply);
            };

            messageDispatcher["analyseFiles"] = analyseFiles;
        }
Пример #11
0
 public StringBuilder req6(string[] args)
 {
     //Console.WriteLine("\n6. Shall find all strong components, if any, in the file collection, based on the dependency analysis, cited above.");
     return(DepAnalysis.demoStrongComp(args));
 }