Пример #1
0
        private static void Position(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This);

            if (stream == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else if (arguments.Length <= 0)
            {
                arguments.SetReturnValue(unchecked ((int)stream.Position));
            }
            else
            {
                NSJSInt32 value = arguments[0] as NSJSInt32;
                if (value == null)
                {
                    arguments.SetReturnValue(false);
                }
                else
                {
                    try
                    {
                        stream.Position = value.Value;
                        arguments.SetReturnValue(true);
                    }
                    catch (Exception e)
                    {
                        Throwable.Exception(arguments.VirtualMachine, e);
                    }
                }
            }
        }
Пример #2
0
        private static void ToUInt32(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            uint result = 0;

            if (arguments.Length > 0)
            {
                NSJSUInt8Array value      = arguments[0] as NSJSUInt8Array;
                NSJSInt32      startIndex = null;
                if (arguments.Length > 1)
                {
                    startIndex = arguments[1] as NSJSInt32;
                }
                if (value != null)
                {
                    int offset = 0;
                    if (startIndex != null)
                    {
                        offset = startIndex.Value;
                    }
                    if (offset < 0)
                    {
                        offset = 0;
                    }
                    byte[] buffer = value.Buffer;
                    if (buffer != null)
                    {
                        result = BITCONVERTER.ToUInt32(buffer, offset);
                    }
                }
            }
            arguments.SetReturnValue(result);
        }
Пример #3
0
 protected override RijndaelCryptoServiceProvider New(byte[] Key, byte[] IV, NSJSFunctionCallbackInfo arguments)
 {
     int[] pushs = new int[5];
     for (int i = 0; i < 5; i++)
     {
         NSJSInt32 int32 = arguments[i] as NSJSInt32;
         if (int32 == null)
         {
             if (i < 3)
             {
                 pushs[i] = 128;
             }
             else if (i < 4)
             {
                 pushs[i] = 2; // PKCS7
             }
             else if (i < 5)
             {
                 pushs[i] = 4; // CFB
             }
             continue;
         }
         pushs[i] = int32.Value;
     }
     return(new RijndaelCryptoServiceProvider(Key, IV, pushs[0], pushs[1], pushs[2], (PaddingMode)pushs[3], (CipherMode)pushs[4]));
 }
Пример #4
0
 private static void ProcessConnected(object sender, SocketAsyncEventArgs e)
 {
     using (e)
     {
         try
         {
             SocketContext context = e.UserToken as SocketContext;
             do
             {
                 if (context == null)
                 {
                     break;
                 }
                 NSJSFunction function = context.ConnectedAsyncCallback;
                 NSJSObject   socket   = context.This;
                 context.ConnectedAsync         = null;
                 context.ConnectedAsyncCallback = null;
                 if (function == null)
                 {
                     break;
                 }
                 NSJSVirtualMachine machine = function.VirtualMachine;
                 if (machine == null)
                 {
                     break;
                 }
                 machine.Join((sendert, statet) => function.Call(socket, NSJSInt32.New(machine, unchecked ((int)e.SocketError))));
             } while (false);
         }
         catch (Exception) { }
     }
 }
