コード例 #1
0
        private void SynchronizedGet()
        {
            if (Cancelled)
            {
                // User cancelled before we made it to kick-off.
                var x = new OKMetadataResponse();
                x.Status = OKIOStatus.Cancelled;
                _didFinish(x);
                return;
            }

            var req = new RestRequest(_uri, Method.GET);

            _killSwitch = _httpClient.ExecuteAsync(req, response => {
                var y = new OKMetadataResponse();

                if (response.ResponseStatus == ResponseStatus.Completed)
                {
                    y.Raw = response.RawBytes;
                }
                else if (response.ResponseStatus == ResponseStatus.Aborted)
                {
                    y.Status = OKIOStatus.Cancelled;
                }
                else
                {
                    y.Status = OKIOStatus.FailedWithError;
                    y.Err    = new OKException("Could not get metadata.  RestSharp response code: " + response.ResponseStatus);
                }

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

                // We're all done.  Disable the kill switch:
                _killSwitch = null;
            });
        }
コード例 #2
0
        private void SynchronizedGet()
        {
            if (Cancelled) {
                // User cancelled before we made it to kick-off.
                var x = new OKMetadataResponse();
                x.Status = OKIOStatus.Cancelled;
                _didFinish(x);
                return;
            }

            var req = new RestRequest(_uri, Method.GET);

            _killSwitch = _httpClient.ExecuteAsync(req, response => {
                var y = new OKMetadataResponse();

                if (response.ResponseStatus == ResponseStatus.Completed)
                    y.Raw = response.RawBytes;
                else if (response.ResponseStatus == ResponseStatus.Aborted)
                    y.Status = OKIOStatus.Cancelled;
                else {
                    y.Status = OKIOStatus.FailedWithError;
                    y.Err = new OKException("Could not get metadata.  RestSharp response code: " + response.ResponseStatus);
                }

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

                // We're all done.  Disable the kill switch:
                _killSwitch = null;
            });
        }