Ejemplo n.º 1
0
        private void GetRequest(string uri, HTTPClientResponseCallback callback)
        {
            var request = new ServerRequest(IpAddress, uri, callback);
            var auth    = Convert.ToBase64String(Encoding.ASCII.GetBytes(_username + ":" + _password));

            request.Header.AddHeader(new HttpHeader("Authorization", "Basic " + auth));
            _server.GetRequest(request);
        }
Ejemplo n.º 2
0
        private void PostRequest(string uri, string data, HTTPClientResponseCallback callback)
        {
            var request = new ServerRequest(IpAddress, uri, callback)
            {
                RequestType = RequestType.Post
            };
            var auth = Convert.ToBase64String(Encoding.ASCII.GetBytes(_username + ":" + _password));

            request.Header.AddHeader(new HttpHeader("Authorization", "Basic " + auth));
            request.Header.ContentType = "application/json";
            request.ContentString      = data;
            _server.GetRequest(request);
        }
Ejemplo n.º 3
0
        internal void GetRequest(ServerRequest request)
        {
            _requestQueue.Enqueue(request);

            if (_dispatchThread == null || _dispatchThread.ThreadState != Thread.eThreadStates.ThreadRunning)
            {
                _dispatchThread = new Thread(specific =>
                {
#if DEBUG
                    CrestronConsole.PrintLine("Launching {0}.DispacthThread, Request Count = {1}", GetType().Name,
                                              _requestQueue.Count);
#endif

                    while (_requestQueue.Count > 0)
                    {
                        if (!HttpClient.ProcessBusy)
                        {
#if DEBUG
                            CrestronConsole.PrintLine("{0}.HttpClient available, dispatching ...", GetType().Name);
#endif
                            var r = _requestQueue.Dequeue();
#if DEBUG
                            CrestronConsole.PrintLine("{0} {1}", r.RequestType.ToString(), r.Url);
                            if (r.RequestType == RequestType.Post)
                            {
                                CrestronConsole.PrintLine(r.ContentString);
                            }
#endif
                            HttpClient.DispatchAsync(r, r.Callback);
                        }

                        CrestronEnvironment.AllowOtherAppsToRun();
                    }

                    return(null);
                }, null);
            }
        }