public override void NativeCallback(string message) { const string VARIABLES_CHANGED = "VariablesChanged:"; const string VARIABLES_CHANGED_NO_DOWNLOAD_PENDING = "VariablesChangedAndNoDownloadsPending:"; const string STARTED = "Started:"; const string VARIABLE_VALUE_CHANGED = "VariableValueChanged:"; const string FORCE_CONTENT_UPDATE_WITH_CALLBACK = "ForceContentUpdateWithCallback:"; const string ACTION_RESPONDER = "ActionResponder:"; if (message.StartsWith(VARIABLES_CHANGED)) { VariablesChanged?.Invoke(); } else if (message.StartsWith(VARIABLES_CHANGED_NO_DOWNLOAD_PENDING)) { VariablesChangedAndNoDownloadsPending?.Invoke(); } else if (message.StartsWith(STARTED)) { if (Started != null) { bool success = message.EndsWith("1"); Started(success); } } else if (message.StartsWith(VARIABLE_VALUE_CHANGED)) { // Drop the beginning of the message to get the name of the variable // Then dispatch to the correct variable LeanplumApple.VariableValueChanged(message.Substring(21)); } else if (message.StartsWith(FORCE_CONTENT_UPDATE_WITH_CALLBACK)) { int key = Convert.ToInt32(message.Substring(FORCE_CONTENT_UPDATE_WITH_CALLBACK.Length)); Action callback; if (ForceContentUpdateCallbackDictionary.TryGetValue(key, out callback)) { callback(); ForceContentUpdateCallbackDictionary.Remove(key); } } else if (message.StartsWith(ACTION_RESPONDER)) { string key = message.Substring(ACTION_RESPONDER.Length); // {actionName:messageId} string actionName = key.Split(':')[0]; ActionContext.ActionResponder callback; if (ActionRespondersDictionary.TryGetValue(actionName, out callback)) { var context = new ActionContextApple(key); callback(context); } } if (Inbox != null) { Inbox.NativeCallback(message); } }
public override void NativeCallback(string message) { const string VARIABLES_CHANGED = "VariablesChanged:"; const string VARIABLES_CHANGED_NO_DOWNLOAD_PENDING = "VariablesChangedAndNoDownloadsPending:"; const string STARTED = "Started:"; const string VARIABLE_VALUE_CHANGED = "VariableValueChanged:"; const string FORCE_CONTENT_UPDATE_WITH_HANDLER = "ForceContentUpdateWithHandler:"; const string DEFINE_ACTION_RESPONDER = "ActionResponder:"; const string ON_ACTION_RESPONDER = "OnAction:"; const string RUN_ACTION_NAMED_RESPONDER = "OnRunActionNamed:"; if (message.StartsWith(VARIABLES_CHANGED)) { VariablesChanged?.Invoke(); } else if (message.StartsWith(VARIABLES_CHANGED_NO_DOWNLOAD_PENDING)) { VariablesChangedAndNoDownloadsPending?.Invoke(); } else if (message.StartsWith(STARTED)) { if (started != null) { startSuccessful = message.EndsWith("1"); started(startSuccessful); } } else if (message.StartsWith(VARIABLE_VALUE_CHANGED)) { // Drop the beginning of the message to get the name of the variable // Then dispatch to the correct variable VariableValueChanged(message.Substring(21)); } else if (message.StartsWith(FORCE_CONTENT_UPDATE_WITH_HANDLER)) { string[] values = message.Substring(FORCE_CONTENT_UPDATE_WITH_HANDLER.Length).Split(':'); int key = Convert.ToInt32(values[0]); bool success = values[1] == "1"; if (ForceContentUpdateHandlersDictionary.TryGetValue(key, out Leanplum.ForceContentUpdateHandler handler)) { handler(success); ForceContentUpdateHandlersDictionary.Remove(key); } } else if (message.StartsWith(DEFINE_ACTION_RESPONDER)) { string key = message.Substring(DEFINE_ACTION_RESPONDER.Length); string actionName = GetActionNameFromMessageKey(key); ActionContext.ActionResponder callback; if (ActionRespondersDictionary.TryGetValue(actionName, out callback)) { string messageId = GetMessageIdFromMessageKey(key); var context = new ActionContextApple(key, messageId); ActionContextsDictionary[key] = context; callback(context); } } else if (message.StartsWith(ON_ACTION_RESPONDER)) { string key = message.Substring(ON_ACTION_RESPONDER.Length); string actionName = GetActionNameFromMessageKey(key); if (OnActionRespondersDictionary.TryGetValue(actionName, out List <ActionContext.ActionResponder> callbacks)) { if (!ActionContextsDictionary.ContainsKey(key)) { string messageId = GetMessageIdFromMessageKey(key); var newContext = new ActionContextApple(key, messageId); ActionContextsDictionary[key] = newContext; } ActionContext context = ActionContextsDictionary[key]; foreach (var callback in callbacks) { callback(context); } } } else if (message.StartsWith(RUN_ACTION_NAMED_RESPONDER)) { char keysSeparator = '|'; string data = message.Substring(RUN_ACTION_NAMED_RESPONDER.Length); string[] keys = data.Split(new char[] { keysSeparator }, StringSplitOptions.RemoveEmptyEntries); if (keys.Length != 2) { return; } string parentKey = keys[0]; string actionKey = keys[1]; if (ActionContextsDictionary.TryGetValue(parentKey, out ActionContext parentContext)) { var context = new ActionContextApple(actionKey, GetMessageIdFromMessageKey(actionKey)); parentContext.TriggerActionNamedResponder(context); } } if (Inbox != null) { Inbox.NativeCallback(message); } }