Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
     });
 }
Exemplo n.º 4
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));
                }
            }
        }
Exemplo n.º 5
0
        private static void New(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            NSJSValue result = null;
            string    Key    = null;

            if (arguments.Length > 0)
            {
                Key = (arguments[0] as NSJSString)?.Value;
                if (!string.IsNullOrEmpty(Key))
                {
                    byte[] SBox        = arguments.Length > 1 ? (arguments[1] as NSJSUInt8Array)?.Buffer : null;
                    int    MaxbitWidth = RC4CSP.DefaultMaxbitWidth;
                    if (arguments.Length > 2)
                    {
                        MaxbitWidth = ((arguments[2] as NSJSInt32)?.Value).GetValueOrDefault();
                    }
                    if (MaxbitWidth < 0)
                    {
                        MaxbitWidth = 0;
                    }
                    if (SBox == null)
                    {
                        SBox = RC4CSP.SBox(Key, MaxbitWidth);
                    }
                    result = New(arguments.VirtualMachine, new RC4CSP(Key, SBox));
                }
            }
            if (result != null)
            {
                arguments.SetReturnValue(result);
            }
            else if (Key != null)
            {
                Throwable.ArgumentException(arguments.VirtualMachine);
            }
            else
            {
                Throwable.ArgumentNullException(arguments.VirtualMachine);
            }
        }