internal override bool Handle(EventTrigger trigger, ActionStore store) { if (trigger.GetAction() == Type()) { // copy the json to avoid modifying original var response = new JSONObject(trigger.GetResponse()); var persistedParams = store.Get(trigger); if (persistedParams != null) { response["parameters"] = persistedParams; } var image = ImageMessage.Create( ddna, new Engagement("dummy") { JSON = response }, null); if (image != null && image.IsReady()) { if (persistedParams != null) { store.Remove(trigger); } callback(image); return(true); } } return(false); }
internal override bool Handle(EventTrigger trigger, ActionStore store) { if (trigger.GetAction() == Type()) { var response = trigger.GetResponse(); var persistedParams = store.Get(trigger); if (persistedParams != null) { store.Remove(trigger); callback(persistedParams); } else if (response.ContainsKey("parameters")) { callback((JSONObject)response["parameters"]); } else { callback(new JSONObject()); } return(true); } return(false); }
public void MissingAttributesAreReplacedWithSaneDefaults() { var uut = new EventTrigger( ddna, 0, "{}".Json()); Expect(uut.GetEventName(), Is.EqualTo("")); Expect(uut.GetResponse(), Is.EqualTo("{}".Json())); }
public void AttributesAreExtractedAtConstruction() { var uut = new EventTrigger( ddna, 0, "{\"eventName\":\"name\",\"response\":{\"a\":1}}".Json()); Expect(uut.GetEventName(), Is.EqualTo("name")); Expect(uut.GetResponse(), Is.EqualTo("{\"a\":1}".Json())); }
internal override bool Handle(EventTrigger trigger) { if (trigger.GetAction() == Type()) { var response = trigger.GetResponse(); if (response.ContainsKey("parameters")) { callback((JSONObject)response["parameters"]); } else { callback(new JSONObject()); } return(true); } return(false); }
internal override bool Handle(EventTrigger trigger) { if (trigger.GetAction() == Type()) { var image = ImageMessage.Create( ddna, new Engagement("dummy") { JSON = trigger.GetResponse() }, null); if (image != null && image.IsReady()) { callback(image); return(true); } } return(false); }
private void HandleSessionConfigurationCallback(JSONObject response) { if (response.Count > 0) { var parameters = response["parameters"]; if (parameters != null && parameters is JSONObject) { object dpWhitelist = null; (parameters as JSONObject).TryGetValue("dpWhitelist", out dpWhitelist); if (dpWhitelist != null && dpWhitelist is List <object> ) { whitelistDps = new ReadOnlyCollection <string>( (dpWhitelist as List <object>) .Select(e => e as string) .ToList()); } object eventsWhitelist = null; (parameters as JSONObject).TryGetValue("eventsWhitelist", out eventsWhitelist); if (eventsWhitelist != null && eventsWhitelist is List <object> ) { whitelistEvents = new ReadOnlyCollection <string>( (eventsWhitelist as List <object>) .Select(e => e as string) .ToList()); } object triggers = null; (parameters as JSONObject).TryGetValue("triggers", out triggers); if (triggers != null && triggers is List <object> ) { eventTriggers = (triggers as List <object>) .Select((e, i) => { var t = new EventTrigger(this, i, e as JSONObject); // save persistent actions var p = t.GetResponse().GetOrDefault("parameters", new JSONObject()); if (p.GetOrDefault("ddnaIsPersistent", false)) { actionStore.Put(t, p); } return(t); }) .GroupBy(e => e.GetEventName()) .ToDictionary(e => e.Key, e => { var list = e.ToList(); list.Sort(); return(new ReadOnlyCollection <EventTrigger>(list)); }); } object imageCache = null; (parameters as JSONObject).TryGetValue("imageCache", out imageCache); if (imageCache != null && imageCache is List <object> ) { cacheImages = new ReadOnlyCollection <string>( (imageCache as List <object>) .Select(e => e as string) .ToList()); DownloadImageAssets(); } #if DDNA_SMARTADS SmartAds.Instance.RegisterForAdsInternal(response); #endif Logger.LogDebug("Session configured"); object cached = null; (parameters as JSONObject).TryGetValue("isCachedResponse", out cached); if (cached != null && cached is bool) { ddna.NotifyOnSessionConfigured(cached as bool? ?? false); } else { ddna.NotifyOnSessionConfigured(false); } } } else { Logger.LogWarning("Session configuration failed"); ddna.NotifyOnSessionConfigurationFailed(); } }