public bool IsSameSigniture(DebugCmd other) { if (other == null) { return(false); } if (other.ParameterCount != this.ParameterCount) { return(false); } for (int i = 0; i < ParameterCount; i++) { var tp = this.Parameters[i]; var op = other.Parameters[i]; if (!tp.SameAs(op)) { return(false); } } return(true); }
private static bool AddCmd(DebugCmd cmd) { if (cmd == null) { return(false); } var key = cmd.Name; if (Loaded.ContainsKey(key)) { // Check for same name, same signiture commands... var list = Loaded[key]; foreach (var comm in list) { if (comm.IsVariationOf(cmd) && comm.IsSameSigniture(cmd)) { return(false); } } // Add to list. list.Add(cmd); return(true); } else { // No other commands with name, make new 'pool'. var list = new List <DebugCmd>(); list.Add(cmd); Loaded.Add(key, list); return(true); } }
private static bool ExecuteFromLine(DebugCmd cmd, string fullCommand) { // Assume both command and args are valid... var argsString = fullCommand.Remove(0, cmd.Name.Length + 1); if (string.IsNullOrWhiteSpace(argsString)) { // No args, lets just do command anyway. return(ExecuteCmd(cmd)); } else { // Has args, turn input in parameters and pass them to command. string error; object[] paramz = ParseArgsFromInput(argsString.Trim(), cmd, out error); if (paramz == null || error != null) { Debug.LogError("Command execution [{1}] failed, argument parsing gave error! Error: '{0}'".Form(error, cmd)); return(false); } return(ExecuteCmd(cmd, paramz)); } }
public DebugCmd ReadOneCmd() { DebugCmd cmd = null; try { string name = _reader.ReadString(); Type type = null; if (_name_map.TryGetValue(name, out type)) { cmd = Activator.CreateInstance(type) as DebugCmd; cmd.ReadFrom(_reader); } else { throw new Exception("do not recognize " + name); } } catch { cmd = null; Close(); } return(cmd); }
public void WriteCmd(DebugCmd cmd) { try { _writer.Write(cmd.GetType().Name); cmd.WriteTo(_writer); } catch { Close(); } }
DebugResponse SendOneCmdAndWaitForResponse(DebugCmd cmd) { try { _net_stream.WriteCmd(cmd); return(WaitForResponse()); } catch { _process = null; // For debug, cmd windows do not close Stop(); return(null); } }
private static bool ExecuteCmd(DebugCmd cmd, params object[] args) { // Assume both command and args are valid... try { // Assume it is static, so invoke using a null object. cmd.Method.Invoke(null, args); return(true); } catch (Exception e) { Debug.LogError("Exception while executing command '{0}', See: {1}".Form(cmd, e.ToString())); return(false); } }
public static void LoadCommands() { Loaded.Clear(); Assembly a = typeof(Commands).Assembly; Debug.Log("Searching for custom commands and variables in assembly '{0}'".Form(a.FullName)); // Partition on the type list initially. var def = typeof(DebugCommandAttribute); var found = from t in a.GetTypes().AsParallel() let methods = t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) from m in methods where m.IsDefined(def, true) select new { Type = t, Method = m, Attribute = m.GetCustomAttribute <DebugCommandAttribute>() }; int count = 0; StringBuilder str = new StringBuilder(); foreach (var cmd in found) { var type = cmd.Type; var method = cmd.Method; var attr = cmd.Attribute; if (!method.IsStatic) { Debug.LogError("Currently non-static debug commands are not supported: {0}.{1}".Form(type.FullName, method.Name)); continue; } DebugCmd c = new DebugCmd(attr, method); string error = c.GetError(); if (error != null) { Debug.LogError("Error with debug command {0}: {1}".Form(c.ToString(), error)); continue; } AddCmd(c); str.Append("Class: {0}, Method: {1}, Info:\n{2}\n".Form(type.FullName, method.Name, c.GetHelp())); count++; } Debug.Log("Found {0} debug commands:\n{1}\n".Form(count, str.ToString())); }
protected void LogDebug(string acao, string mensagem, Exception excecao = null) { IInserirCmd comando = new DebugCmd() { Acao = acao, Mensagem = mensagem, Tipo = this.Referencia, Excecao = excecao }; if (this._udt.HaAlteracoes()) { this._logTemp.Add(comando); } else { this._log.Inserir(comando); } }
public bool IsVariationOf(DebugCmd other) { return(other != null && other.Name == this.Name); }
public DebugResult GossipDebug(DebugCmd cmd) { return(gossipClient.debug(cmd)); }
private static object[] ParseArgsFromInput(string input, DebugCmd cmd, out string error) { // The input string where the command part (/something) has been removed from it. // Exctract the inputs from the string, based on a command. if (string.IsNullOrWhiteSpace(input)) { error = "Null or empty string!"; return(null); } tempParams.Clear(); const char SEP = ','; var parts = input.Split(SEP); if (parts.Length != cmd.ParameterCount) { error = "Expected {0} parameters, got {1}!".Form(cmd.ParameterCount, parts.Length); return(null); } int i = 0; foreach (var param in cmd.Parameters) { string part = parts[i++]; var type = param.Type; object result = null; switch (type) { case DCPType.STRING: if (!string.IsNullOrWhiteSpace(part)) { result = part.Trim(); } break; case DCPType.FLOAT: float resF; bool workedF = float.TryParse(part.Trim(), out resF); if (workedF) { result = resF; } break; case DCPType.INT: int resI; bool workedI = int.TryParse(part.Trim(), out resI); if (workedI) { result = resI; } break; default: result = null; break; } if (result == null) { // Something went wrong! error = "Error when parsing parameter '{0}': Expected type {1}".Form(param.Name, param.Type.ToString()); return(null); } else { tempParams.Add(result); } } error = null; return(tempParams.ToArray()); }