Ejemplo n.º 1
0
        private static void LoadEndpoints(
            string name,
            Action<Endpoints> callback,
            Action<Exception> errorCallback)
        {
            HttpWebClient httpWebClient = new HttpWebClient();

            Action<HttpResponseHandler> responseHandler = delegate(HttpResponseHandler response)
            {
                // If there was an error
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    Endpoints endpoints = new Endpoints(name, response.AsString());

                    CacheLock.EnterWriteLock();

                    try
                    {
                        Cache[name] = endpoints;
                    }
                    finally
                    {
                        CacheLock.ExitWriteLock();
                    }

                    callback(endpoints);
                }
                else
                {
                    log.Error("Error loading endpoints:\n" + response.AsString());
                    errorCallback(new DiskException("Error loading endpoint for " + name));
                }
            };

            httpWebClient.BeginGet(name, responseHandler, errorCallback);
        }