public static void Initialize()
        {
            // Read current values.
            _current = ReadAll();

            // Create helper for coroutine.
            UnityCoroutineHelper.StartCoroutine(MainThreadCoroutine);
        }
예제 #2
0
        public Task <string> SendAsync(string uri, string method, IDictionary <string, string> headers, string jsonContent,
                                       CancellationToken cancellationToken)
        {
            var tcs = new TaskCompletionSource <string>();

            UnityCoroutineHelper.StartCoroutine(() => SendAsync(uri, method, headers, jsonContent, request =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    tcs.SetCanceled();
                    return;
                }
                if (request.isNetworkError)
                {
                    tcs.SetException(new NetworkIngestionException());
                }
                else if (request.isHttpError)
                {
                    tcs.SetException(new HttpIngestionException($"Operation returned an invalid status code '{request.responseCode}'")
                    {
                        Method          = request.method,
                        RequestUri      = new Uri(request.url),
                        StatusCode      = (int)request.responseCode,
                        RequestContent  = jsonContent,
                        ResponseContent = request.downloadHandler.text
                    });
                }
                else
                {
                    var responseContent = request.downloadHandler.text;
                    AppCenterLog.Verbose(AppCenterLog.LogTag, $"HTTP response status={(int)request.responseCode} payload={responseContent}");
                    tcs.SetResult(responseContent);
                }
            }));
            return(tcs.Task);
        }