Example #1
0
        public StringBuilder req5(string[] args)
        {
            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.demoTypeTable(args));
            msg.Append(DepAnalysis.usageDetails(args));
            return(msg);
        }
Example #2
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;
        }