Пример #1
0
        private static IEnumerable <HttpPostValue> array2blobs(NSJSArray array)
        {
            if (array == null)
            {
                return(null);
            }
            IList <HttpPostValue> blobs = new List <HttpPostValue>();
            int count = array.Length;

            for (int i = 0; i < count; i++)
            {
                NSJSObject o = array[i] as NSJSObject;
                if (o == null)
                {
                    continue;
                }
                HttpPostValue blob = new HttpPostValue();
                blob.FileName = (o.Get("FileName") as NSJSString)?.Value;
                NSJSBoolean boolean = o.Get("IsText") as NSJSBoolean;
                if (boolean != null)
                {
                    blob.IsText = boolean.Value;
                }
                blob.Key   = (o.Get("Key") as NSJSString)?.Value;
                blob.Value = (o.Get("Value") as NSJSUInt8Array)?.Buffer;
            }
            return(blobs);
        }
Пример #2
0
        public static double ToDouble(NSJSValue value)
        {
            if (value == null || value.IsNullOrUndfined)
            {
                return(0);
            }
            NSJSInt32 i32 = value as NSJSInt32;

            if (i32 != null)
            {
                return(i32.Value);
            }
            NSJSUInt32 u32 = value as NSJSUInt32;

            if (u32 != null)
            {
                return(u32.Value);
            }
            NSJSBoolean boolean = value as NSJSBoolean;

            if (boolean != null)
            {
                return(boolean.Value ? 1 : 0);
            }
            NSJSDateTime time = value as NSJSDateTime;

            if (time != null)
            {
                return(NSJSDateTime.DateTimeToLocalDate(time.Value));
            }
            NSJSDouble dbl = value as NSJSDouble;

            if (dbl != null)
            {
                return(dbl.Value);
            }
            NSJSInt64 i64 = value as NSJSInt64;

            if (i64 != null)
            {
                return(i64.Value);
            }
            NSJSString str = value as NSJSString;

            if (str != null)
            {
                double n;
                if (double.TryParse(str.Value, NumberStyles.Float | NumberStyles.None, null, out n))
                {
                    return(n);
                }
            }
            return(0);
        }
Пример #3
0
        private static void GetBytes(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);

            byte[] result = null;
            if (arguments.Length > 0)
            {
                NSJSValue value = arguments[0];
                if (value != null)
                {
                    NSJSInt32 int32 = value as NSJSInt32;
                    if (int32 != null)
                    {
                        result = BITCONVERTER.GetBytes(int32.Value);
                    }
                    NSJSUInt32 uint32 = value as NSJSUInt32;
                    if (uint32 != null)
                    {
                        result = BITCONVERTER.GetBytes(uint32.Value);
                    }
                    NSJSBoolean boolean = value as NSJSBoolean;
                    if (boolean != null)
                    {
                        result = BITCONVERTER.GetBytes(boolean.Value);
                    }
                    NSJSDouble float64 = value as NSJSDouble;
                    if (float64 != null)
                    {
                        result = BITCONVERTER.GetBytes(float64.Value);
                    }
                    NSJSDateTime datetime = value as NSJSDateTime;
                    if (datetime != null)
                    {
                        result = BITCONVERTER.GetBytes(NSJSDateTime.DateTimeToLocalDate(datetime.Value));
                    }
                    ;
                }
            }
            if (result != null)
            {
                arguments.SetReturnValue(result);
            }
            else
            {
                arguments.SetReturnValue(NSJSValue.Undefined(arguments.VirtualMachine));
            }
        }
Пример #4
0
        public static bool ToBoolean(NSJSValue value)
        {
            if (value == null || value.IsNullOrUndfined)
            {
                return(false);
            }
            NSJSBoolean boolean = value as NSJSBoolean;

            if (boolean != null)
            {
                return(boolean.Value);
            }
            NSJSObject obj = value as NSJSObject;

            if (obj != null)
            {
                return(true);
            }
            return(ToDouble(value) != 0);
        }
Пример #5
0
        private static HttpClientResponse object2response(NSJSObject response)
        {
            if (response == null)
            {
                return(null);
            }
            HttpClientResponse o       = new HttpClientResponse();
            NSJSBoolean        boolean = response.Get("ManualWriteToStream") as NSJSBoolean;

            if (boolean != null)
            {
                o.ManualWriteToStream = boolean.Value;
            }
            NSJSObject objectt = response.Get("ContentStream") as NSJSObject;

            if (objectt != null)
            {
                o.ContentStream = NSJSStream.Get(objectt);
            }
            return(o);
        }
