Пример #1
0
        public void LoadLinks()
        {
            if (Account.Auth == null)
            {
                MessengerInstance.Send<object>(null, "NavigateBack");
            }

            Links.Clear();

            var uri = "https://indiclesync.firebaseIO.com/users/" +
                      Account.Auth.user.id + "/urls/.json?auth=" + Account.Auth.token;

            var request = new HttpGetRequest(uri);

            Http.Get(request, (response) =>
            {
                if (response.Successful)
                {
                    var links = JsonConvert.DeserializeObject<Dictionary<string,LinkEntity>>(response.Response);
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            foreach (var link in links.Values)
                            {
                                Links.Add(link);
                            }
                        });
                }
            });
        }
Пример #2
0
		private async void OnDownload(object sender, RoutedEventArgs e)
		{
			var prog = new Progress<HttpProgress>();
			prog.ProgressChanged += (o, p) =>
			{
				Progress.Minimum = 0;
				Progress.Value = p.ReadBytes;
				Progress.Maximum = p.TotalBytes;
			};

			var request = new HttpGetRequest(new Uri("http://ipv4.download.thinkbroadband.com/10MB.zip", UriKind.Absolute));
			request.UseCache = false; 

			var response = await Http.GetAsync(request, CancellationToken.None, prog);
		}
Пример #3
0
        public static void Login(string email, string password)
        {
            var uri = "https://auth.firebase.com/auth/firebase?&firebase=indiclesync" +
                      "&email=" + email +
                      "&password=" + password;

            var request = new HttpGetRequest(uri);

            Http.Get(request, (response) =>
            {
                if (response.Successful)
                {
                    Auth = JsonConvert.DeserializeObject<Auth>(response.Response);
                }
            });
        }
Пример #4
0
        [DataRow("H74AIvjDifo")] // vevo 
        //[DataRow("rSy0JtBCZMQ")] // different problem => missing URL key
        public async Task When_loading_video_then_uri_should_be_available_accessible(string youTubeId)
        {
            //// Act
            Debug.WriteLine(youTubeId);
            var uri = await YouTube.GetVideoUriAsync(youTubeId, YouTubeQuality.Quality360P, YouTubeQuality.Quality2160P);

            try
            {
                var request = new HttpGetRequest(uri.Uri);
                request.Timeout = TimeSpan.FromSeconds(1);

                var cancellationToken = new CancellationTokenSource(new TimeSpan(0, 0, 2));
                await Http.GetAsync(uri.Uri, cancellationToken.Token);
            }
            catch (OperationCanceledException exception)
            {
                Assert.IsNotNull(exception);
            }

            //// Assert
            Assert.IsNotNull(uri);
            Assert.IsTrue(uri.HasAudio);
            Assert.IsTrue(uri.HasVideo);
        }
Пример #5
0
 public static Task <HttpResponse> Get(HttpGetRequest request, Action <HttpResponse> completed)
 {
     return(Get(request, CancellationToken.None, completed));
 }
Пример #6
0
        public static HttpResponse Get(HttpGetRequest req, Action <HttpResponse> action)
        {
            var response = new HttpResponse(req);

            try
            {
                if (!req.UseCache)
                {
                    req.Query["__dcachetime"] = DateTime.Now.Ticks.ToString();
                }
                var request = CreateRequest(req);

                if (req.Credentials != null)
                {
                    request.Credentials = req.Credentials;
                }
                response.WebRequest = request;

                if (req.Cookies.Count > 0)
                {
                    request.CookieContainer = new CookieContainer();
                    foreach (var c in req.Cookies)
                    {
                        request.CookieContainer.Add(request.RequestUri, c);
                    }
                }

                request.Method = "GET";
                if (req.ContentType != null)
                {
                    request.ContentType = req.ContentType;
                }

                if (req.Headers.Count > 0)
                {
                    foreach (var item in req.Headers)
                    {
#if WINRT
                        if (item.Key != "User-Agent")                         // TODO fix this => cannot set UserAgent in WinRT
                        {
                            request.Headers[item.Key] = item.Value;
                        }
#elif WPF
                        if (item.Key != "User-Agent")
                        {
                            request.Headers[item.Key] = item.Value;
                        }
                        else
                        {
                            request.UserAgent = item.Value;
                        }
#else
                        request.Headers[item.Key] = item.Value;
#endif
                    }
                }

#if USE_GZIP
                if (req.RequestGzip)
                {
                    request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip";
                }
#endif

                response.CreateTimeoutTimer(request);
                request.BeginGetResponse(r => ProcessResponse(r, request, response, action), request);
            }
            catch (Exception e)
            {
                response.Exception = e;
                if (action != null)
                {
                    action(response);
                }
            }

            lock (pendingRequests)
                pendingRequests.Add(response);
            return(response);
        }
