/// <summary> /// Adds the tracker payload to the emitter. /// </summary> /// <param name="payload">The base event payload.</param> /// <param name="contexts">The list of contexts from the event.</param> private void AddTrackerPayload(TrackerPayload payload, List <IContext> contexts, string eventId) { // Add default parameters to the payload payload.Add(Constants.PLATFORM, this.platform.Value); payload.Add(Constants.APP_ID, this.appId); payload.Add(Constants.NAMESPACE, this.trackerNamespace); payload.Add(Constants.TRACKER_VERSION, Version.VERSION); // Add the subject data if available if (subject != null) { payload.AddDict(subject.GetPayload().GetDictionary()); } // Add the session context if available if (session != null) { contexts.Add(session.GetSessionContext(eventId)); } // Build the final context and add it to the payload if (contexts != null && contexts.Count > 0) { SelfDescribingJson envelope = GetFinalContext(contexts); payload.AddJson(envelope.GetDictionary(), this.base64Encoded, Constants.CONTEXT_ENCODED, Constants.CONTEXT); } Log.Verbose("Tracker: Sending event to the emitter."); Log.Verbose(" + Event: " + payload.ToString()); // Add the event to the emitter. emitter.Add(payload); }
/// <summary> /// Queries the database. /// </summary> /// <returns>A list of rows returned from the database</returns> /// <param name="query">The SQL Query to execute</param> public List <EventRow> QueryDatabase(string query) { List <EventRow> rows = new List <EventRow>(); if (IsDatabaseOpen()) { try { IDbCommand command = dbConnection.CreateCommand(); command.CommandText = query; IDataReader reader = command.ExecuteReader(); // Add the row id and deserialized row data to the list while (reader.Read()) { int rowId = (int)reader[COLUMN_ID]; Dictionary <string, object> payloadDict = Utils.DeserializeDictionary((byte[])reader[COLUMN_EVENT_DATA]); TrackerPayload payload = new TrackerPayload(); payload.AddDict(payloadDict); rows.Add(new EventRow(rowId, payload)); } // Close and dispose of resources reader.Close(); reader = null; command.Dispose(); command = null; } catch (Exception e) { Log.Error("EventStore: Error querying database: " + e.StackTrace); } } return(rows); }
public void TestAddDictFunction() { TrackerPayload payload = new TrackerPayload(); Dictionary <string, object> dict = new Dictionary <string, object> (); dict.Add("hello", "world"); dict.Add("demo", 10); Assert.AreEqual(0, payload.GetDictionary().Count); payload.AddDict(dict); Assert.AreEqual(1, payload.GetDictionary().Count); Assert.AreEqual("world", payload.GetDictionary()["hello"]); }
/// <summary> /// Queries the database. /// </summary> /// <returns>A list of rows returned from the database</returns> /// <param name="query">The SQL Query to execute</param> public List <EventRow> QueryDatabase(string query) { List <EventRow> rows = new List <EventRow>(); if (IsDatabaseOpen()) { try { using (var someCommand = dbConnection.CreateCommand()) { someCommand.CommandText = query; using (var reader = someCommand.ExecuteReader()) { // Add the row id and deserialized row data to the list if (reader.HasRows) { while (reader.Read()) { if (!reader.IsDBNull(reader.GetOrdinal(COLUMN_ID)) && !reader.IsDBNull(reader.GetOrdinal(COLUMN_EVENT_DATA))) { int rowId = (int)reader[COLUMN_ID]; Dictionary <string, object> payloadDict = Utils.DeserializeDictionary((byte[])reader[COLUMN_EVENT_DATA]); TrackerPayload payload = new TrackerPayload(); payload.AddDict(payloadDict); rows.Add(new EventRow(rowId, payload)); } } } } } } catch (Exception e) { Log.Error("EventStore: Error querying database: " + e.StackTrace); } } return(rows); }