internal void RequestEngagement(string request) { Action action = delegate() { JSONObject engagement = null; try { engagement = Json.Deserialize(request) as JSONObject; } catch (Exception exception) { Logger.LogError("Failed to deserialise engage request: " + exception.Message); } if (engagement != null) { var decisionPoint = engagement["decisionPoint"] as string; var flavour = engagement["flavour"] as string; var parameters = engagement["parameters"] as JSONObject; var id = engagement["id"] as string; EngageResponse engageResponse = (response, statusCode, error) => { manager.EngageResponse(id, response, statusCode, error); }; EngageRequest engageRequest = new EngageRequest(decisionPoint); engageRequest.Flavour = flavour; engageRequest.Parameters = parameters; StartCoroutine(Engage.Request(this, engageRequest, engageResponse)); } }; actions.Enqueue(action); }
//////////////////////////////////////////////////////////////////// // Publisher MetaGame Engage Campaign Check //////////////////////////////////////////////////////////////////// public void MetaGameRequestEngagement(Engagement engagement, Action <Engagement> onCompleted, Action <Exception> onError) { DeltaDNA.Logger.LogDebug("MetaGame Campaign Check Click"); if (String.IsNullOrEmpty(ENGAGE_REST_API_URL)) { throw new Exception("Engage URL not configured."); } try { var dict = engagement.AsDictionary(); var request = new EngageRequest(dict["decisionPoint"] as string); request.Flavour = dict["flavour"] as string; request.Parameters = dict["parameters"] as Dictionary <string, object>; EngageResponse handler = (string response, int statusCode, string error) => { engagement.Raw = response; engagement.StatusCode = statusCode; engagement.Error = error; onCompleted(engagement); }; StartCoroutine(MetaGameEngageRequest(this, request, handler)); } catch (Exception ex) { DeltaDNA.Logger.LogWarning("Engagement request failed: " + ex.Message); } }
public async Task EngageRequest(string pendingId) { var model = new EngageRequest() { AgentId = "Ua334d5bb62b049d69d168774b380aaea", CustomerId = pendingId }; this.AuroraLineDbContext.EngageRequests.Add(model); await this.AuroraLineDbContext.SaveChangesAsync(); }
internal static IEnumerator MetaGameEngageRequest(MonoBehaviour caller, EngageRequest request, EngageResponse response) { string requestJSON = request.ToJSON(); string url = String.Format("{0}/{1}", ENGAGE_REST_API_URL, ENVIRONMENT_KEY); HttpRequest httpRequest = new HttpRequest(url); httpRequest.HTTPMethod = HttpRequest.HTTPMethodType.POST; httpRequest.HTTPBody = requestJSON; httpRequest.TimeoutSeconds = DDNA.Instance.Settings.HttpRequestEngageTimeoutSeconds; httpRequest.setHeader("Content-Type", "application/json"); System.Action <int, string, string> httpHandler = (statusCode, data, error) => { string engagementKey = "DDSDK_ENGAGEMENT_" + request.DecisionPoint + "_" + request.Flavour; if (error == null && statusCode >= 200 && statusCode < 300) { try { PlayerPrefs.SetString(engagementKey, data); } catch (Exception exception) { DeltaDNA.Logger.LogWarning("Unable to cache engagement: " + exception.Message); } } else { DeltaDNA.Logger.LogDebug("Engagement failed with " + statusCode + " " + error); if (PlayerPrefs.HasKey(engagementKey)) { DeltaDNA.Logger.LogDebug("Using cached response"); data = "{\"isCachedResponse\":true," + PlayerPrefs.GetString(engagementKey).Substring(1); } else { data = "{}"; } } response(data, statusCode, error); }; yield return(caller.StartCoroutine(DeltaDNA.Network.SendRequest(httpRequest, httpHandler))); }