Exemplo n.º 1
0
        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();
        }