Exemplo n.º 1
0
        internal void DoNavigate(Uri source, NavigationMode f, Object navState)
        {
            /*

*/

            EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordHosting | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Info, EventTrace.Event.Wpf_NavigationAsyncWorkItem);

            // Because shutdown is completed asynchronously, the DoNavigate callback might be called
            // in the meantime.
            if (IsDisposed)
                return;

            // Get or BeginGet WebResponse
            // Special handling PackWebRequest, because it only support [....] right now.
            // D2's plan is to support async in V2. Refer to PS #18958 and #17386.
            // We should switch to async after those tasks are done.
            WebResponse response = null;
            try
            {
                if (_request is PackWebRequest)
                {
                    response = WpfWebRequestHelper.GetResponse(_request);
                    if (response == null)
                    {
                        Uri requestUri = BindUriHelper.GetUriRelativeToPackAppBase(_request.RequestUri);
                        throw new Exception(SR.Get(SRID.GetResponseFailed, requestUri.ToString()));
                    }

                    // Have to use source instead of _request.RequestUri because the work around we put in
                    // to make fragment work with FileWebRequest. See function CreateWebRequest for details.

                    // Get Object from response
                    GetObjectFromResponse(_request, response, source, navState);
                }
                else
                {
                    // Have to use source instead of _request.RequestUri because the work around we put in
                    // to make fragment work with FileWebRequest. See function CreateWebRequest for details.
                    RequestState requestState = new RequestState(_request, source, navState, Dispatcher.CurrentDispatcher);

                    // Async WebResponse for everything other than PackWebRequest

                    _request.BeginGetResponse(new AsyncCallback(HandleWebResponseOnRightDispatcher),
                                                                            requestState);
                }
            }
            // Catch WebException and IOException specifically so other types of exceptions do not lose the context.
            catch (WebException e)
            {
                object extraData = navState is NavigateInfo ? null : navState;
                if (! FireNavigationFailed(new NavigationFailedEventArgs(source, extraData, INavigatorHost, _request, response, e)))
                {
                    throw;
                }
            }
            catch (IOException e)
            {
                object extraData = navState is NavigateInfo ? null : navState;
                if (! FireNavigationFailed(new NavigationFailedEventArgs(source, extraData, INavigatorHost, _request, response, e)))
                {
                    throw;
                }
            }
        }
        Boolean SendMessageToServer()
        {
            Uri url = new Uri("http://gsoc.marcospividori.com.ar/fromdevices/messages");
            RequestState myRequestState = new RequestState();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            myRequestState.request = request;
            request.Method = "POST";
            request.ContentType = "application/json";
            allDone.Reset();

            request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallbackMessage), myRequestState);

            allDone.WaitOne();
            return myRequestState.success;
        }