Ejemplo n.º 1
0
        private static void ContentEncoding(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            HTTPResponse             response  = GetResponse(arguments.This);

            if (response == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                NSJSVirtualMachine machine = arguments.VirtualMachine;
                if (arguments.Length <= 0)
                {
                    arguments.SetReturnValue(NSJSEncoding.New(machine, response.ContentEncoding));
                }
                else
                {
                    var encoding = NSJSEncoding.GetEncoding(arguments[0] as NSJSObject);
                    if (encoding == null)
                    {
                        encoding = NSJSEncoding.DefaultEncoding;
                    }
                    response.ContentEncoding = encoding;
                    arguments.SetReturnValue(true);
                }
            }
        }
Ejemplo n.º 2
0
        private static void Require(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSString rawUri = arguments.Length > 0 ? arguments[0] as NSJSString : null;

            if (rawUri == null || rawUri.DateType != NSJSDataType.kString)
            {
                arguments.SetReturnValue(false);
            }
            else
            {
                NSJSVirtualMachine machine = arguments.VirtualMachine;
                NSJSObject         global  = machine.Global;
                string             path    = rawUri.Value;
                string             source;
                if (string.IsNullOrEmpty(path))
                {
                    arguments.SetReturnValue(false);
                }
                else
                {
                    int index = path.IndexOf('#');
                    if (index > -1)
                    {
                        path = path.Substring(0, index);
                    }
                    index = path.IndexOf('?');
                    if (index > -1)
                    {
                        path = path.Substring(0, index);
                    }
                    do
                    {
                        bool success = false;
                        if (!FileAuxiliary.TryReadAllText(path, out source))
                        {
                            if (!FileAuxiliary.TryReadAllText(Application.StartupPath + "/" + path, out source))
                            {
                                arguments.SetReturnValue(false);
                                break;
                            }
                            success = true;
                        }
                        if (!success)
                        {
                            if (!HttpAuxiliary.TryReadAllText(path, out source))
                            {
                                arguments.SetReturnValue(false);
                                break;
                            }
                        }
                        if (File.Exists(path))
                        {
                            path = Path.GetFullPath(path);
                        }
                        arguments.SetReturnValue(machine.Run(source, path));
                    } while (false);
                }
            }
        }
Ejemplo n.º 3
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);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private static void GetKeyValue(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string value = null;

            if (arguments.Length > 2)
            {
                string path    = GetFullPath((arguments[0] as NSJSString)?.Value);
                string section = (arguments[1] as NSJSString)?.Value;
                string key     = (arguments[2] as NSJSString)?.Value;
                if (File.Exists(path) &&
                    !string.IsNullOrEmpty(section) &&
                    !string.IsNullOrEmpty(key))
                {
                    value = GetKeyValue(path, section, key);
                }
            }
            if (value != null)
            {
                arguments.SetReturnValue(value);
            }
            else
            {
                arguments.SetReturnValue(NSJSValue.Undefined(arguments.VirtualMachine));
            }
        }
Ejemplo n.º 5
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));
                }
            }
        }
Ejemplo n.º 6
0
        private void ComputeHashValueOrString(IntPtr info, bool hashValue)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);

            byte[] buffer = null;
            if (arguments.Length > 0)
            {
                buffer = (arguments[0] as NSJSUInt8Array)?.Buffer;
                if (buffer == null)
                {
                    string s = (arguments[0] as NSJSString).Value;
                    if (s != null)
                    {
                        Encoding encoding = NSJSEncoding.DefaultEncoding;
                        if (arguments.Length > 1)
                        {
                            encoding = NSJSEncoding.GetEncoding(arguments[1] as NSJSObject);
                        }
                        buffer = encoding.GetBytes(s);
                    }
                }
            }
            if (buffer == null)
            {
                Throwable.ArgumentNullException(arguments.VirtualMachine);
            }
            else
            {
                try
                {
                    using (HASHAlgorithm hash = New())
                    {
                        buffer = hash.ComputeHash(buffer);
                        if (hashValue)
                        {
                            arguments.SetReturnValue(buffer);
                        }
                        else
                        {
                            string s = string.Empty;
                            for (int i = 0; i < buffer.Length; i++)
                            {
                                s += buffer[i].ToString("X2");
                            }
                            arguments.SetReturnValue(s);
                        }
                    }
                }
                catch (Exception e)
                {
                    Throwable.Exception(arguments.VirtualMachine, e);
                }
            }
        }
