internal static void logEvent(Event e) { Utils.log("logEvent(" + e.name + ")"); storeEvent(e); if (isEnabled && eventsList.Count == 1) { sendEvent(e); } }
// Private methods private void cleanup() { this.currentEvent = null; this.webBrowser = null; this.webRequestWorker = null; this.autoResetEvent = null; this.OnEventFailed = null; this.OnEventSent = null; }
internal static List<Event> getEvents() { Utils.log("getEvents()"); List<Event> result = new List<Event>(); //Read all event lines from storage (and delete the file) String allEvents = StorageManager.read(FILE_NAME, true); if (allEvents != null) { //Split event lines String[] allEventsLines = allEvents.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); foreach (String eventStr in allEventsLines) { //Base64 decode byte[] eventData = Convert.FromBase64String(eventStr); //Protobuf deserialize MemoryStream stream = new MemoryStream(eventData); Event e = new Event(); Type type = e.GetType(); EventSerializer serializer = new EventSerializer(); serializer.Deserialize(stream, e, type); //Recalculate checksum e.calculateChecksum(SDK.publicKey, SDK.privateKey, SDK.uniqueUserID, SDK.uniqueHardwareID); //Set new ID e.setNewID(); Utils.log("Restored " + e.name + " event with (new) ID " + e._id); //Add to result set result.Add(e); } } else { Utils.log("No stored events found"); } return result; }
internal EventSender(Event e) { this.currentEvent = e; }
internal EventSenderArgs(Event e) { this.theEvent = e; }
private static void sendEvent(Event e) { Utils.log("sendEvent(" + e.name + ")"); eventSender = new EventSender(e); eventSender.OnEventSent += new EventHandler<EventSender.EventSenderArgs>(onEventSent); eventSender.OnEventFailed += new EventHandler<EventSender.EventSenderArgs>(onEventFailed); eventSender.start(); }
private static void removeEvent(Event e) { Utils.log("removeEvent(" + e.name + ")"); if (isEnabled) { //Remove from memory eventsList.Remove(e); } else { //Remove from persistent storage List<Event> tempList = EventStorage.getEvents(); tempList.Remove(e); EventStorage.storeEvents(tempList); } }
// Private methods private static void storeEvent(Event e) { Utils.log("storeEvent(" + e.name + ")"); if (isEnabled) { //Store in memory eventsList.Add(e); } else { //Store in persistent storage List<Event> tempList = EventStorage.getEvents(); tempList.Add(e); EventStorage.storeEvents(tempList); } }