public LogEntry(bool Outwards, double time, PML Event) { if (Outwards) { TargetClient = "Sent"; SourceClient = ""; } else { TargetClient = ""; SourceClient = "Received"; } this.Event = Event; this.EventInfo = Event.ToString(); this.EventName = Event.Name; this.CharacterName = CharacterName; this.Time = time; }
public static List<LogEntry> ConvertCsvToThalamus(string messageName, string filename, MethodInfo convertToMessageType) { /*ConstructorInfo[] ctors = convertToObjectType.GetConstructors(); ConstructorInfo largestCtor = null; foreach(var ctor in ctors) if (largestCtor==null || largestCtor.GetParameters().Length<ctor.GetParameters().Length) largestCtor = ctor; if (largestCtor != null) { ParameterInfo[] parameters = largestCtor.GetParameters();*/ ParameterInfo[] parameters = convertToMessageType.GetParameters(); List<LogEntry> convertedObjects = new List<LogEntry>(); /*foreach (string csvFile in csvFiles) {*/ System.IO.StreamReader file = new System.IO.StreamReader(filename); string line; int lineNumber = 1; while ((line = file.ReadLine()) != null) { string[] paramValues = new string[parameters.Length]; string[] paramTypes = new string[parameters.Length]; string[] s_params = line.Split(','); if (s_params.Length != parameters.Length) { MessageBox.Show("Specified CSV file does not match parameters list of message '" + convertToMessageType.Name + "'!", "Convert CSV to Thalamus", MessageBoxButtons.OK, MessageBoxIcon.Error); return new List<LogEntry>(); } int i; for (i = 0; i < s_params.Length; i++) { paramValues[i] = s_params[i].Trim(); } string[] paramNames = new string[parameters.Length]; i = 0; foreach (var p in parameters) { paramNames[i] = p.Name; paramTypes[i++] = DataTypes.SystemTypeToPMLType(p.ParameterType).ToString(); } var pml = new PML(messageName, paramNames, paramTypes, paramValues); if (pml != null) { string readTime = pml.Parameters.ContainsKey("time") && pml.Parameters["time"].Type == PMLParameterType.Double ? "time" : ""; if (readTime == "") readTime = pml.Parameters.ContainsKey("Time") && pml.Parameters["Time"].Type == PMLParameterType.Double ? "Time" : ""; //object obj = ConvertCsvEntryToObject(line, largestCtor, parameters); convertedObjects.Add(new LogEntry(false, readTime == "" ? lineNumber : pml.Parameters[readTime].GetDouble(), pml)); } else { Console.WriteLine("Failed to convert line " + lineNumber); break; } lineNumber++; } file.Close(); //} return convertedObjects; /*} else { MessageBox.Show("The specified type does not contain any constructor!", "Convert CSV to Thalamus", MessageBoxButtons.OK, MessageBoxIcon.Error); return new List<object>(); }*/ }
public static List<LogEntry> LoadThalamusLogEntries(string filename, string assemblyPath = ".") { if (!File.Exists(filename)) { throw new FileNotFoundException("File '" + filename + "' does not exist!"); } else { string logFile = ""; List<LogEntry> logEntries = new List<LogEntry>(); List<string> failedInterfaces = new List<string>(); using (StreamReader file = File.OpenText(filename)) { logFile = file.ReadToEnd(); string[] stringlogs = logFile.Split('\n'); foreach (string s in stringlogs) { try { if (s.Trim().Length > 0 && Regex.IsMatch(s, thalamusLogRegexValidator)) { string log = s.Replace('\r', ' ').Trim(); string[] split = log.Split(':'); //find split[6] in assemblies string interfaceName = split[6].Substring(0, split[6].IndexOf('.')); if (loadedMessageTypes.ContainsKey(interfaceName)) { MethodInfo[] events = loadedMessageTypes[interfaceName].GetMethods(); string eventName = split[6].Substring(split[6].LastIndexOf('.') + 1); foreach (MethodInfo ev in events) { if (ev.Name == eventName) { string value = log.Substring(LogTool.IndexOfNth(log, ':', 8) + 1); object[] ovalues = new object[] { }; if (value.Length > 2) { value = value.Substring(1, value.Length - 3); string[] splitValues = value.Split(';'); ovalues = new object[splitValues.Length]; for (int i = 0; i < splitValues.Length; i++) { ovalues[i] = splitValues[i].Split('=')[1]; } } else value = ""; PML pml = new PML(split[6], ev, ovalues); LogEntry l = new LogEntry(split[5].Length == 0, double.Parse(split[3].Trim().Replace(',', '.'), ifp), "", split[5].Length == 0 ? split[6] : split[5], pml); logEntries.Add(l); //Console.WriteLine("Loaded LogEntry: " + l.ToString()); break; } } } else { if (!failedInterfaces.Contains(interfaceName)) failedInterfaces.Add(interfaceName); } } } catch (Exception e) { throw e; } } } if (failedInterfaces.Count > 0) { if (LoadingInterfacesErrorEvent != null) LoadingInterfacesErrorEvent(null, new LoadingInterfacesErrorEventArgs(failedInterfaces)); string txt = "Failed to find the following types:\n"; foreach (string s in failedInterfaces) { txt += "\t" + s + "\n"; } Console.WriteLine(txt); //MessageBox.Show(txt, "Load Thalamus LogEntries", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return logEntries; } }
public void PublishEvent(string messageId, string clientId, string eventName, bool dontLogDescription, string[] parameters, string[] types, string[] values, string syncEvent = "") { ThalamusClientProxy sourceClient = null; inboundEventsCounter++; if (remoteClients.ContainsKey(clientId)) sourceClient = remoteClients[clientId]; PML pml = new PML(eventName, parameters, types, values); pml.DontLogDescription = dontLogDescription; if (sourceClient != null) { Environment.Instance.DebugIf("messages", "[T][" + sourceClient.Name + "]Publishing... " + pml.ToString() + "."); } else { Environment.Instance.DebugIf("messages", "[T][Unknown]Publishing... " + pml.ToString() + "."); } Environment.Instance.LogEvent(false, character, sourceClient, pml); if (syncEvent != "") { Behavior b = new Behavior(); b.AddNode(new Actions.SyncAction(new Actions.SyncPoint(eventName), sourceClient, pml)); BehaviorPlan.Instance.Add(b); } else { Character.SendPerception(pml); BroadcastEvent(messageId, sourceClient, eventName, parameters, types, values, pml); } }
public void AnnounceEventInformation(string clientId, string[] eventNames, bool[] isAction, string[][] allParameters, string[][] allTypes, string[] enumNames, string[][] enums) { ThalamusClientProxy client; if (remoteClients.ContainsKey(clientId)) client = remoteClients[clientId]; else return; for (int i = 0; i < enumNames.Length; i++) { PML.LoadEnum(enumNames[i], enums[i]); } for (int i = 0; i < eventNames.Length; i++) { string eventName = eventNames[i]; string[] parameters = allParameters[i]; string[] types = allTypes[i]; PML pml = new PML(eventName, parameters, types); pml.EventType = isAction[i] ? PMLEventType.Action : PMLEventType.Perception; if (!pml.IsNull) { lock (eventInfo) { eventInfo[eventName] = pml; } lock (perceptionInfoQueue) { perceptionInfoQueue.Add(new PerceptionInfoResponse(eventName, parameters, types)); } } } }
private void RouteToClients(MethodBase methodBase, params object[] args) { string[] parameterNames; string[] parameterTypes; string[] parameterValues; string[] methodNameSplit = methodBase.Name.Split('.'); string methodName = (methodNameSplit.Length>=2?methodNameSplit[methodNameSplit.Length-2]:"") + "." + methodNameSplit[methodNameSplit.Length-1]; PML pml = new PML(methodName, methodBase, args); //pml.ToArrays(out parameterNames, out parameterTypes, out parameterValues); BroadcastEvent(null, pml); }
public void BroadcastEvent(string messageId, ThalamusClientProxy sourceClient, string eventName, string[] parameters, string[] types, string[] values, PML ev) { List<ThalamusClientProxy> clients; lock (remoteClients) { clients = new List<ThalamusClientProxy>(remoteClients.Values); } foreach (ThalamusClientProxy client in clients) { if (sourceClient != client && client.SubscribedEvents.Contains(eventName)) { Environment.Instance.LogEvent(true, character, client, ev); client.QueueEvent(messageId, eventName, parameters, types, values, ev.DontLogDescription); outboundEventsCounter++; } } if (sourceClient != null) Environment.Instance.DebugIf("messages", "[T][" + sourceClient.Name + "]Published " + ev.ToString() + "."); else Environment.Instance.DebugIf("messages", "[T][Unknown]Published " + ev.ToString() + "."); }
public void BroadcastEvent(ThalamusClientProxy sourceClient, PML p) { string[] parameters = new string[p.Parameters.Count]; string[] values = new string[p.Parameters.Count]; string[] types = new string[p.Parameters.Count]; int i = 0; foreach (KeyValuePair<string, PMLParameter> param in p.Parameters) { parameters[i] = param.Key; values[i] = param.Value.ToString(); types[i] = param.Value.Type.ToString(); i++; } BroadcastEvent(Guid.NewGuid().ToString(), sourceClient, p.Name, parameters, types, values, p); }
public void SendPerception(PML perception) { //Environment.Instance.DebugIf("all", "Perception: " + perception.ToString()); if (perception.Parameters.ContainsKey("id") && perception.Parameters["id"].Type == PMLParameterType.String) { switch (perception.Name) { case "IAnimationEvents.AnimationStarted": NotifyAnimationStart(perception.Parameters["id"].GetString()); break; case "IAnimationEvents.AnimationFinished": NotifyAnimationEnd(perception.Parameters["id"].GetString()); break; case "BML.FaceLexemeStart": NotifyAnimationStart(perception.Parameters["id"].GetString()); break; case "BML.FaceLexemeAttackPeak": break; case "BML.FaceLexemeRelax": break; case "BML.FaceLexemeEnd": NotifyAnimationEnd(perception.Parameters["id"].GetString()); break; case "BML.FaceFacsStart": break; case "BML.FaceFacsAttackPeak": break; case "BML.FaceFacsRelax": break; case "BML.FaceFacsEnd": break; case "IGazeEvents.GazeStarted": NotifyGazeStart(perception.Parameters["id"].GetString()); break; case "BML.GazeReady": break; case "BML.GazeRelax": break; case "IGazeEvents.GazeFinished": NotifyGazeEnd(perception.Parameters["id"].GetString()); break; case "BML.GestureStart": break; case "BML.GestureReady": break; case "BML.GestureStrokeStart": break; case "BML.GestureStroke": break; case "BML.GestureStrokeEnd": break; case "BML.GestureRelax": break; case "BML.GestureEnd": break; case "BML.HeadStart": break; case "BML.HeadReady": break; case "BML.HeadStrokeStart": break; case "BML.HeadStroke": break; case "BML.HeadStrokeEnd": break; case "BML.HeadRelax": break; case "BML.HeadEnd": break; case "BML.HeadDirectionStart": break; case "BML.HeadDirectionEnd": break; case "ILocomotionEvents.WalkStarted": NotifyWalkStart(perception.Parameters["id"].GetString()); break; case "ILocomotionEvents.WalkFinished": NotifyWalkEnd(perception.Parameters["id"].GetString()); break; case "BML.PointingStart": NotifyPointingStart(perception.Parameters["id"].GetString()); break; case "BML.PointingReady": break; case "BML.PointingStrokeStart": break; case "BML.PointingStroke": break; case "BML.PointingStrokeEnd": break; case "BML.PointingRelax": break; case "BML.PointingEnd": NotifyPointingEnd(perception.Parameters["id"].GetString()); break; case "BML.PostureStart": break; case "BML.PostureReady": break; case "BML.PostureRelax": break; case "BML.PostureEnd": break; case "ISoundEvents.SoundStarted": NotifySoundStart(perception.Parameters["id"].GetString()); break; case "ISoundEvents.SoundFinished": NotifySoundEnd(perception.Parameters["id"].GetString()); break; case "ISpeakEvents.SpeakStarted": NotifySpeechStart(perception.Parameters["id"].GetString()); break; case "ISpeakDetailEvents.Bookmark": NotifyBookmark(perception.Parameters["id"].GetString()); break; case "ISpeakEvents.SpeakFinished": NotifySpeechEnd(perception.Parameters["id"].GetString()); break; default: BehaviorPlan.Instance.Event(perception.Name); break; } }else{ switch(perception.Name) { case "IBMLCodeAction.BML": { Console.WriteLine("BML for character " + name); if (perception.Parameters.ContainsKey("code")) { BehaviorPlan.Instance.Add(BehaviorManager.Instance.BmlToBehavior(GBML.GBML.LoadFromText(perception.Parameters["code"].GetValue())), this); } } break; case "SensorTouched": if (perception.Parameters.ContainsKey("sensor")) { if (perception.Parameters.ContainsKey("state") && perception.Parameters["state"].Type==PMLParameterType.Bool) NotifyTouch(perception.Parameters["sensor"].GetString(), perception.Parameters["state"].GetBool()); else NotifyTouch(perception.Parameters["sensor"].GetString()); } break; case "VisionObjectDetected": if (perception.Parameters.ContainsKey("object")) NotifyVisionObjectDetected(perception.Parameters["object"].GetString()); break; case "SoundLocated": if (perception.Parameters.ContainsKey("angle") && perception.Parameters["angle"].Type==PMLParameterType.Double) { if ((perception.Parameters.ContainsKey("elevation") && perception.Parameters["elevation"].Type == PMLParameterType.Double) && (perception.Parameters.ContainsKey("confidence") && perception.Parameters["confidence"].Type == PMLParameterType.Double)) NotifySoundLocated(perception.Parameters["angle"].GetDouble(), perception.Parameters["elevation"].GetDouble(), perception.Parameters["confidence"].GetDouble()); else NotifySoundLocated(perception.Parameters["angle"].GetDouble()); } break; default: BehaviorPlan.Instance.Event(perception.Name); break; } } }
public override bool TryInvokeMember( InvokeMemberBinder binder, object[] args, out object result) { result = null; try { if (methods.ContainsKey(binder.Name)) { MethodInfo method = methods[binder.Name]; string eventName = method.DeclaringType.Name + "." + binder.Name; if (binder.CallInfo.ArgumentCount != args.Length) { thalamusClient.DebugError("Attempt to publish '" + eventName + "' with incorrect number of parameters (expected " + binder.CallInfo.ArgumentCount + ", got " + args.Length + ")!"); return false; } /*else { thalamusClient.Debug("Publish '" + eventName + " (expected " + binder.CallInfo.ArgumentCount + ", got " + args.Length + ")"); foreach (object o in args) Console.WriteLine(o.ToString()); }*/ /* this isn't working on Mono! List<string> parameterNames = new List<string>(); foreach(ParameterInfo p in method.GetParameters()) { parameterNames.Add(p.Name); if (!binder.CallInfo.ArgumentNames.Contains(p.Name)) { Console.WriteLine("Attemp to publish '" + eventName + "' without specifying parameter '" + p.Name + "'!"); return false; } } foreach(string s in binder.CallInfo.ArgumentNames) { if (!parameterNames.Contains(s)) { Console.WriteLine("Attemp to publish '" + eventName + "' without invalid parameter '" + s + "'!"); return false; } }*/ PML pml = new PML(eventName, method, args); if (isAction[binder.Name]) pml.EventType = PMLEventType.Action; if (method.GetCustomAttributes(typeof(DontLogDetailsAttribute), true).Length > 0) pml.DontLogDescription = true; thalamusClient.QueuePublishedEvent(pml); return true; } else { thalamusClient.DebugError("Method '" + binder.Name + "' not found in type '" + interfaceType.Name + "'!"); return false; } } catch { result = null; return false; } }
private void PopulateDataView(DataGridView dgv, PML thalamusEvent) { int rowNumber = 0; foreach (KeyValuePair<string, PMLParameter> param in thalamusEvent.Parameters) { string[] row = { param.Key, param.Value.Type.ToString(), param.Value.GetValue() }; dgv.Rows.Add(row); if (param.Value.Type == PMLParameterType.Enum && PML.EnumInfo.ContainsKey(param.Value.ShortEnumName)) { DataGridViewComboBoxCell dgvCbcell = new DataGridViewComboBoxCell(); foreach(string enumMember in PML.EnumInfo[param.Value.ShortEnumName]) { dgvCbcell.Items.Add(enumMember); } dgv.Rows[rowNumber].Cells[2] = dgvCbcell; } rowNumber++; } }
public void LogEvent(bool outwards, PML ev) { LogEntry l = new LogEntry(outwards, CentralTimePassed().TotalSeconds, ev); DebugLog(l.ToString()); NotifyEventLogged(l); logs.Add(l); }
private void LogCSV(Character character, PML ev) { }
public void LogEvent(bool outwards, Character character, ThalamusClientProxy client, PML ev) { LogEntry l = new LogEntry(outwards, CentralTimePassed().TotalSeconds, character.Name, client == null ? "GUI" : client.Name, ev); DebugLog(l.ToString()); NotifyEventLogged(l); logs.Add(l); if (character.LogToCSV) lock (csvLogs) { csvLogs.Add(l); } }