public void SendMessageCS(ClientMsg.Command cmd, Uri src,Uri dst, string body ) { ClientMsg msg = new ClientMsg(); msg.cmd = cmd; msg.src = src; msg.dst = dst; msg.body = body; IMessageService proxy = CreateClientChannel(dst.ToString()); proxy.PostMessageCS(msg); }
static void Main(string[] args) { Console.WriteLine("Starting Message Service on Client1\n"); //HOST client at port 8080 ServiceHost host = CreateServiceChannel("http://localhost:8081/MessageService"); host.Open(); //connect to server and send request for projects IMessageService proxy = CreateClientChannel("http://localhost:8080/MessageService"); MsgClient client=new MsgClient(); System.Threading.Thread t1 = new System.Threading.Thread(() => client.SendMessageCS(ClientMsg.Command.ProjectList, new Uri("http://localhost:8081/MessageService"), new Uri("http://localhost:8080/MessageService"),"from client 1 to server 1")); t1.Start(); t1.Join(); //proxy.PostMessageCS(msg); ClientMsg msg2 = new ClientMsg(); MsgService msgsvc = new MsgService(); while (true) { msg2 = msgsvc.GetMessageCS(); Console.Write("\n\n Received Message from server : " + msg2.src.ToString()+"\n\n"); if(msg2.cmd.ToString()=="DependencyAnalysis") { string name = msg2.body; List<string>names=name.Split('!').ToList(); Console.WriteLine("TypeDependencies"); List<string> name1 = names[0].Split(',').ToList(); foreach(string str in name1) Console.WriteLine("\n"+str); Console.WriteLine("\n\n Package Dependencies"); List<string> name2 = names[1].Split(',').ToList(); foreach (string str in name2) Console.WriteLine("\n"+str); } if(msg2.cmd.ToString()=="ProjectList") { Console.Write("\n\n Received Message from server :"); Console.Write("\n src = {0}\n dst = {1}", msg2.src.ToString(), msg2.dst.ToString()); Console.Write("\n cmd = {0}", msg2.cmd.ToString()); Console.Write("\n body: {0}", msg2.body); System.Threading.Thread t3 = new System.Threading.Thread(() => client.SendMessageCS(ClientMsg.Command.DependencyAnalysis, new Uri("http://localhost:8081/MessageService"), msg2.src, msg2.body)); t3.Start(); t3.Join(); //System.Threading.Thread.Sleep(500); } } Console.Write("\n press any key to terminate service"); Console.ReadKey(); Console.Write("\n"); }
static void Main(string[] args) { Console.WriteLine("Starting Message Service on Server hosted at port 8080\n"); ServiceHost host = CreateServiceChannel("http://localhost:8080/MessageService"); host.Open(); Server server = new Server(); ClientMsg msg2 = new ClientMsg(); MsgService msgsvc = new MsgService(); while (true) { msg2 = msgsvc.GetMessageCS(); if (msg2.cmd.ToString() == "ProjectList") { Console.Write("\n\n Received Message from client-server channel from : {0}\n", msg2.src.ToString()); FileMgr fileManager = new FileMgr(); fileManager.findFiles("../../../Test"); List <string> fileList = fileManager.getFiles1(); string str = ProjectsToXML(fileList); IMessageService proxy = CreateClientChannel(msg2.src.ToString()); server.SendMessageCS(ClientMsg.Command.ProjectList, new Uri("http://localhost:8080/MessageService"), msg2.src, str); } if (msg2.cmd.ToString() == "DependencyAnalysis") { Console.Write("\n\n Received Message from client-server channel from : {0}\n", msg2.src.ToString()); List <string> files = new List <string>(); ClientMsg msg4 = new ClientMsg(); XDocument doc = new XDocument(); doc = XDocument.Parse(msg2.body); var q = from x in doc.Root.Elements("filename") select x; FileMgr fileManager = new FileMgr(); List <string> fileListOld = new List <string>(); try { foreach (string x in q) { files.Add(x.ToString()); } string[] fileList = files.ToArray(); foreach (string f in fileList) { Console.WriteLine("filelist=" + f); } for (int i = 0; i < fileList.Length; i++) { fileManager.findProjs(fileList[i]); fileListOld.AddRange(fileManager.getFiles1()); } } catch (Exception exp) { Console.Write("\n exception thrown: {0}", exp); } string[] fileListNew = fileListOld.ToArray(); Analyzer analyze = new Analyzer(); analyze.doAnalysis(fileListNew); analyze.doAnalysisRelationship(fileListNew); analyze.doPackageDependency(fileListNew); List <ElementRelation> table = RelationshipRepository.relationship_; StringBuilder str = new StringBuilder(); foreach (ElementRelation e in table) { str.Append(e.fromNameSpace + "." + e.fromPackage + "." + e.fromClass + " " + e.relationType + " " + e.toNameSpace + "." + e.toPackage + "." + e.toClass + ","); } str.Append("!"); foreach (ElemDependence x in PackageDependence.dependenceTable) { str.Append(x.package1 + " depends on " + x.package2 + ","); } server.SendMessageCS(ClientMsg.Command.DependencyAnalysis, new Uri("http://localhost:8080/MessageService"), msg2.src, str.ToString()); } } Console.Write("\n press key to terminate service\n"); Console.ReadKey(); Console.Write("\n"); host.Close(); }