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); } } }
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); }
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); } }
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)); }
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 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); } } }
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])); }
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))); }
private static void GetEncodings(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); var encodings = ENCODING.GetEncodings(); arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, encodings)); }
private static void Dispose(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); RC4CSP provider; NSJSKeyValueCollection.Release(arguments.This, out provider); }
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 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)); } }
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); } }
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 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 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); } }
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 clear(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); NSJSConsoleHandler handler = GetConsoleHandler(arguments); handler.Clear(arguments); }
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); } } } }
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); } }
public static void Call <TThis>(IntPtr info, Func <TThis, NSJSFunctionCallbackInfo, NSJSValue, NSJSValue> doo) { if (doo == null) { throw new ArgumentNullException("doo"); } NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); TThis self = NSJSKeyValueCollection.Get <TThis>(arguments.This); if (self == null) { Throwable.ObjectDisposedException(arguments.VirtualMachine); } else { try { NSJSValue solt0 = arguments.Length > 0 ? arguments[0] : null; doo(self, arguments, solt0); } catch (Exception exception) { Throwable.Exception(arguments.VirtualMachine, exception); } } }
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); } } }
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); } }
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); } }
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); } }
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)); }
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 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)); }
protected internal static NSJSValue ToObject(NSJSFunctionCallbackInfo arguemnts, object obj) { if (arguemnts == null) { throw new ArgumentNullException("arguemnts"); } return(ToObject(arguemnts.VirtualMachine, obj)); }
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)); }