Exemple #1
0
        protected void SynchronizedPerform()
        {
            _killSwitch = _httpClient.ExecuteAsync(GetHttpRequest(), response => {
                var y = new OKServiceResponse();

                if (response.ResponseStatus == ResponseStatus.Aborted)
                {
                    y.Status = OKIOStatus.Cancelled;
                }
                else
                {
                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.OK:
                        y.Status = OKIOStatus.Succeeded;
                        y.Obj    = JSONObjectExt.decode(response.Content);
                        break;

                    case HttpStatusCode.Forbidden:
                        y.Status = OKIOStatus.FailedWithError;
                        y.Err    = new OKException("Forbidden: Verify that your key and secret are correct.");
                        break;

                    default:
                        y.Status = OKIOStatus.FailedWithError;
                        y.Err    = new OKException("OKServiceRequest failed.  Response body: " + response.Content);
                        break;
                    }
                }

                SynchronizationContext c = OKCtx.Ctx;
                if (c == null)
                {
                    _didFinish(y);
                }
                else
                {
                    c.Post(s => _didFinish(y), null);
                }

                _killSwitch = null;
            });
        }
        protected void SynchronizedPerform()
        {
            _killSwitch = _httpClient.ExecuteAsync(GetHttpRequest(), response => {
                var y = new OKServiceResponse();

                if (response.ResponseStatus == ResponseStatus.Aborted)
                    y.Status = OKIOStatus.Cancelled;
                else {
                    switch (response.StatusCode) {
                        case HttpStatusCode.OK:
                            y.Status = OKIOStatus.Succeeded;
                            y.Obj = JSONObjectExt.decode(response.Content);
                            break;
                        case HttpStatusCode.Forbidden:
                            y.Status = OKIOStatus.FailedWithError;
                            y.Err = new OKException("Forbidden: Verify that your key and secret are correct.");
                            break;
                        default:
                            y.Status = OKIOStatus.FailedWithError;
                            y.Err = new OKException("OKServiceRequest failed.  Response body: " + response.Content);
                            break;
                    }
                }

                SynchronizationContext c = OKCtx.Ctx;
                if (c == null)
                    _didFinish(y);
                else
                    c.Post(s => _didFinish(y), null);

                _killSwitch = null;
            });
        }