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();
        }
Exemplo n.º 3
0
    //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);
    }
Exemplo n.º 4
0
    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");
        }
    }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        /// <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: &#x60;&#x60;&#x60; {  \&quot;apiKey\&quot;: \&quot;a9a2807a2e8fd4602adae9e8f819790a267213234083\&quot;,  \&quot;classification\&quot;: \&quot;Error\&quot;,  \&quot;eventType\&quot;: \&quot;System.Exception\&quot;,  \&quot;eventMessage\&quot;: \&quot;This is a test exception.\&quot;,  \&quot;eventTime\&quot;: 1479477482291,  \&quot;eventStacktrace\&quot;: [    {      \&quot;type\&quot;: \&quot;System.Exception\&quot;,      \&quot;message\&quot;: \&quot;This is a test exception.\&quot;,      \&quot;traceLines\&quot;: [        {          \&quot;function\&quot;: \&quot;Main\&quot;,          \&quot;line\&quot;: 19,          \&quot;file\&quot;: \&quot;TrakerrSampleApp\\\\Program.cs\&quot;        }      ]    }  ],  \&quot;contextAppVersion\&quot;: \&quot;1.0\&quot;,  \&quot;contextEnvName\&quot;: \&quot;development\&quot;,  \&quot;contextEnvHostname\&quot;: \&quot;trakerr.io\&quot;,  \&quot;contextAppOS\&quot;: \&quot;Win32NT Service Pack 1\&quot;,  \&quot;contextAppOSVersion\&quot;: \&quot;6.1.7601.65536\&quot; } &#x60;&#x60;&#x60; ##### Sample POST response body (200 OK): &#x60;&#x60;&#x60; { } &#x60;&#x60;&#x60;
        /// </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));
        }