Пример #5
0
 private static void ReceiveAsync(IntPtr info)
 {
     InternalReceiveAsync(info, false, (socket, socketobject, data, buffer, ofs, count, flags, remoteep, callback) =>
     {
         bool success = false;
         if ((success = SocketExtension.BeginReceive(socket, buffer, ofs, count, flags, (result) =>
         {
             int len = SocketExtension.EndReceive(socket, result, out SocketError error);
             NSJSVirtualMachine machine = socketobject.VirtualMachine;
             machine.Join((sender, state) =>
             {
                 if (len > 0)
                 {
                     for (int i = ofs; i < len; i++)
                     {
                         data[i] = buffer[i];
                     }
                 }
                 if (callback != null)
                 {
                     callback.Call(socketobject, NSJSInt32.New(machine, unchecked ((int)error)), NSJSInt32.New(machine, len));
                 }
             });
         })))
         {
             if (callback != null)
             {
                 callback.CrossThreading = true;
             }
             data.CrossThreading = true;
         }
         return(success);
     });
Пример #6
0
 private static void WriteFile(IntPtr info)
 {
     ObjectAuxiliary.Call <HTTPResponse>(info, (response, arguments, value) =>
     {
         NSJSInt32 count  = null;
         NSJSInt32 offset = null;
         if (arguments.Length == 2)
         {
             count = arguments[1] as NSJSInt32;
         }
         else if (arguments.Length > 2)
         {
             offset = arguments[1] as NSJSInt32;
             count  = arguments[2] as NSJSInt32;
         }
         int ofs  = offset == null ? 0 : offset.Value;
         int size = count == null ? value.Length : count.Value;
         if (ofs < 0)
         {
             ofs = 0;
         }
         if (size < 0)
         {
             size = 0;
         }
         arguments.SetReturnValue(response.WriteFile(value, ofs, size));
     });
 }
Пример #7
0
        public static void GetEncoding(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            Encoding encoding = NSJSEncoding.DefaultEncoding;

            if (arguments.Length > 0)
            {
                string path = (arguments[0] as NSJSString)?.Value;
                if (path != null)
                {
                    encoding = GetEncoding(path);
                }
                else
                {
                    byte[] buffer = (arguments[0] as NSJSUInt8Array)?.Buffer;
                    int    offset = 0;
                    if (buffer != null && arguments.Length > 1)
                    {
                        NSJSInt32 i = arguments[1] as NSJSInt32;
                        offset = (i == null ? 0x00 : i.Value);
                    }
                    encoding = GetEncoding(buffer, offset);
                }
            }
            arguments.SetReturnValue(NSJSEncoding.New(arguments.VirtualMachine, encoding));
        }
Пример #8
0
        private static void GetString(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            ENCODING encoding = NSJSKeyValueCollection.Get <ENCODING>(arguments.This);

            if (encoding == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                string s = null;
                if (arguments.Length > 0)
                {
                    NSJSUInt8Array chars = arguments[0] as NSJSUInt8Array;
                    if (chars != null)
                    {
                        byte[] buffer = chars.Buffer;
                        if (buffer != null)
                        {
                            NSJSInt32 index = null;
                            NSJSInt32 len   = null;
                            switch (arguments.Length)
                            {
                            case 2:
                                len = arguments[1] as NSJSInt32;
                                break;

                            case 3:
                                index = arguments[1] as NSJSInt32;
                                len   = arguments[2] as NSJSInt32;
                                break;
                            }
                            int ofs   = index != null ? index.Value : 0;
                            int count = len != null ? len.Value : buffer.Length;
                            if (count < 0)
                            {
                                count = 0;
                            }
                            if (ofs < 0)
                            {
                                ofs = 0;
                            }
                            s = encoding.GetString(buffer, ofs, count);
                        }
                    }
                }
                if (s != null)
                {
                    arguments.SetReturnValue(s);
                }
                else
                {
                    arguments.SetReturnValue(NSJSValue.Undefined(arguments.VirtualMachine));
                }
            }
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #11
0
        private static void New(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSInt32 capacity = arguments.Length > 0 ? arguments[0] as NSJSInt32 : null;
            MEMStream ms       = null;

            if (capacity != null)
            {
                ms = new MEMStream(capacity.Value);
            }
            else
            {
                ms = new MEMStream();
            }
            arguments.SetReturnValue(NSJSValue.UndefinedMerge(arguments.VirtualMachine, Stream.New(arguments.VirtualMachine, ms)));
        }
Пример #12
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));
            }
        }
Пример #13
0
 private static void CallSetFileInfo(IntPtr info, Action <NSJSFunctionCallbackInfo, string, int> callback)
 {
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     CallGetFileInfo(info, (arguments, path) =>
     {
         NSJSInt32 n = arguments.Length > 0 ? arguments[0] as NSJSInt32 : null;
         if (n == null)
         {
             Throwable.ArgumentNullException(arguments.VirtualMachine);
         }
         else
         {
             callback(arguments, path, n.Value);
         }
     });
 }
