예제 #1
0
 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));
     });
 }
예제 #2
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));
        }
예제 #3
0
        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);
            }
        }
예제 #4
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);
        }