internal static void setEnabled(Boolean enabled) { if (enabled && !isEnabled) { //Read events from storage eventsList = EventStorage.getEvents(); if (eventsList.Count > 0) { sendNextEvent(); } isEnabled = true; } else if (!enabled && isEnabled) { //Stop current eventSender if (eventSender != null) { eventSender.cancel(); eventSender = null; } //Store events to storage EventStorage.storeEvents(eventsList); eventsList = null; isEnabled = false; } }
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); } }