Пример #1
0
        /// <summary>
        ///   Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// 
        /// <param name="format">The format.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// 
        /// <returns>
        ///   A <see cref="System.String"/> that represents this instance.
        /// </returns>
        /// 
        public string ToString(string format, IFormatProvider formatProvider)
        {
            formatter f = new formatter();
            f.format = format;
            f.provider = formatProvider;

            return String.Format("{0}x {1}y {2}z {3} = 0",
                f.s(A), f.s(B), f.s(C), f.s(Offset));
        }
Пример #2
0
        public void formatter_testDefaultConstructor()
        {
            string testMessage = "testLogger {0}, {1}";

            string[]  argsArray = new string[] { "test_args1", "test_args2" };
            formatter b         = new formatter();
            logRecord l         = new logRecord("formatter Test", loggerLevels.CRITICAL, testMessage, argsArray, "");

            Console.WriteLine(b.format(l));
            Assert.AreEqual(String.Format(testMessage, argsArray), b.format(l));
        }
Пример #3
0
        public string format(logRecord record)
        {
            formatter fmt = null;

            if (this.formatter != null)
            {
                fmt = this.formatter;
            }
            else
            {
                fmt = _defaultFormatter;
            }

            return(fmt.format(record));
        }
Пример #4
0
        public void formatter_properlyAddsLoggerName()
        {
            string testMessage = "testLogger {0}, {1}";

            string[]     argsArray  = new string[] { "test_args1", "test_args2" };
            loggerLevels testLevel  = loggerLevels.CRITICAL;
            string       loggerName = "formatter Test";

            formatter b = new formatter("{levelName}:{name}:{message}");
            logRecord l = new logRecord(loggerName, testLevel, testMessage, argsArray, "");

            string resultMessage = String.Format("{0}:{1}:{2}", testLevel, loggerName, String.Format(testMessage, argsArray));

            Console.WriteLine(b.format(l));
            Assert.AreEqual(resultMessage, b.format(l));
        }
Пример #5
0
        private bool needs_apply_formatter(formatter format, column_formatter_base.format_cell cell)
        {
            if (format.column_type == "all")
            {
                return(true);
            }

            var aliases   = cell.parent.filter.log.aliases;
            var cell_type = aliases.to_info_type(format.column_type);

            if (cell_type != info_type.max)
            {
                return(cell.col_type == cell_type);
            }

            // in this case, we don't know what column the formater is to be applied to
            return(false);
        }
Пример #6
0
        private void create_last_formatter(List <formatter> formatters, ref formatter last, ref string errors)
        {
            string error = "";

            last.the_formatter = create_formatter(last.name, last.syntax, ref error);
            if (error != "")
            {
                errors += error + "\r\n";
            }
            if (last.the_formatter != null)
            {
                formatters.Add(last);
            }
            var new_last = new formatter {
                column_type = last.column_type
            };

            last = new_last;
        }
Пример #7
0
        /// <summary>
        ///   Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// 
        /// <param name="variable">The variable to put on the left hand side. Can
        ///   be either 'x', 'y' or 'z'.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// 
        /// <returns>
        ///   A <see cref="System.String"/> that represents this instance.
        /// </returns>
        /// 
        public string ToString(char variable, IFormatProvider formatProvider)
        {
            formatter f = new formatter();
            f.provider = formatProvider;

            switch (variable)
            {
                case 'x': return String.Format("x = {0}y {1}z {2}",
                        f.s(-B / A), f.s(-C / A), f.s(-Offset / A));

                case 'y': return String.Format("y = {0}x {1}z {2}",
                        f.s(-A / B), f.s(-C / B), f.s(-Offset / B));

                case 'z': return String.Format("z = {0}x {1}y {2}",
                        f.s(-A / C), f.s(-B / C), f.s(-Offset / C));

                default:
                    throw new FormatException();
            }
        }