Пример #7
0
 public static HttpResponse Get(HttpGetRequest request, Action <HttpResponse> action, Dispatcher dispatcher)
 {
     return(Get(request, r => dispatcher.BeginInvoke(() => action(r))));
 }
        public void loadVideos()
        {
            var request = new HttpGetRequest("http://gdata.youtube.com/feeds/api/users/ovalianthearts/uploads");
            request.Query.Add("v", "2");
            request.Query.Add("alt", "json");

            Http.Get(request, VideoListRequestFinished);
        }
        public void loadPaging()
        {
            var request = new HttpGetRequest(paging);

            Http.Get(request, FeedRequestFinished);
        }
Пример #10
0
 public static Task<HttpResponse> Get(HttpGetRequest request, Action<HttpResponse> completed)
 {
     return Get(request, CancellationToken.None, completed);
 }
Пример #11
0
		public static HttpResponse Get(HttpGetRequest req, Action<HttpResponse> action)
		{
			var response = new HttpResponse(req);
			try
			{
				if (!req.UseCache)
					req.Query["__dcachetime"] = DateTime.Now.Ticks.ToString(); 
				var request = CreateRequest(req);

				if (req.Credentials != null)
					request.Credentials = req.Credentials;
				response.WebRequest = request;

				if (req.Cookies.Count > 0)
				{
					request.CookieContainer = new CookieContainer();
					foreach (var c in req.Cookies)
						request.CookieContainer.Add(request.RequestUri, c);
				}

				request.Method = "GET";
				if (req.ContentType != null)
					request.ContentType = req.ContentType;

				if (req.Headers.Count > 0)
				{
					foreach (var item in req.Headers)
						request.Headers[item.Key] = item.Value;
				}

#if USE_GZIP
				if (req.RequestGzip)
					request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip";
#endif

				response.CreateTimeoutTimer(request);
				request.BeginGetResponse(r => ProcessResponse(r, request, response, action), request);
			}
			catch (Exception e)
			{
				response.Exception = e;
				if (action != null)
					action(response);
			}

			lock (pendingRequests)
				pendingRequests.Add(response);
			return response;
		}
Пример #12
0
		public static HttpResponse Get(HttpGetRequest request, Action<HttpResponse> action, Dispatcher dispatcher)
		{
			return Get(request, r => dispatcher.BeginInvoke(() => action(r)));
		}
Пример #13
0
		public static Task<HttpResponse> GetAsync(HttpGetRequest request)
		{
			var task = new TaskCompletionSource<HttpResponse>();
			Get(request, result => ProcessAsyncResponse(task, result));
			return task.Task;
		}
Пример #14
0
		private static HttpWebRequest CreateRequest(HttpGetRequest req)
		{
			var queryString = GetQueryString(req.Query);

			HttpWebRequest request = null;
			if (string.IsNullOrEmpty(queryString))
				request = (HttpWebRequest)WebRequest.Create(req.Uri.AbsoluteUri);
			else if (req.Uri.AbsoluteUri.Contains("?"))
				request = (HttpWebRequest)WebRequest.Create(req.Uri.AbsoluteUri + "&" + queryString);
			else 
				request = (HttpWebRequest)WebRequest.Create(req.Uri.AbsoluteUri + "?" + queryString);
			return request;
		}
