using System; using lliurex; namespace lliurex { namespace controlcenter { public class StatusManager { // public const string file_path="/usr/share/zero-center/applications/app_status.sts"; public System.Collections.Generic.Dictionary values; public StatusManager () { // int a=Core.getCore().win.appboxes.Count; // Console.WriteLine(a); try { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput=true; p.StartInfo.FileName = "bash"; p.StartInfo.Arguments="/usr/sbin/zero-sqlmanager -l"; p.Start(); string output=p.StandardOutput.ReadToEnd(); // Console.WriteLine("We're getting..."); // Console.WriteLine(output); p.WaitForExit(); values=new System.Collections.Generic.Dictionary(); string[] strArr = null; char[] split_chr= { ' ','\n' }; strArr = output.Split(split_chr); for (int i=0; i<=strArr.Length - 2; i++) { // Console.WriteLine(i + " " + strArr[i]); values.Add(strArr[i],int.Parse(strArr[i+1])); i++; } /* foreach (System.Collections.Generic.KeyValuePair n in values) { Console.WriteLine(n); // Console.WriteLine(n.Key); // Console.WriteLine(n.Value); } */ } catch(System.ComponentModel.Win32Exception w) { Console.WriteLine(w.Message); Console.WriteLine(w.ErrorCode.ToString()); Console.WriteLine(w.NativeErrorCode.ToString()); Console.WriteLine(w.StackTrace); Console.WriteLine(w.Source); Exception e=w.GetBaseException(); Console.WriteLine(e.Message); } } public void refresh() { Console.WriteLine("[Status Manager] Refreshing info..."); //lliurex.utils.Commands.run(); string std_out=""; string std_error=""; foreach(ConfigApplication conf in Core.getCore().applications) { if(conf.service) { System.Threading.ThreadStart starter; if (conf.using_.Equals("")) { starter = delegate { lliurex.utils.Commands.run(conf.script_path,"status",out std_out,out std_error); }; } else { string command=conf.script_path + " status"; starter = delegate { lliurex.utils.Commands.run(conf.using_,command,out std_out,out std_error); }; } new System.Threading.Thread(starter).Start(); // lliurex.utils.Commands.run(conf.script_path,"status",out std_out,out std_error); Console.WriteLine("[Status Manager] Executing {0} status ...",conf.script_path); } } try { // no conocia lliurex.utils aun, que pasa! System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput=true; p.StartInfo.FileName = "bash"; p.StartInfo.Arguments="/usr/sbin/zero-sqlmanager -l"; p.Start(); string output=p.StandardOutput.ReadToEnd(); // Console.WriteLine("We're getting..."); // Console.WriteLine(output); p.WaitForExit(); values=new System.Collections.Generic.Dictionary(); string[] strArr = null; char[] split_chr= { ' ','\n' }; strArr = output.Split(split_chr); for (int i=0; i<=strArr.Length - 2; i++) { // Console.WriteLine(i + " " + strArr[i]); values.Add(strArr[i],int.Parse(strArr[i+1])); i++; } } catch(System.ComponentModel.Win32Exception w) { Console.WriteLine(w.Message); Console.WriteLine(w.ErrorCode.ToString()); Console.WriteLine(w.NativeErrorCode.ToString()); Console.WriteLine(w.StackTrace); Console.WriteLine(w.Source); Exception e=w.GetBaseException(); Console.WriteLine(e.Message); } Console.WriteLine("[Status Manager] List of scripts running in the system:"); foreach (System.Collections.Generic.KeyValuePair n in values) { Console.WriteLine("[Status Manager] * {0}",n); // Console.WriteLine(n.Key); // Console.WriteLine(n.Value); } //int result=sm.getState(app.name); foreach(ConfigApplication conf in Core.getCore().applications) { int result=Core.getCore().sm.getState(conf.name); if (result!=404) conf.status=(uint)result; } if (Core.getCore().win.appboxes!=null) foreach (ApplicationBox appbox in Core.getCore().win.appboxes) { //because there can be more than one... right? appbox.SetStatusText(); } } public void printReadList() { foreach (System.Collections.Generic.KeyValuePair n in values) { Console.WriteLine("[Status Manager] * {0}",n); // Console.WriteLine(n.Key); // Console.WriteLine(n.Value); } } public int getState(string name) { bool found=false; int return_; int tmp=(int)Core.S_CONF_NEEDED; foreach (System.Collections.Generic.KeyValuePair n in values) { if (name==n.Key) { found=true; tmp=n.Value; } } if (found) { // Console.WriteLine("Found!"); return_=tmp; // Console.WriteLine(return_); } else { return_=404; } return return_; } } } }