Пример #8
0
        public void load(string syntax, ref string errors) {
            syntax_ = syntax;
            errors = "";
            var formatters = new List<formatter>();
            var last = new formatter();
            foreach (string line in syntax.Split(new[] {"\r\n"}, StringSplitOptions.None).Select(x => x.Trim())) {
                if (line.StartsWith("[")) {
                    // a new section
                    if (last.ok) 
                        create_last_formatter(formatters, ref last, ref errors);

                    if (line.EndsWith("]"))
                        last.column_type = line.Substring(1, line.Length - 2).Trim();
                    else
                        errors += "Invalid line: " + line + "\r\n";
                }
                else if (line.StartsWith("#"))
                    // comment
                    continue;
                else if (line != "") {
                    if (last.name == "")
                        // first line = the name of the formatter
                        last.name = line;
                    // has to be syntax like : a=b
                    else if (line.IndexOf("=") > 0)
                        last.syntax += line + "\r\n";
                    else
                        errors += "Invalid line: " + line + "\r\n";
                } else {
                    // empty line - end of a formatter
                    if (last.ok) 
                        create_last_formatter(formatters, ref last, ref errors);
                }
            }

            if ( last.ok)
                create_last_formatter(formatters, ref last, ref errors);

            formatters_ = formatters;
        }
Пример #9
0
        public void TestMethod1()
        {
            logger l = new logger("testingLogger.main");

            l.setLevel(loggerLevels.DEBUG);

            logger l2 = new logger("testingLogger.main2");

            l2.setLevel(loggerLevels.INFO);

            consoleHandler h = new consoleHandler();

            h.setLevel(loggerLevels.DEBUG);

            consoleHandler h2 = new consoleHandler();

            formatter f = new formatter("{levelName}:{name}:{message}");

            h.setFormatter(f);


            l.addHandler(h);

            l2.addHandler(h);
            l2.addHandler(h2);

            string testMessage = "testing this in a new Context {0}";

            string[] argsArray = new string[] { "testArgs1", "testArgs2" };

            l.debug(testMessage, argsArray);

            l.critical(testMessage, argsArray);

            l2.debug(testMessage, argsArray);

            l2.critical(testMessage, argsArray);

            Console.WriteLine("complete");
        }
Пример #10
0
        public void load(string syntax, ref string errors)
        {
            syntax_ = syntax;
            errors  = "";
            var formatters = new List <formatter>();
            var last       = new formatter();

            foreach (string line in syntax.Split(new[] { "\r\n" }, StringSplitOptions.None).Select(x => x.Trim()))
            {
                if (line.StartsWith("["))
                {
                    // a new section
                    if (last.ok)
                    {
                        create_last_formatter(formatters, ref last, ref errors);
                    }

                    if (line.EndsWith("]"))
                    {
                        last.column_type = line.Substring(1, line.Length - 2).Trim();
                    }
                    else
                    {
                        errors += "Invalid line: " + line + "\r\n";
                    }
                }
                else if (line.StartsWith("#"))
                {
                    // comment
                    continue;
                }
                else if (line != "")
                {
                    if (last.name == "")
                    {
                        // first line = the name of the formatter
                        last.name = line;
                    }
                    // has to be syntax like : a=b
                    else if (line.IndexOf("=") > 0)
                    {
                        last.syntax += line + "\r\n";
                    }
                    else
                    {
                        errors += "Invalid line: " + line + "\r\n";
                    }
                }
                else
                {
                    // empty line - end of a formatter
                    if (last.ok)
                    {
                        create_last_formatter(formatters, ref last, ref errors);
                    }
                }
            }

            if (last.ok)
            {
                create_last_formatter(formatters, ref last, ref errors);
            }

            formatters_ = formatters;
        }
Пример #11
0
 public void setFormatter(formatter formatter_in)
 {
     formatter = formatter_in;
 }
Пример #12
0
        private bool needs_apply_formatter(formatter format, column_formatter_base.format_cell cell) {
            if (format.column_type == "all")
                return true;

            var aliases = cell.parent.filter.log.aliases;
            var cell_type = aliases.to_info_type(format.column_type);
            if (cell_type != info_type.max)
                return cell.col_type == cell_type;

            // in this case, we don't know what column the formater is to be applied to
            return false;
        }
Пример #13
0
 private void create_last_formatter(List<formatter> formatters, ref formatter last, ref string errors) {
     string error = "";
     last.the_formatter = create_formatter(last.name, last.syntax, ref error);
     if (error != "")
         errors += error + "\r\n";
     if ( last.the_formatter != null)
         formatters.Add(last);
     var new_last = new formatter { column_type = last.column_type };
     last = new_last;
 }
Пример #14
0
 protected void Page_Load(object sender, EventArgs e)
 {
     theForm = new formatter("USD");
 }