Ejemplo n.º 7
0
        private static void Exists(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSString path = arguments.Length > 0 ? arguments[0] as NSJSString : null;

            if (path == null)
            {
                arguments.SetReturnValue(false);
            }
            else
            {
                arguments.SetReturnValue(FILE.Exists(path.Value));
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        private static void GetBytes(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            ENCODING encoding = GetEncoding(arguments.This);

            if (encoding == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                byte[] buffer = null;
                if (arguments.Length > 0)
                {
                    NSJSString s = arguments[0] as NSJSString;
                    if (s != null)
                    {
                        buffer = encoding.GetBytes(s.Value);
                    }
                }
                if (buffer == null)
                {
                    buffer = BufferExtension.EmptryBuffer;
                }
                arguments.SetReturnValue(buffer);
            }
        }
Ejemplo n.º 11
0
        private static void GetEncodings(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            var encodings = ENCODING.GetEncodings();

            arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, encodings));
        }
Ejemplo n.º 12
0
        private static void New(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            int port = (arguments.Length > 0 ? (arguments[0] as NSJSInt32)?.Value : null).GetValueOrDefault();

            arguments.SetReturnValue(New(arguments.VirtualMachine, new WebSocketListener(port)));
        }
Ejemplo n.º 13
0
        private static void Start(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments   = NSJSFunctionCallbackInfo.From(info);
            HTTPApplication          application = GetApplication(arguments.This);

            if (application == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                try
                {
                    IList <string> prefixes = ArrayAuxiliary.ToStringList(arguments.Length > 0 ? arguments[0] : null);
                    do
                    {
                        if (prefixes.IsNullOrEmpty())
                        {
                            Throwable.ArgumentNullException(arguments.VirtualMachine);
                            break;
                        }
                        application.Start(prefixes);
                        arguments.SetReturnValue(true);
                    } while (false);
                }
                catch (Exception e)
                {
                    Throwable.Exception(arguments.VirtualMachine, e);
                }
            }
        }
Ejemplo n.º 14
0
        private static void GetConfigurationView(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string path = GetFullPath(arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null);

            if (File.Exists(path))
            {
                NSJSObject configuration = NSJSObject.New(arguments.VirtualMachine);
                foreach (string section in GetAllSection(path))
                {
                    if (string.IsNullOrEmpty(section))
                    {
                        continue;
                    }
                    NSJSObject sectionObject = NSJSObject.New(arguments.VirtualMachine);
                    foreach (KeyValuePair <string, string> kv in GetAllKeyValue(path, section))
                    {
                        if (string.IsNullOrEmpty(kv.Key))
                        {
                            continue;
                        }
                        sectionObject.Set(kv.Key, kv.Value);
                    }
                    configuration.Set(section, sectionObject);
                }
                arguments.SetReturnValue(configuration);
            }
        }
Ejemplo n.º 15
0
        private static void GetHostAddresses(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string hostNameOrAddress           = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;

            try
            {
                if (hostNameOrAddress == null)
                {
                    Throwable.ArgumentNullException(arguments.VirtualMachine);
                }
                else if (hostNameOrAddress.Length <= 0)
                {
                    Throwable.ArgumentException(arguments.VirtualMachine);
                }
                else
                {
                    IPAddress[] addresses = DNS.GetHostAddresses(hostNameOrAddress);
                    arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, addresses));
                }
            }
            catch (Exception e)
            {
                Throwable.Exception(arguments.VirtualMachine, e);
            }
        }
Ejemplo n.º 16
0
        private static void Flush(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This);

            if (stream == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                Exception exception = null;
                bool      success   = false;
                try
                {
                    stream.Flush();
                }
                catch (Exception e)
                {
                    exception = e;
                }
                if (exception != null)
                {
                    Throwable.Exception(arguments.VirtualMachine, exception);
                }
                else
                {
                    arguments.SetReturnValue(success);
                }
            }
        }
