/// <summary> /// Track when and how this event was invoked first time; /// Only for development to learn if and when events are called. /// </summary> private static void TrackInvocation(ScriptEvent eventType, ScriptEventArgs eventArgs) { var invocationLog = Environment.NewLine + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Environment.NewLine + JsonMapper.ToJson(eventArgs) + Environment.NewLine + Environment.StackTrace; var invokedEvent = PersistentData.Instance.InvokedEvents.FirstOrDefault(ie => ie.EventName == eventType.ToString()); if (invokedEvent == null) { invokedEvent = new PersistentData.InvokedEvent() { EventName = eventType.ToString(), LastCalls = new List <string>() }; PersistentData.Instance.InvokedEvents.Add(invokedEvent); } // Rotate last 10 call logs with newest on top if (invokedEvent.LastCalls.Count == 10) { invokedEvent.LastCalls.RemoveAt(invokedEvent.LastCalls.Count - 1); } invokedEvent.LastCalls.Insert(0, invocationLog.Indent(10) + Environment.NewLine + new string(' ', 8)); PersistentData.Instance.SaveLater(); }
public void ExecuteEvent(string filePath, ScriptEvent eventType, object eventArgs) { ResetEngine(); InitCommonValues(); SetValue("eventType", eventType.ToString()); SetValue("event", eventArgs); var oldDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Path.GetDirectoryName(filePath) ?? Path.PathSeparator.ToString()); try { ExecuteFile(filePath); } // LuaScriptException is already handled in LuaEngine // JavaScriptException is already handled in JsEngine catch (Exception ex) { var fileRelativePath = FileTools.GetRelativePath(filePath, Constants.ScriptsFolder); Log.Error($"Script {fileRelativePath} failed: " + ex); } Directory.SetCurrentDirectory(oldDirectory); }