Пример #6
0
        public static NSJSValue As(this object value, NSJSVirtualMachine machine)
        {
            if (machine == null)
            {
                return(null);
            }
            if (value == null || value == DBNull.Value)
            {
                return(NSJSValue.Null(machine));
            }
            if (value is NSJSValue)
            {
                return(value as NSJSValue);
            }
            Type typeid = value.GetType();

            if (typeid == typeof(int) ||
                typeid == typeof(short) ||
                typeid == typeof(sbyte) ||
                typeid == typeof(char))
            {
                return(NSJSInt32.New(machine, Convert.ToInt32(value)));
            }
            else if (typeid == typeof(uint) ||
                     typeid == typeof(ushort) ||
                     typeid == typeof(byte))
            {
                return(NSJSUInt32.New(machine, Convert.ToUInt32(value)));
            }
            else if (typeid == typeof(string))
            {
                return(NSJSString.New(machine, value.ToString()));
            }
            else if (typeid == typeof(bool))
            {
                return(NSJSBoolean.New(machine, Convert.ToBoolean(value)));
            }
            else if (typeid == typeof(DateTime))
            {
                DateTime datetime = Convert.ToDateTime(value);
                if (NSJSDateTime.Invalid(datetime))
                {
                    datetime = NSJSDateTime.Min;
                }
                return(NSJSDateTime.New(machine, datetime));
            }
            else if (typeid == typeof(float) || typeid == typeof(double))
            {
                return(NSJSDouble.New(machine, Convert.ToDouble(value)));
            }
            else if (typeid == typeof(byte[]))
            {
                byte[] buffer = (byte[])(object)value;
                if (buffer == null)
                {
                    return(NSJSValue.Null(machine));
                }
                return(NSJSUInt8Array.New(machine, buffer));
            }
            else if (typeid == typeof(sbyte[]))
            {
                sbyte[] buffer = (sbyte[])(object)value;
                if (buffer == null)
                {
                    return(NSJSValue.Null(machine));
                }
                return(NSJSInt8Array.New(machine, buffer));
            }
            else if (typeid == typeof(short[]))
            {
                short[] buffer = (short[])(object)value;
                if (buffer == null)
                {
                    return(NSJSValue.Null(machine));
                }
                return(NSJSInt16Array.New(machine, buffer));
            }
            else if (typeid == typeof(ushort[]))
            {
                ushort[] buffer = (ushort[])(object)value;
                if (buffer == null)
                {
                    return(NSJSValue.Null(machine));
                }
                return(NSJSUInt16Array.New(machine, buffer));
            }
            else if (typeid == typeof(int[]))
            {
                int[] buffer = (int[])(object)value;
                if (buffer == null)
                {
                    return(NSJSValue.Null(machine));
                }
                return(NSJSInt32Array.New(machine, buffer));
            }
            else if (typeid == typeof(uint[]))
            {
                uint[] buffer = (uint[])(object)value;
                if (buffer == null)
                {
                    return(NSJSValue.Null(machine));
                }
                return(NSJSUInt32Array.New(machine, buffer));
            }
            else if (typeid == typeof(float[]))
            {
                float[] buffer = (float[])(object)value;
                if (buffer == null)
                {
                    return(NSJSValue.Null(machine));
                }
                return(NSJSFloat32Array.New(machine, buffer));
            }
            else if (typeid == typeof(double[]))
            {
                double[] buffer = (double[])(object)value;
                if (buffer == null)
                {
                    return(NSJSValue.Null(machine));
                }
                return(NSJSFloat64Array.New(machine, buffer));
            }
            return(NSJSValue.Null(machine));
        }
Пример #7
0
        private static HttpClientOptions object2options(NSJSObject options)
        {
            if (options == null)
            {
                return(null);
            }
            HttpClientOptions o       = new HttpClientOptions();
            NSJSBoolean       boolean = options.Get("AllowAutoRedirect") as NSJSBoolean;

            if (boolean != null)
            {
                o.AllowAutoRedirect = boolean.Value;
            }
            NSJSInt32 int32 = options.Get("AutomaticDecompression") as NSJSInt32;

            if (int32 != null)
            {
                o.AutomaticDecompression = (DecompressionMethods)int32.Value;
            }
            int32 = options.Get("CachePolicy") as NSJSInt32;
            if (int32 != null)
            {
                o.CachePolicy = new HttpRequestCachePolicy((HttpRequestCacheLevel)int32.Value);
            }
            int32 = options.Get("MaximumAutomaticRedirections") as NSJSInt32;
            if (int32 != null)
            {
                o.MaximumAutomaticRedirections = int32.Value;
            }
            int32 = options.Get("Timeout") as NSJSInt32;
            if (int32 != null)
            {
                o.Timeout = int32.Value;
            }
            NSJSString stringt = options.Get("Proxy") as NSJSString;

            if (stringt != null)
            {
                o.Proxy = new WebProxy(stringt.Value);
            }
            stringt = options.Get("Referer") as NSJSString;
            if (stringt != null)
            {
                o.Referer = stringt.Value;
            }
            NSJSInt32Array int32array = options.Get("Range") as NSJSInt32Array;

            if (int32array != null)
            {
                o.Range = int32array.Buffer;
            }
            NSJSArray array = options.Get("Headers") as NSJSArray;

            if (array != null)
            {
                NameValueCollection headers = o.Headers;
                int count = array.Length;
                for (int i = 0; i < count; i++)
                {
                    stringt = array[i] as NSJSString;
                    if (stringt == null)
                    {
                        continue;
                    }
                    headers.Add(headers);
                }
            }
            return(o);
        }