Пример #1
0
    public void Delete(Subject subject, UpdateDelegator delegator)
    {
        if (_delegateMap.ContainsKey(subject) == false)
        {
            return;
        }

        _delegateMap [subject] -= delegator;
    }
Пример #2
0
    public void Add(Subject subject, UpdateDelegator delegator)
    {
        if (_delegateMap.ContainsKey(subject) == false)
        {
            _delegateMap[subject] = delegate() {};
        }

        _delegateMap [subject] += delegator;
    }
Пример #3
0
    public void Delete(Subject subject, UpdateDelegator delegator)
    {
        if (_delegateMap.ContainsKey (subject) == false)
        {
            return;
        }

        _delegateMap [subject] -= delegator;
    }
Пример #4
0
    public void Add(Subject subject, UpdateDelegator delegator)
    {
        if (_delegateMap.ContainsKey (subject) == false)
        {
            _delegateMap[subject] = delegate() {};
        }

        _delegateMap [subject] += delegator;
    }
Пример #5
0
        private void PostEvents(IEnumerable <Dictionary <string, object> > events, Action onSuccess, Action <ErrorCode> onError)
        {
            int eventCount = events.Count();

            if (eventCount <= 0)
            {
                onSuccess();
            }
            else
            {
                string eventsJson = Json.Encode(events.ToList());
                if (eventsJson == null)
                {
                    Debug.LogError((object)"AmplitudeAPI: PostEvents: failed to serialize events to JSON");
                    onError(ErrorCode.GeneralError);
                }
                else if (eventsJson.Length > 131072)
                {
                    Debug.LogWarning((object)("AmplitudeAPI: PostEvents: events payload was two large, breaking up into smaller requests.  Length - " + eventsJson.Length));
                    onError(ErrorCode.EventPayloadTooLarge);
                }
                else if (string.IsNullOrEmpty(apiKey))
                {
                    Debug.LogError((object)"AmplitudeAPI: PostEvents: apiKey is missing!");
                    onError(ErrorCode.GeneralError);
                }
                else
                {
                    UpdateDelegator.Dispatch(delegate
                    {
                        HTTPRequest hTTPRequest = new HTTPRequest(new Uri("https://api.amplitude.com/httpapi"), HTTPMethods.Post, delegate(HTTPRequest req, HTTPResponse resp)
                        {
                            switch (req.State)
                            {
                            case HTTPRequestStates.Finished:
                                if (resp.IsSuccess)
                                {
                                    Debug.Log((object)("AmplitudeAPI: upload finished, successfully posted " + eventCount + " events"));
                                    onSuccess();
                                }
                                else
                                {
                                    Debug.LogError((object)("AmplitudeAPI: upload failed - status code " + resp.StatusCode + " " + resp.Message + ", response `" + resp.DataAsText + "`"));
                                    if (resp.StatusCode == 400)
                                    {
                                        onError(ErrorCode.BadRequest);
                                    }
                                    else if (resp.StatusCode == 413)
                                    {
                                        onError(ErrorCode.TooManyEventsInRequest);
                                    }
                                    else if (resp.StatusCode == 429)
                                    {
                                        onError(ErrorCode.TooManyRequestsForDevice);
                                    }
                                    else if (resp.StatusCode >= 500 && resp.StatusCode < 600)
                                    {
                                        onError(ErrorCode.ServerError);
                                    }
                                    else
                                    {
                                        onError(ErrorCode.GeneralError);
                                    }
                                }
                                break;

                            case HTTPRequestStates.Error:
                                {
                                    string str = (req.Exception == null) ? "No Exception" : (req.Exception.Message + "\n" + req.Exception.StackTrace);
                                    Debug.LogError((object)("AmplitudeAPI: upload failed with exception - " + str));
                                    onError(ErrorCode.Exception);
                                    break;
                                }

                            case HTTPRequestStates.Aborted:
                                Debug.LogError((object)"AmplitudeAPI: upload failed - request aborted");
                                onError(ErrorCode.GeneralError);
                                break;

                            case HTTPRequestStates.ConnectionTimedOut:
                            case HTTPRequestStates.TimedOut:
                                Debug.LogError((object)("AmplitudeAPI: upload failed - " + req.State));
                                onError(ErrorCode.TimedOut);
                                break;

                            default:
                                Debug.LogError((object)("AmplitudeAPI: upload failed - " + req.State));
                                onError(ErrorCode.GeneralError);
                                break;
                            }
                        });
                        hTTPRequest.ConnectTimeout = TimeSpan.FromSeconds(20.0);
                        hTTPRequest.Timeout        = TimeSpan.FromSeconds(60.0);
                        hTTPRequest.FormUsage      = HTTPFormUsage.UrlEncoded;
                        hTTPRequest.AddField("api_key", apiKey);
                        hTTPRequest.AddField("event", eventsJson);
                        hTTPRequest.Send();
                    });
                }
            }
        }