Ejemplo n.º 17
0
        private static void New(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string             url             = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;
            NSJSVirtualMachine machine         = arguments.VirtualMachine;

            if (url == null)
            {
                Throwable.ArgumentNullException(machine);
            }
            else if ((url = url.Trim()).Length <= 0)
            {
                Throwable.ArgumentException(machine);
            }
            else
            {
                try
                {
                    arguments.SetReturnValue(New(machine, new WebSocket(url)));
                }
                catch (Exception exception)
                {
                    Throwable.Exception(machine, exception);
                }
            }
        }
Ejemplo n.º 18
0
        private static void Delete(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSString rawUri    = arguments.Length > 0 ? arguments[0] as NSJSString : null;
            bool       success   = false;
            Exception  exception = null;

            if (rawUri != null)
            {
                string path = rawUri.Value;
                if (DIRECTORY.Exists(path))
                {
                    try
                    {
                        DIRECTORY.Delete(path, true);
                        success = true;
                    }
                    catch (Exception e)
                    {
                        exception = e;
                        success   = false;
                    }
                }
            }
            if (exception == null)
            {
                arguments.SetReturnValue(success);
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }
Ejemplo n.º 19
0
        private static void WriteAllBytes(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSString     url       = arguments.Length > 0 ? arguments[0] as NSJSString : null;
            NSJSUInt8Array buffer    = arguments.Length > 1 ? arguments[1] as NSJSUInt8Array : null;
            bool           success   = false;
            Exception      exception = null;

            if (url != null)
            {
                string path  = url.Value;
                byte[] bytes = (buffer == null ? BufferExtension.EmptryBuffer : buffer.Buffer);
                try
                {
                    FILE.WriteAllBytes(path, bytes);
                    success = true;
                }
                catch (Exception e)
                {
                    exception = e;
                    success   = false;
                }
            }
            if (exception == null)
            {
                arguments.SetReturnValue(success);
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }
Ejemplo n.º 20
0
        private static void CreateDirectory(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string    path      = arguments.Length > 0 ? (arguments[0] as NSJSString).Value : null;
            bool      success   = false;
            Exception exception = null;

            if (!string.IsNullOrEmpty(path) && !DIRECTORY.Exists(path))
            {
                try
                {
                    DIRECTORY.CreateDirectory(path);
                    success = true;
                }
                catch (Exception e)
                {
                    exception = e;
                }
            }
            if (exception == null)
            {
                arguments.SetReturnValue(success);
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }
Ejemplo n.º 21
0
        private static void WriteAllText(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            bool      success   = false;
            Exception exception = null;

            if (arguments.Length > 1)
            {
                string   path      = (arguments[0] as NSJSString)?.Value;
                string   contents  = (arguments[1] as NSJSString)?.Value;
                Encoding encodings = NSJSEncoding.DefaultEncoding;
                if (arguments.Length > 2)
                {
                    encodings = NSJSEncoding.GetEncoding(arguments[2] as NSJSObject);
                }
                try
                {
                    FILE.WriteAllText(path, contents, encodings);
                    success = true;
                }
                catch (Exception e)
                {
                    exception = e;
                }
            }
            if (exception == null)
            {
                arguments.SetReturnValue(success);
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }
Ejemplo n.º 22
0
        private static void ReadAllBytes(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string path = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;

            byte[]    buffer    = null;
            Exception exception = null;

            if (FILE.Exists(path))
            {
                try
                {
                    buffer = FILE.ReadAllBytes(path);
                }
                catch (Exception e)
                {
                    exception = e;
                }
            }
            if (buffer != null)
            {
                arguments.SetReturnValue(buffer);
            }
            else if (exception == null)
            {
                Throwable.FileNotFoundException(arguments.VirtualMachine);
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }
Ejemplo n.º 23
0
        private static void GetFileLength(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string path = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;

            arguments.SetReturnValue(FileAuxiliary.GetFileLength64(path));
        }
Ejemplo n.º 24
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));
            }
        }
Ejemplo n.º 25
0
        private void EncryptOrDecrypt(IntPtr info, bool decrypt)
        {
            NSJSFunctionCallbackInfo      arguments = NSJSFunctionCallbackInfo.From(info);
            RijndaelCryptoServiceProvider provider  = NSJSKeyValueCollection.Get <RijndaelCryptoServiceProvider>(arguments.This);

            if (provider == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                byte[]    result    = null;
                Exception exception = null;
                if (arguments.Length > 0)
                {
                    byte[] buffer = (arguments[0] as NSJSUInt8Array)?.Buffer;
                    if (buffer != null)
                    {
                        int ofs = 0;
                        if (arguments.Length > 1)
                        {
                            ofs = ((arguments[1] as NSJSInt32)?.Value).GetValueOrDefault();
                        }
                        int count = buffer.Length;
                        if (arguments.Length > 2)
                        {
                            count = ((arguments[2] as NSJSInt32)?.Value).GetValueOrDefault();
                        }
                        try
                        {
                            if (decrypt)
                            {
                                result = provider.Decrypt(buffer, ofs, count);
                            }
                            else
                            {
                                result = provider.Encrypt(buffer, ofs, count);
                            }
                        }
                        catch (Exception e)
                        {
                            exception = e;
                        }
                    }
                }
                if (exception != null)
                {
                    Throwable.Exception(arguments.VirtualMachine, exception);
                }
                else if (result != null)
                {
                    arguments.SetReturnValue(result);
                }
                else
                {
                    Throwable.ArgumentNullException(arguments.VirtualMachine, exception);
                }
            }
        }
Ejemplo n.º 26
0
        private static void Invalid(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            SocketContext            context   = GetSocketContext(arguments.Length > 0 ? arguments[0] as NSJSObject : null);
            NSJSObject o = NSJSObject.New(arguments.VirtualMachine);

            arguments.SetReturnValue(!(context != null && context.Socket != null && context.This != null));
        }
Ejemplo n.º 27
0
        private static void SetProxy(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string server  = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null;
            string pac     = arguments.Length > 1 ? (arguments[1] as NSJSString)?.Value : null;
            bool   enabled = arguments.Length > 2 ? ((arguments[2] as NSJSBoolean)?.Value).GetValueOrDefault() : false;

            arguments.SetReturnValue(SetProxy(server, pac, enabled));
        }
Ejemplo n.º 28
0
        private static void ReadBytes(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This);

            if (stream == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                NSJSValue result    = null;
                Exception exception = null;
                if (arguments.Length > 0)
                {
                    int max = ((arguments[0] as NSJSInt32)?.Value).GetValueOrDefault();
                    if (max >= 0)
                    {
                        try
                        {
                            byte[] ch  = new byte[max];
                            int    len = stream.Read(ch, 0, max);
                            result = NSJSUInt8Array.New(arguments.VirtualMachine, ch, len);
                        }
                        catch (Exception e)
                        {
                            exception = e;
                        }
                    }
                }
                if (exception != null)
                {
                    Throwable.Exception(arguments.VirtualMachine, exception);
                }
                else if (result != null)
                {
                    arguments.SetReturnValue(result);
                }
                else
                {
                    arguments.SetReturnValue(NSJSValue.Undefined(arguments.VirtualMachine));
                }
            }
        }
Ejemplo n.º 29
0
        private static void Root(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments   = NSJSFunctionCallbackInfo.From(info);
            HTTPApplication          application = GetApplication(arguments.This);

            if (application == null)
            {
                arguments.SetReturnValue(NSJSValue.Undefined(arguments.VirtualMachine));
            }
            else if (arguments.Length > 0)
            {
                string path = (arguments[0] as NSJSString)?.Value;
                application.Root = path;
            }
            else
            {
                arguments.SetReturnValue(application.Root);
            }
        }
Ejemplo n.º 30
0
        private static void Alert(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string       text    = ValueAuxiliary.ToString(arguments.Length > 0 ? arguments[0] : null) ?? string.Empty;
            string       caption = ValueAuxiliary.ToString(arguments.Length > 1 ? arguments[1] : null) ?? string.Empty;
            int          buttons = ValueAuxiliary.ToInt32(arguments.Length > 2 ? arguments[2] : null);
            int          icon    = ValueAuxiliary.ToInt32(arguments.Length > 3 ? arguments[3] : null);
            DialogResult result  = MessageBox.Show(text, caption, (MessageBoxButtons)buttons, (MessageBoxIcon)icon);

            arguments.SetReturnValue(unchecked ((int)result));
        }