Example #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);
                    }
                }
            }
        }
Example #2
0
        private static void CopyTo(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            BaseStream stream = NSJSKeyValueCollection.Get <BaseStream>(arguments.This);

            if (stream == null)
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                BaseStream destination = NSJSKeyValueCollection.Get <BaseStream>(arguments.Length > 0 ? arguments[0] as NSJSObject : null);
                if (destination == null)
                {
                    Throwable.ArgumentNullException(arguments.VirtualMachine);
                }
                else
                {
                    try
                    {
                        stream.CopyTo(destination);
                    }
                    catch (Exception e)
                    {
                        Throwable.Exception(arguments.VirtualMachine, e);
                    }
                }
            }
        }
Example #3
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);
                }
            }
        }
Example #4
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);
            }
        }
Example #5
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);
                }
            }
        }
Example #6
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);
            }
        }
Example #7
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);
            }
        }
Example #8
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);
            }
        }
Example #9
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);
            }
        }
Example #10
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);
            }
        }
Example #11
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);
                }
            }
        }
Example #12
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);
                }
            }
        }
Example #13
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);
                }
            }
        }
Example #14
0
        private static void MoveOrCopy(IntPtr info, bool copyMode)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            bool      success   = false;
            Exception exception = null;

            do
            {
                if (arguments.Length <= 0)
                {
                    break;
                }
                NSJSString sourceFileName = arguments[0] as NSJSString;
                NSJSString destFileName   = arguments[1] as NSJSString;
                if (sourceFileName == null || destFileName == null)
                {
                    break;
                }
                try
                {
                    if (copyMode)
                    {
                        if (arguments.Length < 3)
                        {
                            FILE.Copy(sourceFileName.Value, destFileName.Value);
                        }
                        else
                        {
                            bool overwrite = ValueAuxiliary.ToBoolean(arguments[2]);
                            FILE.Copy(sourceFileName.Value, destFileName.Value, overwrite);
                        }
                    }
                    else
                    {
                        FILE.Move(sourceFileName.Value, destFileName.Value);
                    }
                    success = true;
                }
                catch (Exception e)
                {
                    exception = e;
                    success   = false;
                }
            } while (false);
            if (exception == null)
            {
                arguments.SetReturnValue(success);
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }
Example #15
0
        private static void GetHostName(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);

            try
            {
                arguments.SetReturnValue(DNS.GetHostName());
            }
            catch (Exception e)
            {
                Throwable.Exception(arguments.VirtualMachine, e);
            }
        }
Example #16
0
        private static void AcceptAsync(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            bool success = false;

            do
            {
                SocketContext context = GetSocketContext(arguments.This);
                if (context == null)
                {
                    Throwable.ObjectDisposedException(arguments.VirtualMachine);
                    break;
                }
                SOCKET socket = context.Socket;
                if (socket == null || SocketExtension.CleanedUp(socket))
                {
                    Throwable.ObjectDisposedException(arguments.VirtualMachine);
                    break;
                }
                NSJSFunction callback = arguments.Length > 0 ? arguments[0] as NSJSFunction : null;
                try
                {
                    SocketAsyncEventArgs e = context.AcceptAsync;
                    if (e != null)
                    {
                        break;
                    }
                    e                   = new SocketAsyncEventArgs();
                    e.Completed        += ProcessAccept;
                    e.UserToken         = context;
                    context.AcceptAsync = e;
                    if (callback != null)
                    {
                        NSJSObject socketobject = arguments.This;
                        callback.CrossThreading     = true;
                        context.AcceptAsyncCallback = callback;
                    }
                    if (!socket.AcceptAsync(e))
                    {
                        ProcessAccept(socket, e);
                    }
                    success = true;
                }
                catch (Exception e)
                {
                    Throwable.Exception(arguments.VirtualMachine, e);
                }
            } while (false);
            arguments.SetReturnValue(success);
        }
Example #17
0
 private static void Start(IntPtr info)
 {
     ObjectAuxiliary.Call <WebSocketListener>(info, (server, arguments) =>
     {
         try
         {
             server.Start();
         }
         catch (Exception exception)
         {
             Throwable.Exception(arguments.VirtualMachine, exception);
         }
     });
 }
Example #18
0
 private static void Open(IntPtr info)
 {
     ObjectAuxiliary.Call <WebSocket>(info, (websocket, arguments) =>
     {
         try
         {
             websocket.Open();
         }
         catch (Exception exception)
         {
             Throwable.Exception(arguments.VirtualMachine, exception);
         }
     });
 }
Example #19
0
 public static void DeriveParameters(NSJSFunctionCallbackInfo arguments)
 {
     InternalExecute(arguments, (gateway, adapter, procedure) =>
     {
         try
         {
             IDbDataParameter[] parameters = adapter.GetParameters(procedure);
             arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, parameters));
         }
         catch (Exception e)
         {
             Throwable.Exception(arguments.VirtualMachine, e);
         }
     });
 }
Example #20
0
 public static void New(NSJSFunctionCallbackInfo arguments)
 {
     try
     {
         string server   = (arguments.Length > 0 ? arguments[0] as NSJSString : null)?.Value;
         string database = (arguments.Length > 1 ? arguments[1] as NSJSString : null)?.Value;
         string loginId  = (arguments.Length > 2 ? arguments[2] as NSJSString : null)?.Value;
         string password = (arguments.Length > 3 ? arguments[3] as NSJSString : null)?.Value;
         arguments.SetReturnValue(New(arguments.VirtualMachine, new MSSQLDatabaseAccessAdapter(arguments.VirtualMachine,
                                                                                               server, database, loginId, password)));
     }
     catch (Exception exception)
     {
         Throwable.Exception(arguments.VirtualMachine, exception);
     }
 }
