public void createProcess(TreeNode site, string role, string name, string s, string url) { string aux = "LocalPMcreateProcess @ url -> " + url + " site -> " + s; Console.WriteLine(aux); if (role.Equals("broker")) { Broker b = new Broker(url, name, s); site.setBroker(b); string port = (portCounter++).ToString(); //Process.Start() ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\DAD\PubSub_v3.1\Broker\bin\Debug\Broker.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args); Process p = new Process(); p.StartInfo = startInfo; p.Start(); } if (role.Equals("subscriber")) { Subscriber sub = new Subscriber(url, name, s); //site.addSubscriber(sub); string port = (portCounter++).ToString(); ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\DAD\PubSub_v3.1\Subscriber\bin\Debug\Subscriber.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args); Process p = new Process(); p.StartInfo = startInfo; p.Start(); } if (role.Equals("publisher")) { Publisher p = new Publisher(url, name, s/*, site.getBroker()*/); //site.addPublisher(p); string port = (portCounter++).ToString(); ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\DAD\PubSub_v3.1\Publisher\bin\Debug\Publisher.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args); Process pro = new Process(); pro.StartInfo = startInfo; pro.Start(); } }
public void createProcess(TreeNode site, string role, string name, string s, string url) { string aux = "LocalPMcreateProcess @ url -> " + url + " site -> " + s; Console.WriteLine(aux); if (role.Equals("broker")) { string port = (portCounter++).ToString(); string brokers = fillArgument(site); ProcessStartInfo startInfo = new ProcessStartInfo(proj_path+@"\Broker\bin\Debug\Broker.exe"); string[] args = { port, url, name, s, brokers }; startInfo.Arguments = String.Join(";", args); Process p = new Process(); p.StartInfo = startInfo; p.Start(); } if (role.Equals("subscriber")) { string port = (portCounter++).ToString(); ProcessStartInfo startInfo = new ProcessStartInfo(proj_path + @"\Subscriber\bin\Debug\Subscriber.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args); Process p = new Process(); p.StartInfo = startInfo; p.Start(); } if (role.Equals("publisher")) { string port = (portCounter++).ToString(); ProcessStartInfo startInfo = new ProcessStartInfo(proj_path + @"\Publisher\bin\Debug\Publisher.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args); Process pro = new Process(); pro.StartInfo = startInfo; pro.Start(); } }
// Search for a string in the specified node and all of its children public TreeNode Find(TreeNode node, string stringToFind) { if (node.ID.Equals(stringToFind)) { return node; } foreach (var child in node._children) { var result = Find(child, stringToFind); if (result != null) return result; } return null; }
//actualiza site_node public TreeNode getRootNodeFromFile(string path) { string[] lines = System.IO.File.ReadAllLines(path); foreach (string line in lines) { if (line.Contains("Parent") && line.Contains("none")) { string[] words = line.Split(' '); TreeNode root = new TreeNode(words[1]); site_treeNode.Add(words[1], root); return root; } } return null; //em principio nao chega aqui }
//actualiza node_broker + site_name public List<MyProcess> fillProcessList(string v, TreeNode root) { PuppetInterface myremote; string[] lines = System.IO.File.ReadAllLines(v); List<MyProcess> res = new List<MyProcess>(); foreach (string line in lines) { if (line.Contains("Is broker")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; fillVizinhos(t); string urlService = words[7].Substring(0, words[7].Length - 6); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface),urlService+"PuppetMasterURL"); myremote.createProcess(t, "broker", words[1], words[5], words[7]); } if (line.Contains("Is publisher")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 9); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface), urlService + "PuppetMasterURL"); myremote.createProcess(t,"publisher", words[1], words[5], words[7]); } if (line.Contains("Is subscriber")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 10); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface), urlService + "PuppetMasterURL"); myremote.createProcess(t,"subscriber", words[1], words[5], words[7]); } } return res; }
public void createProcess(TreeNode site, string role, string name, string s, string url,List<string> urlBroker) { string aux = "LocalPMcreateProcess @ url -> " + url + " site -> " + s; Console.WriteLine(aux); if (role.Equals("broker")) { string[] z = url.Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); string port = y[0]; string brokers = fillArgument(site); string replicas = ""; foreach(var r in urlBroker) { replicas += r + "#"; } ProcessStartInfo startInfo = new ProcessStartInfo(proj_path + @"\Broker\bin\Debug\Broker.exe"); string[] args = { port, url, name, s, replicas, brokers }; startInfo.Arguments = String.Join(";", args); Process p = new Process(); p.StartInfo = startInfo; p.Start(); } if (role.Equals("subscriber")) { string[] z = url.Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); string port = y[0]; ProcessStartInfo startInfo = new ProcessStartInfo(proj_path + @"\Subscriber\bin\Debug\Subscriber.exe"); string[] args = { port, url, name, s }; startInfo.Arguments = String.Join(";", args)+ ";" +String.Join(";",urlBroker); Process p = new Process(); p.StartInfo = startInfo; p.Start(); } if (role.Equals("publisher")) { string[] z = url.Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); string port = y[0]; ProcessStartInfo startInfo = new ProcessStartInfo(proj_path + @"\Publisher\bin\Debug\Publisher.exe"); string[] args = { port, url, name, s}; startInfo.Arguments = String.Join(";", args) + ";" + String.Join(";", urlBroker); Process pro = new Process(); pro.StartInfo = startInfo; pro.Start(); } }
public void AddChild(TreeNode item) { item.Parent = this; this._children.Add(item); }
private void removeChild(TreeNode item) { this._children.Remove(item); }
private void fillVizinhos(TreeNode t) { string brokerName; string info; if (t.Parent != null)//root nao tem PAI { brokerName = node_broker[t.Parent].Name; info = node_broker[t.Parent].Site + "%" + node_broker[t.Parent].URL; t.getVizinhos().Add(brokerName, info); } foreach (var f in t.GetChildren()) { brokerName = node_broker[f].Name; info = node_broker[f].Site + "%" + node_broker[f].URL; t.getVizinhos().Add(brokerName, info); } }
//actualiza site_node ( readTreeFromFile() ) private void find(TreeNode no, string filho, string pai) { List<TreeNode> filhos = no.GetChildren(); if (filhos != null) { foreach (var child in filhos) { if (child.ID.Equals(pai)) { //child e o pai que estavamos a procura TreeNode aux = new TreeNode(filho); child.AddChild(aux); site_treeNode.Add(filho, aux); } } //pai nao esta nos filhos de "no" foreach (var newnode in filhos) { //tentar encontrar pai comecando a procura em cada filho de "no" find(newnode, filho, pai); } } }
public void quickRead(string v, TreeNode root) { string[] lines = System.IO.File.ReadAllLines(v); int siteCount = 0; foreach (string line in lines) { if (line.Contains("LoggingLevel")) { string[] words = line.Split(' ');//words[1] - metodo de log if (words[1].Equals("full")) { logMode = 1; } } if (line.Contains("RoutingPolicy")) { string[] words = line.Split(' ');//words[1] - metodo de routing if(words[1].Equals("filter")){ routing = 1; } } if (line.Contains("Ordering")) { string[] words = line.Split(' ');//words[1] - metodo de ordem if(words[1].Equals("NO")){ order = 0; } if (words[1].Equals("TOTAL")) { order = 2; } } if (line.Contains("Parent")){ string[] words = line.Split(' ');//words[1]-filho, words[3]-pai int mult = 9000 + (siteCount*100); site_port.Add(words[1], mult); siteCount++; } if (line.Contains("Is broker")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar estruturas pname_port[words[1]] = site_port[words[5]] + 1; site_port[words[5]]++; Broker aux = new Broker(words[1], words[5], words[7]); node_broker.Add(t, aux); } if (line.Contains("Is publisher")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar pname_port[words[1]] = site_port[words[5]] + 1; site_port[words[5]]++; } if (line.Contains("Is subscriber")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar pname_port[words[1]] = site_port[words[5]] + 1; site_port[words[5]]++; } } }
//actualiza-se o site_node aqui public void readTreeFromFile(TreeNode root, string path) { string[] lines = System.IO.File.ReadAllLines(path); foreach (string line in lines) { if (line.Contains("Parent") && !line.Contains("none")) { string[] words = line.Split(' '); //words[1]-filho, words[3]-pai if (words[3].Equals(root.ID)) //root e o pai { TreeNode aux = new TreeNode(words[1]); root.AddChild(aux); site_treeNode.Add(words[1], aux); } else { //temos de encontrar o pai, comecando a procura nos filhos do root find(root, words[1], words[3]); } } } }
//actualiza node_broker + site_name public List<MyProcess> fillProcessList(string v, TreeNode root) { PuppetInterface myremote; string[] lines = System.IO.File.ReadAllLines(v); List<MyProcess> res = new List<MyProcess>(); foreach (string line in lines) { if (line.Contains("Is broker")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 6); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface),urlService+"PuppetMasterURL"); myremote.createProcess(t, "broker", words[1], words[5], words[7]); //actualizar estruturas Broker aux = new Broker(words[1], words[5], words[7]); t.setBroker(aux); pname_site.Add(words[1], words[5]); node_broker.Add(t, aux); res.Add(aux); } if (line.Contains("Is publisher")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 9); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface), urlService + "PuppetMasterURL"); myremote.createProcess(t,"publisher", words[1], words[5], words[7]); //actualizar //Broker b = findBroker(words[5]); Publisher aux = new Publisher(words[1], words[5], words[7]/*, b*/); //t.addPublisher(aux); pname_site.Add(words[1], words[5]); res.Add(aux); } if (line.Contains("Is subscriber")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 10); myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface), urlService + "PuppetMasterURL"); myremote.createProcess(t,"subscriber", words[1], words[5], words[7]); //actualizar Subscriber aux = new Subscriber(words[1], words[5], words[7]); //t.addSubscriber(aux); pname_site.Add(words[1], words[5]); res.Add(aux); } } return res; }
private string fillArgument(TreeNode site) { string res = ""; foreach (var aux in site.getVizinhos()) { res += aux.Key + "%" + aux.Value+";"; } return res; }
public void quickRead(string v, TreeNode root) { string[] lines = System.IO.File.ReadAllLines(v); int siteCount = 0; foreach (string line in lines) { if (line.Contains("LoggingLevel")) { string[] words = line.Split(' ');//words[1] - metodo de log if (words[1].Equals("full")) { logMode = 1; } } if (line.Contains("RoutingPolicy")) { string[] words = line.Split(' ');//words[1] - metodo de routing if(words[1].Equals("filtering")){ routing = 1; } } if (line.Contains("Ordering")) { string[] words = line.Split(' ');//words[1] - metodo de ordem if(words[1].Equals("NO")){ order = 0; } if (words[1].Equals("TOTAL")) { order = 2; } } if (line.Contains("Parent")){ string[] words = line.Split(' ');//words[1]-filho, words[3]-pai int mult = 9000 + (siteCount*100); site_port.Add(words[1], mult); siteCount++; } if (line.Contains("is broker")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar estruturas pname_type.Add(words[1], "broker"); string[] z = words[7].Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); int port = Int32.Parse(y[0]); pname_port[words[1]] = port; Broker aux = new Broker(words[7], words[1], words[5]); // se o site já existe adicionar novo broker à lista if (node_broker.ContainsKey(t)) { node_broker[t].Add(aux); } else { node_broker.Add(t, new List<Broker> { aux }); } } if (line.Contains("is publisher")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar pname_type.Add(words[1], "publisher"); string[] z = words[7].Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); int port = Int32.Parse(y[0]); pname_port[words[1]] = port; } if (line.Contains("is subscriber")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; //actualizar pname_type.Add(words[1], "subscriber"); string[] z = words[7].Split(':');//z[0]->tcp;z[1]->//localhost;z[2]->XXXX/broker string[] y = z[2].Split('/'); int port = Int32.Parse(y[0]); pname_port[words[1]] = port; } } }
private void fillVizinhos(TreeNode t) { string brokerName; string info; if (t.Parent != null)//root nao tem PAI { foreach(var b in node_broker[t.Parent]) { brokerName = b.Name; info = b.Site + "%" + b.URL; if (t.getVizinhos().ContainsKey(brokerName) == false) { t.getVizinhos().Add(brokerName, info); } } } foreach (var f in t.GetChildren()) { foreach (var b in node_broker[f]) { brokerName = b.Name; info = b.Site + "%" + b.URL; if (t.getVizinhos().ContainsKey(brokerName) == false) { t.getVizinhos().Add(brokerName, info); } } } }
//actualiza node_broker + site_name public List<MyProcess> fillProcessList(string v, TreeNode root) { PuppetInterface myremote; string[] lines = System.IO.File.ReadAllLines(v); List<MyProcess> res = new List<MyProcess>(); foreach (string line in lines) { if (line.Contains("is broker")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; fillVizinhos(t); //string urlService = words[7].Substring(0, words[7].Length - 6); int portPM = site_port[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 11);//retirar XXXX/broker //get lista de url dos brokers TreeNode pubSite = site_treeNode[words[5]]; List<Broker> siteBroker = node_broker[pubSite]; List<string> urlBrokerList = new List<string>(); foreach (var b in siteBroker) { if (!b.Name.Equals(words[1])) { urlBrokerList.Add(urlService + pname_port[b.Name].ToString() + "/"); } } urlService = urlService + portPM.ToString() + "/"; myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface),urlService+"PuppetMasterURL"); myremote.createProcess(t, "broker", words[1], words[5], words[7],urlBrokerList); } if (line.Contains("is publisher")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 8);//retirar XXXX/publisher //get url do broker /*char idSite = words[5][words[5].Length - 1]; string brokeraux = "broker" + idSite; int portBroker = pname_port[brokeraux]; string urlBroker = urlService + portBroker.ToString()+"/";*/ //get lista de url dos brokers TreeNode pubSite = site_treeNode[words[5]]; List<Broker> siteBroker = node_broker[pubSite]; List<string> urlBrokerList = new List<string>(); foreach(var b in siteBroker) { urlBrokerList.Add(urlService + pname_port[b.Name].ToString() + "/"); } //get url do localPM int portPM = site_port[words[5]]; urlService = urlService + portPM.ToString() + "/"; myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface), urlService + "PuppetMasterURL"); myremote.createProcess(t,"publisher", words[1], words[5], words[7],urlBrokerList); } if (line.Contains("is subscriber")) { string[] words = line.Split(' '); //words[1]-name, words[5]-site, words[7]-url TreeNode t = site_treeNode[words[5]]; string urlService = words[7].Substring(0, words[7].Length - 8);//retirar XXXX/publisher //get url do broker /*char idSite = words[5][words[5].Length - 1]; string brokeraux = "broker" + idSite; int portBroker = pname_port[brokeraux]; string urlBroker = urlService + portBroker.ToString() + "/";*/ //get lista de url dos brokers TreeNode pubSite = site_treeNode[words[5]]; List<Broker> siteBroker = node_broker[pubSite]; List<string> urlBrokerList = new List<string>(); foreach (var b in siteBroker) { urlBrokerList.Add(urlService + pname_port[b.Name].ToString() + "/"); } //get url do localPM int portPM = site_port[words[5]]; urlService = urlService + portPM.ToString() + "/"; myremote = (PuppetInterface)Activator.GetObject(typeof(PuppetInterface), urlService + "PuppetMasterURL"); myremote.createProcess(t,"subscriber", words[1], words[5], words[7],urlBrokerList); } } return res; }