Esempio n. 1
0
        // [native] bool HttpClient.TryDownload(string url, HttpClientOptions options, HttpClientResponse response)
        private static void TryDownload(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            bool success = false;

            if (arguments.Length > 2)
            {
                string             url      = (arguments[0] as NSJSString)?.Value;
                HttpClientOptions  options  = HttpClient.object2options(arguments[1] as NSJSObject);
                HttpClientResponse response = HttpClient.object2response(arguments[2] as NSJSObject);
                success = RESTClient.TryDownload(url, options, response);
            }
            arguments.SetReturnValue(success);
        }
Esempio n. 2
0
        // [native] bool HttpClient.TryUpload(string url, HttpPostValue[] blobs, HttpClientOptions options, HttpClientResponse response)
        private static void TryUpload(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            bool success = false;

            if (arguments.Length > 3)
            {
                string url = (arguments[0] as NSJSString)?.Value;
                IEnumerable <HttpPostValue> blobs    = HttpClient.array2blobs(arguments[1] as NSJSArray);
                HttpClientOptions           options  = HttpClient.object2options(arguments[2] as NSJSObject);
                HttpClientResponse          response = HttpClient.object2response(arguments[3] as NSJSObject);
                success = RESTClient.TryUpload(url, blobs, options, response);
            }
            arguments.SetReturnValue(success);
        }
Esempio n. 3
0
        // [native] bool HttpClient.TryUploadAsync(string url, HttpPostValue[] blobs, HttpClientOptions options, HttpClientResponse response, HttpClientAsyncCallback callback)
        private static void TryUploadAsync(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            bool success = false;

            if (arguments.Length > 4)
            {
                string                      url      = (arguments[0] as NSJSString)?.Value;
                HttpClientOptions           options  = HttpClient.object2options(arguments[2] as NSJSObject);
                NSJSObject                  response = arguments[3] as NSJSObject;
                IEnumerable <HttpPostValue> blobs    = HttpClient.array2blobs(arguments[1] as NSJSArray);
                if (options != null && response != null)
                {
                    NSJSFunction callback = arguments[4] as NSJSFunction;
                    if (callback != null)
                    {
                        callback.CrossThreading = true;
                    }
                    response.CrossThreading = true;
                    bool fillToObject            = false;
                    HttpClientResponse responset = HttpClient.object2response(response);
                    success = RESTClient.TryUploadAsync(url, blobs, options, responset, (error, buffer, count) =>
                    {
                        NSJSVirtualMachine machine = arguments.VirtualMachine;
                        if (error == HttpClientError.Success && !fillToObject)
                        {
                            fillToObject = true;
                            fill2object(response, responset);
                        }
                        if (callback != null)
                        {
                            bool breakto = false;
                            machine.Join((sender, state) => breakto = ((callback.Call
                                                                        (
                                                                            NSJSInt32.New(machine, (int)error),
                                                                            NSJSValue.NullMerge(machine, buffer != null && count >= 0 ? NSJSUInt8Array.New(machine, buffer, count) : null)
                                                                        ) as NSJSBoolean)?.Value) == false);
                            if (breakto)
                            {
                                return(false);
                            }
                        }
                        return(count > 0);
                    });
                }
            }
            arguments.SetReturnValue(success);
        }