private static void AddHeader(IntPtr info) { ObjectAuxiliary.Call(info, (HTTPResponse response, NSJSFunctionCallbackInfo arguments, NSJSValue solt0) => { string value = ValueAuxiliary.ToString(arguments.Length > 1 ? arguments[1] : null); string name = ValueAuxiliary.ToString(solt0); arguments.SetReturnValue(response.AppendHeader(name, value)); }); }
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)); }
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); } }
private static void assert(IntPtr info) { NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info); if (arguments.Length > 0) { bool condition = ValueAuxiliary.ToBoolean(arguments[0]); string message = ValueAuxiliary.ToString(arguments.Length > 1 ? arguments[1] : null) ?? string.Empty; string detailMessage = ValueAuxiliary.ToString(arguments.Length > 1 ? arguments[1] : null) ?? string.Empty; NSJSConsoleHandler handler = GetConsoleHandler(arguments); handler.Assert(arguments, condition, message, detailMessage); } }
protected internal static NSJSValue ConvertValue(NSJSVirtualMachine machine, object obj) { if (machine == null) { return(default(NSJSValue)); } if (obj == null || obj == DBNull.Value) { return(NSJSValue.Null(machine)); } if (obj is NSJSValue) { return(unchecked ((NSJSValue)obj)); } NSJSValue value = ValueAuxiliary.As(obj, machine); if (value != null && !value.IsNullOrUndfined) { return(value); } return(SimpleAgent.ToObject(machine, obj)); }
private static void InternalExecute(NSJSFunctionCallbackInfo arguments, bool nonquery) { InternalExecute(arguments, (gateway, adapter, text) => { DataTable dataTable = null; IDbCommand command = null; try { IDbTransaction transaction = null; NSJSArray parameters = null; NSJSInt32 cmdtype = null; for (int solt = 1, count = arguments.Length; solt < count && (transaction == null || cmdtype == null || parameters == null); solt++) { NSJSValue current = arguments[solt]; if (transaction == null) { transaction = DatabaseTransaction.GetTransaction(current as NSJSObject); } if (cmdtype == null) { cmdtype = current as NSJSInt32; } if (parameters == null) { parameters = current as NSJSArray; } } command = ObjectAuxiliary.ToDbCommand(adapter, text, parameters); int commandType = ValueAuxiliary.ToInt32(cmdtype); switch (commandType) { case 1: command.CommandType = CommandType.StoredProcedure; break; case 2: command.CommandType = CommandType.TableDirect; break; default: command.CommandType = CommandType.Text; break; } command.Transaction = transaction; if (nonquery) { arguments.SetReturnValue(gateway.ExecuteNonQuery(command)); } else { dataTable = gateway.Select(command); arguments.SetReturnValue(ArrayAuxiliary.ToArray(arguments.VirtualMachine, dataTable)); } } catch (Exception e) { Throwable.Exception(arguments.VirtualMachine, e); } if (dataTable != null) { dataTable.Dispose(); } if (command != null) { command.Dispose(); } }); }
private static string sprint(NSJSFunctionCallbackInfo arguments, bool newline) { if (arguments == null) { throw new ArgumentNullException("arguments"); } string contents = null; if (arguments.Length <= 0) { return(contents); } try { string format = arguments.Length > 0 ? ValueAuxiliary.ToString(arguments[0]) : null; if (format == null) { format = newline ? Environment.NewLine : string.Empty; } else if (newline) { format += Environment.NewLine; } int index = -1; int previous = 0; int solt = 1; do { index = format.IndexOf('%', index + 1); if (index > -1) { int ofs = index + 1; for (int i = ofs; i < format.Length; i++) { char character = format[i]; char flags = '\0'; char pending = '\0'; int width = 0; if (character == 'c') { if (solt >= arguments.Length) { break; } int count = (index - previous); count = count < 0 ? 0 : count; string g = format.Substring(previous, count); if (!string.IsNullOrEmpty(g)) { contents += g; } previous = i + 1; contents += unchecked ((char)ValueAuxiliary.ToInt64(arguments[solt++])); index = i; break; } else if (character == '%') { int count = (i - previous); count = count < 0 ? 0 : count; string g = format.Substring(previous, count); if (!string.IsNullOrEmpty(g)) { contents += g; } previous = i + 1; index = i; break; } else if (character == 's') { if (solt >= arguments.Length) { break; } int count = (index - previous); count = count < 0 ? 0 : count; string g = format.Substring(previous, count); if (!string.IsNullOrEmpty(g)) { contents += g; } previous = i + 1; contents += ValueAuxiliary.ToString(arguments[solt++]); index = i; break; } else if (character == 'i' || character == 'd' || character == 'u') { if (sprint_get_format_features(format, ofs, i, ref flags, ref pending, ref width)) { if (solt >= arguments.Length) { break; } int count = (index - previous); count = count < 0 ? 0 : count; string g = format.Substring(previous, count); if (!string.IsNullOrEmpty(g)) { contents += g; } previous = i + 1; string s = NSJSString.Cast(arguments[solt++]).Value; if (flags == '+') { s = s.PadLeft(width, pending); } else { s = s.PadRight(width, pending); } contents += s; index = i; } break; } else if (character == 'b') { if (solt >= arguments.Length) { break; } int count = (index - previous); count = count < 0 ? 0 : count; string g = format.Substring(previous, count); if (!string.IsNullOrEmpty(g)) { contents += g; } previous = i + 1; contents += "0b" + Convert.ToString(ValueAuxiliary.ToInt64(arguments[solt++]), 2); index = i; break; } else if (character == 'o' || character == 'x' || character == 'X') { if (sprint_get_format_features(format, ofs, i, ref flags, ref pending, ref width)) { if (solt >= arguments.Length) { break; } int count = (index - previous); count = count < 0 ? 0 : count; string g = format.Substring(previous, count); if (!string.IsNullOrEmpty(g)) { contents += g; } previous = i + 1; int radix = character == 'o' ? 0x08 : 0x10; string s = Convert.ToString(ValueAuxiliary.ToInt64(arguments[solt++]), radix); if (flags == '+') { s = s.PadLeft(width, pending); } else { s = s.PadRight(width, pending); } if (radix == 0x10) { s = "0x" + (character == 'X' ? s.ToUpper() : s); } contents += s; index = i; } break; } else if (character == 'p' || character == 'P') { if (sprint_get_format_features(format, ofs, i, ref flags, ref pending, ref width)) { if (solt >= arguments.Length) { break; } int count = (index - previous); count = count < 0 ? 0 : count; string g = format.Substring(previous, count); if (!string.IsNullOrEmpty(g)) { contents += g; } previous = i + 1; long ptr = Environment.Is64BitProcess ? ValueAuxiliary.ToInt64(arguments[solt++]) : ValueAuxiliary.ToInt32(arguments[solt++]); string s = ptr.ToString(character == 'p' ? "x2" : "X2"); if (flags == '+') { s = s.PadLeft(width, pending); } else { s = s.PadRight(width, pending); } s = "0x" + s; contents += s; index = i; } break; } else if (character == 'f' || character == 'l' || character == 'e' || character == 'g' || character == 'E' || character == 'G') // lf { int mode = 0; // 0: 单精度浮点数,1:双精度浮点数,2:科学型浮点数数,3:常规型浮点数 int n = i + 1; if (n < format.Length && format[n] == 'f') // lf { mode = 1; i++; } else if (character == 'e' || character == 'E') { mode = 2; } else if (character == 'g' || character == 'G') { mode = 3; } if (sprint_get_format_features(format, ofs, i, ref flags, ref pending, ref width)) { if (solt >= arguments.Length) { break; } int count = (index - previous); count = count < 0 ? 0 : count; string g = format.Substring(previous, count); if (!string.IsNullOrEmpty(g)) { contents += g; } previous = i + 1; double num = ValueAuxiliary.ToDouble(arguments[solt++]); string s = mode == 2 || mode == 3 ? num.ToString(character.ToString()) : num.ToString(); if (flags == '+') { s = s.PadLeft(width, pending); } else { s = s.PadRight(width, pending); } contents += s; index = i; } break; } } } } while (index >= 0); if (format.Length > previous) { string s = format.Substring(previous); if (!string.IsNullOrEmpty(s)) { contents += s; } } } catch (Exception) { contents = null; } return(contents); }