Пример #15
0
 /// <summary>Performs a HTTP GET request. </summary>
 /// <param name="request">The <see cref="HttpGetRequest"/>. </param>
 /// <returns>The <see cref="HttpResponse"/>. </returns>
 public static Task <HttpResponse> GetAsync(HttpGetRequest request)
 {
     return(GetAsync(request, CancellationToken.None));
 }
        public void loadFeeds()
        {
            var request = new HttpGetRequest("https://graph.facebook.com/oauth/access_token");
            request.Query.Add("client_id", "270546663027963");
            request.Query.Add("client_secret", "9c7eb6f1a4ddaef888fa73dd0734d896");
            request.Query.Add("grant_type", "client_credentials");

            Http.Get(request, AccesTokenRequestFinished);
        }
Пример #17
0
 public static Task<HttpResponse> Get(HttpGetRequest request, CancellationToken token, Action<HttpResponse> completed)
 {
     var task = GetAsync(request, token);
     task.ContinueWith(t =>
     {
         if (t.Exception != null)
             completed(new HttpResponse(request) { Exception = t.Exception.InnerException });
         else if (t.IsCanceled)
             completed(new HttpResponse(request) { Canceled = true });
         else
             completed(t.Result);
     }, token);
     return task;
 }
        public void loadTour()
        {
            var request = new HttpGetRequest("http://ovaliantheartsmusic.appspot.com/concerts.json");
            request.Query.Add("period", "last");

            Http.Get(request, TourRequestFinished);
        }
Пример #19
0
 /// <summary>Performs a HTTP GET request. </summary>
 /// <param name="request">The <see cref="HttpGetRequest"/>. </param>
 /// <returns>The <see cref="HttpResponse"/>. </returns>
 public static Task<HttpResponse> GetAsync(HttpGetRequest request)
 {
     return GetAsync(request, CancellationToken.None);
 }
        private void AccesTokenRequestFinished(HttpResponse response)
        {
            if (response.Successful)
            {
                // process response outside UI thread

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    // set your data to view model or control (this code is called in the UI thread)

                    var jsonResponse = response.Response;
                    var request = new HttpGetRequest("https://graph.facebook.com/ovaliantheartsmusic/feed");
                    request.Query.Add("access_token", jsonResponse.Split('=')[1]);

                    Http.Get(request, FeedRequestFinished);

                });
            }
            else
            {
                if (!response.Canceled)
                {
                    feedBusy = false;
                    updateBusy();
                    // display exception
                    MessageBox.Show("Error loading feeds - Try again");
                }
            }
        }
Пример #21
0
        /// <summary>Performs a HTTP GET request. </summary>
        /// <param name="request">The <see cref="HttpGetRequest"/>. </param>
        /// <param name="token">The <see cref="CancellationToken"/>. </param>
        /// <param name="progress">The <see cref="IProgress{T}"/>. </param>
        /// <returns>The <see cref="HttpResponse"/>. </returns>
        public static async Task<HttpResponse> GetAsync(HttpGetRequest request, CancellationToken token, IProgress<HttpProgress> progress = null)
        {
            var uri = GetQueryString(request, request.Query);
            var handler = CreateHandler(request, uri);
            using (var client = CreateClient(request, handler))
            {
                var result = new HttpResponse(request);
                result.HttpClient = client;
                lock (PendingRequests)
                    PendingRequests.Add(result);

                try
                {
                    var response = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, token);
                    await CreateResponse(result, uri, request, handler, response, token, progress);

                    result.HttpStatusCode = response.StatusCode;
                    if (!response.IsSuccessStatusCode)
                        result.Exception = new HttpStatusException(response.StatusCode.ToString())
                        {
                            Result = result,
                            HttpStatusCode = result.HttpStatusCode
                        };
                }
                catch (Exception ex)
                {
                    if (result.Exception == null)
                    {
                        result.Exception = ex;
                        throw;
                    }
                }
                finally
                {
                    lock (PendingRequests)
                        PendingRequests.Remove(result);
                }

                if (result.Exception != null)
                    throw result.Exception;
                return result;
            }
        }