/*----< 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; }
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)); }