using System; using lliurex; namespace lliurex { namespace controlcenter { public class StatusManager { public System.Collections.Generic.Dictionary values; public StatusManager () { int option; option=0; // old initialization using zero-sqlmanager option=1; // initialization asking sql db directly. switch (option) { case 0: 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(); 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++) { 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); } break; case 1: values=new System.Collections.Generic.Dictionary(); lliurex.controlcenter.Core.getCore().sql.select_query("SELECT * FROM status", out values); break; default: break; } } public void refresh() { Console.WriteLine("[Status Manager] Refreshing info..."); int option; option=1; // executing status on every script and asking zero-sqlmanager option=2; // asking sql database directly switch (option) { case 1: string std_out=""; string std_error=""; foreach(ConfigApplication conf in Core.getCore().applications) { if(conf.service) { string cmd; string arguments; if (conf.using_.Equals("")) { cmd=conf.script_path; arguments="status"; Console.WriteLine("[Status Manager] Executing {0} status ...",cmd); } else { cmd=conf.using_; arguments=conf.script_path + " status"; Console.WriteLine("[Status Manager] Executing {0} {1} ...",cmd,arguments); } System.Threading.ThreadStart starter= delegate { lliurex.utils.Commands.run(cmd,arguments,out std_out,out std_error); };; new System.Threading.Thread(starter).Start(); } } 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(); 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++) { 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); } break; case 2: lliurex.controlcenter.Core.getCore().sql.select_query("SELECT * FROM status", out values); break; default: break; } 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); } 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); } } public int getState(string name) { int return_; if (values.ContainsKey(name)) { return_=values[name]; } else return_=404; return return_; } } } }