Пример #14
0
        public static void New(NSJSFunctionCallbackInfo arguments)
        {
            NSJSObject options = arguments.Length > 0 ? arguments[0] as NSJSObject : null;

            if (options == null)
            {
                Throwable.ArgumentNullException(arguments.VirtualMachine);
            }
            else
            {
                string username = options.Get("UserName").As <string>();
                string password = options.Get("Password").As <string>();
                string domain   = options.Get("Domain").As <string>();
                string server   = options.Get("Server").As <string>();
                if (username == null || password == null || server == null)
                {
                    Throwable.ArgumentNullException(arguments.VirtualMachine);
                }
                else if (username.Length <= 0 || password.Length <= 0 || server.Length <= 0)
                {
                    Throwable.ArgumentException(arguments.VirtualMachine);
                }
                else
                {
                    int       port = MailClient.DefaultPort;
                    NSJSInt32 i    = (options.Get("Port") as NSJSInt32);
                    if (i != null)
                    {
                        port = i.Value;
                    }
                    MailClient smtp = new MailClient(server, port, username, password, domain);
                    smtp.EnableSsl = options.Get("EnableSsl").As <bool>();
                    i = (options.Get("Timeout") as NSJSInt32);
                    if (i != null)
                    {
                        smtp.Timeout = i.Value;
                    }
                    arguments.SetReturnValue(New(arguments.VirtualMachine, smtp));
                }
            }
        }
Пример #15
0
        private static void New(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string     path   = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;
            FileMode   mode   = FileMode.Open;
            FileAccess access = FileAccess.ReadWrite;

            if (arguments.Length > 1)
            {
                NSJSInt32 n = arguments[1] as NSJSInt32;
                if (n != null)
                {
                    mode = (FileMode)n.Value;
                }
                n = arguments.Length > 2 ? arguments[2] as NSJSInt32 : null;
                if (n != null)
                {
                    access = (FileAccess)n.Value;
                }
            }
            Exception exception = null;
            FStream   stream    = null;

            try
            {
                stream = new FStream(path, mode, access);
            }
            catch (Exception e)
            {
                exception = e;
            }
            if (exception == null)
            {
                arguments.SetReturnValue(Stream.New(arguments.VirtualMachine, stream));
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }
Пример #16
0
 private static void ProcessAccept(object sender, SocketAsyncEventArgs e)
 {
     try
     {
         SocketContext context = e.UserToken as SocketContext;
         do
         {
             SOCKET client = e.AcceptSocket;
             SOCKET server = (SOCKET)sender;
             e.AcceptSocket = null;
             do
             {
                 if (context == null)
                 {
                     break;
                 }
                 NSJSFunction function = context.AcceptAsyncCallback;
                 NSJSObject   socket   = context.This;
                 if (function == null)
                 {
                     break;
                 }
                 NSJSVirtualMachine machine = function.VirtualMachine;
                 if (machine == null)
                 {
                     break;
                 }
                 machine.Join((sendert, statet) => function.Call(socket,
                                                                 NSJSInt32.New(machine, unchecked ((int)e.SocketError)),
                                                                 NSJSValue.NullMerge(machine, New(machine, client))));
             } while (false);
             if (!server.AcceptAsync(e))
             {
                 ProcessAccept(server, e);
             }
         } while (false);
     }
     catch (Exception) { }
 }
Пример #17
0
        private static void ToDateTime(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSValue result = null;

            if (arguments.Length > 0)
            {
                NSJSUInt8Array value      = arguments[0] as NSJSUInt8Array;
                NSJSInt32      startIndex = null;
                if (arguments.Length > 1)
                {
                    startIndex = arguments[1] as NSJSInt32;
                }
                if (value != null)
                {
                    int offset = 0;
                    if (startIndex != null)
                    {
                        offset = startIndex.Value;
                    }
                    if (offset < 0)
                    {
                        offset = 0;
                    }
                    byte[] buffer = value.Buffer;
                    if (buffer != null)
                    {
                        long ticks = BITCONVERTER.ToInt64(buffer, offset);
                        result = NSJSDateTime.New(arguments.VirtualMachine, ticks);
                    }
                }
            }
            if (result == null)
            {
                result = NSJSValue.Undefined(arguments.VirtualMachine);
            }
            arguments.SetReturnValue(result);
        }
Пример #18
0
        private static void Sort(IntPtr info, Action <NSJSArray, int, int, Func <NSJSValue, NSJSValue, bool> > sorting)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            bool success = false;

            if (arguments.Length > 1)
            {
                NSJSArray    s    = arguments[0] as NSJSArray;
                NSJSFunction max  = arguments[1] as NSJSFunction;
                int          low  = 0;
                int          high = -1;
                if (arguments.Length > 3 && max == null)
                {
                    max = arguments[3] as NSJSFunction;
                    NSJSInt32 i32 = arguments[1] as NSJSInt32;
                    if (i32 != null)
                    {
                        low = i32.Value;
                    }
                    i32 = arguments[2] as NSJSInt32;
                    if (i32 != null)
                    {
                        high = i32.Value;
                    }
                }
                if (max != null && s != null)
                {
                    if (high < 0)
                    {
                        high = s.Length - 1;
                    }
                    sorting(s, low, high, (x, y) => ((max.Call(x, y) as NSJSBoolean)?.Value).GetValueOrDefault());
                }
            }
            arguments.SetReturnValue(success);
        }
