static StackObject *BeginGetResponse_5(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object @state = (System.Object) typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.AsyncCallback @callback = (System.AsyncCallback) typeof(System.AsyncCallback).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Net.WebRequest instance_of_this_method = (System.Net.WebRequest) typeof(System.Net.WebRequest).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.BeginGetResponse(@callback, @state);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Example #2
0
        public MainPage()
        {
            InitializeComponent();
            status.Text = "carregando.";
            Uri uri = new Uri("https://developer.xamarin.com/demo/stock.json");

            request = System.Net.WebRequest.Create(uri);
            request.BeginGetResponse(HandleAsyncCallback, null);
        }
    public static System.Threading.Tasks.Task <System.Net.WebResponse> GetResponseAsync(this System.Net.WebRequest wr)
    {
        var tcs = new System.Threading.Tasks.TaskCompletionSource <System.Net.WebResponse>();

        wr.BeginGetResponse((result) =>
        {
            var source = (System.Net.WebRequest)result.AsyncState;
            tcs.TrySetResult(source.EndGetResponse(result));
        }, wr);
        return(tcs.Task);
    }
Example #4
0
        public static Task <System.Net.WebResponse> GetResponseAsync(this System.Net.WebRequest webReq)
        {
            TaskCompletionSource <System.Net.WebResponse> taskCR = new TaskCompletionSource <System.Net.WebResponse>();

            //
            webReq.BeginGetResponse((asyncR) =>
            {
                try
                {
                    taskCR.TrySetResult(webReq.EndGetResponse(asyncR));
                }
                catch (Exception ex1)
                {
                    taskCR.TrySetException(ex1);
                }
            }, null);
            //
            return(taskCR.Task);
        }
Example #5
0
        static void AsyncronousPattern()
        {
            var Url = "https://solishealthplans.com";

            System.Net.WebRequest req = System.Net.WebRequest.Create(Url);

            var res = req.BeginGetResponse(ReadResponse, null);

            void ReadResponse(IAsyncResult ar)
            {
                using (var response = req.EndGetResponse(ar))
                {
                    System.IO.Stream stream = response.GetResponseStream();
                    var reader = new System.IO.StreamReader(stream);

                    var content = reader.ReadToEnd();
                    Console.WriteLine(content.Substring(0, 100));
                }
            }
        }
 protected void LoadPbfFile(string url, Action <double> progressCallback)
 {
     System.Net.WebRequest request = System.Net.HttpWebRequest.CreateHttp(url);
     using (System.Net.WebResponse response = request.EndGetResponse(request.BeginGetResponse(ar => { }, null)))
     {
         long contentLength       = response.ContentLength;
         long loadedContentLength = 0;
         using (System.IO.Stream responseStream = response.GetResponseStream())
             using (System.IO.Stream targetStream = GetDownloadCacheStream())
             {
                 byte[] buffer = new byte[1024];
                 int    bytesRead;
                 while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
                 {
                     targetStream.Write(buffer, 0, bytesRead);
                     loadedContentLength += bytesRead;
                     progressCallback((double)loadedContentLength / (double)contentLength);
                 }
             }
     }
 }
Example #7
0
 public static Task <System.Net.WebResponse> GetResponseAsync(this System.Net.WebRequest request)
 {
     return(Task.Factory.FromAsync(request.BeginGetResponse(null, null), ia => request.EndGetResponse(ia)));
 }
Example #8
0
        public Route Execute()
        {
            string uri = this.GetRequestUri();

            System.Net.WebRequest request = System.Net.HttpWebRequest.Create(uri);

            AutoResetEvent waitEvent = new AutoResetEvent(false);
            IAsyncResult   result    = request.BeginGetResponse((AsyncCallback) delegate(IAsyncResult ar)
            {
                waitEvent.Set();
                Thread.Sleep(0);
            }, this);

            waitEvent.WaitOne();

            RouteRestResponse response;

            using (System.IO.StreamReader str = new System.IO.StreamReader(request.EndGetResponse(result).GetResponseStream()))
            {
                response = DeserializeResponse(str.ReadToEnd());
            }

            Route restRoute = null;

            if (response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources.Length > 0)
            {
                restRoute = response.ResourceSets[0].Resources[0] as Route;
            }

            if (null != restRoute)
            {
                StringBuilder sb1 = new StringBuilder();
                StringBuilder sb2 = new StringBuilder();

                foreach (RouteLeg leg in restRoute.RouteLeg)
                {
                    foreach (ItineraryItem item in leg.ItineraryItem)
                    {
                        sb1.AppendLine(item.Instruction.maneuverType + "\t" + item.Instruction.Value);
                    }
                    sb1.AppendLine();
                }

                // Apparently we don't get good traffic data from this call
                MobileSrc.Services.RouteServices.RouteServiceClient client = new Services.RouteServices.RouteServiceClient("BasicHttpBinding_IRouteService");
#if SERVER
                if (response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources.Length > 0)
                {
                    Services.RouteServices.RouteRequest soapRequest = GetRequest(response.ResourceSets[0].Resources[0] as Route);

                    try
                    {
                        Services.RouteServices.RouteResponse soapResponse = client.CalculateRoute(soapRequest);
                        restRoute.TravelDuration = soapResponse.Result.Summary.TimeInSeconds;

                        foreach (MobileSrc.Services.RouteServices.RouteLeg leg in soapResponse.Result.Legs)
                        {
                            foreach (MobileSrc.Services.RouteServices.ItineraryItem item in leg.Itinerary)
                            {
                                sb2.AppendLine(item.ManeuverType + "\t" + item.Text);
                            }
                            sb2.AppendLine();
                        }
                    }
                    catch
                    {
                    }
                }
#else
                client.CalculateRouteCompleted += new EventHandler <Services.RouteServices.CalculateRouteCompletedEventArgs>
                                                  (
                    delegate(object sender, Services.RouteServices.CalculateRouteCompletedEventArgs e)
                {
                    if (null == e.Error)
                    {
                        restRoute.TravelDuration = e.Result.Result.Summary.TimeInSeconds;

                        foreach (MobileSrc.Services.RouteServices.RouteLeg leg in e.Result.Result.Legs)
                        {
                            foreach (MobileSrc.Services.RouteServices.ItineraryItem item in leg.Itinerary)
                            {
                                sb2.AppendLine(item.ManeuverType + "\t" + item.Text);
                            }
                            sb2.AppendLine();
                        }
                    }
                    waitEvent.Set();
                }
                                                  );
                if (response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources.Length > 0)
                {
                    Services.RouteServices.RouteRequest soapRequest = GetRequest(response.ResourceSets[0].Resources[0] as Route);
                    client.CalculateRouteAsync(soapRequest);
                }

                waitEvent.WaitOne();
#endif
            }

            return(restRoute);
        }
 public IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
 {
     return(_actual.BeginGetResponse(callback, state));
 }
Example #10
0
        internal string GetWeatherData()
        {
            RegionInfo region = RegionInfo.CurrentRegion;
            string     query  = @"https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=" +
                                string.Format("{0}{1}{0}", "\"", _location) +
                                string.Format(") and u=\"{0}\"&format=xml", region.IsMetric ? "c" : "f");
            string queryUri = Uri.EscapeUriString(query);

            System.Net.WebRequest     queryRequest          = System.Net.WebRequest.Create(queryUri);
            System.Net.WebResponse    queryResponse         = queryRequest.EndGetResponse(queryRequest.BeginGetResponse(null, null));
            System.IO.Stream          queryResponseStream   = queryResponse.GetResponseStream();
            System.Xml.Linq.XDocument queryResponseDocument = System.Xml.Linq.XDocument.Load(queryResponseStream);
            _data = queryResponseDocument;
            return(query);
        }