public Hashtable ProcessDiagnostics() { Hashtable ret = new Hashtable(); foreach (Type t in Utility.LocateTypeInstances(typeof(IDiagnosable))) { Object obj = null; foreach (MethodInfo mi in t.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)) { if (mi.GetCustomAttributes(typeof(DiagnosticFunctionAttribute), false).Length > 0) { DiagnosticFunctionAttribute att = ((DiagnosticFunctionAttribute)mi.GetCustomAttributes(typeof(DiagnosticFunctionAttribute), false)[0]); bool run = true; if (att.RequiredRights != null) { foreach (string str in att.RequiredRights) { if (!User.Current.HasRight(str)) { run = false; break; } } } if (run) { Delegate del = null; if (mi.IsStatic) { del = Delegate.CreateDelegate(typeof(DiagnosticFunctionAttribute.DiagnosticsDelegate), mi); } else { if (obj == null) { obj = t.GetConstructor(Type.EmptyTypes).Invoke(null); } del = DiagnosticFunctionAttribute.DiagnosticsDelegate.CreateDelegate(t, obj, mi.Name); } List <string> tmp = ((DiagnosticFunctionAttribute.DiagnosticsDelegate)del).Invoke(); if (tmp != null) { string name = att.GroupName; if (ret.ContainsKey(name)) { tmp.AddRange((List <string>)ret[name]); ret.Remove(name); ret.Add(name, tmp); } else { ret.Add(name, tmp); } } } } } } return(ret); }
static void Main(string[] args) { if (new List <string>(args).Contains("--RunDiagnostics")) { Console.Clear(); Dictionary <string, List <string> > diags = new Dictionary <string, List <string> >(); foreach (Type t in Utility.LocateTypeInstances(typeof(IDiagnosable))) { Object obj = null; foreach (MethodInfo mi in t.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)) { if (mi.GetCustomAttributes(typeof(DiagnosticFunctionAttribute), false).Length > 0) { DiagnosticFunctionAttribute att = ((DiagnosticFunctionAttribute)mi.GetCustomAttributes(typeof(DiagnosticFunctionAttribute), false)[0]); Delegate del = null; if (mi.IsStatic) { del = Delegate.CreateDelegate(typeof(DiagnosticFunctionAttribute.DiagnosticsDelegate), mi); } else { if (obj == null) { obj = t.GetConstructor(Type.EmptyTypes).Invoke(null); } del = DiagnosticFunctionAttribute.DiagnosticsDelegate.CreateDelegate(t, obj, mi.Name); } List <string> tmp = ((DiagnosticFunctionAttribute.DiagnosticsDelegate)del).Invoke(); if (tmp != null) { string name = att.GroupName; if (diags.ContainsKey(name)) { tmp.AddRange((List <string>)diags[name]); diags.Remove(name); diags.Add(name, tmp); } else { diags.Add(name, tmp); } } } } } Console.WriteLine("Diagnostics Results:"); foreach (string key in diags.Keys) { Console.WriteLine(key + ":"); foreach (string line in diags[key]) { Console.WriteLine(string.Format("\t{0}", line)); } } return; } Thread.CurrentThread.Name = "MainThread"; Console.TreatControlCAsInput = false; Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress); _service = new ServerService(args); _service.WaitForExit(); }