Exemplo n.º 1
0
        private void AsyncRequest(QueryCommand command, string method, HttpRemoteConnectionCallback callback)
        {
            if (string.IsNullOrEmpty(Token) || !IsInitialized)
                throw new TokenException("Token has not been acquired. Use OpenAsync() method to acquire the token.");

            var query = "/gui/" + command.ToQuery() + "&token=" + Token;
            var request = CreateRequest(new Uri(Url, query), method);

            var handler = new ManualResetEvent(false);
            var result = string.Empty;

            request.BeginGetResponse((asyncResult) =>
            {
                if (callback != null)
                {
                    var req = (HttpWebRequest) asyncResult.AsyncState;
                    using (var resp = (HttpWebResponse) req.EndGetResponse(asyncResult))
                    using (var reader = new StreamReader(resp.GetResponseStream()))
                    {
                        var data = reader.ReadToEnd();
                        callback(data);
                    }
                }
            }, request);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Executes target QueryCommand via GET request asynchronously and invokes callback when response arrives.
 /// </summary>
 public void GetAsync(QueryCommand command, HttpRemoteConnectionCallback callback)
 {
     AsyncRequest(command, "GET", callback);
 }