Пример #19
0
        private static void GetEncoding(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSValue result = null;

            if (arguments.Length > 0)
            {
                NSJSInt32 codepage = arguments[0] as NSJSInt32;
                try
                {
                    if (codepage != null)
                    {
                        result = New(arguments.VirtualMachine, ENCODING.GetEncoding(codepage.Value));
                    }
                    NSJSString name = arguments[0] as NSJSString;
                    if (name != null)
                    {
                        result = New(arguments.VirtualMachine, ENCODING.GetEncoding(name.Value));
                    }
                }
                catch (Exception) { }
            }
            arguments.SetReturnValue(NSJSValue.UndefinedMerge(arguments.VirtualMachine, result));
        }
Пример #20
0
        private static void SetTimer(IntPtr info, bool period)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            int handle = -1;

            if (arguments.Length > 1)
            {
                NSJSFunction callback = arguments[0] as NSJSFunction;
                NSJSInt32    millisec = arguments[1] as NSJSInt32;
                if (callback != null && millisec != null && millisec.Value >= 0)
                {
                    NSJSVirtualMachine machine = arguments.VirtualMachine;
                    callback.CrossThreading = true;
                    TIMER             timer = NSJSTimerScheduler.New(arguments.VirtualMachine);
                    IList <NSJSValue> argv  = new List <NSJSValue>();
                    for (int i = 2; i < arguments.Length; i++)
                    {
                        NSJSValue item = arguments[i];
                        item.CrossThreading = true;
                        argv.Add(item);
                    }
                    timer.Tick += (sender, e) =>
                    {
                        if (!period)
                        {
                            CloseTimer(handle);
                        }
                        machine.Join((sendert, statet) => callback.Call(argv));
                    };
                    handle         = AddTimer(timer);
                    timer.Interval = millisec.Value;
                    timer.Enabled  = true;
                }
            }
            arguments.SetReturnValue(handle);
        }
Пример #21
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));
        }
Пример #22
0
        private static void InternalExecute(NSJSFunctionCallbackInfo arguments, bool nonquery)
        {
            InternalExecute(arguments, (gateway, adapter, text) =>
            {
                DataTable dataTable = null;
                IDbCommand command  = null;
                try
                {
                    IDbTransaction transaction = null;
                    NSJSArray parameters       = null;
                    NSJSInt32 cmdtype          = null;
                    for (int solt = 1, count = arguments.Length; solt < count && (transaction == null ||
                                                                                  cmdtype == null || parameters == null); solt++)
                    {
                        NSJSValue current = arguments[solt];
                        if (transaction == null)
                        {
                            transaction = DatabaseTransaction.GetTransaction(current as NSJSObject);
                        }
                        if (cmdtype == null)
                        {
                            cmdtype = current as NSJSInt32;
                        }
                        if (parameters == null)
                        {
                            parameters = current as NSJSArray;
                        }
                    }
                    command         = ObjectAuxiliary.ToDbCommand(adapter, text, parameters);
                    int commandType = ValueAuxiliary.ToInt32(cmdtype);
                    switch (commandType)
                    {
                    case 1:
                        command.CommandType = CommandType.StoredProcedure;
                        break;

                    case 2:
                        command.CommandType = CommandType.TableDirect;
                        break;

                    default:
                        command.CommandType = CommandType.Text;
                        break;
                    }
                    command.Transaction = transaction;
                    if (nonquery)
                    {
                        arguments.SetReturnValue(gateway.ExecuteNonQuery(command));
                    }
                    else
                    {
                        dataTable = gateway.Select(command);
                        arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, dataTable));
                    }
                }
                catch (Exception e)
                {
                    Throwable.Exception(arguments.VirtualMachine, e);
                }
                if (dataTable != null)
                {
                    dataTable.Dispose();
                }
                if (command != null)
                {
                    command.Dispose();
                }
            });
        }
Пример #23
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);
        }