Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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();
                }
            });
        }
Ejemplo n.º 3
0
        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);
        }