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); } } } }
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); } } }
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); } } }
private static void InternalExecute(NSJSFunctionCallbackInfo arguments, Action <DATATableGateway, DatabaseAccessAdapter, string> executing) { if (executing == null) { throw new ArgumentNullException("executing"); } DATATableGateway gateway = GetGateway(arguments.This); if (gateway == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else if (arguments.Length <= 0) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { string text = arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null; if (text == null) { Throwable.ArgumentNullException(arguments.VirtualMachine); } else { executing(gateway, gateway.DatabaseAccessAdapter, text); } } }
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); } }
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); } } }
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); } } }
public static void New(NSJSFunctionCallbackInfo arguments) { DatabaseAccessAdapter adapter = GetAdapter(arguments.Length > 0 ? arguments[0] as NSJSObject : null); if (adapter == null) { Throwable.ArgumentNullException(arguments.VirtualMachine); } else { arguments.SetReturnValue(New(arguments.VirtualMachine, new DATATableGateway(adapter))); } }
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); }); }
private static void CallSetFileInfo(IntPtr info, Action <NSJSFunctionCallbackInfo, string, DateTime> callback) { if (callback == null) { throw new ArgumentNullException("callback"); } CallGetFileInfo(info, (arguments, path) => { NSJSDateTime datetime = arguments.Length > 0 ? arguments[0] as NSJSDateTime : null; if (datetime == null) { Throwable.ArgumentNullException(arguments.VirtualMachine); } else { callback(arguments, path, datetime.Value); } }); }
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)); } } }
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); } }
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); } }