public void Visit(Process process, string cmd, AppType type) { var e = new AppEvent(); var session = FindSession(); e.Session = session; e.SequenceId = ++_sessions[session]; e.Type = e.GetType().Name; e.TriggeredAt = DateTime.Now; e.TimeStamp = (long)e.TriggeredAt.Value.Subtract(new DateTime(2010, 01, 01)).TotalMilliseconds; e.TriggeredBy = "-"; e.Duration = 1000.ToString(); e.ActiveDocumentName = ""; e.ActiveDocumentType = ""; e.ActiveWindowCaption = process.MainWindowTitle; e.ActiveWindowType = ""; e.Details = process.ProcessName + " : " + process.StartInfo.FileName; e.AppType = type.ToString(); e.ProcessHandle = process.Handle.ToString(); e.ProcessName = process.ProcessName; e.ProcessPath = process.StartInfo.FileName; e.WindowTitle = process.MainWindowTitle; e.IsActive = true; session.Events.Add(e); _baseContext.Events.Add(e); SaveChanges(); }
public void Visit(ForegroundApp result, string type, bool isActive = false) { var e = new AppEvent(); var session = FindSession(); e.Session = session; e.SequenceId = ++_sessions[session]; e.Type = e.GetType().Name; e.TriggeredAt = result.TriggeredAt; e.TimeStamp = (long)e.TriggeredAt.Value.Subtract(new DateTime(2010, 01, 01)).TotalMilliseconds; e.TriggeredBy = isActive ? type : "-"; e.Duration = 1000.ToString(); e.ActiveDocumentName = ""; e.ActiveDocumentType = ""; e.ActiveWindowCaption = result.WindowTitle; e.ActiveWindowType = ""; e.Details = result.Details; e.AppType = type; e.ProcessHandle = result.ProcessHandle; e.ProcessName = result.ProcessName; e.ProcessPath = result.ProcessPath; e.WindowTitle = result.WindowTitle; e.IsActive = isActive; session.Events.Add(e); _baseContext.Events.Add(e); SaveChanges(); }
//Inserts the event into the current queue. public bool QueueEvent(AppEvent evt) { if (!delegates.ContainsKey(evt.GetType())) { Debug.LogWarning("EventManager: QueueEvent failed due to no listeners for event: " + evt.GetType()); return(false); } m_eventQueue.Enqueue(evt); return(true); }
public void TriggerEvent(AppEvent e) { EventDelegate del; if (delegates.TryGetValue(e.GetType(), out del)) { del.Invoke(e); // remove listeners which should only be called once foreach (EventDelegate k in delegates[e.GetType()].GetInvocationList()) { if (onceLookups.ContainsKey(k)) { delegates[e.GetType()] -= k; if (delegates[e.GetType()] == null) { delegates.Remove(e.GetType()); } delegateLookup.Remove(onceLookups[k]); onceLookups.Remove(k); } } } else { Debug.LogWarning("Event: " + e.GetType() + " has no listeners"); } }
private string CreateEventName(AppEvent appEvent) { var eventName = typeNameRegistry.GetName(appEvent.GetType()); if (appEvent is SchemaEvent schemaEvent) { if (eventName.StartsWith(ContentPrefix, StringComparison.Ordinal)) { eventName = eventName.Substring(ContentPrefix.Length); } return($"{schemaEvent.SchemaId.Name.ToPascalCase()}{eventName}"); } return(eventName); }
public string GetName(AppEvent @event) { foreach (var handler in ruleTriggerHandlers.Values) { if (handler.Handles(@event)) { var name = handler.GetName(@event); if (!string.IsNullOrWhiteSpace(name)) { return(name); } } } return(@event.GetType().Name); }
private void ListenNetEvents() { while (Running) { AppEvent appEvent = AppNetChannel.TakeFromNet(); Target target = appEvent.Target; Action action = appEvent.Action; Subject subject = appEvent.Subject; object data = appEvent.Data; if (appEvent.GetType() == typeof(ClientAppEvent)) { Client client = ((ClientAppEvent)appEvent).Client; if (subject == Subject.Desktop) { if (action == Action.Fetched) { string path = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + client.PcName; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.WriteAllBytes(path + Path.DirectorySeparatorChar + "screenshot.png", (byte[])data); appEvent.Data = path; } } } AppUiChannel.SubmitToUi(appEvent); } }
/// <summary> /// Submit an application event or error to Trakerr The events endpoint submits an application event or an application error / exception with an optional stacktrace field to Trakerr. ##### Sample POST request body: ``` { \"apiKey\": \"a9a2807a2e8fd4602adae9e8f819790a267213234083\", \"classification\": \"Error\", \"eventType\": \"System.Exception\", \"eventMessage\": \"This is a test exception.\", \"eventTime\": 1479477482291, \"eventStacktrace\": [ { \"type\": \"System.Exception\", \"message\": \"This is a test exception.\", \"traceLines\": [ { \"function\": \"Main\", \"line\": 19, \"file\": \"TrakerrSampleApp\\\\Program.cs\" } ] } ], \"contextAppVersion\": \"1.0\", \"contextEnvName\": \"development\", \"contextEnvHostname\": \"trakerr.io\", \"contextAppOS\": \"Win32NT Service Pack 1\", \"contextAppOSVersion\": \"6.1.7601.65536\" } ``` ##### Sample POST response body (200 OK): ``` { } ``` /// </summary> /// <exception cref="IO.Trakerr.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="data">Event to submit</param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task <ApiResponse <Object> > EventsPostAsyncWithHttpInfo(AppEvent data) { // verify the required parameter 'data' is set if (data == null) { throw new ApiException(400, "Missing required parameter 'data' when calling EventsApi->EventsPost"); } var localVarPath = "/events"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new Dictionary <String, String>(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } // set "format" to json by default // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json localVarPathParams.Add("format", "json"); if (data != null && data.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(data); // http body (model) parameter } else { localVarPostBody = data; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("EventsPost", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), null)); }