Example #21
0
 private static void InternalSend(IntPtr info, bool synchronization)
 {
     ObjectAuxiliary.Call <MailClient>(info, (smtp, arguments) =>
     {
         do
         {
             NSJSVirtualMachine machine = arguments.VirtualMachine;
             if (arguments.Length <= 0)
             {
                 Throwable.ArgumentException(machine);
                 break;
             }
             MailMessage message = null;
             try
             {
                 message = ObjectAuxiliary.ToMailMessage(arguments[0]);
             }
             catch (Exception exception)
             {
                 Throwable.Exception(machine, exception);
                 break;
             }
             if (message == null)
             {
                 Throwable.ArgumentNullException(machine);
                 break;
             }
             if (synchronization)
             {
                 arguments.SetReturnValue(smtp.Send(message));
             }
             else
             {
                 NSJSFunction function        = arguments.Length > 1 ? arguments[1] as NSJSFunction : null;
                 Action <Exception> callbackt = null;
                 if (function != null)
                 {
                     callbackt = (exception) => machine.Join((sender, state) =>
                                                             function.Call(new[] { Throwable.FormatMessage(exception) }));
                     function.CrossThreading = true;
                 }
                 arguments.SetReturnValue(smtp.SendAsync(message, callbackt));
             }
         } while (false);
     });
 }
Example #22
0
            public static void Close(IntPtr info)
            {
                NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
                IDbTransaction           transaction;

                NSJSKeyValueCollection.Release(arguments.This, out transaction);
                if (transaction != null)
                {
                    try
                    {
                        transaction.Dispose();
                    }
                    catch (Exception exception)
                    {
                        Throwable.Exception(arguments.VirtualMachine, exception);
                    }
                }
            }
Example #23
0
        private static void Seek(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;
                int       offset    = 0;
                int?      result    = null;
                if (stream != null)
                {
                    SeekOrigin origin = SeekOrigin.Begin;
                    if (arguments.Length > 0)
                    {
                        offset = ((arguments[0] as NSJSInt32)?.Value).GetValueOrDefault();
                    }
                    if (arguments.Length > 1)
                    {
                        origin = (SeekOrigin)((arguments[1] as NSJSInt32)?.Value).GetValueOrDefault();
                    }
                    try
                    {
                        result = unchecked ((int)stream.Seek(offset, origin));
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                }
                if (exception != null)
                {
                    Throwable.Exception(arguments.VirtualMachine, exception);
                }
                else
                {
                    arguments.SetReturnValue(result.GetValueOrDefault());
                }
            }
        }
Example #24
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));
                }
            }
        }
Example #25
0
 private static void RollbackOrCommit(IntPtr info, bool commiting)
 {
     ObjectAuxiliary.Call <IDbTransaction>(info, (transaction, arguments) =>
     {
         try
         {
             if (commiting)
             {
                 transaction.Commit();
             }
             else
             {
                 transaction.Rollback();
             }
         }
         catch (Exception exception)
         {
             Throwable.Exception(arguments.VirtualMachine, exception);
         }
     });
 }
Example #26
0
        private static void Accept(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            SOCKET socket = GetSocket(arguments.This);

            if (socket == null || SocketExtension.CleanedUp(socket))
            {
                Throwable.ObjectDisposedException(arguments.VirtualMachine);
            }
            else
            {
                try
                {
                    arguments.SetReturnValue(New(arguments.VirtualMachine, socket.Accept()));
                }
                catch (Exception e)
                {
                    Throwable.Exception(arguments.VirtualMachine, e);
                }
            }
        }
Example #27
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);
            }
        }
Example #28
0
        private void New(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSValue result    = null;
            Exception exception = null;

            if (arguments.Length > 1)
            {
                byte[] key = (arguments[0] as NSJSUInt8Array)?.Buffer;
                byte[] IV  = (arguments[1] as NSJSUInt8Array)?.Buffer;
                if (key != null && IV != null)
                {
                    try
                    {
                        RijndaelCryptoServiceProvider provider = New(key, IV, arguments);
                        if (provider != null)
                        {
                            result = New(arguments.VirtualMachine, provider);
                        }
                    }
                    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);
            }
        }
Example #29
0
        private void DecompressOrCompress(IntPtr info, bool decompress)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);

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

            if (arguments.Length > 0)
            {
                byte[] buffer = (arguments[0] as NSJSUInt8Array)?.Buffer;
                if (buffer != null)
                {
                    try
                    {
                        if (decompress)
                        {
                            result = LZ77Auxiliary.Decompress(buffer, algorithm);
                        }
                        else
                        {
                            result = LZ77Auxiliary.Compress(buffer, algorithm);
                        }
                    }
                    catch (Exception e)
                    {
                        exception = e;
                    }
                }
            }
            if (exception == null)
            {
                arguments.SetReturnValue(result);
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }
Example #30
0
        private static void Move(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            bool      success   = false;
            Exception exception = null;

            do
            {
                if (arguments.Length <= 0)
                {
                    break;
                }
                NSJSString sourceFileName = arguments[0] as NSJSString;
                NSJSString destFileName   = arguments[1] as NSJSString;
                if (sourceFileName == null || destFileName == null)
                {
                    break;
                }
                try
                {
                    DIRECTORY.Move(sourceFileName.Value, destFileName.Value);
                    success = true;
                }
                catch (Exception e)
                {
                    exception = e;
                    success   = false;
                }
            } while (false);
            if (exception == null)
            {
                arguments.SetReturnValue(success);
            }
            else
            {
                Throwable.Exception(arguments.VirtualMachine, exception);
            }
        }