Пример #1
0
        public override Task <string> GetStringAsync(Uri requestUri)
        {
            if (requestUri == null)
            {
                return(null);
            }

            string absoluteURI = string.Empty;

            if (requestUri.IsAbsoluteUri)
            {
                absoluteURI = requestUri.AbsoluteUri;
            }
            else
            {
                absoluteURI = BaseAddress + requestUri.PathAndQuery;
            }

            int id = TaskDispatcher.CreateTaskToDispatch(TaskDispatcher.CommonTask.StringToCSharp(), out Task <string> futurTask);

            RegisteredFunction.Invoke <string>("daddoon_jQuery_SendAsync", id, WebRequestMethods.Http.Get, absoluteURI, new RequestMetadata()
            {
                timeout = Timeout.TotalMilliseconds,
                headers = ParseHeaders(DefaultRequestHeaders)
            }, null);
            return(futurTask);
        }
Пример #2
0
        public override Task <HttpResult <string> > GetStringAsyncSafe(Uri requestUri)
        {
            if (requestUri == null)
            {
                return(null);
            }

            string absoluteURI = RequestUriDetermination(requestUri);

            int id = TaskDispatcher.CreateTaskToDispatch(TaskDispatcher.CommonTask.StringToCSharpSafe(), out Task <HttpResult <string> > futurTask);

            RegisteredFunction.Invoke <string>("daddoon_jQuery_SendAsync", id, WebRequestMethods.Http.Get, absoluteURI, new RequestMetadata()
            {
                contentType = ContentType.Default,
                timeout     = Timeout.TotalMilliseconds
            }, null);
            return(futurTask);
        }
Пример #3
0
        public override Task <HttpResult <T> > SendJsonAsyncSafe <T>(HttpMethod method, Uri requestUri, object content)
        {
            var failedHttpResult = new HttpResult <T>()
            {
                ClientError = true
            };

            Task <HttpResult <T> > failedTask = Task.FromResult(failedHttpResult);

            if (requestUri == null)
            {
                return(failedTask);
            }

            try
            {
                string absoluteURI = RequestUriDetermination(requestUri);

                string contentJSON = null;

                if (content != null)
                {
                    contentJSON = JsonUtil.Serialize(content);
                }

                int id = TaskDispatcher.CreateTaskToDispatch(TaskDispatcher.CommonTask.JsonToCSharpSafe <T>(), out Task <HttpResult <T> > futurTask);

                RegisteredFunction.Invoke <string>("daddoon_jQuery_SendAsync", id, method.ToWebRequestMethods(), absoluteURI, new RequestMetadata()
                {
                    contentType = ContentType.Json,
                    timeout     = Timeout.TotalMilliseconds,
                    headers     = ParseHeaders(DefaultRequestHeaders)
                }, contentJSON);
                return(futurTask);
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogException(ex);

                //In case of premature exception
                return(failedTask);
            }
        }